前提・実現したいこと
下記のような,拡張子のないファイルの
一部分のみを読み取りたいのですが
どうすればよいかわかりません.
とくにTime = 0.005やTime = 0.01などの時間と、Total lift: -0.0869131394の物理量のみを読み込みたいです。
例えば,拡張子をcsvにして,データ区切りを施したファイルには
pandasを使えばできるのですが,
このようなファイルを大量に読み込む必要があり,
どうにかcsv等に変換せずにそのまま読み込める方法を探しています.
どなたか知っている方はいませんか?
■■ファイル(ワードパッドで開いたもの,拡張子なし)長くてすいません。。。
-------------------------------------------------------------------------- WARNING: No preset parameters were found for the device that Open MPI detected: Local host: ccfd01 Device name: mlx5_0 Device vendor ID: 0x02c9 Device vendor part ID: 4119 Default device parameters will be used, which may result in lower performance. You can edit any of the files specified by the btl_openib_device_param_files MCA parameter to set values for your device. NOTE: You can turn off this warning by setting the MCA parameter btl_openib_warn_no_device_params_found to 0. -------------------------------------------------------------------------- /*---------------------------------------------------------------------------*\ | o | | | o o | HELYX(R) Core: Open-source CFD for Enterprise | | o O o | Version: 3.2.0 | | o o | ENGYS Ltd. <http://engys.com/> | | o | | *---------------------------------------------------------------------------*/ Build : 3.2.0-49f935506940 Arch : "LSB;label=32;scalar=64" Exec : /home/user/Engys/HELYX/v3.2.0/CORE/HELYXcore-3.2.0/platforms/linux64Gcc51DPInt32Opt/bin/pisoFoam -case ./ -parallel Date : Jul 27 2020 Time : 14:30:30 Host : "ccfd01" PID : 131538 Case : /home/wd1a/Engys/helyx-3.2.0/run/les_Re5000_hamada_5upwind nProcs : 150 Slaves : 149 ( "ccfd01.131539" "ccfd01.131540" "ccfd01.131541" "ccfd01.131542" "ccfd01.131543" "ccfd01.131544" ・ ・ ・ ・ Starting time loop liftDrag LD1 read: Creating lift/drag file. --> FOAM Warning : From function virtual bool Foam::functionObjects::liftDrag::read(const Foam::dictionary&) in file liftDrag/liftDrag.C at line 1334 Old format used in binData. Time = 0.005 Courant Number mean: 0.0008401181416 max: 0.5415492641 smoothSolver: Solving for Ux, Initial residual = 1, Final residual = 5.622808846e-05, No Iterations 1 smoothSolver: Solving for Uy, Initial residual = 0, Final residual = 0, No Iterations 1 smoothSolver: Solving for Uz, Initial residual = 0, Final residual = 0, No Iterations 1 GAMG: Solving for p, Initial residual = 1, Final residual = 0.009588823783, No Iterations 21 time step continuity errors : mean magnitude = 1.611158484e-05, global = -1.044559554e-07, cumulative = -1.044559554e-07 GAMG: Solving for p, Initial residual = 0.0004913348773, Final residual = 4.592637766e-06, No Iterations 18 time step continuity errors : mean magnitude = 2.478992397e-06, global = -2.910135626e-09, cumulative = -1.07366091e-07 GAMG: Solving for p, Initial residual = 5.511542216e-05, Final residual = 9.159198339e-07, No Iterations 12 time step continuity errors : mean magnitude = 4.93626578e-07, global = -2.35525591e-10, cumulative = -1.076016166e-07 ExecutionTime = 1.84 s ClockTime = 1 s liftDrag LD1 execute: Viscous drag: 0.328838746, pressure drag: 61.43967168, porous drag: 0 Viscous lift: -0.0004461338866, pressure lift: -0.08646700552, porous lift: 0 Total lift: -0.0869131394, Front lift: 0.009149628478, Rear lift: -0.09606276788, Drag: 61.76851042 Time = 0.01 Courant Number mean: 0.350709318 max: 155.1787849 smoothSolver: Solving for Ux, Initial residual = 0.7216084361, Final residual = 0.0001919553515, No Iterations 3
該当のソースコード
import pandas as pd df = pd.read_csv('test', delim_whitespace=True, comment='#', names=['X', 'Y', 'Z'])
なんとなくこんな感じなのはわかるのですが、、、、
読み取りのルール
まず1行目から "Old format used in binData."(Time = 0.005の上行)までスキップします。
そして、Time = 0.005、Time = 0.010、Time = 0.015...をすべてと
各タイムステップのTotal lift: -0.0869131394、Total lift:....をすべて読みとりたいです。
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。