diff --git a/ntrfc/cascade_case/solution/ansys.py b/ntrfc/cascade_case/solution/ansys.py new file mode 100644 index 0000000000000000000000000000000000000000..a8723f635ecd45294428e6d71abaa149027970c7 --- /dev/null +++ b/ntrfc/cascade_case/solution/ansys.py @@ -0,0 +1,60 @@ +import numpy as np +import pandas as pd +import pyvista as pv + +from ntrfc.cascade_case.solution.generic import GenericCascadeCase +from ntrfc.filehandling.mesh import load_mesh + + +class ansys_case(GenericCascadeCase): + def __init__(self): + super().__init__() + self.solver = "ansys" + + def read_fluid(self, path): + self.fluid = load_mesh(path) + + def read_inlet(self, path): + self.inlet = read_ansys_csv(path) + + def read_outlet(self, path): + self.outlet = read_ansys_csv(path) + + def read_blade(self, path): + self.blade = load_mesh(path) + + def read_yper_low(self, path): + self.yper_low = read_ansys_csv(path) + + def read_yper_high(self, path): + self.yper_high = read_ansys_csv(path) + + def read_zper_low(self, path): + self.zper_low = read_ansys_csv(path) + + def read_zper_high(self, path): + self.zper_high = read_ansys_csv(path) + + +def read_ansys_csv(path): + dats = { + "p": " Pressure [ Pa ]", + "T": " Temperature [ K ]", + "U": " Velocity [ m s^-1 ]", + "u": " Velocity u [ m s^-1 ]", + "v": " Velocity v [ m s^-1 ]", + "w": " Velocity w [ m s^-1 ]", + "rho": " Density [ kg m^-3 ]", + } + + data = pd.read_csv(path, skiprows=5) + xs, ys, zs = data["X [ m ]"], data[" Y [ m ]"], data[" Z [ m ]"] + points = np.stack([xs, ys, zs]).T + poly = pv.PolyData(points) + + for k, v in dats.items(): + poly[k] = data[v] + + surface = poly.delaunay_2d() + surface = surface.point_data_to_cell_data() + return surface diff --git a/ntrfc/cascade_case/solution/openfoam.py b/ntrfc/cascade_case/solution/openfoam.py new file mode 100644 index 0000000000000000000000000000000000000000..c06224cffefbae8925c772818aff9c70e2bd39ca --- /dev/null +++ b/ntrfc/cascade_case/solution/openfoam.py @@ -0,0 +1,57 @@ +import os +from pathlib import Path + +import numpy as np +from fluidfoam.readpostpro import readprobes + +from ntrfc.cascade_case.solution.generic import GenericCascadeCase + + +class openfoam_case(GenericCascadeCase): + def __init__(self): + super().__init__() + self.solver = "openfoam" + + def read_openfoam_probes(self, path_to_probes): + """ + adds probes from an openfoam case to an ntrfc-case + :param path_to_probes: points on the directory + """ + openfoam_probesets_starttimes = os.listdir(path_to_probes) + openfoam_probesets_starttimes.sort() + postprocessing_dir = Path(path_to_probes).parent.parent + basename = Path(path_to_probes).stem + + probe_time = {} + probe_vals = {} + timestamps = [float(i) for i in openfoam_probesets_starttimes] + + vals = os.listdir(os.path.join(path_to_probes, openfoam_probesets_starttimes[0])) + for val in vals: + _, times, values = readprobes(f"{postprocessing_dir}", basename, time_name="mergeTime", name=val) + values[values == -1e300] = np.nan + probe_time[val] = times + probe_vals[val] = values + + for valname in probe_time.keys(): + self.probes.add_probeset(valname, basename, probe_time[valname], probe_vals[valname], timestamps) + + def read_openfoam_sliceseries(self, path_to_slices, filename): + """ + adds slices to + """ + timedirs = os.listdir(path_to_slices) + timedirs.sort() + + groupname = os.path.basename(path_to_slices) + paths = [] + timestamps = [] + for td in timedirs: + files = os.listdir(os.path.join(path_to_slices, td)) + if filename in files: + slicepath = os.path.join(path_to_slices, td, filename) + print(f"adding {slicepath} to the slice-list") + paths.append(slicepath) + timestamps.append(td) + print(f"creating sliceseries with {len(timestamps)} slices") + self.sliceseries.add_sliceset(paths, groupname, timestamps) diff --git a/tests/cascadecase/solution/test_ansys.py b/tests/cascadecase/solution/test_ansys.py new file mode 100644 index 0000000000000000000000000000000000000000..16219dad3a84aeede3472a047913da8d893860fe --- /dev/null +++ b/tests/cascadecase/solution/test_ansys.py @@ -0,0 +1,49 @@ +def test_solution(tmpdir): + from ntrfc.cascade_case.solution.generic import GenericCascadeCase + import numpy as np + import pyvista as pv + + fake_inlet = pv.Plane() + + fake_inlet["u"] = np.array([1] * fake_inlet.number_of_cells) + fake_inlet["v"] = np.array([0] * fake_inlet.number_of_cells) + fake_inlet["w"] = np.array([0] * fake_inlet.number_of_cells) + fake_inlet["rho"] = np.array([1] * fake_inlet.number_of_cells) + fake_inlet["U"] = np.stack([fake_inlet["u"], fake_inlet["v"], fake_inlet["w"]]).T + + fake_outlet = pv.Plane() + + fake_outlet["u"] = np.array([1] * fake_outlet.number_of_cells) + fake_outlet["v"] = np.array([0] * fake_outlet.number_of_cells) + fake_outlet["w"] = np.array([0] * fake_outlet.number_of_cells) + fake_outlet["rho"] = np.array([1] * fake_outlet.number_of_cells) + fake_outlet["U"] = np.stack([fake_outlet["u"], fake_outlet["v"], fake_outlet["w"]]).T + + case = GenericCascadeCase() + case.inlet = fake_inlet + case.outlet = fake_outlet + case.compute_avdr_inout_massave() + assert case.avdr == 1, "should be avdr==1" + + +def test_read_ansys_csv(tmpdir): + from ntrfc.cascade_case.solution.ansys import read_ansys_csv + + data = """ +[Name] +inlet + +[Data] +X [ m ], Y [ m ], Z [ m ], Absolute Pressure [ Pa ], Approximated Mass Flow [ kg s^-1 ], Area [ m^2 ], Aspect Ratio, Connectivity Number, Courant Number, Density [ kg m^-3 ], Density.Beta, Density.Gradient [ kg m^-4 ], Density.Gradient X [ kg m^-4 ], Density.Gradient Y [ kg m^-4 ], Density.Gradient Z [ kg m^-4 ], Domain Node Number [ ], Dynamic Viscosity [ Pa s ], Eddy Viscosity [ Pa s ], Edge Length Ratio, Element Volume Ratio, First Blending Function for BSL and SST model, Force [ N ], Force X [ N ], Force Y [ N ], Force Z [ N ], H Energy.Residual, Heat Flux [ W m^-2 ], Interpolated Mass Flow [ kg s^-1 ], Isothermal Compressibility [ Pa^-1 ], K TurbKE.Residual, Length [ m ], Local Speed of Sound [ m s^-1 ], Mach Number, Mass Flow [ kg s^-1 ], Maximum Face Angle [ degree ], Mesh Expansion Factor, Minimum Face Angle [ degree ], Normal, Normal X, Normal Y, Normal Z, O TurbFreq.Residual, Orthogonality Angle [ degree ], Orthogonality Angle Minimum [ degree ], Orthogonality Factor, Orthogonality Factor Minimum, P Mass.Residual, Pressure [ Pa ], Pressure.Gradient [ kg m^-2 s^-2 ], Pressure.Gradient X [ kg m^-2 s^-2 ], Pressure.Gradient Y [ kg m^-2 s^-2 ], Pressure.Gradient Z [ kg m^-2 s^-2 ], Real Partition Number, Second Blending Function for SST model, Shear Strain Rate [ s^-1 ], Solver Yplus, Specific Heat Capacity at Constant Pressure [ J kg^-1 K^-1 ], Specific Heat Capacity at Constant Volume [ J kg^-1 K^-1 ], Specific Volume [ kg^-1 m^3 ], Static Enthalpy [ J kg^-1 ], Static Entropy [ J kg^-1 K^-1 ], Temperature [ K ], Thermal Conductivity [ W m^-1 K^-1 ], Total Density [ kg m^-3 ], Total Enthalpy [ J kg^-1 ], Total Enthalpy.Beta, Total Enthalpy.Gradient [ m s^-2 ], Total Enthalpy.Gradient X [ m s^-2 ], Total Enthalpy.Gradient Y [ m s^-2 ], Total Enthalpy.Gradient Z [ m s^-2 ], Total Pressure [ Pa ], Total Temperature [ K ], Turbulence Eddy Dissipation [ m^2 s^-3 ], Turbulence Eddy Frequency [ s^-1 ], Turbulence Eddy Frequency.Beta, Turbulence Eddy Frequency.Gradient [ m^-1 s^-1 ], Turbulence Eddy Frequency.Gradient X [ m^-1 s^-1 ], Turbulence Eddy Frequency.Gradient Y [ m^-1 s^-1 ], Turbulence Eddy Frequency.Gradient Z [ m^-1 s^-1 ], Turbulence Kinetic Energy [ m^2 s^-2 ], Turbulence Kinetic Energy.Beta, Turbulence Kinetic Energy.Gradient [ m s^-2 ], Turbulence Kinetic Energy.Gradient X [ m s^-2 ], Turbulence Kinetic Energy.Gradient Y [ m s^-2 ], Turbulence Kinetic Energy.Gradient Z [ m s^-2 ], U Mom.Residual, V Mom.Residual, Velocity [ m s^-1 ], Velocity u [ m s^-1 ], Velocity u.Beta, Velocity u.Gradient [ s^-1 ], Velocity u.Gradient X [ s^-1 ], Velocity u.Gradient Y [ s^-1 ], Velocity u.Gradient Z [ s^-1 ], Velocity v [ m s^-1 ], Velocity v.Beta, Velocity v.Gradient [ s^-1 ], Velocity v.Gradient X [ s^-1 ], Velocity v.Gradient Y [ s^-1 ], Velocity v.Gradient Z [ s^-1 ], Velocity w [ m s^-1 ], Velocity w.Beta, Velocity w.Gradient [ s^-1 ], Velocity w.Gradient X [ s^-1 ], Velocity w.Gradient Y [ s^-1 ], Velocity w.Gradient Z [ s^-1 ], Velocity.Absolute Helicity [ m s^-2 ], Velocity.Curl [ s^-1 ], Velocity.Curl X [ s^-1 ], Velocity.Curl Y [ s^-1 ], Velocity.Curl Z [ s^-1 ], Velocity.Divergence [ s^-1 ], Velocity.Helicity [ m s^-2 ], Velocity.Invariant Q [ s^-2 ], Velocity.Lambda 2 [ s^-2 ], Velocity.Normal Eigen Helicity [ s^-1 ], Velocity.Real Eigen Helicity [ s^-1 ], Velocity.Real Eigenvalue [ s^-1 ], Velocity.Stretched Swirling Strength, Velocity.Swirling Discriminant [ s^-6 ], Velocity.Swirling Normal [ s^-1 ], Velocity.Swirling Normal X [ s^-1 ], Velocity.Swirling Normal Y [ s^-1 ], Velocity.Swirling Normal Z [ s^-1 ], Velocity.Swirling Strength [ s^-1 ], Velocity.Swirling Vector [ s^-1 ], Velocity.Swirling Vector X [ s^-1 ], Velocity.Swirling Vector Y [ s^-1 ], Velocity.Swirling Vector Z [ s^-1 ], Volume [ m^3 ], Volume of Finite Volumes [ m^3 ], Volume Porosity, Vorticity [ s^-1 ], Vorticity X [ s^-1 ], Vorticity Y [ s^-1 ], Vorticity Z [ s^-1 ], W Mom.Residual, Wall Adjacent Temperature [ K ], Wall Distance [ m ], Wall Heat Flow [ W ], Wall Heat Flux [ W m^-2 ], Wall Heat Transfer Coefficient [ W m^-2 K^-1 ], Wall Scale [ m^2 ], Wall Scale.Gradient [ m ], Wall Scale.Gradient X [ m ], Wall Scale.Gradient Y [ m ], Wall Scale.Gradient Z [ m ], Wall Shear [ Pa ], Wall Shear X [ Pa ], Wall Shear Y [ Pa ], Wall Shear Z [ Pa ], X [ m ], Y [ m ], Yplus, Z [ m ] +-4.32099998e-02, 2.71667223e-02, 7.19999988e-03, 1.01331688e+05, 1.62292727e-05, 2.66620447e-07, 3.37049460e+00, 4.00000000e+00, 9.12652771e+02, 1.18748534e+00, 5.01880765e-01, 1.34980842e-03, 1.34323630e-03, -1.33037305e-04, 6.60186517e-10, 374391, 1.83100001e-05, 3.43179890e-05, 3.37050295e+00, 1.00003362e+00, 2.61355156e-11, 2.78491471e-02, -2.78491471e-02, -9.37765310e-10, -1.39739641e-17, 4.58205873e-09, 2.32318477e+04, null, 9.86858140e-06, -1.93089618e-05, 0.00000000e+00, 3.45670288e+02, 1.48291185e-01, 1.62288197e-05, 9.00006638e+01, 1.00001681e+00, 8.99993362e+01, 1.00000000e+00, -1.00000000e+00, 0.00000000e+00, 0.00000000e+00, -1.99453579e-10, 8.99982605e+01, 8.99960709e+01, 1.00000000e+00, 1.00000000e+00, 8.19327681e-08, 1.01331688e+05, 7.51635056e+01, 7.34949417e+01, -1.57494955e+01, -1.37857307e-04, 9.00000000e+00, 2.04488151e-05, 2.02078962e+00, 0.00000000e+00, 1.00440002e+03, 7.17298096e+02, 8.42115641e-01, -9.32114319e+02, -3.15015936e+00, 2.97221954e+02, 2.61000004e-02, 1.20058501e+00, 3.81671967e+02, 9.99995887e-01, 3.64671946e-02, 3.62061970e-02, -4.35509486e-03, 2.89117197e-05, 1.02900391e+05, 2.98529999e+02, 1.55833891e+05, 2.44772672e+05, 9.99962628e-01, 4.66622000e+07, -4.66622000e+07, 3.39963232e+03, -3.13899219e-01, 7.07386017e+00, 9.99986231e-01, 1.42712659e+03, -1.42712659e+03, 1.29137948e-01, -2.24357689e-04, -1.64391804e-06, 1.92604976e-09, 5.12598534e+01, 5.12598534e+01, 9.27763045e-01, 1.04183638e+00, -1.00948608e+00, 2.57605970e-01, 1.63376335e-05, 5.12517290e-05, 9.93830085e-01, 9.78014767e-01, 2.74372727e-01, -9.38739836e-01, 1.91479980e-04, 9.84862591e-09, 9.99980032e-01, 2.10201233e-05, -6.23396636e-06, -4.76814137e-07, 2.00687791e-05, 9.83967539e-03, 1.67678706e-02, -1.91956788e-04, 2.25715994e-05, 1.67667568e-02, -1.94820595e+00, -9.83967539e-03, 8.76925588e-01, 4.98057723e-01, 0.00000000e+00, 0.00000000e+00, -2.06232771e-01, 0.00000000e+00, -2.04907195e-03, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 1.49751295e-10, 1.00000000e+00, 1.78413745e-02, -2.48892920e-05, 9.24213873e-06, 1.78413559e-02, -8.24649030e-11, 0.00000000e+00, 5.33972532e-02, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 1.48127729e-03, 1.04207487e-03, -1.04196486e-03, -1.51321983e-05, -5.06062690e-07, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00, -4.32099998e-02, 2.71667223e-02, 0.00000000e+00, 7.19999988e-03 +-4.32099998e-02, 2.71667223e-02, 7.99999945e-03, 1.01331688e+05, 8.11463906e-06, 1.33310266e-07, 3.37049460e+00, 2.00000000e+00, 9.12652771e+02, 1.18748534e+00, 5.01879096e-01, 1.34980842e-03, 1.34323630e-03, -1.33037305e-04, 6.60186517e-10, 415915, 1.83100001e-05, 3.43179890e-05, 3.37050295e+00, 1.00003314e+00, 2.61355278e-11, 1.39245735e-02, -1.39245735e-02, -4.68882710e-10, 9.73717974e-18, 4.57652538e-09, 2.32318418e+04, null, 9.86858140e-06, -1.93082142e-05, 0.00000000e+00, 3.45670288e+02, 1.48291185e-01, 8.11440987e-06, 9.00006638e+01, 1.00001681e+00, 8.99993362e+01, 1.00000000e+00, -1.00000000e+00, 0.00000000e+00, 0.00000000e+00, -1.99453204e-10, 8.99982605e+01, 8.99960709e+01, 1.00000000e+00, 1.00000000e+00, 8.19329884e-08, 1.01331688e+05, 7.51635056e+01, 7.34949417e+01, -1.57494955e+01, -1.37857307e-04, 9.00000000e+00, 2.04488206e-05, 2.02078962e+00, 0.00000000e+00, 1.00440002e+03, 7.17298096e+02, 8.42115641e-01, -9.32114319e+02, -3.15015936e+00, 2.97221954e+02, 2.61000004e-02, 1.20058501e+00, 3.81671967e+02, 9.99995828e-01, 3.64671946e-02, 3.62061970e-02, -4.35509486e-03, 2.89117197e-05, 1.02900391e+05, 2.98529999e+02, 1.55833891e+05, 2.44772672e+05, 9.99962628e-01, 4.66622000e+07, -4.66622000e+07, 3.39963232e+03, -3.13899219e-01, 7.07386017e+00, 9.99986231e-01, 1.42712659e+03, -1.42712659e+03, 1.29137948e-01, -2.24357689e-04, -1.64392475e-06, 1.71203141e-09, 5.12598534e+01, 5.12598534e+01, 9.27762151e-01, 1.04183638e+00, -1.00948608e+00, 2.57605970e-01, 1.63376335e-05, 5.12942097e-05, 9.93829012e-01, 9.78014767e-01, 2.74372727e-01, -9.38739836e-01, 1.91479980e-04, 1.79399660e-08, 9.99936461e-01, 2.10201233e-05, -6.23396636e-06, -4.76814137e-07, 2.00687791e-05, 9.83967539e-03, 1.67678706e-02, -1.91956788e-04, 2.25715994e-05, 1.67667568e-02, -1.94820595e+00, -9.83967539e-03, 8.76925588e-01, 4.98057723e-01, 0.00000000e+00, 0.00000000e+00, -2.06232771e-01, 0.00000000e+00, -2.04907195e-03, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 7.48756473e-11, 1.00000000e+00, 1.78413745e-02, -2.48892920e-05, 9.24213873e-06, 1.78413559e-02, -1.45853093e-10, 2.97221954e+02, 5.33972457e-02, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 1.48127694e-03, 1.04207487e-03, -1.04196486e-03, -1.51321983e-05, -5.06062690e-07, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00, -4.32099998e-02, 2.71667223e-02, 0.00000000e+00, 7.99999945e-03 +-4.32099998e-02, 2.74999999e-02, 7.99999945e-03, 1.01331688e+05, 4.05736591e-06, 6.66558719e-08, 3.37038159e+00, 1.00000000e+00, 9.12714111e+02, 1.18748534e+00, 4.99523699e-01, 1.34255935e-03, 1.34254259e-03, 6.70538884e-06, 1.29888444e-09, 415916, 1.83100001e-05, 3.43180363e-05, 3.37039137e+00, 1.00000000e+00, 2.61352606e-11, 6.96228677e-03, -6.96228677e-03, -2.35011482e-10, -1.56872173e-17, 4.39857706e-09, 2.32315957e+04, null, 9.86858140e-06, -1.92995467e-05, 0.00000000e+00, 3.45670288e+02, 1.48291230e-01, 4.05720721e-06, 9.00000000e+01, 1.00936902e+00, 9.00000000e+01, 1.00000000e+00, -1.00000000e+00, 0.00000000e+00, 0.00000000e+00, -1.99358502e-10, 8.99954071e+01, 8.99854965e+01, 1.00000000e+00, 9.99999940e-01, 8.24684037e-08, 1.01331688e+05, 7.33581314e+01, 7.33540726e+01, 7.71475077e-01, -1.57518953e-04, 9.00000000e+00, 2.04487151e-05, 1.66363788e+00, 0.00000000e+00, 1.00440002e+03, 7.17298096e+02, 8.42115641e-01, -9.32115295e+02, -3.15015912e+00, 2.97221954e+02, 2.61000004e-02, 1.20058501e+00, 3.81671967e+02, 9.99996245e-01, 3.57960202e-02, 3.57882977e-02, 7.41339638e-04, 5.55646839e-05, 1.02900391e+05, 2.98529999e+02, 1.55837453e+05, 2.44775297e+05, 9.99962628e-01, 4.66642120e+07, -4.66642120e+07, 3.92008179e+03, 6.66646361e-02, 7.07394648e+00, 9.99986231e-01, 1.42719189e+03, -1.42719189e+03, 1.20498359e-01, -1.39350595e-04, -1.63957395e-06, -6.61273647e-10, 5.12598724e+01, 5.12598724e+01, 9.27555621e-01, 1.00561595e+00, -1.00553632e+00, -1.26521336e-02, 9.91433808e-06, 1.59196556e-04, 9.99969363e-01, 6.10395074e-01, -1.29792942e-02, -6.10257030e-01, 1.98969123e-04, 2.10169304e-08, 9.99912798e-01, 2.30479927e-05, -1.93298874e-05, -8.09781341e-06, 9.59118370e-06, 1.06142201e-02, 3.88285960e-04, -2.07066943e-04, 2.92442255e-05, -3.27160582e-04, -1.61578381e+00, -1.06142201e-02, 6.13455892e-01, 3.71907204e-01, 0.00000000e+00, 0.00000000e+00, -1.23083629e-01, 0.00000000e+00, -5.46785363e-04, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 3.74368835e-11, 1.00000000e+00, 4.00465477e-04, -3.11194526e-05, 1.11410372e-05, -3.99099052e-04, -1.43711210e-10, 2.97221954e+02, 5.33971339e-02, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 1.48126925e-03, 1.04204600e-03, -1.04167068e-03, -2.79504129e-05, -9.13810879e-07, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00, -4.32099998e-02, 2.74999999e-02, 0.00000000e+00, 7.99999945e-03 +""" + + fname = tmpdir / "data.csv" + with open(fname, "w") as fobj: + fobj.writelines(data) + surface = read_ansys_csv(fname) + testarrays = ['rho', 'p', 'T', 'U', 'u', 'v', 'w'] + for tn in testarrays: + assert tn in surface.array_names diff --git a/tests/cascadecase/solution/test_openfoam.py b/tests/cascadecase/solution/test_openfoam.py new file mode 100644 index 0000000000000000000000000000000000000000..539dfcf32db234b2b0fb6bc2b8c871e312643a39 --- /dev/null +++ b/tests/cascadecase/solution/test_openfoam.py @@ -0,0 +1,92 @@ +def test_solution(): + from ntrfc.cascade_case.solution.openfoam import openfoam_case + import numpy as np + import pyvista as pv + + fake_inlet = pv.Plane() + fake_inlet["u"] = np.array([1] * fake_inlet.number_of_cells) + fake_inlet["v"] = np.array([0] * fake_inlet.number_of_cells) + fake_inlet["w"] = np.array([0] * fake_inlet.number_of_cells) + fake_inlet["rho"] = np.array([1] * fake_inlet.number_of_cells) + fake_inlet["U"] = np.stack([fake_inlet["u"], fake_inlet["v"], fake_inlet["w"]]).T + + fake_outlet = pv.Plane() + + fake_outlet["u"] = np.array([1] * fake_outlet.number_of_cells) + fake_outlet["v"] = np.array([0] * fake_outlet.number_of_cells) + fake_outlet["w"] = np.array([0] * fake_outlet.number_of_cells) + fake_outlet["rho"] = np.array([1] * fake_outlet.number_of_cells) + fake_outlet["U"] = np.stack([fake_outlet["u"], fake_outlet["v"], fake_outlet["w"]]).T + case = openfoam_case() + case.inlet = fake_inlet + case.outlet = fake_outlet + case.compute_avdr_inout_massave() + assert case.avdr == 1, "should be avdr==1" + + +def test_openfoam_probereading(tmpdir): + from ntrfc.filehandling.datafiles import create_dirstructure + from ntrfc.cascade_case.solution.openfoam import openfoam_case + + probefilestring = """# Probe 0 (-0.1599997156611697 -0.1430012427480623 0.02) # Not Found +# Probe 1 (-0.1411821182118212 -0.1216852152363719 0.02) # Not Found +# Probe 2 (-0.1223642364236424 -0.1003691877246815 0.02) +# Probe 3 (-0.1035463546354636 -0.07905316021299112 0.02) +# Probe 4 (-0.08472847284728473 -0.05773713270130074 0.02) +# Probe 5 (-0.06591059105910591 -0.03642110518961036 0.02) +# Probe 6 (-0.0470927092709271 -0.01510507767791999 0.02) +# Probe 7 (-0.02827482748274826 0.006210949833770418 0.02) +# Probe 8 (-0.009456945694569452 0.02752697734546078 0.02) +# Probe 9 (0.009192919291929197 0.04894795650267177 0.02) +# Probe 10 (0.02960696069606961 0.06865296732743971 0.02) +# Probe 11 (0.05224722472247226 0.08574924993606114 0.02) +# Probe 12 (0.07652565256525654 0.1004819781869841 0.02) +# Probe 13 (0.1023582358235824 0.1122743312794287 0.02) +# Probe 14 (0.1287368736873687 0.1227380007946636 0.02) +# Probe 15 (0.1551155115511551 0.1331984540812058 0.02) +# Probe 16 (0.1814941494149415 0.143658907367748 0.02) +# Probe 17 (0.2078727872787279 0.1541193606542902 0.02) +# Probe 18 (0.2342514251425143 0.1645798139408323 0.02) +# Probe 19 (0.2599997156611698 0.1747904156361355 0.02) +# Probe 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 +# Time + 0.03161670583519985 (-1e+300 -1e+300 -1e+300) (-1e+300 -1e+300 -1e+300) (46.35401464237102 49.64485123866201 0.009270176741351522) (46.79550306530624 50.08611033681288 0.09272118874391876) (45.9459533343206 49.87779685922583 0.01462953458600582) (46.12027564799758 49.97996423468657 -0.0527782967305729) (46.36383372668006 49.89889593844771 -0.155023459154379) (45.67672615951206 49.65029568884417 -0.2918631257735307) (47.68305274004029 51.3575417928603 -0.1594578663112666) (50.35197988441984 47.62926323629534 0.2878495929921642) (50.94802741389357 40.49905535044272 """ + dirstructure = ["of_fake_case/postProcessing/Probes/", + "of_fake_case/postProcessing/Probes/0.01"] + create_dirstructure(dirstructure, tmpdir) + + tmpfname = f"{tmpdir}/{dirstructure[1]}/U" + with open(tmpfname, "w") as fobj: + fobj.writelines(probefilestring) + + case = openfoam_case() + case.read_openfoam_probes(f"{tmpdir}/{dirstructure[0]}") + case.probes.plot_all() + case.probes.plot_val("U") + + +def test_read_openfoam_sliceseries(tmpdir): + from ntrfc.cascade_case.solution.openfoam import openfoam_case + import pyvista as pv + import os + import numpy as np + + noslices = 3 + test_slices = [pv.Plane() for i in range(noslices)] + slices = [] + ts = [] + post = f"{tmpdir}/postProcessing/" + slicegroupdir = f"{tmpdir}/postProcessing/some" + os.mkdir(post) + os.mkdir(slicegroupdir) + for idx, slice in enumerate(test_slices): + slice["U"] = np.zeros(slice.number_of_cells) + slice = slice.point_data_to_cell_data() + os.mkdir(f"{slicegroupdir}/{idx}") + fpath = f"{slicegroupdir}/{idx}/someface.vtk" + slices.append(fpath) + slice.save(fpath) + ts.append(idx) + + test_solution = openfoam_case() + test_solution.read_openfoam_sliceseries(f"{tmpdir}/postProcessing/some", "someface.vtk")