Frank_LBM/scripts/Paraview_test.ipynb
2026-02-15 19:21:28 +08:00

488 lines
34 KiB
Plaintext

{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"import sys\n",
"import os\n",
"\n",
"current_dir = os.path.dirname(os.path.abspath(\"__file__\"))\n",
"parent_dir = os.path.abspath(os.path.join(current_dir, os.pardir))\n",
"paraview_dir = os.path.join(parent_dir, \"ParaView\")\n",
"\n",
"os.environ['PYTHONPATH'] = f\"{paraview_dir}/lib:{paraview_dir}/lib/python3.9/site-packages\"\n",
"os.environ['LD_LIBRARY_PATH'] = os.path.join(paraview_dir, \"bin\")\n",
"\n",
"sys.path.append(parent_dir)\n",
"sys.path.append(os.path.join(paraview_dir, \"lib\"))\n",
"sys.path.append(os.path.join(paraview_dir, \"bin\"))\n",
"sys.path.append(os.path.join(paraview_dir, \"lib/python3.9/site-packages\"))\n",
"\n",
"# from paraview.simple import *\n",
"import paraview.simple as pv\n",
"from CelerisLab import FlowField\n",
"from CelerisLab import utils\n",
"\n",
"from collections import deque\n",
"import matplotlib.pyplot as plt\n",
"import numpy as np\n",
"from gym_env import CustomEnv\n",
"from stable_baselines3 import PPO\n",
"import pycuda.driver as cuda\n",
"import pickle\n",
"\n",
"FIFO_LEN = 120\n",
"# SAMPLE_INTERVAL = 600\n",
"DATA_TYPE = np.float32\n",
"CONV_LEN = 60\n",
"SAMP_RATE = 60"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"filename = \"field\"\n",
"targetname = \"target\"\n",
"outputname = \"ref\"\n",
"folder = \"plot\""
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"renderView1 = pv.GetActiveViewOrCreate('RenderView')\n",
"renderView1.ViewSize = [1200, 480]\n",
"renderView1.InteractionMode = '2D'\n",
"renderView1.OrientationAxesVisibility = 0\n",
"renderView1.CameraPosition = [0.0, 0.0, 3.0]\n",
"renderView1.UseLight = 0\n",
"\n",
"name_files = []\n",
"for i in range(1, 151):\n",
" name_files.append(os.path.join(parent_dir, f\"output/250729/anim/field.dat.{i:03}\"))\n",
"dat = pv.TecplotReader(registrationName='data.dat*', FileNames=name_files)\n",
"\n",
"# dat = pv.TecplotReader(registrationName='data.dat', FileNames=os.path.join(parent_dir, \"output/250729/\", folder, filename + \".dat\"))\n",
"# dat = pv.TecplotReader(registrationName='data.dat', FileNames=os.path.join(parent_dir, \"output/250326/episode/500/d1a3o12.dat.150\"))\n",
"dat.DataArrayStatus = ['flag', 'U', 'V']\n",
"# dat0 = pv.TecplotReader(registrationName='data0.dat', FileNames=os.path.join(parent_dir, \"output/250729/\", folder, targetname + \".dat\"))\n",
"# dat0.DataArrayStatus = ['flag', 'U', 'V']\n",
"\n",
"# programmableFilter1 = pv.ProgrammableFilter(registrationName='ProgrammableFilter1', Input=[dat, dat0])\n",
"# programmableFilter1.Script = \"\"\"U_0 = inputs[0].PointData['U']\n",
"# U_1 = inputs[1].PointData['U']\n",
"# V_0 = inputs[0].PointData['V']\n",
"# V_1 = inputs[1].PointData['V']\n",
"# output.PointData.append((U_1 - U_0), 'dU')\n",
"# output.PointData.append((V_1 - V_0), 'dV')\n",
"# output.PointData.append(sqrt(U_1**2+V_1**2), 'Speed')\"\"\"\n",
"\n",
"calculator0 = pv.Calculator(registrationName='Calculator0', Input=dat)\n",
"calculator0.ResultArrayName = 'W'\n",
"calculator0.Function = '0'\n",
"# calculator1 = pv.Calculator(registrationName='Calculator1', Input=programmableFilter1)\n",
"# calculator1.ResultArrayName = 'dZ'\n",
"# calculator1.Function = '0'\n",
"mergeVectorComponents1 = pv.MergeVectorComponents(registrationName='MergeVectorComponents1', Input=calculator0)\n",
"mergeVectorComponents1.XArray = 'U'\n",
"mergeVectorComponents1.YArray = 'V'\n",
"mergeVectorComponents1.ZArray = 'W'\n",
"# mergeVectorComponents1 = pv.MergeVectorComponents(registrationName='MergeVectorComponents1', Input=calculator1)\n",
"# mergeVectorComponents1.XArray = 'dU'\n",
"# mergeVectorComponents1.YArray = 'dV'\n",
"# mergeVectorComponents1.ZArray = 'dZ'\n",
"gradient1 = pv.Gradient(registrationName='Gradient1', Input=mergeVectorComponents1)\n",
"gradient1.ScalarArray = ['POINTS', 'Vector']\n",
"gradient1.ComputeGradient = 0\n",
"gradient1.ComputeVorticity = 1\n",
"calculator1 = pv.Calculator(registrationName='Calculator1', Input=dat)\n",
"calculator1.ResultArrayName = 'Sensor'\n",
"calculator1.Function = '1/(flag-17)'\n",
"calculator1.ReplacementValue = 1000.0\n",
"calculator2 = pv.Calculator(registrationName='Calculator2', Input=dat)\n",
"calculator2.ResultArrayName = 'Solid'\n",
"calculator2.Function = '1/(flag-2)/(flag-10)'\n",
"calculator2.ReplacementValue = 1000.0\n",
"# calculator3 = pv.Calculator(registrationName='Calculator3', Input=mergeVectorComponents1)\n",
"# calculator3.ResultArrayName = 'Error'\n",
"# calculator3.Function = 'Vector/Speed'\n",
"# calculator3 = pv.Calculator(registrationName='Calculator3', Input=mergeVectorComponents1)\n",
"# calculator3.ResultArrayName = 'Speed'\n",
"# calculator3.Function = 'mag(Vector)'\n",
"calculator3 = pv.Calculator(registrationName='Calculator3', Input=gradient1)\n",
"calculator3.ResultArrayName = 'Z_Vort'\n",
"calculator3.Function = 'Vorticity_Z'\n",
"\n",
"slice1 = pv.Slice(registrationName='Slice1', Input=mergeVectorComponents1)\n",
"slice1.SliceType = 'Plane'\n",
"slice1.HyperTreeGridSlicer = 'Plane'\n",
"slice1.SliceOffsetValues = [0.0]\n",
"slice1.SliceType.Origin = [800.0, 255.5, 0.0]\n",
"\n",
"glyph1 = pv.Glyph(registrationName='Glyph1', Input=slice1, GlyphType='Arrow')\n",
"glyph1.OrientationArray = ['POINTS', 'Vector']\n",
"glyph1.ScaleArray = ['POINTS', 'Vector']\n",
"glyph1.ScaleFactor = 50.0\n",
"glyph1.GlyphTransform = 'Transform2'\n",
"glyph1.GlyphMode = 'Every Nth Point'\n",
"glyph1.MaximumNumberOfSamplePoints = 50\n",
"glyph1.Stride = 20\n",
"\n",
"# init the 'Arrow' selected for 'GlyphType'\n",
"glyph1.GlyphType.TipLength = 0.3\n",
"\n",
"# init the 'Transform2' selected for 'GlyphTransform'\n",
"glyph1.GlyphTransform.Scale = [1.0, 1.0, 0.0]\n",
"\n",
"# streamTracer1 = pv.StreamTracer(registrationName='StreamTracer1', Input=mergeVectorComponents1, SeedType='Line')\n",
"# streamTracer1.Vectors = ['POINTS', 'Vector']\n",
"# streamTracer1.IntegratorType = 'Runge-Kutta 4'\n",
"# streamTracer1.MaximumSteps = 4000\n",
"# streamTracer1.MaximumStreamlineLength = 2000.0\n",
"# streamTracer1.SeedType.Point1 = [200.0, 0.0, 0.0]\n",
"# streamTracer1.SeedType.Point2 = [200.0, 500.0, 0.0]\n",
"# streamTracer1.SeedType.Resolution = 50\n",
"# contour1 = pv.Contour(registrationName='Contour1', Input=calculator3)\n",
"# contour1.ContourBy = ['POINTS', 'Speed']\n",
"# contour1.Isosurfaces = [1.0]\n",
"# contour1.PointMergeMethod = 'Uniform Binning'\n",
"# contour2 = pv.Contour(registrationName='Contour2', Input=calculator3)\n",
"# contour2.ContourBy = ['POINTS', 'Z_Vort']\n",
"# contour2.Isosurfaces = [0.0]\n",
"# contour2.PointMergeMethod = 'Uniform Binning'\n",
"\n",
"vorticityTF2D = pv.GetTransferFunction2D('Vorticity')\n",
"vorticityTF2D.ScalarRangeInitialized = 1\n",
"vorticityTF2D.Range = [-0.1, 0.1, 0.0, 1.0]\n",
"vorticityLUT = pv.GetColorTransferFunction('Vorticity')\n",
"vorticityLUT.AutomaticRescaleRangeMode = 'Never'\n",
"vorticityLUT.TransferFunction2D = vorticityTF2D\n",
"vorticityLUT.RGBPoints = [-0.1, 0.23137254902, 0.298039215686, 0.752941176471, -0.0125, 1.0, 1.0, 1.0, 0.0125, 1.0, 1.0, 1.0, 0.1, 0.705882352941, 0.0156862745098, 0.149019607843]\n",
"vorticityLUT.NumberOfTableValues = 16\n",
"vorticityLUT.ScalarRangeInitialized = 1.0\n",
"vorticityLUT.VectorComponent = 2\n",
"vorticityLUT.VectorMode = 'Component'\n",
"vorticityPWF = pv.GetOpacityTransferFunction('Vorticity')\n",
"vorticityPWF.Points = [-0.1, 0.0, 0.5, 0.0, 0.1, 1.0, 0.5, 0.0]\n",
"vorticityPWF.ScalarRangeInitialized = 1\n",
"\n",
"# vorticityTF2D = pv.GetTransferFunction2D('Vorticity')\n",
"# vorticityTF2D.ScalarRangeInitialized = 1\n",
"# vorticityTF2D.Range = [-0.1, 0.1, 0.0, 1.0]\n",
"# vorticityLUT = pv.GetColorTransferFunction('Vorticity')\n",
"# vorticityLUT.AutomaticRescaleRangeMode = 'Never'\n",
"# vorticityLUT.TransferFunction2D = vorticityTF2D\n",
"# vorticityLUT.RGBPoints = [-0.1, 0.18995, 0.07176, 0.23217, -0.09921568, 0.19483, 0.08339, 0.26149, -0.09843138, 0.19956, 0.09498, 0.29024, -0.09764700000000001, 0.20415, 0.10652, 0.31844, -0.0968628, 0.2086, 0.11802, 0.34607, -0.09607840000000001, 0.21291, 0.12947, 0.37314, -0.09529420000000001, 0.21708, 0.14087, 0.39964, -0.0945098, 0.22111, 0.15223, 0.42558, -0.0937254, 0.225, 0.16354, 0.45096, -0.0929412, 0.22875, 0.17481, 0.47578, -0.09215680000000001, 0.23236, 0.18603, 0.50004, -0.0913726, 0.23582, 0.1972, 0.52373, -0.09058820000000001, 0.23915, 0.20833, 0.54686, -0.08980400000000001, 0.24234, 0.21941, 0.56942, -0.0890196, 0.24539, 0.23044, 0.59142, -0.0882352, 0.2483, 0.24143, 0.61286, -0.087451, 0.25107, 0.25237, 0.63374, -0.08666660000000001, 0.25369, 0.26327, 0.65406, -0.0858824, 0.25618, 0.27412, 0.67381, -0.08509800000000001, 0.25853, 0.28492, 0.693, -0.08431380000000001, 0.26074, 0.29568, 0.71162, -0.0835294, 0.2628, 0.30639, 0.72968, -0.082745, 0.26473, 0.31706, 0.74718, -0.0819608, 0.26652, 0.32768, 0.76412, -0.08117640000000001, 0.26816, 0.33825, 0.7805, -0.0803922, 0.26967, 0.34878, 0.79631, -0.07960800000000001, 0.27103, 0.35926, 0.81156, -0.078824, 0.27226, 0.3697, 0.82624, -0.07804, 0.27334, 0.38008, 0.84037, -0.077254, 0.27429, 0.39043, 0.85393, -0.07647000000000001, 0.27509, 0.40072, 0.86692, -0.075686, 0.27576, 0.41097, 0.87936, -0.07490200000000001, 0.27628, 0.42118, 0.89123, -0.074118, 0.27667, 0.43134, 0.90254, -0.07333400000000001, 0.27691, 0.44145, 0.91328, -0.07255, 0.27701, 0.45152, 0.92347, -0.07176400000000001, 0.27698, 0.46153, 0.93309, -0.07098, 0.2768, 0.47151, 0.94214, -0.07019600000000001, 0.27648, 0.48144, 0.95064, -0.069412, 0.27603, 0.49132, 0.95857, -0.068628, 0.27543, 0.50115, 0.96594, -0.067844, 0.27469, 0.51094, 0.97275, -0.067058, 0.27381, 0.52069, 0.97899, -0.066274, 0.27273, 0.5304, 0.98461, -0.06548999999999999, 0.27106, 0.54015, 0.9893, -0.06470600000000001, 0.26878, 0.54995, 0.99303, -0.063922, 0.26592, 0.55979, 0.99583, -0.063138, 0.26252, 0.56967, 0.99773, -0.062352000000000005, 0.25862, 0.57958, 0.99876, -0.061568000000000005, 0.25425, 0.5895, 0.99896, -0.060784000000000005, 0.24946, 0.59943, 0.99835, -0.06, 0.24427, 0.60937, 0.99697, -0.059216000000000005, 0.23874, 0.61931, 0.99485, -0.058432000000000005, 0.23288, 0.62923, 0.99202, -0.057648000000000005, 0.22676, 0.63913, 0.98851, -0.056862, 0.22039, 0.64901, 0.98436, -0.056078, 0.21382, 0.65886, 0.97959, -0.055294, 0.20708, 0.66866, 0.97423, -0.05451, 0.20021, 0.67842, 0.96833, -0.053726, 0.19326, 0.68812, 0.9619, -0.052942, 0.18625, 0.69775, 0.95498, -0.05215600000000001, 0.17923, 0.70732, 0.94761, -0.051372, 0.17223, 0.7168, 0.93981, -0.050588, 0.16529, 0.7262, 0.93161, -0.04980400000000001, 0.15844, 0.73551, 0.92305, -0.04902, 0.15173, 0.74472, 0.91416, -0.048236, 0.14519, 0.75381, 0.90496, -0.047450000000000006, 0.13886, 0.76279, 0.8955, -0.046666, 0.13278, 0.77165, 0.8858, -0.045882000000000006, 0.12698, 0.78037, 0.8759, -0.045098000000000006, 0.12151, 0.78896, 0.86581, -0.044314, 0.11639, 0.7974, 0.85559, -0.043530000000000006, 0.11167, 0.80569, 0.84525, -0.042746, 0.10738, 0.81381, 0.83484, -0.04196, 0.10357, 0.82177, 0.82437, -0.041176000000000004, 0.10026, 0.82955, 0.81389, -0.040392, 0.0975, 0.83714, 0.80342, -0.039608000000000004, 0.09532, 0.84455, 0.79299, -0.038824000000000004, 0.09377, 0.85175, 0.78264, -0.03804, 0.09287, 0.85875, 0.7724, -0.037253999999999995, 0.09267, 0.86554, 0.7623, -0.03647, 0.0932, 0.87211, 0.75237, -0.035685999999999996, 0.09451, 0.87844, 0.74265, -0.034902, 0.09662, 0.88454, 0.73316, -0.03411800000000001, 0.09958, 0.8904, 0.72393, -0.033334, 0.10342, 0.896, 0.715, -0.03255000000000001, 0.10815, 0.90142, 0.70599, -0.031764, 0.11374, 0.90673, 0.69651, -0.030979999999999994, 0.12014, 0.91193, 0.6866, -0.030196, 0.12733, 0.91701, 0.67627, -0.029412000000000008, 0.13526, 0.92197, 0.66556, -0.028628, 0.14391, 0.9268, 0.65448, -0.027844000000000008, 0.15323, 0.93151, 0.64308, -0.027058000000000013, 0.16319, 0.93609, 0.63137, -0.026274000000000006, 0.17377, 0.94053, 0.61938, -0.02549, 0.18491, 0.94484, 0.60713, -0.024705999999999992, 0.19659, 0.94901, 0.59466, -0.023922, 0.20877, 0.95304, 0.58199, -0.023138000000000006, 0.22142, 0.95692, 0.56914, -0.02235200000000001, 0.23449, 0.96065, 0.55614, -0.021568000000000004, 0.24797, 0.96423, 0.54303, -0.020783999999999997, 0.2618, 0.96765, 0.52981, -0.01999999999999999, 0.27597, 0.97092, 0.51653, -0.019215999999999997, 0.29042, 0.97403, 0.50321, -0.018432000000000004, 0.30513, 0.97697, 0.48987, -0.017647999999999997, 0.32006, 0.97974, 0.47654, -0.016862000000000002, 0.33517, 0.98234, 0.46325, -0.01607800000000001, 0.35043, 0.98477, 0.45002, -0.015294000000000002, 0.36581, 0.98702, 0.43688, -0.014509999999999995, 0.38127, 0.98909, 0.42386, -0.013726000000000002, 0.39678, 0.99098, 0.41098, -0.012941999999999995, 0.41229, 0.99268, 0.39826, -0.012156, 0.42778, 0.99419, 0.38575, -0.011372000000000007, 0.44321, 0.99551, 0.37345, -0.010588, 0.45854, 0.99663, 0.3614, -0.009804000000000007, 0.47375, 0.99755, 0.34963, -0.00902, 0.48879, 0.99828, 0.33816, -0.008235999999999993, 0.50362, 0.99879, 0.32701, -0.007449999999999998, 0.51822, 0.9991, 0.31622, -0.006666000000000005, 0.53255, 0.99919, 0.30581, -0.005881999999999998, 0.54658, 0.99907, 0.29581, -0.005098000000000005, 0.56026, 0.99873, 0.28623, -0.004313999999999998, 0.57357, 0.99817, 0.27712, -0.0035300000000000054, 0.58646, 0.99739, 0.26849, -0.0027459999999999984, 0.59891, 0.99638, 0.26038, -0.0019599999999999895, 0.61088, 0.99514, 0.2528, -0.0011759999999999965, 0.62233, 0.99366, 0.24579, -0.00039200000000000346, 0.63323, 0.99195, 0.23937, 0.0003919999999999896, 0.64362, 0.98999, 0.23356, 0.0011759999999999965, 0.65394, 0.98775, 0.22835, 0.0019600000000000034, 0.66428, 0.98524, 0.2237, 0.0027459999999999984, 0.67462, 0.98246, 0.2196, 0.0035300000000000054, 0.68494, 0.97941, 0.21602, 0.004313999999999998, 0.69525, 0.9761, 0.21294, 0.005098000000000005, 0.70553, 0.97255, 0.21032, 0.005882000000000012, 0.71577, 0.96875, 0.20815, 0.006665999999999991, 0.72596, 0.9647, 0.2064, 0.007449999999999998, 0.7361, 0.96043, 0.20504, 0.008235999999999993, 0.74617, 0.95593, 0.20406, 0.00902, 0.75617, 0.95121, 0.20343, 0.009803999999999993, 0.76608, 0.94627, 0.20311, 0.010588, 0.77591, 0.94113, 0.2031, 0.011372000000000007, 0.78563, 0.93579, 0.20336, 0.012155999999999986, 0.79524, 0.93025, 0.20386, 0.012942000000000009, 0.80473, 0.92452, 0.20459, 0.013725999999999988, 0.8141, 0.91861, 0.20552, 0.014509999999999995, 0.82333, 0.91253, 0.20663, 0.015294000000000002, 0.83241, 0.90627, 0.20788, 0.016077999999999995, 0.84133, 0.89986, 0.20926, 0.016862000000000002, 0.8501, 0.89328, 0.21074, 0.017647999999999997, 0.85868, 0.88655, 0.2123, 0.018432000000000004, 0.86709, 0.87968, 0.21391, 0.01921600000000001, 0.8753, 0.87267, 0.21555, 0.01999999999999999, 0.88331, 0.86553, 0.21719, 0.020783999999999997, 0.89112, 0.85826, 0.2188, 0.021568000000000004, 0.8987, 0.85087, 0.22038, 0.022351999999999997, 0.90605, 0.84337, 0.22188, 0.023137999999999992, 0.91317, 0.83576, 0.22328, 0.023922, 0.92004, 0.82806, 0.22456, 0.024706000000000006, 0.92666, 0.82025, 0.2257, 0.025489999999999985, 0.93301, 0.81236, 0.22667, 0.026273999999999992, 0.93909, 0.80439, 0.22744, 0.027058, 0.94489, 0.79634, 0.228, 0.027844000000000008, 0.95039, 0.78823, 0.22831, 0.028628000000000015, 0.9556, 0.78005, 0.22836, 0.029411999999999994, 0.96049, 0.77181, 0.22811, 0.030196, 0.96507, 0.76352, 0.22754, 0.030980000000000008, 0.96931, 0.75519, 0.22663, 0.03176399999999999, 0.97323, 0.74682, 0.22536, 0.032549999999999996, 0.97679, 0.73842, 0.22369, 0.033334, 0.98, 0.73, 0.22161, 0.03411800000000001, 0.98289, 0.7214, 0.21918, 0.034902000000000016, 0.98549, 0.7125, 0.2165, 0.035685999999999996, 0.98781, 0.7033, 0.21358, 0.03647, 0.98986, 0.69382, 0.21043, 0.03725400000000001, 0.99163, 0.68408, 0.20706, 0.03804000000000002, 0.99314, 0.67408, 0.20348, 0.038824, 0.99438, 0.66386, 0.19971, 0.039608000000000004, 0.99535, 0.65341, 0.19577, 0.04039200000000001, 0.99607, 0.64277, 0.19165, 0.04117599999999999, 0.99654, 0.63193, 0.18738, 0.04196, 0.99675, 0.62093, 0.18297, 0.042746000000000006, 0.99672, 0.60977, 0.17842, 0.04353000000000001, 0.99644, 0.59846, 0.17376, 0.04431400000000002, 0.99593, 0.58703, 0.16899, 0.045098, 0.99517, 0.57549, 0.16412, 0.045882000000000006, 0.99419, 0.56386, 0.15918, 0.04666600000000001, 0.99297, 0.55214, 0.15417, 0.04744999999999999, 0.99153, 0.54036, 0.1491, 0.048236, 0.98987, 0.52854, 0.14398, 0.04902000000000001, 0.98799, 0.51667, 0.13883, 0.049804000000000015, 0.9859, 0.50479, 0.13367, 0.05058800000000002, 0.9836, 0.49291, 0.12849, 0.051372, 0.98108, 0.48104, 0.12332, 0.05215600000000001, 0.97837, 0.4692, 0.11817, 0.05294200000000002, 0.97545, 0.4574, 0.11305, 0.053726000000000024, 0.97234, 0.44565, 0.10797, 0.05451, 0.96904, 0.43399, 0.10294, 0.05529400000000001, 0.96555, 0.42241, 0.09798, 0.05607800000000002, 0.96187, 0.41093, 0.0931, 0.056861999999999996, 0.95801, 0.39958, 0.08831, 0.057648000000000005, 0.95398, 0.38836, 0.08362, 0.05843200000000001, 0.94977, 0.37729, 0.07905, 0.05921600000000002, 0.94538, 0.36638, 0.07461, 0.060000000000000026, 0.94084, 0.35566, 0.07031, 0.060784000000000005, 0.93612, 0.34513, 0.06616, 0.06156800000000001, 0.93125, 0.33482, 0.06218, 0.06235200000000002, 0.92623, 0.32473, 0.05837, 0.063138, 0.92105, 0.31489, 0.05475, 0.063922, 0.91572, 0.3053, 0.05134, 0.06470600000000001, 0.91024, 0.29599, 0.04814, 0.06549000000000002, 0.90463, 0.28696, 0.04516, 0.06627400000000003, 0.89888, 0.27824, 0.04243, 0.067058, 0.89298, 0.26981, 0.03993, 0.06784399999999999, 0.88691, 0.26152, 0.03753, 0.068628, 0.88066, 0.25334, 0.03521, 0.069412, 0.87422, 0.24526, 0.03297, 0.07019600000000001, 0.8676, 0.2373, 0.03082, 0.07098000000000002, 0.86079, 0.22945, 0.02875, 0.07176400000000002, 0.8538, 0.2217, 0.02677, 0.07255, 0.84662, 0.21407, 0.02487, 0.07333400000000001, 0.83926, 0.20654, 0.02305, 0.07411799999999999, 0.83172, 0.19912, 0.02131, 0.074902, 0.82399, 0.19182, 0.01966, 0.075686, 0.81608, 0.18462, 0.01809, 0.07647000000000001, 0.80799, 0.17753, 0.0166, 0.07725400000000002, 0.79971, 0.17055, 0.0152, 0.07804, 0.79125, 0.16368, 0.01387, 0.078824, 0.7826, 0.15693, 0.01264, 0.07960799999999998, 0.77377, 0.15028, 0.01148, 0.08039199999999999, 0.76476, 0.14374, 0.01041, 0.081176, 0.75556, 0.13731, 0.00942, 0.08196, 0.74617, 0.13098, 0.00851, 0.08274600000000001, 0.73661, 0.12477, 0.00769, 0.08353, 0.72686, 0.11867, 0.00695, 0.084314, 0.71692, 0.11268, 0.00629, 0.08509800000000001, 0.7068, 0.1068, 0.00571, 0.08588199999999999, 0.6965, 0.10102, 0.00522, 0.08666599999999999, 0.68602, 0.09536, 0.00481, 0.08745, 0.67535, 0.0898, 0.00449, 0.08823600000000001, 0.66449, 0.08436, 0.00424, 0.08902000000000002, 0.65345, 0.07902, 0.00408, 0.089804, 0.64223, 0.0738, 0.00401, 0.090588, 0.63082, 0.06868, 0.00401, 0.09137200000000001, 0.61923, 0.06367, 0.0041, 0.09215599999999999, 0.60746, 0.05878, 0.00427, 0.092942, 0.5955, 0.05399, 0.00453, 0.093726, 0.58336, 0.04931, 0.00486, 0.09451000000000001, 0.57103, 0.04474, 0.00529, 0.09529399999999999, 0.55852, 0.04028, 0.00579, 0.096078, 0.54583, 0.03593, 0.00638, 0.096862, 0.53295, 0.03169, 0.00705, 0.09764800000000001, 0.51989, 0.02756, 0.0078, 0.09843200000000002, 0.50664, 0.02354, 0.00863, 0.099216, 0.49321, 0.01963, 0.00955, 0.1, 0.4796, 0.01583, 0.01055]\n",
"# vorticityLUT.ColorSpace = 'RGB'\n",
"# vorticityLUT.NumberOfTableValues = 11\n",
"# vorticityLUT.ScalarRangeInitialized = 1.0\n",
"# vorticityLUT.VectorComponent = 2\n",
"# vorticityLUT.VectorMode = 'Component'\n",
"# vorticityPWF = pv.GetOpacityTransferFunction('Vorticity')\n",
"# vorticityPWF.Points = [-0.1, 0.0, 0.5, 0.0, 0.1, 1.0, 0.5, 0.0]\n",
"# vorticityPWF.ScalarRangeInitialized = 1\n",
"\n",
"sensorTF2D = pv.GetTransferFunction2D('Sensor')\n",
"sensorLUT = pv.GetColorTransferFunction('Sensor')\n",
"sensorLUT.EnableOpacityMapping = 1\n",
"sensorLUT.TransferFunction2D = sensorTF2D\n",
"sensorLUT.RGBPoints = [-0.14285714285714285, 1.0, 1.0, 1.0, 1000.0, 0.4, 0.8, 0.4]\n",
"sensorLUT.ColorSpace = 'RGB'\n",
"sensorLUT.NanColor = [1.0, 0.0, 0.0]\n",
"sensorLUT.NumberOfTableValues = 10\n",
"sensorLUT.ScalarRangeInitialized = 1.0\n",
"sensorPWF = pv.GetOpacityTransferFunction('Sensor')\n",
"sensorPWF.Points = [-0.14285714285714285, 0.0, 0.5, 0.0, 499.87855928449983, 0.0, 0.5, 0.0, 1000.0, 1.0, 0.5, 0.0]\n",
"sensorPWF.ScalarRangeInitialized = 1\n",
"\n",
"solidTF2D = pv.GetTransferFunction2D('Solid')\n",
"solidLUT = pv.GetColorTransferFunction('Solid')\n",
"solidLUT.EnableOpacityMapping = 1\n",
"solidLUT.TransferFunction2D = solidTF2D\n",
"solidLUT.RGBPoints = [-0.14285714285714285, 1.0, 1.0, 1.0, 1000.0, 0.0, 0.0, 0.0]\n",
"solidLUT.ColorSpace = 'RGB'\n",
"solidLUT.NanColor = [1.0, 0.0, 0.0]\n",
"solidLUT.NumberOfTableValues = 10\n",
"solidLUT.ScalarRangeInitialized = 1.0\n",
"solidPWF = pv.GetOpacityTransferFunction('Solid')\n",
"solidPWF.Points = [-0.14285714285714285, 0.0, 0.5, 0.0, 500.0, 0.0, 0.5, 0.0, 1000.0, 1.0, 0.5, 0.0]\n",
"solidPWF.ScalarRangeInitialized = 1\n",
"\n",
"# speedTF2D = pv.GetTransferFunction2D('Speed')\n",
"# speedTF2D.ScalarRangeInitialized = 1\n",
"# speedTF2D.Range = [0.0, 2.0, 0.0, 1.0]\n",
"# speedLUT = pv.GetColorTransferFunction('Speed')\n",
"# speedLUT.AutomaticRescaleRangeMode = 'Never'\n",
"# speedLUT.TransferFunction2D = speedTF2D\n",
"# speedLUT.RGBPoints = [0.0, 0.231373, 0.298039, 0.752941, 1.0, 0.865003, 0.865003, 0.865003, 2.0, 0.705882, 0.0156863, 0.14902]\n",
"# speedLUT.NumberOfTableValues = 10\n",
"# speedLUT.ScalarRangeInitialized = 1.0\n",
"# speedPWF = pv.GetOpacityTransferFunction('Speed')\n",
"# speedPWF.Points = [0.0, 0.0, 0.5, 0.0, 2.0, 1.0, 0.5, 0.0]\n",
"# speedPWF.ScalarRangeInitialized = 1\n",
"\n",
"# errorTF2D = pv.GetTransferFunction2D('Error')\n",
"# errorTF2D.ScalarRangeInitialized = 1\n",
"# errorLUT = pv.GetColorTransferFunction('Error')\n",
"# errorLUT.AutomaticRescaleRangeMode = 'Never'\n",
"# errorLUT.TransferFunction2D = errorTF2D\n",
"# errorLUT.RGBPoints = [0.0, 1.0, 1.0, 1.0, 3.0, 0.0, 0.0, 0.0]\n",
"# errorLUT.ColorSpace = 'RGB'\n",
"# errorLUT.NanColor = [1.0, 0.0, 0.0]\n",
"# errorLUT.NumberOfTableValues = 10\n",
"# errorLUT.ScalarRangeInitialized = 1.0\n",
"# errorPWF = pv.GetOpacityTransferFunction('Error')\n",
"# errorPWF.ScalarRangeInitialized = 1\n",
"\n",
"Display = pv.Show(gradient1, renderView1)\n",
"Display.ColorArrayName = ['POINTS', 'Vorticity']\n",
"Display.LookupTable = vorticityLUT\n",
"Display.ScalarOpacityFunction = vorticityPWF\n",
"\n",
"# streamTracer1Display = pv.Show(streamTracer1, renderView1, 'GeometryRepresentation')\n",
"# streamTracer1Display.ColorArrayName = ['POINTS', '']\n",
"# streamTracer1Display.ScaleTransferFunction.Points = [0.0, 0.0, 0.5, 0.0, 4.2148476072182355, 1.0, 0.5, 0.0]\n",
"\n",
"# calculator3Display = pv.Show(calculator3, renderView1, 'StructuredGridRepresentation')\n",
"# calculator3Display.ColorArrayName = ['POINTS', 'Speed']\n",
"# calculator3Display.LookupTable = speedLUT\n",
"# calculator3Display.ScalarOpacityFunction = speedPWF\n",
"\n",
"calculator1Display = pv.Show(calculator1, renderView1, 'StructuredGridRepresentation')\n",
"calculator1Display.ColorArrayName = ['POINTS', 'Sensor']\n",
"calculator1Display.LookupTable = sensorLUT\n",
"calculator1Display.ScalarOpacityFunction = sensorPWF\n",
"\n",
"calculator2Display = pv.Show(calculator2, renderView1, 'StructuredGridRepresentation')\n",
"calculator2Display.ColorArrayName = ['POINTS', 'Solid']\n",
"calculator2Display.LookupTable = solidLUT\n",
"calculator2Display.ScalarOpacityFunction = solidPWF\n",
"\n",
"# calculator3Display = pv.Show(calculator3, renderView1, 'StructuredGridRepresentation')\n",
"# calculator3Display.ColorArrayName = ['POINTS', 'Error']\n",
"# calculator3Display.LookupTable = errorLUT\n",
"# calculator3Display.ScalarOpacityFunction = errorPWF\n",
"\n",
"# contour1Display = pv.Show(contour1, renderView1, 'GeometryRepresentation')\n",
"# contour1Display.AmbientColor = [0.0, 0.7843137254901961, 0.0]\n",
"# contour1Display.ColorArrayName = ['POINTS', '']\n",
"# contour1Display.DiffuseColor = [0.0, 0.7843137254901961, 0.0]\n",
"# contour1Display.LineWidth = 2.0\n",
"\n",
"# contour2Display = pv.Show(contour2, renderView1, 'GeometryRepresentation')\n",
"# contour2Display.AmbientColor = [0.0, 0.0, 0.0]\n",
"# contour2Display.ColorArrayName = [None, '']\n",
"# contour2Display.DiffuseColor = [0.0, 0.0, 0.0]\n",
"# contour2Display.LineWidth = 2.0\n",
"\n",
"glyph1Display = pv.Show(glyph1, renderView1, 'GeometryRepresentation')\n",
"\n",
"# trace defaults for the display properties.\n",
"glyph1Display.Representation = 'Surface'\n",
"glyph1Display.AmbientColor = [0.0, 1.0, 0.0]\n",
"glyph1Display.ColorArrayName = ['POINTS', '']\n",
"glyph1Display.DiffuseColor = [0.0, 1.0, 0.0]\n",
"glyph1Display.SelectTCoordArray = 'None'\n",
"glyph1Display.SelectNormalArray = 'None'\n",
"glyph1Display.SelectTangentArray = 'None'\n",
"glyph1Display.OSPRayScaleArray = 'Result'\n",
"glyph1Display.OSPRayScaleFunction = 'PiecewiseFunction'\n",
"glyph1Display.SelectOrientationVectors = 'None'\n",
"glyph1Display.ScaleFactor = 51.100000000001\n",
"glyph1Display.SelectScaleArray = 'Result'\n",
"glyph1Display.GlyphType = 'Arrow'\n",
"glyph1Display.GlyphTableIndexArray = 'Result'\n",
"glyph1Display.GaussianRadius = 2.55500000000005\n",
"glyph1Display.SetScaleArray = ['POINTS', 'Result']\n",
"glyph1Display.ScaleTransferFunction = 'PiecewiseFunction'\n",
"glyph1Display.OpacityArray = ['POINTS', 'Result']\n",
"glyph1Display.OpacityTransferFunction = 'PiecewiseFunction'\n",
"glyph1Display.DataAxesGrid = 'GridAxesRepresentation'\n",
"glyph1Display.PolarAxes = 'PolarAxesRepresentation'\n",
"glyph1Display.SelectInputVectors = ['POINTS', 'Vector']\n",
"glyph1Display.WriteLog = ''"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"True"
]
},
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"pv.Render()\n",
"renderView1.CameraParallelScale = 240\n",
"# pv.SaveScreenshot(os.path.join(parent_dir, \"output\", \"250729\", folder, outputname + \".png\"), view=renderView1)\n",
"pv.SaveScreenshot(os.path.join(parent_dir, \"output/250729/test.png\"), view=renderView1)"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"True"
]
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"scene = pv.GetAnimationScene()\n",
"scene.NumberOfFrames = 150\n",
"pv.SaveAnimation(filename=os.path.join(parent_dir, \"output\", \"250729\", \"anim\", \"anim.png\"), viewOrLayout=renderView1, SuffixFormat='.%03d')"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"找到文件: ['/home/frank14f/Frank_LBM/output/250729/anim/frame.00.png', '/home/frank14f/Frank_LBM/output/250729/anim/frame.01.png', '/home/frank14f/Frank_LBM/output/250729/anim/frame.02.png', '/home/frank14f/Frank_LBM/output/250729/anim/frame.03.png', '/home/frank14f/Frank_LBM/output/250729/anim/frame.04.png']\n"
]
}
],
"source": [
"import glob\n",
"\n",
"# 列出目录下所有匹配文件\n",
"dir_path = os.path.join(parent_dir, \"output\", \"250729\", \"anim\")\n",
"files = sorted(glob.glob(os.path.join(dir_path, \"frame.[0-9][0-9].png\")))\n",
"print(\"找到文件:\", files[:5]) # 打印前5个文件"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"ffmpeg version 4.2.2 Copyright (c) 2000-2019 the FFmpeg developers\n",
" built with gcc 7.3.0 (crosstool-NG 1.23.0.449-a04d0)\n",
" configuration: --prefix=/tmp/build/80754af9/ffmpeg_1587154242452/_h_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placeho --cc=/tmp/build/80754af9/ffmpeg_1587154242452/_build_env/bin/x86_64-conda_cos6-linux-gnu-cc --disable-doc --enable-avresample --enable-gmp --enable-hardcoded-tables --enable-libfreetype --enable-libvpx --enable-pthreads --enable-libopus --enable-postproc --enable-pic --enable-pthreads --enable-shared --enable-static --enable-version3 --enable-zlib --enable-libmp3lame --disable-nonfree --enable-gpl --enable-gnutls --disable-openssl --enable-libopenh264 --enable-libx264\n",
" libavutil 56. 31.100 / 56. 31.100\n",
" libavcodec 58. 54.100 / 58. 54.100\n",
" libavformat 58. 29.100 / 58. 29.100\n",
" libavdevice 58. 8.100 / 58. 8.100\n",
" libavfilter 7. 57.100 / 7. 57.100\n",
" libavresample 4. 0. 0 / 4. 0. 0\n",
" libswscale 5. 5.100 / 5. 5.100\n",
" libswresample 3. 5.100 / 3. 5.100\n",
" libpostproc 55. 5.100 / 55. 5.100\n",
"Input #0, image2, from '/home/frank14f/Frank_LBM/output/250729/anim/anim.%03d.png':\n",
" Duration: 00:00:15.00, start: 0.000000, bitrate: N/A\n",
" Stream #0:0: Video: png, rgb24(pc), 1200x480, 10 fps, 10 tbr, 10 tbn, 10 tbc\n",
"Stream mapping:\n",
" Stream #0:0 -> #0:0 (png (native) -> h264 (libx264))\n",
"Press [q] to stop, [?] for help\n",
"[libx264 @ 0x56b63b5f6700] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX FMA3 BMI2 AVX2\n",
"[libx264 @ 0x56b63b5f6700] profile High, level 3.1, 4:2:0, 8-bit\n",
"[libx264 @ 0x56b63b5f6700] 264 - core 157 - H.264/MPEG-4 AVC codec - Copyleft 2003-2018 - http://www.videolan.org/x264.html - options: cabac=1 ref=3 deblock=1:0:0 analyse=0x3:0x113 me=hex subme=7 psy=1 psy_rd=1.00:0.00 mixed_ref=1 me_range=16 chroma_me=1 trellis=1 8x8dct=1 cqm=0 deadzone=21,11 fast_pskip=1 chroma_qp_offset=-2 threads=15 lookahead_threads=2 sliced_threads=0 nr=0 decimate=1 interlaced=0 bluray_compat=0 constrained_intra=0 bframes=3 b_pyramid=2 b_adapt=1 b_bias=0 direct=1 weightb=1 open_gop=0 weightp=2 keyint=250 keyint_min=10 scenecut=40 intra_refresh=0 rc_lookahead=40 rc=crf mbtree=1 crf=23.0 qcomp=0.60 qpmin=0 qpmax=69 qpstep=4 ip_ratio=1.40 aq=1:1.00\n",
"Output #0, mp4, to '/home/frank14f/Frank_LBM/output/250729/erase2.mp4':\n",
" Metadata:\n",
" encoder : Lavf58.29.100\n",
" Stream #0:0: Video: h264 (libx264) (avc1 / 0x31637661), yuv420p, 1200x480, q=-1--1, 10 fps, 10240 tbn, 10 tbc\n",
" Metadata:\n",
" encoder : Lavc58.54.100 libx264\n",
" Side data:\n",
" cpb: bitrate max/min/avg: 0/0/0 buffer size: 0 vbv_delay: -1\n",
"frame= 150 fps=124 q=-1.0 Lsize= 567kB time=00:00:14.70 bitrate= 316.2kbits/s speed=12.2x \n",
"video:565kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.452751%\n",
"[libx264 @ 0x56b63b5f6700] frame I:1 Avg QP:13.03 size: 16821\n",
"[libx264 @ 0x56b63b5f6700] frame P:40 Avg QP:20.97 size: 5629\n",
"[libx264 @ 0x56b63b5f6700] frame B:109 Avg QP:24.12 size: 3081\n",
"[libx264 @ 0x56b63b5f6700] consecutive B-frames: 1.3% 4.0% 4.0% 90.7%\n",
"[libx264 @ 0x56b63b5f6700] mb I I16..4: 50.2% 31.6% 18.2%\n",
"[libx264 @ 0x56b63b5f6700] mb P I16..4: 0.7% 4.1% 1.5% P16..4: 12.0% 5.7% 4.1% 0.0% 0.0% skip:71.9%\n",
"[libx264 @ 0x56b63b5f6700] mb B I16..4: 0.2% 0.2% 0.3% B16..8: 12.5% 5.8% 2.5% direct: 0.8% skip:77.7% L0:47.6% L1:45.5% BI: 6.9%\n",
"[libx264 @ 0x56b63b5f6700] 8x8 transform intra:51.7% inter:33.5%\n",
"[libx264 @ 0x56b63b5f6700] coded y,uvDC,uvAC intra: 20.4% 35.2% 32.4% inter: 3.2% 4.4% 2.5%\n",
"[libx264 @ 0x56b63b5f6700] i16 v,h,dc,p: 60% 36% 5% 0%\n",
"[libx264 @ 0x56b63b5f6700] i8 v,h,dc,ddl,ddr,vr,hd,vl,hu: 9% 6% 78% 1% 1% 1% 2% 1% 1%\n",
"[libx264 @ 0x56b63b5f6700] i4 v,h,dc,ddl,ddr,vr,hd,vl,hu: 19% 29% 28% 4% 4% 4% 6% 3% 4%\n",
"[libx264 @ 0x56b63b5f6700] i8c dc,h,v,p: 62% 23% 12% 4%\n",
"[libx264 @ 0x56b63b5f6700] Weighted P-Frames: Y:0.0% UV:0.0%\n",
"[libx264 @ 0x56b63b5f6700] ref P L0: 48.5% 1.6% 16.2% 33.7%\n",
"[libx264 @ 0x56b63b5f6700] ref B L0: 86.1% 7.6% 6.3%\n",
"[libx264 @ 0x56b63b5f6700] ref B L1: 97.4% 2.6%\n",
"[libx264 @ 0x56b63b5f6700] kb/s:308.15\n"
]
},
{
"data": {
"text/plain": [
"(None, None)"
]
},
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"import ffmpeg\n",
"input_pattern = os.path.join(parent_dir, \"output\", \"250729\", \"anim\", \"anim.%03d.png\")\n",
"output_file = os.path.join(parent_dir, \"output\", \"250729\", \"erase2.mp4\")\n",
"(\n",
" ffmpeg\n",
" .input(input_pattern, framerate=10)\n",
" .output(output_file, vcodec=\"libx264\", pix_fmt=\"yuv420p\", vframes=150)\n",
" .run()\n",
")"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "pycuda_3_10",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.13"
}
},
"nbformat": 4,
"nbformat_minor": 2
}