メモに残しておきます。
追加していくのでたまに役に立つかもしれません。
気になる部分は目次からジャンプしてください_(._.)_
bashのプロンプトを変更する
ターミナルのパスが長すぎたりすると改行したり見づらかったりしますよね。
今回は以下のように時刻と改行を入れた設定に変えるようにします。
1 | vi ~/.bashrc |
一番最後の行に下記を追加します。
1 | PS1='\ek\e\\\][\e[32m\u@\h \e[35m\t \e[34m\w\e[0m]\n\$ ' |
「:wq」と打てば保存してvimから抜けることができます。
OpenFOAMグループ
こちらに質問と回答が蓄積されているので同じ悩みの方に出会えるかもしれません。
ただ良い回答を得るためには良い質問の仕方があります。
snappyHexMeshでメッシュが思った通りに生成されていないとき
- 「locationInMesh (2.1 0.09 -1.1);」の座標がおかしい
- メッシュサイズが大きくて形状変化の解像度をとらえられていない
だいたいどちらか。
並列計算しているなら結合しないとParaViewでは見れない。
並列分割してフォルダ内にprocessorがあるなら、ParaviewのCase TypeをDecomposed Caseに変えると並列分割した状態でも読み込めます。
流量を知りたい
①に残差の例もあります。
実験データと比較したい
だいたいここを見ます。
境界条件を楽にする
共通の設定の場合
1 2 3 4 5 | "(inlet|outlet)" { type fixedValue; value uniform (0 0 0); } |
デフォルト(全て壁条件)
1 2 3 4 | ".*" { type noSlip; } |
設定の使いまわし
1 2 3 4 5 6 7 8 9 10 | inlet1 { type fixedValue; value uniform (1 0 0); } inlet2 { $inlet1; } |
並列計算
1 2 3 | decomposePar reconstructParMesh -constant -mergeTol 1e-6 mpirun -np 4 renumberMesh -overwrite -parallel |
特定のフォルダの容量調べる
1 2 3 4 | du -sh /mnt/d/OpenFOAM/ #出力結果 50G /mnt/d/OpenFOAM/ |
境界条件の候補を調べる
1 | foamHelp boundary -field U |
以下が出力される。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 | Create mesh for time = 0 Available boundary conditions for vector field: U SRFFreestreamVelocity SRFVelocity SRFWallVelocity acousticWaveTransmissive activeBaffleVelocity activePressureForceBaffleVelocity advective calculated codedFixedValue codedMixed cyclic cyclicACMI cyclicAMI cyclicSlip cylindricalInletVelocity directionMixed empty exprFixedValue exprMixed extrapolatedCalculated fixedGradient fixedInternalValue fixedJump fixedJumpAMI fixedMean fixedMeanOutletInlet fixedNormalInletOutletVelocity fixedNormalSlip fixedProfile fixedShearStress fixedValue flowRateInletVelocity flowRateOutletVelocity fluxCorrectedVelocity freestream freestreamVelocity inletOutlet interstitialInletVelocity kqRWallFunction mapped mappedField mappedFixedInternalValue mappedFixedPushedInternalValue mappedFlowRate mappedMixed mappedMixedField mappedVelocityFlux matchedFlowRateOutletVelocity mixed movingWallVelocity noSlip nonuniformTransformCyclic outletInlet outletMappedUniformInlet outletPhaseMeanVelocity partialSlip pressureDirectedInletOutletVelocity pressureDirectedInletVelocity pressureInletOutletParSlipVelocity pressureInletOutletVelocity pressureInletUniformVelocity pressureInletVelocity pressureNormalInletOutletVelocity pressurePIDControlInletVelocity processor processorCyclic rotatingPressureInletOutletVelocity rotatingWallVelocity scaledFixedValue sliced slip supersonicFreestream surfaceNormalFixedValue swirlFanVelocity swirlFlowRateInletVelocity swirlInletVelocity symmetry symmetryPlane timeVaryingMappedFixedValue translatingWallVelocity turbulentDFSEMInlet turbulentDigitalFilterInlet turbulentInlet uniformFixedGradient uniformFixedValue uniformInletOutlet uniformJump uniformJumpAMI uniformNormalFixedValue variableHeightFlowRateInletVelocity waveTransmissive wedge zeroGradient End |
ソースコードを探す
全ての$FOAM_APPを出力しておいて、laplacianFoam.Cの検索に引っかかったものだけを抽出
1 | find $FOAM_APP |grep "laplacianFoam.C" |
$FOAM_APPの中で拡張子.Cだけを出力しておいて、laplacianFoam検索に引っかかったものだけを抽出
1 | find $FOAM_APP -name *.C | grep "laplacianFoam" |
検索したい文字列のファイルを探す
1 2 | # find ファイルパス -type f | xargs grep -n '検索したい文字列' find $FOAM_TUTORIALS -type f| xargs grep -ln "noSlip" |
- l:ファイル名のみ出力
- n:行番号を出力
メッシュ品質の基準を検索
ファイルのありかを調べる。
1 | find $FOAM_SRC -name "primitiveMeshCheck" |
以下にあることがわかる。
1 | /opt/OpenFOAM/OpenFOAM-v2012/src/OpenFOAM/meshes/primitiveMesh/primitiveMeshCheck |
viコマンドで中身を確認。
1 | vi /opt/OpenFOAM/OpenFOAM-v2012/src/OpenFOAM/meshes/primitiveMesh/primitiveMeshCheck/primitiveMeshCheck.C |
品質基準は以下を参照。
1 2 3 4 5 | Foam::scalar Foam::primitiveMesh::closedThreshold_ = 1.0e-6; Foam::scalar Foam::primitiveMesh::aspectThreshold_ = 1000; Foam::scalar Foam::primitiveMesh::nonOrthThreshold_ = 70; // deg Foam::scalar Foam::primitiveMesh::skewThreshold_ = 4; Foam::scalar Foam::primitiveMesh::planarCosAngle_ = 1.0e-6; |
メッシュ品質の悪い部分を確認
1 2 | foamToVTK -faceSet skewFaces -time 0 foamToVTK -faceSet nonOrthoFaces -time 0 |
ls constant/polyMesh/setsで品質の悪い項目のファイルを確認。
constant/polyMesh/sets/ファイル名
ファイル名 = skewFaces
paraviewでvtkを読み込む
- 高アスペクト比(Aspect Ratio)
非常に微細な境界層で現れる。
ソルバーの安定性にとって致命的なものではありませんが、収束速度を著しく低下させる可能性があり - 非直交性(Orthogonality)
3つの値の範囲を定義する
・n0 < 70 – 安全な値
70 < n0 < 90 – fvSolutionのnonOrthoCorrectorやfvSchemesの数値スキームに対して特別な処理を行う必要あり
・n0 > 90 – シミュレーションに使用できない悪いメッシュ - 歪度(skewness)
値が大きいと結果の品質(正確さ)が損なわれる可能性がありますが、適度な大きさの歪度パラメータ(20)であれば、シミュレーションに使用することができる - Smoothness.
viコマンド
例えばメッシュ品質基準を調べたい場合。
1 | vi /opt/OpenFOAM/OpenFOAM-v2012/src/OpenFOAM/meshes/primitiveMesh/primitiveMeshCheck/primitiveMeshCheck.C |
#行数を表示
:set number
/primitiveMesh
n:下へ検索
N(Shift + n):上へ検索
- :q (上書きせずに閉じる)
- :q! (編集した場合でも上書きせずに閉じる)
- :wq (上書き保存)
- iでその場所から編集
- Aで最終列に移動して編集
- uで戻す
圧縮ファイルの解凍
tar.gz
1 2 3 4 | 圧縮 tar -zcvf xxxx.tar.gz directory 解凍 tar -zxvf xxxx.tar.gz |
zip
1 2 3 4 | 圧縮 zip -r xxxx.zip directory 解凍 unzip xxxx.zip |
treeコマンドが使えないとき
1 | pwd;find . | sort | sed '1d;s/^\.//;s/\/\([^/]*\)$/|--\1/;s/\/[^/|]*/| /g' |
OpenFOAMの環境変数の確認
1 2 3 | echo $FOAM_TUTORIALS # 出力結果 /opt/OpenFOAM/OpenFOAM-v2012/tutorials |
ケースファイルの初期化
初期化したいないように応じてコマンドを使い分ける。
1 2 3 4 5 6 7 8 | #設定の初期化 foamCleanTutorials #メッシュを初期化 foamCleanPolyMesh #計算結果の初期化 foamListTimes -rm |
postProcess
controlDictで設定。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | Q1 { // Mandatory entries (unmodifiable) type Q; libs (fieldFunctionObjects); // Optional (inherited) entries field <inpField>; result <fieldResult>; region region0; enabled true; log true; timeStart 0; timeEnd 1000; executeControl timeStep; executeInterval 1; writeControl timeStep; writeInterval 1; } |
コマンド実行
1 | postProcess -func Q |
とすると時刻のフォルダにQが出力
sampling
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 | type sets; //libs ("libsampling.so"); interpolationScheme cellPoint; setFormat raw; surfaceFormat raw; fields ( U k ); sets ( x=-2H { type uniform; axis xyz; start (-2 1 -1); end (-2 4 -1); nPoints 200; } x=15H { type uniform; axis xyz; start (14.99999 0 -1); end (14.99999 4 -1); nPoints 200; } ); |
以下のコマンドで結果をpostProcessingに出力。
1 | postProcess -latestTime -func sampleDict | tee log.sample |
特定の流束の大きさのみを表示(ParaView)
ParaViewで設定を変えます。
「Edit」>[Settings]から以下の項目にちゅえっくを入れます。
流速のコンターも描くことができます。
特定の流速の範囲に絞って表示することができます。
WSLでメモリ不足になったとき
WSLは何も設定しない場合、ホスト(Windows)メモリの 50%または8GBのどちらか少ない方になるように調整します。
Windows側が16GBのメモリの場合は以下のように、
1 | free -h |
で確認するとトータル7.7BGB使えるようになっており、あふれた分はスワップで2GBまで保持できるようになっています。
シミュレーションをしているとためにメモリが足らなくなるのでもう少し使えるように設定を変えます。
使えるメモリを80%までに引き上げて、残り足らなくなった分は少々遅くなっても良いのでスワップで保持するようにします。
.wslconfig は以下のパスに作成することで、WSL2 起動時に設定が読み込まれる仕組みになっています。
1 | C:\Users\[ユーザ名]\.wslconfig |
.wslconfigを以下とします。
.wslconfig
1 2 3 | [wsl2] memory=13GB swap=10GB |
PowerShellを管理者権限でシャットダウンします。
1 | wsl --shutdown |