# HG changeset patch # User Pooria DANAEIFAR <pouryadanaeifar@gmail.com> # Date 1683711271 -7200 # Wed May 10 11:34:31 2023 +0200 # Node ID 186d5c24aa9c6f567ab8a089ce864c7de05df46a # Parent 13b83c2f4ec58023cb64686270f7741ca5417e16 Add fluidsimfoam_phill solver diff --git a/doc/examples/fluidsimfoam-phill/LICENSE b/doc/examples/fluidsimfoam-phill/LICENSE new file mode 100644 --- /dev/null +++ b/doc/examples/fluidsimfoam-phill/LICENSE @@ -0,0 +1,29 @@ +BSD 3-Clause License + +Copyright (c) 2023, Pierre Augier +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + +1. Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + +2. Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + +3. Neither the name of the copyright holder nor the names of its + contributors may be used to endorse or promote products derived from + this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/doc/examples/fluidsimfoam-phill/README.md b/doc/examples/fluidsimfoam-phill/README.md new file mode 100644 --- /dev/null +++ b/doc/examples/fluidsimfoam-phill/README.md @@ -0,0 +1,109 @@ +# Fluidsimfoam solver for periodic hills (phill) + +This [Fluidsimfoam] solver demonstrates how to write a solver for the simulation of the flow over periodic hills (phill). + +## Install +You can install this solver using this command: + +```sh +pip install fluidsimfoam-phill +``` + +## Run +After installing this solver you can use this script to run a phill case. +```sh +python3 doc/examples/scripts/tuto_phill.py +``` +## Customized Run + +The first step to run a simulation is to create a `params` object with default parameters: +```sh +from fluidsimfoam_phill import Simul + +params = Simul.create_default_params() +``` + +## Modifying the parameters + + +Of course, the parameters can be modified. For instance, let's change the default 2D flow over 2D topography to a 3D flow over a 2D topography by just changing the number of elements in the z-direction in the blochMeshDict: + +```sh +params.block_mesh_dict.lz = 0.5 +params.block_mesh_dict.nz = 50 +``` + +Or you can change the subdirectory: + +```sh +params.output.sub_directory = "tests_fluidsimfoam/phill/" +``` +We are able to change other parameters in the controlDict or some other files in order to run different simulations, for instance: +```sh +params.control_dict.end_time = 0.5 +params.control_dict.delta_t = 0.01 +params.control_dict.start_from = 'startTime' +params.turbulence_properties.simulation_type = "RAS" +``` +After you assign or change all parameters you need, you could create the simulation object. + +## Creation of the simulation object and directory + +Now let’s create the simulation object (We usually use the name `sim`): +```sh +sim = Simul(params) +``` +Information is given about the structure of the sim object (which has attributes sim.oper, sim.output and sim.make corresponding to different aspects of the simulation) and about the creation of some files. When you create this object, you have made a directory for your case that contains all necessary directories (`0`, `system`, `constant`) and files (`fvSolution`, `fvSchemes`, `blockMeshDict` and etc). This directory is accessible by using this command: + +```sh +sim.path_run +``` + +Or you can easily see the list of contents of this directory: + +```sh +ls {sim.path_run} +``` +Something like this: +```sh +0/ constant/ info_solver.xml params_simul.xml system/ tasks.py +``` + +## Run Control + +Now, you have the case ready to start the simulation. You can run this case by this command: + +```sh +sim.make.exec("run") +``` +Or if you want to clean this case even polyMesh: +```sh +sim.make.exec("clean") +``` +If you want to see the run command list: + +```sh +sim.make.list() +``` + +```sh +Available tasks: + + block-mesh + clean + funky-set-fields + run + sets-to-zones + topo-set +``` +If you want to use any of these commands like making blockMeshDict you can easily use this: +```sh +sim.make.exec("block-mesh") +``` + + + + +For more details, see https://fluidsimfoam.readthedocs.io/en/latest/install.html + +[fluidsimfoam]: https://foss.heptapod.net/fluiddyn/fluidsimfoam diff --git a/doc/examples/fluidsimfoam-phill/pyproject.toml b/doc/examples/fluidsimfoam-phill/pyproject.toml new file mode 100644 --- /dev/null +++ b/doc/examples/fluidsimfoam-phill/pyproject.toml @@ -0,0 +1,24 @@ +[build-system] +requires = [ + "setuptools>=49.5.0", + "wheel", + ] +build-backend = "setuptools.build_meta" + +[project] +name = "fluidsimfoam-phill" +authors = [ + {name = "Pierre Augier", email = "pierre.augier@univ-grenoble-alpes.fr"}, + {name = "Pooria Danaeifar", email = "pouryadanaeifar@gmail.com"}, +] +description = 'Simulations of the flow over periodic hills (phill)' +readme = "README.md" +requires-python = ">=3.8" +license = {text = "BSD-3-Clause"} +version = "0.0.1" +dependencies = [ + "fluidsimfoam >= 0.0.1", +] + +[project.entry-points."fluidsimfoam.solvers"] +phill = "fluidsimfoam_phill.solver" diff --git a/doc/examples/fluidsimfoam-phill/src/fluidsimfoam_phill/__init__.py b/doc/examples/fluidsimfoam-phill/src/fluidsimfoam_phill/__init__.py new file mode 100644 --- /dev/null +++ b/doc/examples/fluidsimfoam-phill/src/fluidsimfoam_phill/__init__.py @@ -0,0 +1,3 @@ +from fluidsimfoam_phill.solver import Simul + +__all__ = ["Simul"] diff --git a/doc/examples/fluidsimfoam-phill/src/fluidsimfoam_phill/output.py b/doc/examples/fluidsimfoam-phill/src/fluidsimfoam_phill/output.py new file mode 100644 --- /dev/null +++ b/doc/examples/fluidsimfoam-phill/src/fluidsimfoam_phill/output.py @@ -0,0 +1,247 @@ +from textwrap import dedent + +from inflection import underscore + +from fluidsimfoam.foam_input_files import DEFAULT_HEADER, Dict, FoamInputFile +from fluidsimfoam.foam_input_files.blockmeshhelper import ( + BlockMeshDict, + Point, + SimpleGrading, + Vertex, +) +from fluidsimfoam.output import Output + +code_control_dict_functions = dedent( + """ + adjustTimeStep yes; + libs (atmosphericModels); + + functions + { + fieldAverage1 + { + type fieldAverage; + libs (fieldFunctionObjects); + writeControl writeTime; + + fields + ( + U + { + mean on; + prime2Mean off; + base time; + } + ); + } + } + +""" +) + +_attribs_transport_prop = { + "transportModel": "Newtonian", + "nu nu [0 2 -1 0 0 0 0]": 0.0001, + "Pr Pr [0 0 0 0 0 0 0]": 10, + "beta": 3e-03, + "TRef": 300, + "Prt": 0.85, +} + + +class OutputPHill(Output): + """Output for the phill solver""" + + variable_names = ["U", "rhok", "p_rgh", "T", "alphat"] + system_files_names = Output.system_files_names + [ + "blockMeshDict", + "topoSetDict", + "funkySetFieldsDict", + ] + constant_files_names = Output.constant_files_names + [ + "g", + "fvOptions", + "MRFProperties", + ] + + # @classmethod + # def _set_info_solver_classes(cls, classes): + # """Set the the classes for info_solver.classes.Output""" + # super()._set_info_solver_classes(classes) + + @classmethod + def _complete_params_control_dict(cls, params): + super()._complete_params_control_dict(params) + + default = { + "application": "buoyantBoussinesqPimpleFoam", + "startFrom": "startTime", + "endTime": 60, + "deltaT": 0.05, + "writeControl": "adjustableRunTime", + "writeInterval": 1, + "writeFormat": "ascii", + "writeCompression": "off", + "runTimeModifiable": "yes", + "adjustTimeStep": "yes", + "maxCo": 0.6, + "maxAlphaCo": 0.6, + "maxDeltaT": 1, + } + for key, value in default.items(): + try: + params.control_dict[underscore(key)] = value + except AttributeError: + # TODO: Fix adding keys which are not in DEFAULT_CONTROL_DICT + params.control_dict._set_attribs({underscore(key): value}) + + def make_code_control_dict(self, params): + code = super().make_code_control_dict(params) + return code + code_control_dict_functions + + @classmethod + def _complete_params_transport_properties(cls, params): + params._set_child( + "transport_properties", + attribs=_attribs_transport_prop, + doc="""TODO""", + ) + + def make_tree_transport_properties(self, params): + return FoamInputFile( + info={ + "version": "2.0", + "format": "ascii", + "class": "dictionary", + "object": "transportProperties", + }, + children={ + key: params.transport_properties[key] + for key in _attribs_transport_prop.keys() + }, + header=DEFAULT_HEADER, + ) + + @classmethod + def _complete_params_turbulence_properties(cls, params): + params._set_child( + "turbulence_properties", + attribs={"simulation_type": "laminar"}, + doc="""TODO""", + ) + + def make_tree_turbulence_properties(self, params): + tree = super().make_tree_turbulence_properties(params) + return tree + + @classmethod + def _complete_params_block_mesh_dict(cls, params): + super()._complete_params_block_mesh_dict(params) + default = {"nx": 20, "ny": 30, "nz": 1} + default.update({"lx": 1.0, "ly": 1.0, "lz": 0.01, "scale": 1}) + for key, value in default.items(): + params.block_mesh_dict[key] = value + + def make_code_block_mesh_dict(self, params): + nx = params.block_mesh_dict.nx + ny = params.block_mesh_dict.ny + nz = params.block_mesh_dict.nz + + lx = params.block_mesh_dict.lx + ly = params.block_mesh_dict.ly + lz = params.block_mesh_dict.lz + + bmd = BlockMeshDict() + bmd.set_scale(params.block_mesh_dict.scale) + bmd.set_metric(params.block_mesh_dict.metric) + + basevs = [ + Vertex(0, ly, 0, "v0"), + Vertex(0.5, ly, 0, "v1"), + Vertex(1.5, ly, 0, "v2"), + Vertex(6, ly, 0, "v3"), + Vertex(6, ly, lz, "v4"), + Vertex(1.5, ly, lz, "v5"), + Vertex(0.5, ly, lz, "v6"), + Vertex(0, ly, lz, "v7"), + ] + + for v in basevs: + bmd.add_vertex(v.x, 0, v.z, v.name + "-0") + bmd.add_vertex(v.x, v.y, v.z, v.name + "+y") + + b0 = bmd.add_hexblock( + ("v0-0", "v1-0", "v1+y", "v0+y", "v7-0", "v6-0", "v6+y", "v7+y"), + (nx, ny, nz), + "b0", + SimpleGrading(1, [[0.1, 0.25, 41.9], [0.9, 0.75, 1]], 1), + ) + + b1 = bmd.add_hexblock( + ("v1-0", "v2-0", "v2+y", "v1+y", "v6-0", "v5-0", "v5+y", "v6+y"), + (nx, ny, nz), + "b1", + SimpleGrading(1, [[0.1, 0.25, 41.9], [0.9, 0.75, 1]], 1), + ) + + b2 = bmd.add_hexblock( + ("v2-0", "v3-0", "v3+y", "v2+y", "v5-0", "v4-0", "v4+y", "v5+y"), + (225, ny, nz), + "b2", + SimpleGrading(1, [[0.1, 0.25, 41.9], [0.9, 0.75, 1]], 1), + ) + + bmd.add_splineedge( + ["v1-0", "v2-0"], + "spline0", + [ + Point(0.6, 0.0124, 0), + Point(0.7, 0.0395, 0), + Point(0.8, 0.0724, 0), + Point(0.9, 0.132, 0), + Point(1, 0.172, 0), + Point(1.1, 0.132, 0), + Point(1.2, 0.0724, 0), + Point(1.3, 0.0395, 0), + Point(1.4, 0.0124, 0), + ], + ) + bmd.add_splineedge( + ["v6-0", "v5-0"], + "spline1", + [ + Point(0.6, 0.0124, lz), + Point(0.7, 0.0395, lz), + Point(0.8, 0.0724, lz), + Point(0.9, 0.132, lz), + Point(1, 0.172, lz), + Point(1.1, 0.132, lz), + Point(1.2, 0.0724, lz), + Point(1.3, 0.0395, lz), + Point(1.4, 0.0124, lz), + ], + ) + + bmd.add_boundary( + "wall", "top", [b0.face("n"), b1.face("n"), b2.face("n")] + ) + bmd.add_boundary( + "wall", "bottom", [b0.face("s"), b1.face("s"), b2.face("s")] + ) + bmd.add_cyclic_boundaries("outlet", "inlet", b2.face("e"), b0.face("w")) + # bmd.add_boundary("inlet", "inlet", [b2.face("e")]) + # bmd.add_boundary("outlet", "outlet", [b0.face("w")]) + bmd.add_boundary( + "empty", + "frontandbackplanes", + [ + b0.face("b"), + b1.face("b"), + b2.face("b"), + b0.face("t"), + b1.face("t"), + b2.face("t"), + ], + ) + + return bmd.format() diff --git a/doc/examples/fluidsimfoam-phill/src/fluidsimfoam_phill/solver.py b/doc/examples/fluidsimfoam-phill/src/fluidsimfoam_phill/solver.py new file mode 100644 --- /dev/null +++ b/doc/examples/fluidsimfoam-phill/src/fluidsimfoam_phill/solver.py @@ -0,0 +1,27 @@ +from fluidsimfoam.info import InfoSolver +from fluidsimfoam.solvers.base import SimulFoam + + +class InfoSolverPHill(InfoSolver): + """Contain the information on a :class:`fluidsimfoam_phill.solver.Simul` + instance. + + """ + + def _init_root(self): + super()._init_root() + self.module_name = "fluidsimfoam_phill.solver" + self.class_name = "Simul" + self.short_name = "phill" + + self.classes.Output.module_name = "fluidsimfoam_phill.output" + self.classes.Output.class_name = "OutputPHill" + + +class SimulPHill(SimulFoam): + """A solver which compiles and runs using a Snakefile.""" + + InfoSolver = InfoSolverPHill + + +Simul = SimulPHill diff --git a/doc/examples/fluidsimfoam-phill/src/fluidsimfoam_phill/templates/MRFProperties.jinja b/doc/examples/fluidsimfoam-phill/src/fluidsimfoam_phill/templates/MRFProperties.jinja new file mode 100644 --- /dev/null +++ b/doc/examples/fluidsimfoam-phill/src/fluidsimfoam_phill/templates/MRFProperties.jinja @@ -0,0 +1,21 @@ +FoamFile +{ + version 2.0; + format ascii; + class dictionary; + location "constant"; + object MRFProperties; +} + +/* +MRF1 +{ + active true; + selectionMode cellZone; + cellZone rotor; + + origin (0 0 0); + axis (0 0 1); + omega constant 0.2; +} +*/ \ No newline at end of file diff --git a/doc/examples/fluidsimfoam-phill/src/fluidsimfoam_phill/templates/T.jinja b/doc/examples/fluidsimfoam-phill/src/fluidsimfoam_phill/templates/T.jinja new file mode 100644 --- /dev/null +++ b/doc/examples/fluidsimfoam-phill/src/fluidsimfoam_phill/templates/T.jinja @@ -0,0 +1,45 @@ +FoamFile +{ + version 2.0; + format ascii; + class volScalarField; + object T; +} + +dimensions [0 0 0 1 0 0 0]; + +internalField uniform 300; + +boundaryField +{ + outlet + { + type cyclic; + } + + inlet + { + type cyclic; + } + + bottom + { + type atmTurbulentHeatFluxTemperature; + heatSource flux; + alphaEff alphaEff; + Cp0 1005.0; + q uniform 0; + value uniform 300; + + } + + top + { + type zeroGradient; + } + + frontandbackplanes + { + type empty; + } +} diff --git a/doc/examples/fluidsimfoam-phill/src/fluidsimfoam_phill/templates/U.jinja b/doc/examples/fluidsimfoam-phill/src/fluidsimfoam_phill/templates/U.jinja new file mode 100644 --- /dev/null +++ b/doc/examples/fluidsimfoam-phill/src/fluidsimfoam_phill/templates/U.jinja @@ -0,0 +1,42 @@ +FoamFile +{ + version 2.0; + format binary; + class volVectorField; + location "0"; + object U; +} + +dimensions [0 1 -1 0 0 0 0]; + +internalField uniform (0.12 0 0); + +boundaryField +{ + outlet + { + type cyclic; + } + + inlet + { + type cyclic; + } + + bottom + { + type fixedValue; + value uniform (0 0 0); + } + + top + { + type slip; + } + + frontandbackplanes + { + type empty; + } + +} diff --git a/doc/examples/fluidsimfoam-phill/src/fluidsimfoam_phill/templates/alphat.jinja b/doc/examples/fluidsimfoam-phill/src/fluidsimfoam_phill/templates/alphat.jinja new file mode 100644 --- /dev/null +++ b/doc/examples/fluidsimfoam-phill/src/fluidsimfoam_phill/templates/alphat.jinja @@ -0,0 +1,40 @@ +FoamFile +{ + version 2.0; + format ascii; + class volScalarField; + location "0"; + object alphat; +} + +dimensions [0 2 -1 0 0 0 0]; + +internalField uniform 0; + +boundaryField +{ + bottom + { + type zeroGradient; + } + + inlet + { + type cyclic; + } + + outlet + { + type cyclic; + } + + top + { + type zeroGradient; + } + + frontandbackplanes + { + type empty; + } +} diff --git a/doc/examples/fluidsimfoam-phill/src/fluidsimfoam_phill/templates/funkySetFieldsDict.jinja b/doc/examples/fluidsimfoam-phill/src/fluidsimfoam_phill/templates/funkySetFieldsDict.jinja new file mode 100644 --- /dev/null +++ b/doc/examples/fluidsimfoam-phill/src/fluidsimfoam_phill/templates/funkySetFieldsDict.jinja @@ -0,0 +1,27 @@ + +FoamFile +{ + version 2.0; + format ascii; + class dictionary; + location "system"; + object setFieldsDict; +} + +expressions +( + grad_inv_rhok + { + variables + ( + "rho0=1000;" + "height=1;" + "delta_rho=-0.000102;" + ); + + field rhok; + value uniform 1000; + expression "rho0 + pos().y / height * delta_rho"; + keepPatches 1; + } +); diff --git a/doc/examples/fluidsimfoam-phill/src/fluidsimfoam_phill/templates/fvOptions.jinja b/doc/examples/fluidsimfoam-phill/src/fluidsimfoam_phill/templates/fvOptions.jinja new file mode 100644 --- /dev/null +++ b/doc/examples/fluidsimfoam-phill/src/fluidsimfoam_phill/templates/fvOptions.jinja @@ -0,0 +1,50 @@ +FoamFile +{ + version 2.0; + format ascii; + class dictionary; + location "constant"; + object fvOptions; +} + +/* +pressureGradient +{ + type vectorSemiImplicitSource; + selectionMode all; + volumeMode specific; + sources + { + U ((0 1.978046e-03 0) 0); + } +} +/* + + +atmCoriolisUSource1 +{ + type atmCoriolisUSource; + atmCoriolisUSourceCoeffs + { + selectionMode all; + // Omega (0 0 5.65156e-5); + latitude 45.188; + planetaryRotationPeriod 23.9344694; + } +} + + +/* +momentumSource +{ + type meanVelocityForce; + active yes; + + meanVelocityForceCoeffs + { + selectionMode all; + fields (U); + Ubar (1.0 0 0); + } +} +*/ diff --git a/doc/examples/fluidsimfoam-phill/src/fluidsimfoam_phill/templates/fvSchemes.jinja b/doc/examples/fluidsimfoam-phill/src/fluidsimfoam_phill/templates/fvSchemes.jinja new file mode 100644 --- /dev/null +++ b/doc/examples/fluidsimfoam-phill/src/fluidsimfoam_phill/templates/fvSchemes.jinja @@ -0,0 +1,46 @@ +FoamFile +{ + version 2.0; + format ascii; + class dictionary; + location "system"; + object fvSchemes; +} + +ddtSchemes +{ + default Euler implicit; +} + +gradSchemes +{ + default Gauss linear; +} + +divSchemes +{ + default none; + + div(phi,U) Gauss upwind; + div(phi,T) Gauss upwind; + div(phi,rhok) Gauss upwind; + div(phi,R) Gauss upwind; + div(R) Gauss linear; + div((nuEff*dev2(T(grad(U))))) Gauss linear; + div((nuEff*dev(T(grad(U))))) Gauss linear; +} + +laplacianSchemes +{ + default Gauss linear corrected; +} + +interpolationSchemes +{ + default linear; +} + +snGradSchemes +{ + default uncorrected; +} diff --git a/doc/examples/fluidsimfoam-phill/src/fluidsimfoam_phill/templates/fvSolution.jinja b/doc/examples/fluidsimfoam-phill/src/fluidsimfoam_phill/templates/fvSolution.jinja new file mode 100644 --- /dev/null +++ b/doc/examples/fluidsimfoam-phill/src/fluidsimfoam_phill/templates/fvSolution.jinja @@ -0,0 +1,56 @@ +FoamFile +{ + version 2.0; + format ascii; + class dictionary; + location "system"; + object fvSolution; +} + +solvers +{ + p_rgh + { + solver PCG; + preconditioner DIC; + tolerance 1e-8; + relTol 0.01; + } + + p_rghFinal + { + $p_rgh; + relTol 0; + } + + "(U|rhok|R|T)" + { + solver PBiCG; + preconditioner DILU; + tolerance 1e-6; + relTol 0.1; + } + + "(U|rhok|R|T)Final" + { + $U; + relTol 0; + } +} + +PIMPLE +{ + momentumPredictor no; + nNonOrthogonalCorrectors 0; + nCorrectors 2; + pRefCell 0; + pRefValue 0; +} + +relaxationFactors +{ + equations + { + ".*" 1.0; + } +} diff --git a/doc/examples/fluidsimfoam-phill/src/fluidsimfoam_phill/templates/g.jinja b/doc/examples/fluidsimfoam-phill/src/fluidsimfoam_phill/templates/g.jinja new file mode 100644 --- /dev/null +++ b/doc/examples/fluidsimfoam-phill/src/fluidsimfoam_phill/templates/g.jinja @@ -0,0 +1,11 @@ +FoamFile +{ + version 2.0; + format ascii; + class uniformDimensionedVectorField; + location "constant"; + object g; +} + +dimensions [0 1 -2 0 0 0 0]; +value (0 -9.81 0); diff --git a/doc/examples/fluidsimfoam-phill/src/fluidsimfoam_phill/templates/p_rgh.jinja b/doc/examples/fluidsimfoam-phill/src/fluidsimfoam_phill/templates/p_rgh.jinja new file mode 100644 --- /dev/null +++ b/doc/examples/fluidsimfoam-phill/src/fluidsimfoam_phill/templates/p_rgh.jinja @@ -0,0 +1,41 @@ +FoamFile +{ + version 2.0; + format ascii; + class volScalarField; + object p_rgh; +} + +dimensions [0 2 -2 0 0 0 0]; + +internalField uniform 0; + +boundaryField +{ + inlet + { + type cyclic; + } + + outlet + { + type cyclic; + } + + bottom + { + type fixedFluxPressure; + rho rhok; + value uniform 0; + } + + top + { + type zeroGradient; + } + + frontandbackplanes + { + type empty; + } +} diff --git a/doc/examples/fluidsimfoam-phill/src/fluidsimfoam_phill/templates/rhok.jinja b/doc/examples/fluidsimfoam-phill/src/fluidsimfoam_phill/templates/rhok.jinja new file mode 100644 --- /dev/null +++ b/doc/examples/fluidsimfoam-phill/src/fluidsimfoam_phill/templates/rhok.jinja @@ -0,0 +1,40 @@ +FoamFile +{ + version 2.0; + format ascii; + class volScalarField; + location "0"; + object rhok; +} + +dimensions [0 0 0 0 0 0 0]; + +internalField uniform 1.15; + +boundaryField +{ + top + { + type zeroGradient; + } + + bottom + { + type zeroGradient; + } + + frontandbackplanes + { + type empty; + } + + outlet + { + type cyclic; + } + + inlet + { + type cyclic; + } +} diff --git a/doc/examples/fluidsimfoam-phill/src/fluidsimfoam_phill/templates/tasks.py b/doc/examples/fluidsimfoam-phill/src/fluidsimfoam_phill/templates/tasks.py new file mode 100644 --- /dev/null +++ b/doc/examples/fluidsimfoam-phill/src/fluidsimfoam_phill/templates/tasks.py @@ -0,0 +1,20 @@ +from invoke import task + +from fluidsimfoam.tasks import ( + block_mesh, + clean, + funky_set_fields, + sets_to_zones, + topo_set, +) + + +@task(funky_set_fields) +def run(context): + with open("system/controlDict") as file: + for line in file: + if line.startswith("application "): + application = line.split()[-1] + break + + context.run(application) diff --git a/doc/examples/fluidsimfoam-phill/src/fluidsimfoam_phill/templates/topoSetDict.jinja b/doc/examples/fluidsimfoam-phill/src/fluidsimfoam_phill/templates/topoSetDict.jinja new file mode 100644 --- /dev/null +++ b/doc/examples/fluidsimfoam-phill/src/fluidsimfoam_phill/templates/topoSetDict.jinja @@ -0,0 +1,24 @@ +FoamFile +{ + version 2.0; + format ascii; + class dictionary; + location "system"; + object topoSetDict; +} + +actions +( + { + name rotor; + type cellSet; + action new; + source cylinderToCell; + sourceInfo + { + p1 (0 0 0); + p2 (0 0 0.5); + radius 6.5; + } + } +); diff --git a/doc/examples/scripts/tuto_phill.py b/doc/examples/scripts/tuto_phill.py new file mode 100644 --- /dev/null +++ b/doc/examples/scripts/tuto_phill.py @@ -0,0 +1,7 @@ +from fluidsimfoam_phill import Simul + +params = Simul.create_default_params() + +params.output.sub_directory = "examples_fluidsimfoam/phill" + +sim = Simul(params) diff --git a/pyproject.toml b/pyproject.toml --- a/pyproject.toml +++ b/pyproject.toml @@ -33,6 +33,7 @@ fluidsimfoam-cbox = { path = "./doc/examples/fluidsimfoam-cbox/", develop = true } fluidsimfoam-sed = { path = "./doc/examples/fluidsimfoam-sed/", develop = true } fluidsimfoam-cavity = { path = "./doc/examples/fluidsimfoam-cavity/", develop = true } +fluidsimfoam-phill = { path = "./doc/examples/fluidsimfoam-phill/", develop = true } pytest-mock = "^3.10.0" pytest-cov = "^4.0.0" diff --git a/src/fluidsimfoam/foam_input_files/blockmesh/__init__.py b/src/fluidsimfoam/foam_input_files/blockmesh/__init__.py --- a/src/fluidsimfoam/foam_input_files/blockmesh/__init__.py +++ b/src/fluidsimfoam/foam_input_files/blockmesh/__init__.py @@ -112,7 +112,7 @@ """Generate Face object index is number or keyword to identify the face of Hex 0 = 'w' = 'xm' = '-100' = (0 4 7 3) - 1 = 'e' = 'xp' = '100' = (1 2 5 6) + 1 = 'e' = 'xp' = '100' = (1 2 6 5) 2 = 's' = 'ym' = '0-10' = (0 1 5 4) 3 = 'n' = 'yp' = '010' = (2 3 7 6) 4 = 'b' = 'zm' = '00-1' = (0 3 2 1) = "bottom" @@ -199,8 +199,8 @@ "{\n" + f" type {self.type_};\n neighbourPatch {self.neighbour};\n faces\n (" ) - for f in self.faces: - tmp.append(f" {f.format(vertices)}") + for face in self.faces: + tmp.append(f" {face.format(vertices)}") tmp.append(" );\n}") return "\n".join(tmp) @@ -309,6 +309,28 @@ return b def add_cyclic_boundaries(self, name0, name1, faces0, faces1): + """In order to add cyclic boundary: + boundary name, neighbour name, boundary face, neighbour face. For example: + add_cyclic_boundaries("outlet", "inlet", b0.face("e"), b0.face("w")) + The result will be like: + outlet + { + type cyclic; + neighbourPatch inlet; + faces + ( + (3 7 15 11) // f-b2-n (v3-0 v3+y v4+y v4-0) + ); + } + inlet + { + type cyclic; + neighbourPatch outlet; + faces + ( + (0 8 12 4) // f-b0-w (v0-0 v7-0 v7+y v0+y) + ); + }""" b0 = self.add_boundary("cyclic", name0, faces0, neighbour=name1) b1 = self.add_boundary("cyclic", name1, faces1, neighbour=name0) return b0, b1 diff --git a/src/fluidsimfoam/tasks.py b/src/fluidsimfoam/tasks.py --- a/src/fluidsimfoam/tasks.py +++ b/src/fluidsimfoam/tasks.py @@ -26,11 +26,32 @@ @task(block_mesh) +def topo_set(context): + if not Path("system/topoSetDict").exists(): + print("topoSet not found!") + else: + context.run("topoSet") + + +@task(topo_set) +def sets_to_zones(context): + context.run("setsToZones") + + +@task(sets_to_zones) +def funky_set_fields(context): + if not Path("system/funkySetFieldsDict").exists(): + print("funkySetFields not found!") + else: + context.run("funkySetFields -time 0") + + +@task(block_mesh) def polymesh(context): pass -@task(polymesh) +@task(block_mesh) def run(context): """Main target to launch a simulation""" with open("system/controlDict") as file: diff --git a/tests/data_blockmesh/blockmesh_phill b/tests/data_blockmesh/blockmesh_phill new file mode 100644 --- /dev/null +++ b/tests/data_blockmesh/blockmesh_phill @@ -0,0 +1,133 @@ +/*--------------------------------*- C++ -*----------------------------------*\ +| ========= | | +| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox | +| \\ / O peration | Version: v2206 | +| \\ / A nd | Website: www.openfoam.com | +| \\/ M anipulation | | +\*---------------------------------------------------------------------------*/ +FoamFile +{ + version 2.0; + format ascii; + class dictionary; + object blockMeshDict; +} +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +scale 1; + +vertices +( + ( 0 0 0 ) // 0 v0-0 + ( 0.5 0 0 ) // 1 v1-0 + ( 1.5 0 0 ) // 2 v2-0 + ( 6 0 0 ) // 3 v3-0 + ( 0 1 0 ) // 4 v0+y + ( 0.5 1 0 ) // 5 v1+y + ( 1.5 1 0 ) // 6 v2+y + ( 6 1 0 ) // 7 v3+y + ( 0 0 0.05 ) // 8 v7-0 + ( 0.5 0 0.05 ) // 9 v6-0 + ( 1.5 0 0.05 ) // 10 v5-0 + ( 6 0 0.05 ) // 11 v4-0 + ( 0 1 0.05 ) // 12 v7+y + ( 0.5 1 0.05 ) // 13 v6+y + ( 1.5 1 0.05 ) // 14 v5+y + ( 6 1 0.05 ) // 15 v4+y +); + +blocks +( + hex (0 1 5 4 8 9 13 12) b0 (50 100 1) simpleGrading (1 ( ( 0.1 0.25 41.9 ) ( 0.9 0.75 1 ) ) 1) // b0 (v0-0 v1-0 v1+y v0+y v7-0 v6-0 v6+y v7+y) + hex (1 2 6 5 9 10 14 13) b1 (50 100 1) simpleGrading (1 ( ( 0.1 0.25 41.9 ) ( 0.9 0.75 1 ) ) 1) // b1 (v1-0 v2-0 v2+y v1+y v6-0 v5-0 v5+y v6+y) + hex (2 3 7 6 10 11 15 14) b2 (225 100 1) simpleGrading (1 ( ( 0.1 0.25 41.9 ) ( 0.9 0.75 1 ) ) 1) // b2 (v2-0 v3-0 v3+y v2+y v5-0 v4-0 v4+y v5+y) +); + +edges +( + spline 1 2 // spline0 (v1-0 v2-0) + ( + ( 0.6 0.0124 0 ) + ( 0.7 0.0395 0 ) + ( 0.8 0.0724 0 ) + ( 0.9 0.132 0 ) + ( 1 0.172 0 ) + ( 1.1 0.132 0 ) + ( 1.2 0.0724 0 ) + ( 1.3 0.0395 0 ) + ( 1.4 0.0124 0 ) +) + spline 9 10 // spline1 (v6-0 v5-0) + ( + ( 0.6 0.0124 0.05 ) + ( 0.7 0.0395 0.05 ) + ( 0.8 0.0724 0.05 ) + ( 0.9 0.132 0.05 ) + ( 1 0.172 0.05 ) + ( 1.1 0.132 0.05 ) + ( 1.2 0.0724 0.05 ) + ( 1.3 0.0395 0.05 ) + ( 1.4 0.0124 0.05 ) +) +); + +boundary +( + top + { + type wall; + faces + ( + (5 4 12 13) // f-b0-n (v1+y v0+y v7+y v6+y) + (6 5 13 14) // f-b1-n (v2+y v1+y v6+y v5+y) + (7 6 14 15) // f-b2-n (v3+y v2+y v5+y v4+y) + ); + } + bottom + { + type wall; + faces + ( + (0 1 9 8) // f-b0-s (v0-0 v1-0 v6-0 v7-0) + (1 2 10 9) // f-b1-s (v1-0 v2-0 v5-0 v6-0) + (2 3 11 10) // f-b2-s (v2-0 v3-0 v4-0 v5-0) + ); + } + outlet + { + type cyclic; + neighbourPatch inlet; + faces + ( + (3 7 15 11) // f-b2-n (v3-0 v3+y v4+y v4-0) + ); + } + inlet + { + type cyclic; + neighbourPatch outlet; + faces + ( + (0 8 12 4) // f-b0-w (v0-0 v7-0 v7+y v0+y) + ); + } + frontandbackplanes + { + type empty; + faces + ( + (0 4 5 1) // f-b0-b (v0-0 v0+y v1+y v1-0) + (1 5 6 2) // f-b1-b (v1-0 v1+y v2+y v2-0) + (2 6 7 3) // f-b2-b (v2-0 v2+y v3+y v3-0) + (8 9 13 12) // f-b0-t (v7-0 v6-0 v6+y v7+y) + (9 10 14 13) // f-b1-t (v6-0 v5-0 v5+y v6+y) + (10 11 15 14) // f-b2-t (v5-0 v4-0 v4+y v5+y) + ); + } +); + +mergePatchPairs +( +); + +// ************************************************************************* // diff --git a/tests/data_blockmesh/blockmesh_phill_3d b/tests/data_blockmesh/blockmesh_phill_3d new file mode 100644 --- /dev/null +++ b/tests/data_blockmesh/blockmesh_phill_3d @@ -0,0 +1,133 @@ +/*--------------------------------*- C++ -*----------------------------------*\ +| ========= | | +| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox | +| \\ / O peration | Version: v2206 | +| \\ / A nd | Website: www.openfoam.com | +| \\/ M anipulation | | +\*---------------------------------------------------------------------------*/ +FoamFile +{ + version 2.0; + format ascii; + class dictionary; + object blockMeshDict; +} +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +scale 1; + +vertices +( + ( 0 0 0 ) // 0 v0-0 + ( 0.5 0 0 ) // 1 v1-0 + ( 1.5 0 0 ) // 2 v2-0 + ( 6 0 0 ) // 3 v3-0 + ( 0 1 0 ) // 4 v0+y + ( 0.5 1 0 ) // 5 v1+y + ( 1.5 1 0 ) // 6 v2+y + ( 6 1 0 ) // 7 v3+y + ( 0 0 0.5 ) // 8 v7-0 + ( 0.5 0 0.5 ) // 9 v6-0 + ( 1.5 0 0.5 ) // 10 v5-0 + ( 6 0 0.5 ) // 11 v4-0 + ( 0 1 0.5 ) // 12 v7+y + ( 0.5 1 0.5 ) // 13 v6+y + ( 1.5 1 0.5 ) // 14 v5+y + ( 6 1 0.5 ) // 15 v4+y +); + +blocks +( + hex (0 1 5 4 8 9 13 12) b0 (50 100 20) simpleGrading (1 ( ( 0.1 0.25 41.9 ) ( 0.9 0.75 1 ) ) 1) // b0 (v0-0 v1-0 v1+y v0+y v7-0 v6-0 v6+y v7+y) + hex (1 2 6 5 9 10 14 13) b1 (50 100 20) simpleGrading (1 ( ( 0.1 0.25 41.9 ) ( 0.9 0.75 1 ) ) 1) // b1 (v1-0 v2-0 v2+y v1+y v6-0 v5-0 v5+y v6+y) + hex (2 3 7 6 10 11 15 14) b2 (225 100 20) simpleGrading (1 ( ( 0.1 0.25 41.9 ) ( 0.9 0.75 1 ) ) 1) // b2 (v2-0 v3-0 v3+y v2+y v5-0 v4-0 v4+y v5+y) +); + +edges +( + spline 1 2 // spline0 (v1-0 v2-0) + ( + ( 0.6 0.0124 0 ) + ( 0.7 0.0395 0 ) + ( 0.8 0.0724 0 ) + ( 0.9 0.132 0 ) + ( 1 0.172 0 ) + ( 1.1 0.132 0 ) + ( 1.2 0.0724 0 ) + ( 1.3 0.0395 0 ) + ( 1.4 0.0124 0 ) +) + spline 9 10 // spline1 (v6-0 v5-0) + ( + ( 0.6 0.0124 0.5 ) + ( 0.7 0.0395 0.5 ) + ( 0.8 0.0724 0.5 ) + ( 0.9 0.132 0.5 ) + ( 1 0.172 0.5 ) + ( 1.1 0.132 0.5 ) + ( 1.2 0.0724 0.5 ) + ( 1.3 0.0395 0.5 ) + ( 1.4 0.0124 0.5 ) +) +); + +boundary +( + top + { + type wall; + faces + ( + (5 4 12 13) // f-b0-n (v1+y v0+y v7+y v6+y) + (6 5 13 14) // f-b1-n (v2+y v1+y v6+y v5+y) + (7 6 14 15) // f-b2-n (v3+y v2+y v5+y v4+y) + ); + } + bottom + { + type wall; + faces + ( + (0 1 9 8) // f-b0-s (v0-0 v1-0 v6-0 v7-0) + (1 2 10 9) // f-b1-s (v1-0 v2-0 v5-0 v6-0) + (2 3 11 10) // f-b2-s (v2-0 v3-0 v4-0 v5-0) + ); + } + outlet + { + type cyclic; + neighbourPatch inlet; + faces + ( + (3 7 15 11) // f-b2-n (v3-0 v3+y v4+y v4-0) + ); + } + inlet + { + type cyclic; + neighbourPatch outlet; + faces + ( + (0 8 12 4) // f-b0-w (v0-0 v7-0 v7+y v0+y) + ); + } + frontandbackplanes + { + type empty; + faces + ( + (0 4 5 1) // f-b0-b (v0-0 v0+y v1+y v1-0) + (1 5 6 2) // f-b1-b (v1-0 v1+y v2+y v2-0) + (2 6 7 3) // f-b2-b (v2-0 v2+y v3+y v3-0) + (8 9 13 12) // f-b0-t (v7-0 v6-0 v6+y v7+y) + (9 10 14 13) // f-b1-t (v6-0 v5-0 v5+y v6+y) + (10 11 15 14) // f-b2-t (v5-0 v4-0 v4+y v5+y) + ); + } +); + +mergePatchPairs +( +); + +// ************************************************************************* // diff --git a/tests/test_blockmesh.py b/tests/test_blockmesh.py --- a/tests/test_blockmesh.py +++ b/tests/test_blockmesh.py @@ -170,6 +170,196 @@ return bmd.format(sort_vortices=False) +def create_code_phill(): + nx = [50, 50, 225] + ny = 100 + nz = 1 + lx = ly = 1 + lz = 0.05 + bmd = BlockMeshDict() + bmd.set_scale(1) + + basevs = [ + Vertex(0, ly, 0, "v0"), + Vertex(0.5, ly, 0, "v1"), + Vertex(1.5, ly, 0, "v2"), + Vertex(6, ly, 0, "v3"), + Vertex(6, ly, lz, "v4"), + Vertex(1.5, ly, lz, "v5"), + Vertex(0.5, ly, lz, "v6"), + Vertex(0, ly, lz, "v7"), + ] + + for v in basevs: + bmd.add_vertex(v.x, 0, v.z, v.name + "-0") + bmd.add_vertex(v.x, v.y, v.z, v.name + "+y") + + b0 = bmd.add_hexblock( + ("v0-0", "v1-0", "v1+y", "v0+y", "v7-0", "v6-0", "v6+y", "v7+y"), + (nx[0], ny, nz), + "b0", + SimpleGrading(1, [[0.1, 0.25, 41.9], [0.9, 0.75, 1]], 1), + ) + + b1 = bmd.add_hexblock( + ("v1-0", "v2-0", "v2+y", "v1+y", "v6-0", "v5-0", "v5+y", "v6+y"), + (nx[1], ny, nz), + "b1", + SimpleGrading(1, [[0.1, 0.25, 41.9], [0.9, 0.75, 1]], 1), + ) + + b2 = bmd.add_hexblock( + ("v2-0", "v3-0", "v3+y", "v2+y", "v5-0", "v4-0", "v4+y", "v5+y"), + (nx[2], ny, nz), + "b2", + SimpleGrading(1, [[0.1, 0.25, 41.9], [0.9, 0.75, 1]], 1), + ) + + bmd.add_splineedge( + ["v1-0", "v2-0"], + "spline0", + [ + Point(0.6, 0.0124, 0), + Point(0.7, 0.0395, 0), + Point(0.8, 0.0724, 0), + Point(0.9, 0.132, 0), + Point(1, 0.172, 0), + Point(1.1, 0.132, 0), + Point(1.2, 0.0724, 0), + Point(1.3, 0.0395, 0), + Point(1.4, 0.0124, 0), + ], + ) + bmd.add_splineedge( + ["v6-0", "v5-0"], + "spline1", + [ + Point(0.6, 0.0124, lz), + Point(0.7, 0.0395, lz), + Point(0.8, 0.0724, lz), + Point(0.9, 0.132, lz), + Point(1, 0.172, lz), + Point(1.1, 0.132, lz), + Point(1.2, 0.0724, lz), + Point(1.3, 0.0395, lz), + Point(1.4, 0.0124, lz), + ], + ) + + bmd.add_boundary("wall", "top", [b0.face("n"), b1.face("n"), b2.face("n")]) + bmd.add_boundary("wall", "bottom", [b0.face("s"), b1.face("s"), b2.face("s")]) + bmd.add_cyclic_boundaries("outlet", "inlet", b2.face("e"), b0.face("w")) + bmd.add_boundary( + "empty", + "frontandbackplanes", + [ + b0.face("b"), + b1.face("b"), + b2.face("b"), + b0.face("t"), + b1.face("t"), + b2.face("t"), + ], + ) + + return bmd.format() + + +def create_code_phill_3d_extrusion(): + nx = [50, 50, 225] + ny = 100 + nz = 20 + lx = ly = 1 + lz = 0.5 + bmd = BlockMeshDict() + bmd.set_scale(1) + + basevs = [ + Vertex(0, ly, 0, "v0"), + Vertex(0.5, ly, 0, "v1"), + Vertex(1.5, ly, 0, "v2"), + Vertex(6, ly, 0, "v3"), + Vertex(6, ly, lz, "v4"), + Vertex(1.5, ly, lz, "v5"), + Vertex(0.5, ly, lz, "v6"), + Vertex(0, ly, lz, "v7"), + ] + + for v in basevs: + bmd.add_vertex(v.x, 0, v.z, v.name + "-0") + bmd.add_vertex(v.x, v.y, v.z, v.name + "+y") + + b0 = bmd.add_hexblock( + ("v0-0", "v1-0", "v1+y", "v0+y", "v7-0", "v6-0", "v6+y", "v7+y"), + (nx[0], ny, nz), + "b0", + SimpleGrading(1, [[0.1, 0.25, 41.9], [0.9, 0.75, 1]], 1), + ) + + b1 = bmd.add_hexblock( + ("v1-0", "v2-0", "v2+y", "v1+y", "v6-0", "v5-0", "v5+y", "v6+y"), + (nx[1], ny, nz), + "b1", + SimpleGrading(1, [[0.1, 0.25, 41.9], [0.9, 0.75, 1]], 1), + ) + + b2 = bmd.add_hexblock( + ("v2-0", "v3-0", "v3+y", "v2+y", "v5-0", "v4-0", "v4+y", "v5+y"), + (nx[2], ny, nz), + "b2", + SimpleGrading(1, [[0.1, 0.25, 41.9], [0.9, 0.75, 1]], 1), + ) + + bmd.add_splineedge( + ["v1-0", "v2-0"], + "spline0", + [ + Point(0.6, 0.0124, 0), + Point(0.7, 0.0395, 0), + Point(0.8, 0.0724, 0), + Point(0.9, 0.132, 0), + Point(1, 0.172, 0), + Point(1.1, 0.132, 0), + Point(1.2, 0.0724, 0), + Point(1.3, 0.0395, 0), + Point(1.4, 0.0124, 0), + ], + ) + bmd.add_splineedge( + ["v6-0", "v5-0"], + "spline1", + [ + Point(0.6, 0.0124, lz), + Point(0.7, 0.0395, lz), + Point(0.8, 0.0724, lz), + Point(0.9, 0.132, lz), + Point(1, 0.172, lz), + Point(1.1, 0.132, lz), + Point(1.2, 0.0724, lz), + Point(1.3, 0.0395, lz), + Point(1.4, 0.0124, lz), + ], + ) + + bmd.add_boundary("wall", "top", [b0.face("n"), b1.face("n"), b2.face("n")]) + bmd.add_boundary("wall", "bottom", [b0.face("s"), b1.face("s"), b2.face("s")]) + bmd.add_cyclic_boundaries("outlet", "inlet", b2.face("e"), b0.face("w")) + bmd.add_boundary( + "empty", + "frontandbackplanes", + [ + b0.face("b"), + b1.face("b"), + b2.face("b"), + b0.face("t"), + b1.face("t"), + b2.face("t"), + ], + ) + + return bmd.format() + + path_data = Path(__file__).absolute().parent / "data_blockmesh" diff --git a/tests/test_phill.py b/tests/test_phill.py new file mode 100644 --- /dev/null +++ b/tests/test_phill.py @@ -0,0 +1,45 @@ +import shutil +from pathlib import Path + +import pytest +from fluidsimfoam_phill import Simul + +from fluidsimfoam.foam_input_files import dump, parse + +here = Path(__file__).absolute().parent + + +path_foam_executable = shutil.which("interFoam") + + +@pytest.mark.skipif( + path_foam_executable is None, reason="executable icoFoam not available" +) +def test_run(): + params = Simul.create_default_params() + + params.output.sub_directory = "tests_fluidsimfoam/phill/" + + params.control_dict.end_time = 0.002 + + sim = Simul(params) + + sim.make.exec("run") + sim.make.exec("clean") + + +@pytest.mark.skipif( + path_foam_executable is None, reason="executable icoFoam not available" +) +def test_run_2d_topo_3d(): + params = Simul.create_default_params() + + params.output.sub_directory = "tests_fluidsimfoam/phill/" + + params.control_dict.end_time = 0.001 + params.block_mesh_dict.lz = 0.2 + params.block_mesh_dict.nz = 4 + sim = Simul(params) + + sim.make.exec("run") + sim.make.exec("clean") # HG changeset patch # User Pooria DANAEIFAR <pouryadanaeifar@gmail.com> # Date 1683713491 -7200 # Wed May 10 12:11:31 2023 +0200 # Node ID 01225bfe5559d12f7e33dde4e2e5ee761d34afe1 # Parent 186d5c24aa9c6f567ab8a089ce864c7de05df46a Update poetry.lock diff --git a/poetry.lock b/poetry.lock --- a/poetry.lock +++ b/poetry.lock @@ -903,6 +903,23 @@ url = "doc/examples/fluidsimfoam-cbox" [[package]] +name = "fluidsimfoam-phill" +version = "0.0.1" +description = "Simulations of the flow over periodic hills (phill)" +category = "dev" +optional = false +python-versions = ">=3.8" +files = [] +develop = true + +[package.dependencies] +fluidsimfoam = ">=0.0.1" + +[package.source] +type = "directory" +url = "doc/examples/fluidsimfoam-phill" + +[[package]] name = "fluidsimfoam-sed" version = "0.0.1" description = "SedFOAM simulations with fluidsimfoam" # HG changeset patch # User Pooria DANAEIFAR <pouryadanaeifar@gmail.com> # Date 1683713513 -7200 # Wed May 10 12:11:53 2023 +0200 # Node ID fe5d214c446093a984a881bd938613948cb72ebd # Parent 01225bfe5559d12f7e33dde4e2e5ee761d34afe1 Fix phill diff --git a/doc/examples/fluidsimfoam-phill/src/fluidsimfoam_phill/output.py b/doc/examples/fluidsimfoam-phill/src/fluidsimfoam_phill/output.py --- a/doc/examples/fluidsimfoam-phill/src/fluidsimfoam_phill/output.py +++ b/doc/examples/fluidsimfoam-phill/src/fluidsimfoam_phill/output.py @@ -3,7 +3,7 @@ from inflection import underscore from fluidsimfoam.foam_input_files import DEFAULT_HEADER, Dict, FoamInputFile -from fluidsimfoam.foam_input_files.blockmeshhelper import ( +from fluidsimfoam.foam_input_files.blockmesh import ( BlockMeshDict, Point, SimpleGrading, @@ -123,18 +123,6 @@ ) @classmethod - def _complete_params_turbulence_properties(cls, params): - params._set_child( - "turbulence_properties", - attribs={"simulation_type": "laminar"}, - doc="""TODO""", - ) - - def make_tree_turbulence_properties(self, params): - tree = super().make_tree_turbulence_properties(params) - return tree - - @classmethod def _complete_params_block_mesh_dict(cls, params): super()._complete_params_block_mesh_dict(params) default = {"nx": 20, "ny": 30, "nz": 1} @@ -153,7 +141,6 @@ bmd = BlockMeshDict() bmd.set_scale(params.block_mesh_dict.scale) - bmd.set_metric(params.block_mesh_dict.metric) basevs = [ Vertex(0, ly, 0, "v0"), # HG changeset patch # User Pooria DANAEIFAR <pouryadanaeifar@gmail.com> # Date 1683713537 -7200 # Wed May 10 12:12:17 2023 +0200 # Node ID 649c50bdf0a8eafc0c9393ffe05dba116ba25677 # Parent fe5d214c446093a984a881bd938613948cb72ebd fluidsimfoam-phill/tests/saved_cases/case0 diff --git a/doc/examples/fluidsimfoam-phill/tests/saved_cases/case0/0/T b/doc/examples/fluidsimfoam-phill/tests/saved_cases/case0/0/T new file mode 100644 --- /dev/null +++ b/doc/examples/fluidsimfoam-phill/tests/saved_cases/case0/0/T @@ -0,0 +1,45 @@ +FoamFile +{ + version 2.0; + format ascii; + class volScalarField; + object T; +} + +dimensions [0 0 0 1 0 0 0]; + +internalField uniform 300; + +boundaryField +{ + outlet + { + type cyclic; + } + + inlet + { + type cyclic; + } + + bottom + { + type atmTurbulentHeatFluxTemperature; + heatSource flux; + alphaEff alphaEff; + Cp0 1005.0; + q uniform 0; + value uniform 300; + + } + + top + { + type zeroGradient; + } + + frontandbackplanes + { + type empty; + } +} diff --git a/doc/examples/fluidsimfoam-phill/tests/saved_cases/case0/0/U b/doc/examples/fluidsimfoam-phill/tests/saved_cases/case0/0/U new file mode 100644 --- /dev/null +++ b/doc/examples/fluidsimfoam-phill/tests/saved_cases/case0/0/U @@ -0,0 +1,42 @@ +FoamFile +{ + version 2.0; + format binary; + class volVectorField; + location "0"; + object U; +} + +dimensions [0 1 -1 0 0 0 0]; + +internalField uniform (0.12 0 0); + +boundaryField +{ + outlet + { + type cyclic; + } + + inlet + { + type cyclic; + } + + bottom + { + type fixedValue; + value uniform (0 0 0); + } + + top + { + type slip; + } + + frontandbackplanes + { + type empty; + } + +} diff --git a/doc/examples/fluidsimfoam-phill/tests/saved_cases/case0/0/alphat b/doc/examples/fluidsimfoam-phill/tests/saved_cases/case0/0/alphat new file mode 100644 --- /dev/null +++ b/doc/examples/fluidsimfoam-phill/tests/saved_cases/case0/0/alphat @@ -0,0 +1,40 @@ +FoamFile +{ + version 2.0; + format ascii; + class volScalarField; + location "0"; + object alphat; +} + +dimensions [0 2 -1 0 0 0 0]; + +internalField uniform 0; + +boundaryField +{ + bottom + { + type zeroGradient; + } + + inlet + { + type cyclic; + } + + outlet + { + type cyclic; + } + + top + { + type zeroGradient; + } + + frontandbackplanes + { + type empty; + } +} diff --git a/doc/examples/fluidsimfoam-phill/tests/saved_cases/case0/0/p_rgh b/doc/examples/fluidsimfoam-phill/tests/saved_cases/case0/0/p_rgh new file mode 100644 --- /dev/null +++ b/doc/examples/fluidsimfoam-phill/tests/saved_cases/case0/0/p_rgh @@ -0,0 +1,41 @@ +FoamFile +{ + version 2.0; + format ascii; + class volScalarField; + object p_rgh; +} + +dimensions [0 2 -2 0 0 0 0]; + +internalField uniform 0; + +boundaryField +{ + inlet + { + type cyclic; + } + + outlet + { + type cyclic; + } + + bottom + { + type fixedFluxPressure; + rho rhok; + value uniform 0; + } + + top + { + type zeroGradient; + } + + frontandbackplanes + { + type empty; + } +} diff --git a/doc/examples/fluidsimfoam-phill/tests/saved_cases/case0/0/rhok b/doc/examples/fluidsimfoam-phill/tests/saved_cases/case0/0/rhok new file mode 100644 --- /dev/null +++ b/doc/examples/fluidsimfoam-phill/tests/saved_cases/case0/0/rhok @@ -0,0 +1,40 @@ +FoamFile +{ + version 2.0; + format ascii; + class volScalarField; + location "0"; + object rhok; +} + +dimensions [0 0 0 0 0 0 0]; + +internalField uniform 1.15; + +boundaryField +{ + top + { + type zeroGradient; + } + + bottom + { + type zeroGradient; + } + + frontandbackplanes + { + type empty; + } + + outlet + { + type cyclic; + } + + inlet + { + type cyclic; + } +} diff --git a/doc/examples/fluidsimfoam-phill/tests/saved_cases/case0/constant/MRFProperties b/doc/examples/fluidsimfoam-phill/tests/saved_cases/case0/constant/MRFProperties new file mode 100644 --- /dev/null +++ b/doc/examples/fluidsimfoam-phill/tests/saved_cases/case0/constant/MRFProperties @@ -0,0 +1,21 @@ +FoamFile +{ + version 2.0; + format ascii; + class dictionary; + location "constant"; + object MRFProperties; +} + +/* +MRF1 +{ + active true; + selectionMode cellZone; + cellZone rotor; + + origin (0 0 0); + axis (0 0 1); + omega constant 0.2; +} +*/ \ No newline at end of file diff --git a/doc/examples/fluidsimfoam-phill/tests/saved_cases/case0/constant/fvOptions b/doc/examples/fluidsimfoam-phill/tests/saved_cases/case0/constant/fvOptions new file mode 100644 --- /dev/null +++ b/doc/examples/fluidsimfoam-phill/tests/saved_cases/case0/constant/fvOptions @@ -0,0 +1,50 @@ +FoamFile +{ + version 2.0; + format ascii; + class dictionary; + location "constant"; + object fvOptions; +} + +/* +pressureGradient +{ + type vectorSemiImplicitSource; + selectionMode all; + volumeMode specific; + sources + { + U ((0 1.978046e-03 0) 0); + } +} +/* + + +atmCoriolisUSource1 +{ + type atmCoriolisUSource; + atmCoriolisUSourceCoeffs + { + selectionMode all; + // Omega (0 0 5.65156e-5); + latitude 45.188; + planetaryRotationPeriod 23.9344694; + } +} + + +/* +momentumSource +{ + type meanVelocityForce; + active yes; + + meanVelocityForceCoeffs + { + selectionMode all; + fields (U); + Ubar (1.0 0 0); + } +} +*/ diff --git a/doc/examples/fluidsimfoam-phill/tests/saved_cases/case0/constant/g b/doc/examples/fluidsimfoam-phill/tests/saved_cases/case0/constant/g new file mode 100644 --- /dev/null +++ b/doc/examples/fluidsimfoam-phill/tests/saved_cases/case0/constant/g @@ -0,0 +1,11 @@ +FoamFile +{ + version 2.0; + format ascii; + class uniformDimensionedVectorField; + location "constant"; + object g; +} + +dimensions [0 1 -2 0 0 0 0]; +value (0 -9.81 0); diff --git a/doc/examples/fluidsimfoam-phill/tests/saved_cases/case0/constant/transportProperties b/doc/examples/fluidsimfoam-phill/tests/saved_cases/case0/constant/transportProperties new file mode 100644 --- /dev/null +++ b/doc/examples/fluidsimfoam-phill/tests/saved_cases/case0/constant/transportProperties @@ -0,0 +1,26 @@ +/*--------------------------------*- C++ -*----------------------------------*\ +| ========= | | +| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox | +| \\ / O peration | Version: v2206 | +| \\ / A nd | Website: www.openfoam.com | +| \\/ M anipulation | | +\*---------------------------------------------------------------------------*/ +FoamFile +{ + version 2.0; + format ascii; + class dictionary; + object transportProperties; +} + +transportModel Newtonian; + +nu nu [0 2 -1 0 0 0 0] 0.0001; + +Pr Pr [0 0 0 0 0 0 0] 10; + +beta 0.003; + +TRef 300; + +Prt 0.85; diff --git a/doc/examples/fluidsimfoam-phill/tests/saved_cases/case0/constant/turbulenceProperties b/doc/examples/fluidsimfoam-phill/tests/saved_cases/case0/constant/turbulenceProperties new file mode 100644 --- /dev/null +++ b/doc/examples/fluidsimfoam-phill/tests/saved_cases/case0/constant/turbulenceProperties @@ -0,0 +1,10 @@ +FoamFile +{ + version 2.0; + format ascii; + class dictionary; + location "constant"; + object turbulenceProperties; +} + +simulationType laminar; diff --git a/doc/examples/fluidsimfoam-phill/tests/saved_cases/case0/system/blockMeshDict b/doc/examples/fluidsimfoam-phill/tests/saved_cases/case0/system/blockMeshDict new file mode 100644 --- /dev/null +++ b/doc/examples/fluidsimfoam-phill/tests/saved_cases/case0/system/blockMeshDict @@ -0,0 +1,129 @@ +/*--------------------------------*- C++ -*----------------------------------*\ +| ========= | | +| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox | +| \\ / O peration | Version: v2206 | +| \\ / A nd | Website: www.openfoam.com | +| \\/ M anipulation | | +\*---------------------------------------------------------------------------*/ +FoamFile +{ + version 2.0; + format ascii; + class dictionary; + object blockMeshDict; +} +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +scale 1; + +vertices +( + ( 0 0 0 ) // 0 v0-0 + ( 0.5 0 0 ) // 1 v1-0 + ( 1.5 0 0 ) // 2 v2-0 + ( 6 0 0 ) // 3 v3-0 + ( 0 1 0 ) // 4 v0+y + ( 0.5 1 0 ) // 5 v1+y + ( 1.5 1 0 ) // 6 v2+y + ( 6 1 0 ) // 7 v3+y + ( 0 0 0.01 ) // 8 v7-0 + ( 0.5 0 0.01 ) // 9 v6-0 + ( 1.5 0 0.01 ) // 10 v5-0 + ( 6 0 0.01 ) // 11 v4-0 + ( 0 1 0.01 ) // 12 v7+y + ( 0.5 1 0.01 ) // 13 v6+y + ( 1.5 1 0.01 ) // 14 v5+y + ( 6 1 0.01 ) // 15 v4+y +); + +blocks +( + hex (0 1 5 4 8 9 13 12) b0 (20 30 1) simpleGrading (1 ( ( 0.1 0.25 41.9 ) ( 0.9 0.75 1 ) ) 1) // b0 (v0-0 v1-0 v1+y v0+y v7-0 v6-0 v6+y v7+y) + hex (1 2 6 5 9 10 14 13) b1 (20 30 1) simpleGrading (1 ( ( 0.1 0.25 41.9 ) ( 0.9 0.75 1 ) ) 1) // b1 (v1-0 v2-0 v2+y v1+y v6-0 v5-0 v5+y v6+y) + hex (2 3 7 6 10 11 15 14) b2 (225 30 1) simpleGrading (1 ( ( 0.1 0.25 41.9 ) ( 0.9 0.75 1 ) ) 1) // b2 (v2-0 v3-0 v3+y v2+y v5-0 v4-0 v4+y v5+y) +); + +edges +( + spline 1 2 // spline0 (v1-0 v2-0) + ( + ( 0.6 0.0124 0 ) + ( 0.7 0.0395 0 ) + ( 0.8 0.0724 0 ) + ( 0.9 0.132 0 ) + ( 1 0.172 0 ) + ( 1.1 0.132 0 ) + ( 1.2 0.0724 0 ) + ( 1.3 0.0395 0 ) + ( 1.4 0.0124 0 ) +) + spline 9 10 // spline1 (v6-0 v5-0) + ( + ( 0.6 0.0124 0.01 ) + ( 0.7 0.0395 0.01 ) + ( 0.8 0.0724 0.01 ) + ( 0.9 0.132 0.01 ) + ( 1 0.172 0.01 ) + ( 1.1 0.132 0.01 ) + ( 1.2 0.0724 0.01 ) + ( 1.3 0.0395 0.01 ) + ( 1.4 0.0124 0.01 ) +) +); + +boundary +( + top + { + type wall; + faces + ( + (5 4 12 13) // f-b0-n (v1+y v0+y v7+y v6+y) + (6 5 13 14) // f-b1-n (v2+y v1+y v6+y v5+y) + (7 6 14 15) // f-b2-n (v3+y v2+y v5+y v4+y) + ); + } + bottom + { + type wall; + faces + ( + (0 1 9 8) // f-b0-s (v0-0 v1-0 v6-0 v7-0) + (1 2 10 9) // f-b1-s (v1-0 v2-0 v5-0 v6-0) + (2 3 11 10) // f-b2-s (v2-0 v3-0 v4-0 v5-0) + ); + } + outlet + { + type cyclic; + neighbourPatch inlet; + faces + ( + (3 7 15 11) // f-b2-e (v3-0 v3+y v4+y v4-0) + ); + } + inlet + { + type cyclic; + neighbourPatch outlet; + faces + ( + (0 8 12 4) // f-b0-w (v0-0 v7-0 v7+y v0+y) + ); + } + frontandbackplanes + { + type empty; + faces + ( + (0 4 5 1) // f-b0-b (v0-0 v0+y v1+y v1-0) + (1 5 6 2) // f-b1-b (v1-0 v1+y v2+y v2-0) + (2 6 7 3) // f-b2-b (v2-0 v2+y v3+y v3-0) + (8 9 13 12) // f-b0-t (v7-0 v6-0 v6+y v7+y) + (9 10 14 13) // f-b1-t (v6-0 v5-0 v5+y v6+y) + (10 11 15 14) // f-b2-t (v5-0 v4-0 v4+y v5+y) + ); + } +); + +// ************************************************************************* // diff --git a/doc/examples/fluidsimfoam-phill/tests/saved_cases/case0/system/controlDict b/doc/examples/fluidsimfoam-phill/tests/saved_cases/case0/system/controlDict new file mode 100644 --- /dev/null +++ b/doc/examples/fluidsimfoam-phill/tests/saved_cases/case0/system/controlDict @@ -0,0 +1,69 @@ +/*--------------------------------*- C++ -*----------------------------------*\ +| ========= | | +| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox | +| \\ / O peration | Version: v2206 | +| \\ / A nd | Website: www.openfoam.com | +| \\/ M anipulation | | +\*---------------------------------------------------------------------------*/ +FoamFile +{ + version 2.0; + format ascii; + class dictionary; + location "system"; + object controlDict; +} + +application buoyantBoussinesqPimpleFoam; + +startFrom startTime; + +startTime 0; + +stopAt endTime; + +endTime 60; + +deltaT 0.05; + +writeControl adjustableRunTime; + +writeInterval 1; + +purgeWrite 0; + +writeFormat ascii; + +writePrecision 6; + +writeCompression off; + +timeFormat general; + +timePrecision 6; + +runTimeModifiable yes; + +adjustTimeStep yes; +libs (atmosphericModels); + +functions +{ + fieldAverage1 + { + type fieldAverage; + libs (fieldFunctionObjects); + writeControl writeTime; + + fields + ( + U + { + mean on; + prime2Mean off; + base time; + } + ); + } +} + diff --git a/doc/examples/fluidsimfoam-phill/tests/saved_cases/case0/system/fvSchemes b/doc/examples/fluidsimfoam-phill/tests/saved_cases/case0/system/fvSchemes new file mode 100644 --- /dev/null +++ b/doc/examples/fluidsimfoam-phill/tests/saved_cases/case0/system/fvSchemes @@ -0,0 +1,46 @@ +FoamFile +{ + version 2.0; + format ascii; + class dictionary; + location "system"; + object fvSchemes; +} + +ddtSchemes +{ + default Euler implicit; +} + +gradSchemes +{ + default Gauss linear; +} + +divSchemes +{ + default none; + + div(phi,U) Gauss upwind; + div(phi,T) Gauss upwind; + div(phi,rhok) Gauss upwind; + div(phi,R) Gauss upwind; + div(R) Gauss linear; + div((nuEff*dev2(T(grad(U))))) Gauss linear; + div((nuEff*dev(T(grad(U))))) Gauss linear; +} + +laplacianSchemes +{ + default Gauss linear corrected; +} + +interpolationSchemes +{ + default linear; +} + +snGradSchemes +{ + default uncorrected; +} diff --git a/doc/examples/fluidsimfoam-phill/tests/saved_cases/case0/system/fvSolution b/doc/examples/fluidsimfoam-phill/tests/saved_cases/case0/system/fvSolution new file mode 100644 --- /dev/null +++ b/doc/examples/fluidsimfoam-phill/tests/saved_cases/case0/system/fvSolution @@ -0,0 +1,56 @@ +FoamFile +{ + version 2.0; + format ascii; + class dictionary; + location "system"; + object fvSolution; +} + +solvers +{ + p_rgh + { + solver PCG; + preconditioner DIC; + tolerance 1e-8; + relTol 0.01; + } + + p_rghFinal + { + $p_rgh; + relTol 0; + } + + "(U|rhok|R|T)" + { + solver PBiCG; + preconditioner DILU; + tolerance 1e-6; + relTol 0.1; + } + + "(U|rhok|R|T)Final" + { + $U; + relTol 0; + } +} + +PIMPLE +{ + momentumPredictor no; + nNonOrthogonalCorrectors 0; + nCorrectors 2; + pRefCell 0; + pRefValue 0; +} + +relaxationFactors +{ + equations + { + ".*" 1.0; + } +} diff --git a/doc/examples/fluidsimfoam-phill/tests/saved_cases/case0/system/topoSetDict b/doc/examples/fluidsimfoam-phill/tests/saved_cases/case0/system/topoSetDict new file mode 100644 --- /dev/null +++ b/doc/examples/fluidsimfoam-phill/tests/saved_cases/case0/system/topoSetDict @@ -0,0 +1,24 @@ +FoamFile +{ + version 2.0; + format ascii; + class dictionary; + location "system"; + object topoSetDict; +} + +actions +( + { + name rotor; + type cellSet; + action new; + source cylinderToCell; + sourceInfo + { + p1 (0 0 0); + p2 (0 0 0.5); + radius 6.5; + } + } +); # HG changeset patch # User Pooria DANAEIFAR <pouryadanaeifar@gmail.com> # Date 1683798562 -7200 # Thu May 11 11:49:22 2023 +0200 # Node ID d9df96df761991e36ef73b369f2518faebf9fff8 # Parent 649c50bdf0a8eafc0c9393ffe05dba116ba25677 Change phill blockmesh to sinusoidal diff --git a/doc/examples/fluidsimfoam-phill/src/fluidsimfoam_phill/output.py b/doc/examples/fluidsimfoam-phill/src/fluidsimfoam_phill/output.py --- a/doc/examples/fluidsimfoam-phill/src/fluidsimfoam_phill/output.py +++ b/doc/examples/fluidsimfoam-phill/src/fluidsimfoam_phill/output.py @@ -1,5 +1,5 @@ from textwrap import dedent - +from math import cos, pi from inflection import underscore from fluidsimfoam.foam_input_files import DEFAULT_HEADER, Dict, FoamInputFile @@ -125,8 +125,8 @@ @classmethod def _complete_params_block_mesh_dict(cls, params): super()._complete_params_block_mesh_dict(params) - default = {"nx": 20, "ny": 30, "nz": 1} - default.update({"lx": 1.0, "ly": 1.0, "lz": 0.01, "scale": 1}) + default = {"nx": 30, "ny": 30, "nz": 1} + default.update({"lx": 2000, "ly": 2000, "lz": 0.01, "scale": 1}) for key, value in default.items(): params.block_mesh_dict[key] = value @@ -142,93 +142,59 @@ bmd = BlockMeshDict() bmd.set_scale(params.block_mesh_dict.scale) + h_max = 80 basevs = [ - Vertex(0, ly, 0, "v0"), - Vertex(0.5, ly, 0, "v1"), - Vertex(1.5, ly, 0, "v2"), - Vertex(6, ly, 0, "v3"), - Vertex(6, ly, lz, "v4"), - Vertex(1.5, ly, lz, "v5"), - Vertex(0.5, ly, lz, "v6"), - Vertex(0, ly, lz, "v7"), + Vertex(0, h_max, lz, "v0"), + Vertex(lx, h_max, lz, "v1"), + Vertex(lx, ly, lz, "v2"), + Vertex(0, ly, lz, "v3"), ] for v in basevs: - bmd.add_vertex(v.x, 0, v.z, v.name + "-0") - bmd.add_vertex(v.x, v.y, v.z, v.name + "+y") + bmd.add_vertex(v.x, v.y, 0, v.name + "-0") + for v in basevs: + bmd.add_vertex(v.x, v.y, v.z, v.name + "+z") b0 = bmd.add_hexblock( - ("v0-0", "v1-0", "v1+y", "v0+y", "v7-0", "v6-0", "v6+y", "v7+y"), - (nx, ny, nz), + ("v0-0", "v1-0", "v2-0", "v3-0", "v0+z", "v1+z", "v2+z", "v3+z"), + (nx + 1, ny, nz), "b0", SimpleGrading(1, [[0.1, 0.25, 41.9], [0.9, 0.75, 1]], 1), ) - b1 = bmd.add_hexblock( - ("v1-0", "v2-0", "v2+y", "v1+y", "v6-0", "v5-0", "v5+y", "v6+y"), - (nx, ny, nz), - "b1", - SimpleGrading(1, [[0.1, 0.25, 41.9], [0.9, 0.75, 1]], 1), - ) - - b2 = bmd.add_hexblock( - ("v2-0", "v3-0", "v3+y", "v2+y", "v5-0", "v4-0", "v4+y", "v5+y"), - (225, ny, nz), - "b2", - SimpleGrading(1, [[0.1, 0.25, 41.9], [0.9, 0.75, 1]], 1), - ) + x_dot = [] + y_dot = [] + dots = [] + h_max = 80 + for dot in range(nx + 1): + x_dot.append(dot * lx / nx) + y_dot.append( + (h_max / 2) + * (1 - cos(2 * pi * min(abs((x_dot[dot] - (lx / 2)) / lx), 1))) + ) + dots.append([x_dot[dot], y_dot[dot]]) bmd.add_splineedge( - ["v1-0", "v2-0"], + ["v0-0", "v1-0"], "spline0", - [ - Point(0.6, 0.0124, 0), - Point(0.7, 0.0395, 0), - Point(0.8, 0.0724, 0), - Point(0.9, 0.132, 0), - Point(1, 0.172, 0), - Point(1.1, 0.132, 0), - Point(1.2, 0.0724, 0), - Point(1.3, 0.0395, 0), - Point(1.4, 0.0124, 0), - ], + [Point(dot[0], dot[1], 0) for dot in dots], ) bmd.add_splineedge( - ["v6-0", "v5-0"], + ["v0+z", "v1+z"], "spline1", - [ - Point(0.6, 0.0124, lz), - Point(0.7, 0.0395, lz), - Point(0.8, 0.0724, lz), - Point(0.9, 0.132, lz), - Point(1, 0.172, lz), - Point(1.1, 0.132, lz), - Point(1.2, 0.0724, lz), - Point(1.3, 0.0395, lz), - Point(1.4, 0.0124, lz), - ], + [Point(dot[0], dot[1], lz) for dot in dots], ) - bmd.add_boundary( - "wall", "top", [b0.face("n"), b1.face("n"), b2.face("n")] - ) - bmd.add_boundary( - "wall", "bottom", [b0.face("s"), b1.face("s"), b2.face("s")] - ) - bmd.add_cyclic_boundaries("outlet", "inlet", b2.face("e"), b0.face("w")) - # bmd.add_boundary("inlet", "inlet", [b2.face("e")]) - # bmd.add_boundary("outlet", "outlet", [b0.face("w")]) + bmd.add_boundary("wall", "top", [b0.face("n")]) + bmd.add_boundary("wall", "bottom", [b0.face("s")]) + bmd.add_cyclic_boundaries("outlet", "inlet", b0.face("e"), b0.face("w")) bmd.add_boundary( "empty", "frontandbackplanes", [ b0.face("b"), - b1.face("b"), - b2.face("b"), b0.face("t"), - b1.face("t"), - b2.face("t"), ], ) - return bmd.format() + return bmd.format(sort_vortices="as_added") diff --git a/doc/examples/fluidsimfoam-phill/tests/saved_cases/case0/system/blockMeshDict b/doc/examples/fluidsimfoam-phill/tests/saved_cases/case0/system/blockMeshDict --- a/doc/examples/fluidsimfoam-phill/tests/saved_cases/case0/system/blockMeshDict +++ b/doc/examples/fluidsimfoam-phill/tests/saved_cases/case0/system/blockMeshDict @@ -18,56 +18,90 @@ vertices ( - ( 0 0 0 ) // 0 v0-0 - ( 0.5 0 0 ) // 1 v1-0 - ( 1.5 0 0 ) // 2 v2-0 - ( 6 0 0 ) // 3 v3-0 - ( 0 1 0 ) // 4 v0+y - ( 0.5 1 0 ) // 5 v1+y - ( 1.5 1 0 ) // 6 v2+y - ( 6 1 0 ) // 7 v3+y - ( 0 0 0.01 ) // 8 v7-0 - ( 0.5 0 0.01 ) // 9 v6-0 - ( 1.5 0 0.01 ) // 10 v5-0 - ( 6 0 0.01 ) // 11 v4-0 - ( 0 1 0.01 ) // 12 v7+y - ( 0.5 1 0.01 ) // 13 v6+y - ( 1.5 1 0.01 ) // 14 v5+y - ( 6 1 0.01 ) // 15 v4+y + ( 0 80 0 ) // 0 v0-0 + ( 2000 80 0 ) // 1 v1-0 + ( 2000 2000 0 ) // 2 v2-0 + ( 0 2000 0 ) // 3 v3-0 + ( 0 80 0.01 ) // 4 v0+z + ( 2000 80 0.01 ) // 5 v1+z + ( 2000 2000 0.01 ) // 6 v2+z + ( 0 2000 0.01 ) // 7 v3+z ); blocks ( - hex (0 1 5 4 8 9 13 12) b0 (20 30 1) simpleGrading (1 ( ( 0.1 0.25 41.9 ) ( 0.9 0.75 1 ) ) 1) // b0 (v0-0 v1-0 v1+y v0+y v7-0 v6-0 v6+y v7+y) - hex (1 2 6 5 9 10 14 13) b1 (20 30 1) simpleGrading (1 ( ( 0.1 0.25 41.9 ) ( 0.9 0.75 1 ) ) 1) // b1 (v1-0 v2-0 v2+y v1+y v6-0 v5-0 v5+y v6+y) - hex (2 3 7 6 10 11 15 14) b2 (225 30 1) simpleGrading (1 ( ( 0.1 0.25 41.9 ) ( 0.9 0.75 1 ) ) 1) // b2 (v2-0 v3-0 v3+y v2+y v5-0 v4-0 v4+y v5+y) + hex (0 1 2 3 4 5 6 7) b0 (31 30 1) simpleGrading (1 ( ( 0.1 0.25 41.9 ) ( 0.9 0.75 1 ) ) 1) // b0 (v0-0 v1-0 v2-0 v3-0 v0+z v1+z v2+z v3+z) ); edges ( - spline 1 2 // spline0 (v1-0 v2-0) + spline 0 1 // spline0 (v0-0 v1-0) ( - ( 0.6 0.0124 0 ) - ( 0.7 0.0395 0 ) - ( 0.8 0.0724 0 ) - ( 0.9 0.132 0 ) - ( 1 0.172 0 ) - ( 1.1 0.132 0 ) - ( 1.2 0.0724 0 ) - ( 1.3 0.0395 0 ) - ( 1.4 0.0124 0 ) + ( 0 80 0 ) + ( 66.6666666666667 79.1259040293522 0 ) + ( 133.333333333333 76.541818305704 0 ) + ( 200 72.3606797749979 0 ) + ( 266.666666666667 66.7652242543543 0 ) + ( 333.333333333333 60 0 ) + ( 400 52.3606797749979 0 ) + ( 466.666666666667 44.1811385307061 0 ) + ( 533.333333333333 35.8188614692939 0 ) + ( 600 27.6393202250021 0 ) + ( 666.666666666667 20 0 ) + ( 733.333333333333 13.2347757456457 0 ) + ( 800 7.6393202250021 0 ) + ( 866.666666666667 3.45818169429597 0 ) + ( 933.333333333333 0.874095970647772 0 ) + ( 1000 0 0 ) + ( 1066.66666666667 0.874095970647777 0 ) + ( 1133.33333333333 3.45818169429596 0 ) + ( 1200 7.6393202250021 0 ) + ( 1266.66666666667 13.2347757456457 0 ) + ( 1333.33333333333 20 0 ) + ( 1400 27.6393202250021 0 ) + ( 1466.66666666667 35.8188614692939 0 ) + ( 1533.33333333333 44.1811385307061 0 ) + ( 1600 52.3606797749979 0 ) + ( 1666.66666666667 60 0 ) + ( 1733.33333333333 66.7652242543543 0 ) + ( 1800 72.3606797749979 0 ) + ( 1866.66666666667 76.541818305704 0 ) + ( 1933.33333333333 79.1259040293522 0 ) + ( 2000 80 0 ) ) - spline 9 10 // spline1 (v6-0 v5-0) + spline 4 5 // spline1 (v0+z v1+z) ( - ( 0.6 0.0124 0.01 ) - ( 0.7 0.0395 0.01 ) - ( 0.8 0.0724 0.01 ) - ( 0.9 0.132 0.01 ) - ( 1 0.172 0.01 ) - ( 1.1 0.132 0.01 ) - ( 1.2 0.0724 0.01 ) - ( 1.3 0.0395 0.01 ) - ( 1.4 0.0124 0.01 ) + ( 0 80 0.01 ) + ( 66.6666666666667 79.1259040293522 0.01 ) + ( 133.333333333333 76.541818305704 0.01 ) + ( 200 72.3606797749979 0.01 ) + ( 266.666666666667 66.7652242543543 0.01 ) + ( 333.333333333333 60 0.01 ) + ( 400 52.3606797749979 0.01 ) + ( 466.666666666667 44.1811385307061 0.01 ) + ( 533.333333333333 35.8188614692939 0.01 ) + ( 600 27.6393202250021 0.01 ) + ( 666.666666666667 20 0.01 ) + ( 733.333333333333 13.2347757456457 0.01 ) + ( 800 7.6393202250021 0.01 ) + ( 866.666666666667 3.45818169429597 0.01 ) + ( 933.333333333333 0.874095970647772 0.01 ) + ( 1000 0 0.01 ) + ( 1066.66666666667 0.874095970647777 0.01 ) + ( 1133.33333333333 3.45818169429596 0.01 ) + ( 1200 7.6393202250021 0.01 ) + ( 1266.66666666667 13.2347757456457 0.01 ) + ( 1333.33333333333 20 0.01 ) + ( 1400 27.6393202250021 0.01 ) + ( 1466.66666666667 35.8188614692939 0.01 ) + ( 1533.33333333333 44.1811385307061 0.01 ) + ( 1600 52.3606797749979 0.01 ) + ( 1666.66666666667 60 0.01 ) + ( 1733.33333333333 66.7652242543543 0.01 ) + ( 1800 72.3606797749979 0.01 ) + ( 1866.66666666667 76.541818305704 0.01 ) + ( 1933.33333333333 79.1259040293522 0.01 ) + ( 2000 80 0.01 ) ) ); @@ -78,9 +112,7 @@ type wall; faces ( - (5 4 12 13) // f-b0-n (v1+y v0+y v7+y v6+y) - (6 5 13 14) // f-b1-n (v2+y v1+y v6+y v5+y) - (7 6 14 15) // f-b2-n (v3+y v2+y v5+y v4+y) + (2 3 7 6) // f-b0-n (v2-0 v3-0 v3+z v2+z) ); } bottom @@ -88,9 +120,7 @@ type wall; faces ( - (0 1 9 8) // f-b0-s (v0-0 v1-0 v6-0 v7-0) - (1 2 10 9) // f-b1-s (v1-0 v2-0 v5-0 v6-0) - (2 3 11 10) // f-b2-s (v2-0 v3-0 v4-0 v5-0) + (0 1 5 4) // f-b0-s (v0-0 v1-0 v1+z v0+z) ); } outlet @@ -99,7 +129,7 @@ neighbourPatch inlet; faces ( - (3 7 15 11) // f-b2-e (v3-0 v3+y v4+y v4-0) + (1 2 6 5) // f-b0-e (v1-0 v2-0 v2+z v1+z) ); } inlet @@ -108,7 +138,7 @@ neighbourPatch outlet; faces ( - (0 8 12 4) // f-b0-w (v0-0 v7-0 v7+y v0+y) + (0 4 7 3) // f-b0-w (v0-0 v0+z v3+z v3-0) ); } frontandbackplanes @@ -116,12 +146,8 @@ type empty; faces ( - (0 4 5 1) // f-b0-b (v0-0 v0+y v1+y v1-0) - (1 5 6 2) // f-b1-b (v1-0 v1+y v2+y v2-0) - (2 6 7 3) // f-b2-b (v2-0 v2+y v3+y v3-0) - (8 9 13 12) // f-b0-t (v7-0 v6-0 v6+y v7+y) - (9 10 14 13) // f-b1-t (v6-0 v5-0 v5+y v6+y) - (10 11 15 14) // f-b2-t (v5-0 v4-0 v4+y v5+y) + (0 3 2 1) // f-b0-b (v0-0 v3-0 v2-0 v1-0) + (4 5 6 7) // f-b0-t (v0+z v1+z v2+z v3+z) ); } ); # HG changeset patch # User Pooria DANAEIFAR <pouryadanaeifar@gmail.com> # Date 1683798641 -7200 # Thu May 11 11:50:41 2023 +0200 # Node ID 7618f3e40e0ee6c02766f9a82a9048b3c8e6c6f8 # Parent d9df96df761991e36ef73b369f2518faebf9fff8 Add test for phill diff --git a/doc/examples/fluidsimfoam-phill/src/fluidsimfoam_phill/output.py b/doc/examples/fluidsimfoam-phill/src/fluidsimfoam_phill/output.py --- a/doc/examples/fluidsimfoam-phill/src/fluidsimfoam_phill/output.py +++ b/doc/examples/fluidsimfoam-phill/src/fluidsimfoam_phill/output.py @@ -1,5 +1,6 @@ +from math import cos, pi from textwrap import dedent -from math import cos, pi + from inflection import underscore from fluidsimfoam.foam_input_files import DEFAULT_HEADER, Dict, FoamInputFile diff --git a/doc/examples/fluidsimfoam-cavity/tests/test_cavity.py b/doc/examples/fluidsimfoam-phill/tests/test_phill.py copy from doc/examples/fluidsimfoam-cavity/tests/test_cavity.py copy to doc/examples/fluidsimfoam-phill/tests/test_phill.py --- a/doc/examples/fluidsimfoam-cavity/tests/test_cavity.py +++ b/doc/examples/fluidsimfoam-phill/tests/test_phill.py @@ -2,18 +2,18 @@ from pathlib import Path import pytest -from fluidsimfoam_cavity import Simul +from fluidsimfoam_phill import Simul from fluidsimfoam.testing import check_saved_case here = Path(__file__).absolute().parent -path_saved_case = here / "saved_cases/cavity" +path_saved_case = here / "saved_cases/case0" def test_reproduce_case(): params = Simul.create_default_params() - params.output.sub_directory = "tests_fluidsimfoam/cavity" + params.output.sub_directory = "tests_fluidsimfoam/phill" sim = Simul(params) check_saved_case(path_saved_case, sim.path_run) @@ -26,7 +26,7 @@ ) def test_run(): params = Simul.create_default_params() - params.output.sub_directory = "tests_fluidsimfoam/cavity" + params.output.sub_directory = "tests_fluidsimfoam/phill" params.control_dict.end_time = 0.001 sim = Simul(params) sim.make.exec("run") # HG changeset patch # User Pooria DANAEIFAR <pouryadanaeifar@gmail.com> # Date 1683897720 -7200 # Fri May 12 15:22:00 2023 +0200 # Node ID 3cc7764e1562e07e0ce08f053c3a81b85ed44f9b # Parent 7618f3e40e0ee6c02766f9a82a9048b3c8e6c6f8 Update output of phill diff --git a/doc/examples/fluidsimfoam-phill/src/fluidsimfoam_phill/output.py b/doc/examples/fluidsimfoam-phill/src/fluidsimfoam_phill/output.py --- a/doc/examples/fluidsimfoam-phill/src/fluidsimfoam_phill/output.py +++ b/doc/examples/fluidsimfoam-phill/src/fluidsimfoam_phill/output.py @@ -3,131 +3,140 @@ from inflection import underscore -from fluidsimfoam.foam_input_files import DEFAULT_HEADER, Dict, FoamInputFile +from fluidsimfoam.foam_input_files import ( + BlockMeshDict, + ConstantFileHelper, + FoamInputFile, + FvSchemesHelper, + VolScalarField, + VolVectorField, +) + from fluidsimfoam.foam_input_files.blockmesh import ( - BlockMeshDict, Point, SimpleGrading, Vertex, ) from fluidsimfoam.output import Output -code_control_dict_functions = dedent( - """ - adjustTimeStep yes; - libs (atmosphericModels); - functions - { - fieldAverage1 - { - type fieldAverage; - libs (fieldFunctionObjects); - writeControl writeTime; +def add_default_boundaries(field): + for name, type_ in ( + ("inlet", "cyclic"), + ("outlet", "cyclic"), + ("top", "zeroGradient"), + ("bottom", "zeroGradient"), + ("frontAndBackPlanes", "empty"), + ): + field.set_boundary(name, type_) + + +def make_scalar_field(name, dimension, values=None): + field = VolScalarField(name, dimension, values=values) + add_default_boundaries(field) + return field + - fields - ( - U - { - mean on; - prime2Mean off; - base time; - } - ); - } +def make_vector_field(name, dimension, values=None): + field = VolVectorField(name, dimension, values=values) + add_default_boundaries(field) + return field + + +code_fv_options = dedent( + r""" +atmCoriolisUSource1 +{ + type atmCoriolisUSource; + atmCoriolisUSourceCoeffs + { + selectionMode all; + Omega (0 7.2921e-5 0); } - +} """ ) -_attribs_transport_prop = { - "transportModel": "Newtonian", - "nu nu [0 2 -1 0 0 0 0]": 0.0001, - "Pr Pr [0 0 0 0 0 0 0]": 10, - "beta": 3e-03, - "TRef": 300, - "Prt": 0.85, -} - class OutputPHill(Output): """Output for the phill solver""" variable_names = ["U", "rhok", "p_rgh", "T", "alphat"] - system_files_names = Output.system_files_names + [ - "blockMeshDict", - "topoSetDict", - "funkySetFieldsDict", - ] - constant_files_names = Output.constant_files_names + [ + system_files_names = Output.system_files_names + ["blockMeshDict"] + constant_files_names = [ "g", "fvOptions", "MRFProperties", + "transportProperties", + "turbulenceProperties", ] - # @classmethod - # def _set_info_solver_classes(cls, classes): - # """Set the the classes for info_solver.classes.Output""" - # super()._set_info_solver_classes(classes) - - @classmethod - def _complete_params_control_dict(cls, params): - super()._complete_params_control_dict(params) - - default = { + default_control_dict_params = Output.default_control_dict_params.copy() + default_control_dict_params.update( + { "application": "buoyantBoussinesqPimpleFoam", - "startFrom": "startTime", - "endTime": 60, - "deltaT": 0.05, + "startFrom": "latestTime", + "endTime": 1200000, + "deltaT": 10, "writeControl": "adjustableRunTime", - "writeInterval": 1, - "writeFormat": "ascii", - "writeCompression": "off", - "runTimeModifiable": "yes", - "adjustTimeStep": "yes", + "writeInterval": 5000, + "adjustTimeStep": "on", "maxCo": 0.6, "maxAlphaCo": 0.6, "maxDeltaT": 1, } - for key, value in default.items(): - try: - params.control_dict[underscore(key)] = value - except AttributeError: - # TODO: Fix adding keys which are not in DEFAULT_CONTROL_DICT - params.control_dict._set_attribs({underscore(key): value}) - - def make_code_control_dict(self, params): - code = super().make_code_control_dict(params) - return code + code_control_dict_functions + ) - @classmethod - def _complete_params_transport_properties(cls, params): - params._set_child( - "transport_properties", - attribs=_attribs_transport_prop, - doc="""TODO""", - ) + helper_fv_schemes = FvSchemesHelper( + ddt="default Euler implicit", + grad="default Gauss linear", + div=""" + default none + div(phi,U) Gauss upwind + div(phi,T) Gauss upwind + div(phi,rhok) Gauss upwind + div(phi,R) Gauss upwind + div(R) Gauss linear + div((nuEff*dev2(T(grad(U))))) Gauss linear + div((nuEff*dev(T(grad(U))))) Gauss linear +""", + laplacian=""" + default Gauss linear corrected +""", + interpolation={ + "default": "linear", + }, + sn_grad={ + "default": "uncorrected", + }, + ) - def make_tree_transport_properties(self, params): - return FoamInputFile( - info={ - "version": "2.0", - "format": "ascii", - "class": "dictionary", - "object": "transportProperties", - }, - children={ - key: params.transport_properties[key] - for key in _attribs_transport_prop.keys() - }, - header=DEFAULT_HEADER, - ) + helper_transport_properties = ConstantFileHelper( + "transportProperties", + { + "transportModel": "Newtonian", + "nu": 1.0e-2, + "Pr": 10, + "beta": 2.23e-4, + "TRef": 1.0e-2, + "Prt": 1e2, + }, + dimensions={ + "nu": "m^2/s", + "Pr": "1", + "beta": "1/K", + "TRef": "K", + "Prt": "1", + }, + default_dimension="", + comments={}, + ) @classmethod def _complete_params_block_mesh_dict(cls, params): super()._complete_params_block_mesh_dict(params) - default = {"nx": 30, "ny": 30, "nz": 1} - default.update({"lx": 2000, "ly": 2000, "lz": 0.01, "scale": 1}) + default = {"nx": 20, "ny": 50, "nz": 1} + default.update({"lx": 2000, "ly": 5000, "lz": 0.01, "scale": 1}) for key, value in default.items(): params.block_mesh_dict[key] = value @@ -199,3 +208,21 @@ ) return bmd.format(sort_vortices="as_added") + + def make_tree_alphat(self, params): + return make_scalar_field("alphat", dimension="m^2/s", values=0) + + def make_tree_p_rgh(self, params): + return make_scalar_field("p_rgh", dimension="m^2/s^2", values=0) + + def make_tree_rhok(self, params): + return make_scalar_field("rhok", dimension="", values=1.15) + + def make_tree_t(self, params): + return make_scalar_field("T", dimension="K", values=300) + + def make_tree_u(self, params): + field = make_vector_field("U", dimension="m/s", values=[0.1, 0, 0]) + field.set_boundary("top", "slip") + field.set_boundary("bottom", "noSlip") + return field diff --git a/doc/examples/fluidsimfoam-phill/src/fluidsimfoam_phill/templates/T.jinja b/doc/examples/fluidsimfoam-phill/src/fluidsimfoam_phill/templates/T.jinja deleted file mode 100644 --- a/doc/examples/fluidsimfoam-phill/src/fluidsimfoam_phill/templates/T.jinja +++ /dev/null @@ -1,45 +0,0 @@ -FoamFile -{ - version 2.0; - format ascii; - class volScalarField; - object T; -} - -dimensions [0 0 0 1 0 0 0]; - -internalField uniform 300; - -boundaryField -{ - outlet - { - type cyclic; - } - - inlet - { - type cyclic; - } - - bottom - { - type atmTurbulentHeatFluxTemperature; - heatSource flux; - alphaEff alphaEff; - Cp0 1005.0; - q uniform 0; - value uniform 300; - - } - - top - { - type zeroGradient; - } - - frontandbackplanes - { - type empty; - } -} diff --git a/doc/examples/fluidsimfoam-phill/src/fluidsimfoam_phill/templates/U.jinja b/doc/examples/fluidsimfoam-phill/src/fluidsimfoam_phill/templates/U.jinja deleted file mode 100644 --- a/doc/examples/fluidsimfoam-phill/src/fluidsimfoam_phill/templates/U.jinja +++ /dev/null @@ -1,42 +0,0 @@ -FoamFile -{ - version 2.0; - format binary; - class volVectorField; - location "0"; - object U; -} - -dimensions [0 1 -1 0 0 0 0]; - -internalField uniform (0.12 0 0); - -boundaryField -{ - outlet - { - type cyclic; - } - - inlet - { - type cyclic; - } - - bottom - { - type fixedValue; - value uniform (0 0 0); - } - - top - { - type slip; - } - - frontandbackplanes - { - type empty; - } - -} diff --git a/doc/examples/fluidsimfoam-phill/src/fluidsimfoam_phill/templates/alphat.jinja b/doc/examples/fluidsimfoam-phill/src/fluidsimfoam_phill/templates/alphat.jinja deleted file mode 100644 --- a/doc/examples/fluidsimfoam-phill/src/fluidsimfoam_phill/templates/alphat.jinja +++ /dev/null @@ -1,40 +0,0 @@ -FoamFile -{ - version 2.0; - format ascii; - class volScalarField; - location "0"; - object alphat; -} - -dimensions [0 2 -1 0 0 0 0]; - -internalField uniform 0; - -boundaryField -{ - bottom - { - type zeroGradient; - } - - inlet - { - type cyclic; - } - - outlet - { - type cyclic; - } - - top - { - type zeroGradient; - } - - frontandbackplanes - { - type empty; - } -} diff --git a/doc/examples/fluidsimfoam-phill/src/fluidsimfoam_phill/templates/fvSchemes.jinja b/doc/examples/fluidsimfoam-phill/src/fluidsimfoam_phill/templates/fvSchemes.jinja deleted file mode 100644 --- a/doc/examples/fluidsimfoam-phill/src/fluidsimfoam_phill/templates/fvSchemes.jinja +++ /dev/null @@ -1,46 +0,0 @@ -FoamFile -{ - version 2.0; - format ascii; - class dictionary; - location "system"; - object fvSchemes; -} - -ddtSchemes -{ - default Euler implicit; -} - -gradSchemes -{ - default Gauss linear; -} - -divSchemes -{ - default none; - - div(phi,U) Gauss upwind; - div(phi,T) Gauss upwind; - div(phi,rhok) Gauss upwind; - div(phi,R) Gauss upwind; - div(R) Gauss linear; - div((nuEff*dev2(T(grad(U))))) Gauss linear; - div((nuEff*dev(T(grad(U))))) Gauss linear; -} - -laplacianSchemes -{ - default Gauss linear corrected; -} - -interpolationSchemes -{ - default linear; -} - -snGradSchemes -{ - default uncorrected; -} diff --git a/doc/examples/fluidsimfoam-phill/src/fluidsimfoam_phill/templates/p_rgh.jinja b/doc/examples/fluidsimfoam-phill/src/fluidsimfoam_phill/templates/p_rgh.jinja deleted file mode 100644 --- a/doc/examples/fluidsimfoam-phill/src/fluidsimfoam_phill/templates/p_rgh.jinja +++ /dev/null @@ -1,41 +0,0 @@ -FoamFile -{ - version 2.0; - format ascii; - class volScalarField; - object p_rgh; -} - -dimensions [0 2 -2 0 0 0 0]; - -internalField uniform 0; - -boundaryField -{ - inlet - { - type cyclic; - } - - outlet - { - type cyclic; - } - - bottom - { - type fixedFluxPressure; - rho rhok; - value uniform 0; - } - - top - { - type zeroGradient; - } - - frontandbackplanes - { - type empty; - } -} diff --git a/doc/examples/fluidsimfoam-phill/src/fluidsimfoam_phill/templates/rhok.jinja b/doc/examples/fluidsimfoam-phill/src/fluidsimfoam_phill/templates/rhok.jinja deleted file mode 100644 --- a/doc/examples/fluidsimfoam-phill/src/fluidsimfoam_phill/templates/rhok.jinja +++ /dev/null @@ -1,40 +0,0 @@ -FoamFile -{ - version 2.0; - format ascii; - class volScalarField; - location "0"; - object rhok; -} - -dimensions [0 0 0 0 0 0 0]; - -internalField uniform 1.15; - -boundaryField -{ - top - { - type zeroGradient; - } - - bottom - { - type zeroGradient; - } - - frontandbackplanes - { - type empty; - } - - outlet - { - type cyclic; - } - - inlet - { - type cyclic; - } -} diff --git a/doc/examples/fluidsimfoam-phill/src/fluidsimfoam_phill/templates/topoSetDict.jinja b/doc/examples/fluidsimfoam-phill/src/fluidsimfoam_phill/templates/topoSetDict.jinja deleted file mode 100644 --- a/doc/examples/fluidsimfoam-phill/src/fluidsimfoam_phill/templates/topoSetDict.jinja +++ /dev/null @@ -1,24 +0,0 @@ -FoamFile -{ - version 2.0; - format ascii; - class dictionary; - location "system"; - object topoSetDict; -} - -actions -( - { - name rotor; - type cellSet; - action new; - source cylinderToCell; - sourceInfo - { - p1 (0 0 0); - p2 (0 0 0.5); - radius 6.5; - } - } -); diff --git a/doc/examples/fluidsimfoam-phill/tests/saved_cases/case0/system/topoSetDict b/doc/examples/fluidsimfoam-phill/tests/saved_cases/case0/system/topoSetDict deleted file mode 100644 --- a/doc/examples/fluidsimfoam-phill/tests/saved_cases/case0/system/topoSetDict +++ /dev/null @@ -1,24 +0,0 @@ -FoamFile -{ - version 2.0; - format ascii; - class dictionary; - location "system"; - object topoSetDict; -} - -actions -( - { - name rotor; - type cellSet; - action new; - source cylinderToCell; - sourceInfo - { - p1 (0 0 0); - p2 (0 0 0.5); - radius 6.5; - } - } -); # HG changeset patch # User Pooria DANAEIFAR <pouryadanaeifar@gmail.com> # Date 1683897768 -7200 # Fri May 12 15:22:48 2023 +0200 # Node ID b7334d123c50819d2837acfd4dae6a81e66d8c9b # Parent 3cc7764e1562e07e0ce08f053c3a81b85ed44f9b Update phill saved case diff --git a/doc/examples/fluidsimfoam-phill/tests/saved_cases/case0/0/T b/doc/examples/fluidsimfoam-phill/tests/saved_cases/case0/0/T --- a/doc/examples/fluidsimfoam-phill/tests/saved_cases/case0/0/T +++ b/doc/examples/fluidsimfoam-phill/tests/saved_cases/case0/0/T @@ -6,40 +6,30 @@ object T; } -dimensions [0 0 0 1 0 0 0]; +dimensions [0 0 0 1 0 0 0]; -internalField uniform 300; +internalField uniform 300; boundaryField { + inlet + { + type cyclic; + } outlet { - type cyclic; + type cyclic; } - - inlet + top { - type cyclic; + type zeroGradient; } - bottom { - type atmTurbulentHeatFluxTemperature; - heatSource flux; - alphaEff alphaEff; - Cp0 1005.0; - q uniform 0; - value uniform 300; - + type zeroGradient; } - - top + frontAndBackPlanes { - type zeroGradient; - } - - frontandbackplanes - { - type empty; + type empty; } } diff --git a/doc/examples/fluidsimfoam-phill/tests/saved_cases/case0/0/U b/doc/examples/fluidsimfoam-phill/tests/saved_cases/case0/0/U --- a/doc/examples/fluidsimfoam-phill/tests/saved_cases/case0/0/U +++ b/doc/examples/fluidsimfoam-phill/tests/saved_cases/case0/0/U @@ -1,42 +1,35 @@ FoamFile { version 2.0; - format binary; + format ascii; class volVectorField; - location "0"; object U; } -dimensions [0 1 -1 0 0 0 0]; +dimensions [0 1 -1 0 0 0 0]; -internalField uniform (0.12 0 0); +internalField uniform (0.1 0 0); boundaryField { + inlet + { + type cyclic; + } outlet { - type cyclic; + type cyclic; } - - inlet + top { - type cyclic; + type slip; } - bottom { - type fixedValue; - value uniform (0 0 0); - } - - top - { - type slip; + type noSlip; } - - frontandbackplanes + frontAndBackPlanes { - type empty; + type empty; } - } diff --git a/doc/examples/fluidsimfoam-phill/tests/saved_cases/case0/0/alphat b/doc/examples/fluidsimfoam-phill/tests/saved_cases/case0/0/alphat --- a/doc/examples/fluidsimfoam-phill/tests/saved_cases/case0/0/alphat +++ b/doc/examples/fluidsimfoam-phill/tests/saved_cases/case0/0/alphat @@ -3,38 +3,33 @@ version 2.0; format ascii; class volScalarField; - location "0"; object alphat; } -dimensions [0 2 -1 0 0 0 0]; +dimensions [0 2 -1 0 0 0 0]; -internalField uniform 0; +internalField uniform 0; boundaryField { - bottom - { - type zeroGradient; - } - inlet { - type cyclic; + type cyclic; } - outlet { - type cyclic; + type cyclic; } - top { - type zeroGradient; + type zeroGradient; } - - frontandbackplanes + bottom { - type empty; + type zeroGradient; + } + frontAndBackPlanes + { + type empty; } } diff --git a/doc/examples/fluidsimfoam-phill/tests/saved_cases/case0/0/p_rgh b/doc/examples/fluidsimfoam-phill/tests/saved_cases/case0/0/p_rgh --- a/doc/examples/fluidsimfoam-phill/tests/saved_cases/case0/0/p_rgh +++ b/doc/examples/fluidsimfoam-phill/tests/saved_cases/case0/0/p_rgh @@ -6,36 +6,30 @@ object p_rgh; } -dimensions [0 2 -2 0 0 0 0]; +dimensions [0 2 -2 0 0 0 0]; -internalField uniform 0; +internalField uniform 0; boundaryField { inlet { - type cyclic; + type cyclic; } - outlet { - type cyclic; + type cyclic; } - + top + { + type zeroGradient; + } bottom { - type fixedFluxPressure; - rho rhok; - value uniform 0; + type zeroGradient; } - - top + frontAndBackPlanes { - type zeroGradient; - } - - frontandbackplanes - { - type empty; + type empty; } } diff --git a/doc/examples/fluidsimfoam-phill/tests/saved_cases/case0/0/rhok b/doc/examples/fluidsimfoam-phill/tests/saved_cases/case0/0/rhok --- a/doc/examples/fluidsimfoam-phill/tests/saved_cases/case0/0/rhok +++ b/doc/examples/fluidsimfoam-phill/tests/saved_cases/case0/0/rhok @@ -3,38 +3,33 @@ version 2.0; format ascii; class volScalarField; - location "0"; object rhok; } -dimensions [0 0 0 0 0 0 0]; +dimensions [0 0 0 0 0 0 0]; -internalField uniform 1.15; +internalField uniform 1.15; boundaryField { + inlet + { + type cyclic; + } + outlet + { + type cyclic; + } top { - type zeroGradient; + type zeroGradient; } - bottom { - type zeroGradient; - } - - frontandbackplanes - { - type empty; + type zeroGradient; } - - outlet + frontAndBackPlanes { - type cyclic; - } - - inlet - { - type cyclic; + type empty; } } diff --git a/doc/examples/fluidsimfoam-phill/tests/saved_cases/case0/constant/fvOptions b/doc/examples/fluidsimfoam-phill/tests/saved_cases/case0/constant/fvOptions --- a/doc/examples/fluidsimfoam-phill/tests/saved_cases/case0/constant/fvOptions +++ b/doc/examples/fluidsimfoam-phill/tests/saved_cases/case0/constant/fvOptions @@ -27,9 +27,7 @@ atmCoriolisUSourceCoeffs { selectionMode all; - // Omega (0 0 5.65156e-5); - latitude 45.188; - planetaryRotationPeriod 23.9344694; + Omega (0 7.2921e-5 0); } } diff --git a/doc/examples/fluidsimfoam-phill/tests/saved_cases/case0/constant/transportProperties b/doc/examples/fluidsimfoam-phill/tests/saved_cases/case0/constant/transportProperties --- a/doc/examples/fluidsimfoam-phill/tests/saved_cases/case0/constant/transportProperties +++ b/doc/examples/fluidsimfoam-phill/tests/saved_cases/case0/constant/transportProperties @@ -1,26 +1,20 @@ -/*--------------------------------*- C++ -*----------------------------------*\ -| ========= | | -| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox | -| \\ / O peration | Version: v2206 | -| \\ / A nd | Website: www.openfoam.com | -| \\/ M anipulation | | -\*---------------------------------------------------------------------------*/ FoamFile { version 2.0; format ascii; class dictionary; + location "constant"; object transportProperties; } transportModel Newtonian; -nu nu [0 2 -1 0 0 0 0] 0.0001; +nu nu [0 2 -1 0 0 0 0] 0.01; -Pr Pr [0 0 0 0 0 0 0] 10; +Pr Pr [0 0 0 0 0 0 0] 10; -beta 0.003; +beta beta [0 0 0 -1 0 0 0] 0.000223; -TRef 300; +TRef TRef [0 0 0 1 0 0 0] 0.01; -Prt 0.85; +Prt Prt [0 0 0 0 0 0 0] 100.0; diff --git a/doc/examples/fluidsimfoam-phill/tests/saved_cases/case0/system/blockMeshDict b/doc/examples/fluidsimfoam-phill/tests/saved_cases/case0/system/blockMeshDict --- a/doc/examples/fluidsimfoam-phill/tests/saved_cases/case0/system/blockMeshDict +++ b/doc/examples/fluidsimfoam-phill/tests/saved_cases/case0/system/blockMeshDict @@ -20,17 +20,17 @@ ( ( 0 80 0 ) // 0 v0-0 ( 2000 80 0 ) // 1 v1-0 - ( 2000 2000 0 ) // 2 v2-0 - ( 0 2000 0 ) // 3 v3-0 + ( 2000 5000 0 ) // 2 v2-0 + ( 0 5000 0 ) // 3 v3-0 ( 0 80 0.01 ) // 4 v0+z ( 2000 80 0.01 ) // 5 v1+z - ( 2000 2000 0.01 ) // 6 v2+z - ( 0 2000 0.01 ) // 7 v3+z + ( 2000 5000 0.01 ) // 6 v2+z + ( 0 5000 0.01 ) // 7 v3+z ); blocks ( - hex (0 1 2 3 4 5 6 7) b0 (31 30 1) simpleGrading (1 ( ( 0.1 0.25 41.9 ) ( 0.9 0.75 1 ) ) 1) // b0 (v0-0 v1-0 v2-0 v3-0 v0+z v1+z v2+z v3+z) + hex (0 1 2 3 4 5 6 7) b0 (21 50 1) simpleGrading (1 ( ( 0.1 0.25 41.9 ) ( 0.9 0.75 1 ) ) 1) // b0 (v0-0 v1-0 v2-0 v3-0 v0+z v1+z v2+z v3+z) ); edges @@ -38,69 +38,49 @@ spline 0 1 // spline0 (v0-0 v1-0) ( ( 0 80 0 ) - ( 66.6666666666667 79.1259040293522 0 ) - ( 133.333333333333 76.541818305704 0 ) + ( 100 78.0422606518061 0 ) ( 200 72.3606797749979 0 ) - ( 266.666666666667 66.7652242543543 0 ) - ( 333.333333333333 60 0 ) + ( 300 63.5114100916989 0 ) ( 400 52.3606797749979 0 ) - ( 466.666666666667 44.1811385307061 0 ) - ( 533.333333333333 35.8188614692939 0 ) + ( 500 40 0 ) ( 600 27.6393202250021 0 ) - ( 666.666666666667 20 0 ) - ( 733.333333333333 13.2347757456457 0 ) + ( 700 16.4885899083011 0 ) ( 800 7.6393202250021 0 ) - ( 866.666666666667 3.45818169429597 0 ) - ( 933.333333333333 0.874095970647772 0 ) + ( 900 1.95773934819386 0 ) ( 1000 0 0 ) - ( 1066.66666666667 0.874095970647777 0 ) - ( 1133.33333333333 3.45818169429596 0 ) + ( 1100 1.95773934819386 0 ) ( 1200 7.6393202250021 0 ) - ( 1266.66666666667 13.2347757456457 0 ) - ( 1333.33333333333 20 0 ) + ( 1300 16.4885899083011 0 ) ( 1400 27.6393202250021 0 ) - ( 1466.66666666667 35.8188614692939 0 ) - ( 1533.33333333333 44.1811385307061 0 ) + ( 1500 40 0 ) ( 1600 52.3606797749979 0 ) - ( 1666.66666666667 60 0 ) - ( 1733.33333333333 66.7652242543543 0 ) + ( 1700 63.5114100916989 0 ) ( 1800 72.3606797749979 0 ) - ( 1866.66666666667 76.541818305704 0 ) - ( 1933.33333333333 79.1259040293522 0 ) + ( 1900 78.0422606518061 0 ) ( 2000 80 0 ) ) spline 4 5 // spline1 (v0+z v1+z) ( ( 0 80 0.01 ) - ( 66.6666666666667 79.1259040293522 0.01 ) - ( 133.333333333333 76.541818305704 0.01 ) + ( 100 78.0422606518061 0.01 ) ( 200 72.3606797749979 0.01 ) - ( 266.666666666667 66.7652242543543 0.01 ) - ( 333.333333333333 60 0.01 ) + ( 300 63.5114100916989 0.01 ) ( 400 52.3606797749979 0.01 ) - ( 466.666666666667 44.1811385307061 0.01 ) - ( 533.333333333333 35.8188614692939 0.01 ) + ( 500 40 0.01 ) ( 600 27.6393202250021 0.01 ) - ( 666.666666666667 20 0.01 ) - ( 733.333333333333 13.2347757456457 0.01 ) + ( 700 16.4885899083011 0.01 ) ( 800 7.6393202250021 0.01 ) - ( 866.666666666667 3.45818169429597 0.01 ) - ( 933.333333333333 0.874095970647772 0.01 ) + ( 900 1.95773934819386 0.01 ) ( 1000 0 0.01 ) - ( 1066.66666666667 0.874095970647777 0.01 ) - ( 1133.33333333333 3.45818169429596 0.01 ) + ( 1100 1.95773934819386 0.01 ) ( 1200 7.6393202250021 0.01 ) - ( 1266.66666666667 13.2347757456457 0.01 ) - ( 1333.33333333333 20 0.01 ) + ( 1300 16.4885899083011 0.01 ) ( 1400 27.6393202250021 0.01 ) - ( 1466.66666666667 35.8188614692939 0.01 ) - ( 1533.33333333333 44.1811385307061 0.01 ) + ( 1500 40 0.01 ) ( 1600 52.3606797749979 0.01 ) - ( 1666.66666666667 60 0.01 ) - ( 1733.33333333333 66.7652242543543 0.01 ) + ( 1700 63.5114100916989 0.01 ) ( 1800 72.3606797749979 0.01 ) - ( 1866.66666666667 76.541818305704 0.01 ) - ( 1933.33333333333 79.1259040293522 0.01 ) + ( 1900 78.0422606518061 0.01 ) ( 2000 80 0.01 ) ) ); diff --git a/doc/examples/fluidsimfoam-phill/tests/saved_cases/case0/system/controlDict b/doc/examples/fluidsimfoam-phill/tests/saved_cases/case0/system/controlDict --- a/doc/examples/fluidsimfoam-phill/tests/saved_cases/case0/system/controlDict +++ b/doc/examples/fluidsimfoam-phill/tests/saved_cases/case0/system/controlDict @@ -16,19 +16,19 @@ application buoyantBoussinesqPimpleFoam; -startFrom startTime; +startFrom latestTime; startTime 0; stopAt endTime; -endTime 60; +endTime 1200000; -deltaT 0.05; +deltaT 10; writeControl adjustableRunTime; -writeInterval 1; +writeInterval 5000; purgeWrite 0; @@ -42,28 +42,12 @@ timePrecision 6; -runTimeModifiable yes; - -adjustTimeStep yes; -libs (atmosphericModels); +runTimeModifiable true; -functions -{ - fieldAverage1 - { - type fieldAverage; - libs (fieldFunctionObjects); - writeControl writeTime; +adjustTimeStep on; - fields - ( - U - { - mean on; - prime2Mean off; - base time; - } - ); - } -} +maxCo 0.6; +maxAlphaCo 0.6; + +maxDeltaT 1; diff --git a/doc/examples/fluidsimfoam-phill/tests/saved_cases/case0/system/fvSchemes b/doc/examples/fluidsimfoam-phill/tests/saved_cases/case0/system/fvSchemes --- a/doc/examples/fluidsimfoam-phill/tests/saved_cases/case0/system/fvSchemes +++ b/doc/examples/fluidsimfoam-phill/tests/saved_cases/case0/system/fvSchemes @@ -3,44 +3,42 @@ version 2.0; format ascii; class dictionary; - location "system"; object fvSchemes; } ddtSchemes { - default Euler implicit; + default Euler implicit; } gradSchemes { - default Gauss linear; + default Gauss linear; } divSchemes { - default none; - - div(phi,U) Gauss upwind; - div(phi,T) Gauss upwind; - div(phi,rhok) Gauss upwind; - div(phi,R) Gauss upwind; - div(R) Gauss linear; - div((nuEff*dev2(T(grad(U))))) Gauss linear; - div((nuEff*dev(T(grad(U))))) Gauss linear; + default none; + div(phi,U) Gauss upwind; + div(phi,T) Gauss upwind; + div(phi,rhok) Gauss upwind; + div(phi,R) Gauss upwind; + div(R) Gauss linear; + div((nuEff*dev2(T(grad(U))))) Gauss linear; + div((nuEff*dev(T(grad(U))))) Gauss linear; } laplacianSchemes { - default Gauss linear corrected; + default Gauss linear corrected; } interpolationSchemes { - default linear; + default linear; } snGradSchemes { - default uncorrected; + default uncorrected; } # HG changeset patch # User Pooria DANAEIFAR <pouryadanaeifar@gmail.com> # Date 1683897884 -7200 # Fri May 12 15:24:44 2023 +0200 # Node ID 929f796f178845a06dc32a1d73aa80b538f92e1c # Parent b7334d123c50819d2837acfd4dae6a81e66d8c9b Simplify task.py and fvOptions diff --git a/doc/examples/fluidsimfoam-phill/src/fluidsimfoam_phill/templates/fvOptions.jinja b/doc/examples/fluidsimfoam-phill/src/fluidsimfoam_phill/templates/fvOptions.jinja --- a/doc/examples/fluidsimfoam-phill/src/fluidsimfoam_phill/templates/fvOptions.jinja +++ b/doc/examples/fluidsimfoam-phill/src/fluidsimfoam_phill/templates/fvOptions.jinja @@ -27,9 +27,7 @@ atmCoriolisUSourceCoeffs { selectionMode all; - // Omega (0 0 5.65156e-5); - latitude 45.188; - planetaryRotationPeriod 23.9344694; + Omega (0 7.2921e-5 0); } } diff --git a/doc/examples/fluidsimfoam-phill/src/fluidsimfoam_phill/templates/tasks.py b/doc/examples/fluidsimfoam-phill/src/fluidsimfoam_phill/templates/tasks.py --- a/doc/examples/fluidsimfoam-phill/src/fluidsimfoam_phill/templates/tasks.py +++ b/doc/examples/fluidsimfoam-phill/src/fluidsimfoam_phill/templates/tasks.py @@ -1,20 +1,1 @@ -from invoke import task - -from fluidsimfoam.tasks import ( - block_mesh, - clean, - funky_set_fields, - sets_to_zones, - topo_set, -) - - -@task(funky_set_fields) -def run(context): - with open("system/controlDict") as file: - for line in file: - if line.startswith("application "): - application = line.split()[-1] - break - - context.run(application) +from fluidsimfoam.tasks import block_mesh, clean, polymesh, run # HG changeset patch # User Pooria DANAEIFAR <pouryadanaeifar@gmail.com> # Date 1684145717 -7200 # Mon May 15 12:15:17 2023 +0200 # Node ID 1f5be11332d9c641f63fd6db83e4e3bc8eaf3db3 # Parent 929f796f178845a06dc32a1d73aa80b538f92e1c Phill no need for rhok diff --git a/doc/examples/fluidsimfoam-phill/src/fluidsimfoam_phill/output.py b/doc/examples/fluidsimfoam-phill/src/fluidsimfoam_phill/output.py --- a/doc/examples/fluidsimfoam-phill/src/fluidsimfoam_phill/output.py +++ b/doc/examples/fluidsimfoam-phill/src/fluidsimfoam_phill/output.py @@ -11,12 +11,7 @@ VolScalarField, VolVectorField, ) - -from fluidsimfoam.foam_input_files.blockmesh import ( - Point, - SimpleGrading, - Vertex, -) +from fluidsimfoam.foam_input_files.blockmesh import Point, SimpleGrading, Vertex from fluidsimfoam.output import Output @@ -61,7 +56,7 @@ class OutputPHill(Output): """Output for the phill solver""" - variable_names = ["U", "rhok", "p_rgh", "T", "alphat"] + variable_names = ["U", "p_rgh", "T", "alphat"] system_files_names = Output.system_files_names + ["blockMeshDict"] constant_files_names = [ "g", @@ -94,7 +89,6 @@ default none div(phi,U) Gauss upwind div(phi,T) Gauss upwind - div(phi,rhok) Gauss upwind div(phi,R) Gauss upwind div(R) Gauss linear div((nuEff*dev2(T(grad(U))))) Gauss linear @@ -215,9 +209,6 @@ def make_tree_p_rgh(self, params): return make_scalar_field("p_rgh", dimension="m^2/s^2", values=0) - def make_tree_rhok(self, params): - return make_scalar_field("rhok", dimension="", values=1.15) - def make_tree_t(self, params): return make_scalar_field("T", dimension="K", values=300) diff --git a/doc/examples/fluidsimfoam-phill/tests/saved_cases/case0/0/rhok b/doc/examples/fluidsimfoam-phill/tests/saved_cases/case0/0/rhok deleted file mode 100644 --- a/doc/examples/fluidsimfoam-phill/tests/saved_cases/case0/0/rhok +++ /dev/null @@ -1,35 +0,0 @@ -FoamFile -{ - version 2.0; - format ascii; - class volScalarField; - object rhok; -} - -dimensions [0 0 0 0 0 0 0]; - -internalField uniform 1.15; - -boundaryField -{ - inlet - { - type cyclic; - } - outlet - { - type cyclic; - } - top - { - type zeroGradient; - } - bottom - { - type zeroGradient; - } - frontAndBackPlanes - { - type empty; - } -} diff --git a/doc/examples/fluidsimfoam-phill/tests/saved_cases/case0/system/fvSchemes b/doc/examples/fluidsimfoam-phill/tests/saved_cases/case0/system/fvSchemes --- a/doc/examples/fluidsimfoam-phill/tests/saved_cases/case0/system/fvSchemes +++ b/doc/examples/fluidsimfoam-phill/tests/saved_cases/case0/system/fvSchemes @@ -21,7 +21,6 @@ default none; div(phi,U) Gauss upwind; div(phi,T) Gauss upwind; - div(phi,rhok) Gauss upwind; div(phi,R) Gauss upwind; div(R) Gauss linear; div((nuEff*dev2(T(grad(U))))) Gauss linear; diff --git a/tests/test_phill.py b/tests/test_phill.py deleted file mode 100644 --- a/tests/test_phill.py +++ /dev/null @@ -1,45 +0,0 @@ -import shutil -from pathlib import Path - -import pytest -from fluidsimfoam_phill import Simul - -from fluidsimfoam.foam_input_files import dump, parse - -here = Path(__file__).absolute().parent - - -path_foam_executable = shutil.which("interFoam") - - -@pytest.mark.skipif( - path_foam_executable is None, reason="executable icoFoam not available" -) -def test_run(): - params = Simul.create_default_params() - - params.output.sub_directory = "tests_fluidsimfoam/phill/" - - params.control_dict.end_time = 0.002 - - sim = Simul(params) - - sim.make.exec("run") - sim.make.exec("clean") - - -@pytest.mark.skipif( - path_foam_executable is None, reason="executable icoFoam not available" -) -def test_run_2d_topo_3d(): - params = Simul.create_default_params() - - params.output.sub_directory = "tests_fluidsimfoam/phill/" - - params.control_dict.end_time = 0.001 - params.block_mesh_dict.lz = 0.2 - params.block_mesh_dict.nz = 4 - sim = Simul(params) - - sim.make.exec("run") - sim.make.exec("clean") # HG changeset patch # User Pooria DANAEIFAR <pouryadanaeifar@gmail.com> # Date 1684167049 -7200 # Mon May 15 18:10:49 2023 +0200 # Node ID 6196fc2e5d14bc9f9fa2c58d48928524a4f7e04b # Parent 1f5be11332d9c641f63fd6db83e4e3bc8eaf3db3 Update output of phill diff --git a/doc/examples/fluidsimfoam-phill/src/fluidsimfoam_phill/output.py b/doc/examples/fluidsimfoam-phill/src/fluidsimfoam_phill/output.py --- a/doc/examples/fluidsimfoam-phill/src/fluidsimfoam_phill/output.py +++ b/doc/examples/fluidsimfoam-phill/src/fluidsimfoam_phill/output.py @@ -82,7 +82,7 @@ } ) - helper_fv_schemes = FvSchemesHelper( + _helper_fv_schemes = FvSchemesHelper( ddt="default Euler implicit", grad="default Gauss linear", div=""" @@ -105,13 +105,13 @@ }, ) - helper_transport_properties = ConstantFileHelper( + _helper_transport_properties = ConstantFileHelper( "transportProperties", { "transportModel": "Newtonian", "nu": 1.0e-2, "Pr": 10, - "beta": 2.23e-4, + "beta": 1, "TRef": 1.0e-2, "Prt": 1e2, }, @@ -134,7 +134,7 @@ for key, value in default.items(): params.block_mesh_dict[key] = value - def make_code_block_mesh_dict(self, params): + def _make_code_block_mesh_dict(self, params): nx = params.block_mesh_dict.nx ny = params.block_mesh_dict.ny nz = params.block_mesh_dict.nz @@ -203,16 +203,16 @@ return bmd.format(sort_vortices="as_added") - def make_tree_alphat(self, params): + def _make_tree_alphat(self, params): return make_scalar_field("alphat", dimension="m^2/s", values=0) - def make_tree_p_rgh(self, params): + def _make_tree_p_rgh(self, params): return make_scalar_field("p_rgh", dimension="m^2/s^2", values=0) - def make_tree_t(self, params): + def _make_tree_t(self, params): return make_scalar_field("T", dimension="K", values=300) - def make_tree_u(self, params): + def _make_tree_u(self, params): field = make_vector_field("U", dimension="m/s", values=[0.1, 0, 0]) field.set_boundary("top", "slip") field.set_boundary("bottom", "noSlip") diff --git a/doc/examples/fluidsimfoam-phill/src/fluidsimfoam_phill/templates/fvSolution.jinja b/doc/examples/fluidsimfoam-phill/src/fluidsimfoam_phill/templates/fvSolution.jinja --- a/doc/examples/fluidsimfoam-phill/src/fluidsimfoam_phill/templates/fvSolution.jinja +++ b/doc/examples/fluidsimfoam-phill/src/fluidsimfoam_phill/templates/fvSolution.jinja @@ -23,7 +23,7 @@ relTol 0; } - "(U|rhok|R|T)" + "(U|R|T)" { solver PBiCG; preconditioner DILU; @@ -31,7 +31,7 @@ relTol 0.1; } - "(U|rhok|R|T)Final" + "(U|R|T)Final" { $U; relTol 0; diff --git a/doc/examples/fluidsimfoam-phill/tests/saved_cases/case0/constant/transportProperties b/doc/examples/fluidsimfoam-phill/tests/saved_cases/case0/constant/transportProperties --- a/doc/examples/fluidsimfoam-phill/tests/saved_cases/case0/constant/transportProperties +++ b/doc/examples/fluidsimfoam-phill/tests/saved_cases/case0/constant/transportProperties @@ -13,7 +13,7 @@ Pr Pr [0 0 0 0 0 0 0] 10; -beta beta [0 0 0 -1 0 0 0] 0.000223; +beta beta [0 0 0 -1 0 0 0] 1; TRef TRef [0 0 0 1 0 0 0] 0.01; diff --git a/doc/examples/fluidsimfoam-phill/tests/saved_cases/case0/system/fvSolution b/doc/examples/fluidsimfoam-phill/tests/saved_cases/case0/system/fvSolution --- a/doc/examples/fluidsimfoam-phill/tests/saved_cases/case0/system/fvSolution +++ b/doc/examples/fluidsimfoam-phill/tests/saved_cases/case0/system/fvSolution @@ -23,7 +23,7 @@ relTol 0; } - "(U|rhok|R|T)" + "(U|R|T)" { solver PBiCG; preconditioner DILU; @@ -31,7 +31,7 @@ relTol 0.1; } - "(U|rhok|R|T)Final" + "(U|R|T)Final" { $U; relTol 0; # HG changeset patch # User Pooria DANAEIFAR <pouryadanaeifar@gmail.com> # Date 1684243499 -7200 # Tue May 16 15:24:59 2023 +0200 # Node ID 59f842cc2b30742229a7a91a6aa6e3af1ea10e98 # Parent 6196fc2e5d14bc9f9fa2c58d48928524a4f7e04b Add scalarfield for T diff --git a/doc/examples/fluidsimfoam-phill/src/fluidsimfoam_phill/output.py b/doc/examples/fluidsimfoam-phill/src/fluidsimfoam_phill/output.py --- a/doc/examples/fluidsimfoam-phill/src/fluidsimfoam_phill/output.py +++ b/doc/examples/fluidsimfoam-phill/src/fluidsimfoam_phill/output.py @@ -112,8 +112,8 @@ "nu": 1.0e-2, "Pr": 10, "beta": 1, - "TRef": 1.0e-2, - "Prt": 1e2, + "TRef": 0, + "Prt": 1, }, dimensions={ "nu": "m^2/s", @@ -166,17 +166,14 @@ SimpleGrading(1, [[0.1, 0.25, 41.9], [0.9, 0.75, 1]], 1), ) - x_dot = [] - y_dot = [] dots = [] h_max = 80 for dot in range(nx + 1): - x_dot.append(dot * lx / nx) - y_dot.append( - (h_max / 2) - * (1 - cos(2 * pi * min(abs((x_dot[dot] - (lx / 2)) / lx), 1))) + x_dot = dot * lx / nx + y_dot = (h_max / 2) * ( + 1 - cos(2 * pi * min(abs((x_dot - (lx / 2)) / lx), 1)) ) - dots.append([x_dot[dot], y_dot[dot]]) + dots.append([x_dot, y_dot]) bmd.add_splineedge( ["v0-0", "v1-0"], @@ -209,11 +206,26 @@ def _make_tree_p_rgh(self, params): return make_scalar_field("p_rgh", dimension="m^2/s^2", values=0) - def _make_tree_t(self, params): - return make_scalar_field("T", dimension="K", values=300) - def _make_tree_u(self, params): field = make_vector_field("U", dimension="m/s", values=[0.1, 0, 0]) field.set_boundary("top", "slip") field.set_boundary("bottom", "noSlip") return field + + @classmethod + def _complete_params_t(cls, params): + params._set_child( + "init_fields", + attribs={"buoyancy_frequency": 1e-3, "T0": 0}, + doc="""The fluid is linearly stratifed with a buoyancy frequency""", + ) + + def _make_tree_t(self, params): + field = make_scalar_field("T", dimension="K") + + x, y, z = self.sim.oper.get_cells_coords() + N = params.init_fields.buoyancy_frequency + T0 = params.init_fields.T0 + field.set_values(T0 + (N**2) / 9.81 * y) + + return field diff --git a/doc/examples/fluidsimfoam-phill/src/fluidsimfoam_phill/templates/funkySetFieldsDict.jinja b/doc/examples/fluidsimfoam-phill/src/fluidsimfoam_phill/templates/funkySetFieldsDict.jinja deleted file mode 100644 --- a/doc/examples/fluidsimfoam-phill/src/fluidsimfoam_phill/templates/funkySetFieldsDict.jinja +++ /dev/null @@ -1,27 +0,0 @@ - -FoamFile -{ - version 2.0; - format ascii; - class dictionary; - location "system"; - object setFieldsDict; -} - -expressions -( - grad_inv_rhok - { - variables - ( - "rho0=1000;" - "height=1;" - "delta_rho=-0.000102;" - ); - - field rhok; - value uniform 1000; - expression "rho0 + pos().y / height * delta_rho"; - keepPatches 1; - } -); # HG changeset patch # User Pooria DANAEIFAR <pouryadanaeifar@gmail.com> # Date 1684244519 -7200 # Tue May 16 15:41:59 2023 +0200 # Node ID 19ec7f9d8f240024698531e09a6927c636cfcf81 # Parent 59f842cc2b30742229a7a91a6aa6e3af1ea10e98 Phill fix test diff --git a/doc/examples/fluidsimfoam-phill/src/fluidsimfoam_phill/output.py b/doc/examples/fluidsimfoam-phill/src/fluidsimfoam_phill/output.py --- a/doc/examples/fluidsimfoam-phill/src/fluidsimfoam_phill/output.py +++ b/doc/examples/fluidsimfoam-phill/src/fluidsimfoam_phill/output.py @@ -56,9 +56,9 @@ class OutputPHill(Output): """Output for the phill solver""" - variable_names = ["U", "p_rgh", "T", "alphat"] - system_files_names = Output.system_files_names + ["blockMeshDict"] - constant_files_names = [ + name_variables = ["U", "p_rgh", "T", "alphat"] + name_system_files = Output.name_system_files + ["blockMeshDict"] + name_constant_files = [ "g", "fvOptions", "MRFProperties", @@ -66,8 +66,8 @@ "turbulenceProperties", ] - default_control_dict_params = Output.default_control_dict_params.copy() - default_control_dict_params.update( + _default_control_dict_params = Output._default_control_dict_params.copy() + _default_control_dict_params.update( { "application": "buoyantBoussinesqPimpleFoam", "startFrom": "latestTime", diff --git a/doc/examples/fluidsimfoam-phill/tests/saved_cases/case0/0/T b/doc/examples/fluidsimfoam-phill/tests/saved_cases/case0/0/T --- a/doc/examples/fluidsimfoam-phill/tests/saved_cases/case0/0/T +++ b/doc/examples/fluidsimfoam-phill/tests/saved_cases/case0/0/T @@ -6,9 +6,123 @@ object T; } -dimensions [0 0 0 1 0 0 0]; +dimensions [0 0 0 1 0 0 0]; -internalField uniform 300; +internalField nonuniform +List<scalar> +110 +( + 8.332507645259937e-06 + 7.1306523955147804e-06 + 5.128083588175331e-06 + 2.9617635066258914e-06 + 1.3106218144750253e-06 + 6.946819571865443e-07 + 1.3106218144750253e-06 + 2.9617635066258914e-06 + 5.128083588175331e-06 + 7.1306523955147804e-06 + 8.332507645259937e-06 + 1.213058103975535e-05 + 1.093781855249745e-05 + 8.950417940876656e-06 + 6.800489296636085e-06 + 5.1618450560652396e-06 + 4.550550458715596e-06 + 5.1618450560652396e-06 + 6.800489296636085e-06 + 8.950417940876656e-06 + 1.093781855249745e-05 + 1.213058103975535e-05 + 3.671549439347604e-05 + 3.5580530071355754e-05 + 3.369327217125382e-05 + 3.164923547400611e-05 + 3.0090519877675836e-05 + 2.9508970438328233e-05 + 3.0090519877675836e-05 + 3.164923547400611e-05 + 3.369327217125382e-05 + 3.5580530071355754e-05 + 3.671549439347604e-05 + 9.027319062181447e-05 + 8.926503567787971e-05 + 8.759418960244647e-05 + 8.578103975535166e-05 + 8.439745158002038e-05 + 8.388103975535167e-05 + 8.439745158002038e-05 + 8.578103975535166e-05 + 8.759418960244647e-05 + 8.926503567787971e-05 + 9.027319062181447e-05 + 0.00015479816513761465 + 0.00015394495412844036 + 0.00015253109072375126 + 0.00015099694189602445 + 0.00014982568807339448 + 0.00014938837920489294 + 0.00014982568807339448 + 0.00015099694189602445 + 0.00015253109072375126 + 0.00015394495412844036 + 0.00015479816513761465 + 0.00021932313965341484 + 0.00021862385321100912 + 0.00021746890927624868 + 0.00021621304791029562 + 0.00021525484199796125 + 0.0002148970438328236 + 0.00021525484199796125 + 0.00021621304791029562 + 0.00021746890927624868 + 0.00021862385321100912 + 0.00021932313965341484 + 0.00028384811416921505 + 0.0002833037716615698 + 0.0002824057084607543 + 0.00028142915392456676 + 0.00028068297655453616 + 0.00028040468909276245 + 0.00028068297655453616 + 0.00028142915392456676 + 0.0002824057084607543 + 0.0002833037716615698 + 0.00028384811416921505 + 0.0003483720693170234 + 0.0003479826707441386 + 0.00034734352701325174 + 0.0003466452599388379 + 0.00034611213047910293 + 0.00034591233435270126 + 0.00034611213047910293 + 0.0003466452599388379 + 0.00034734352701325174 + 0.0003479826707441386 + 0.0003483720693170234 + 0.0004128970438328236 + 0.0004126625891946992 + 0.00041228032619775734 + 0.00041186136595310904 + 0.0004115402650356778 + 0.00041141997961264014 + 0.0004115402650356778 + 0.00041186136595310904 + 0.00041228032619775734 + 0.0004126625891946992 + 0.0004128970438328236 + 0.0004774220183486238 + 0.0004773425076452598 + 0.0004772181447502548 + 0.0004770774719673802 + 0.00047696839959225276 + 0.0004769276248725789 + 0.00047696839959225276 + 0.0004770774719673802 + 0.0004772181447502548 + 0.0004773425076452598 + 0.0004774220183486238 +); boundaryField { diff --git a/doc/examples/fluidsimfoam-phill/tests/saved_cases/case0/constant/transportProperties b/doc/examples/fluidsimfoam-phill/tests/saved_cases/case0/constant/transportProperties --- a/doc/examples/fluidsimfoam-phill/tests/saved_cases/case0/constant/transportProperties +++ b/doc/examples/fluidsimfoam-phill/tests/saved_cases/case0/constant/transportProperties @@ -15,6 +15,6 @@ beta beta [0 0 0 -1 0 0 0] 1; -TRef TRef [0 0 0 1 0 0 0] 0.01; +TRef TRef [0 0 0 1 0 0 0] 0; -Prt Prt [0 0 0 0 0 0 0] 100.0; +Prt Prt [0 0 0 0 0 0 0] 1; diff --git a/doc/examples/fluidsimfoam-phill/tests/saved_cases/case0/system/blockMeshDict b/doc/examples/fluidsimfoam-phill/tests/saved_cases/case0/system/blockMeshDict --- a/doc/examples/fluidsimfoam-phill/tests/saved_cases/case0/system/blockMeshDict +++ b/doc/examples/fluidsimfoam-phill/tests/saved_cases/case0/system/blockMeshDict @@ -30,7 +30,7 @@ blocks ( - hex (0 1 2 3 4 5 6 7) b0 (21 50 1) simpleGrading (1 ( ( 0.1 0.25 41.9 ) ( 0.9 0.75 1 ) ) 1) // b0 (v0-0 v1-0 v2-0 v3-0 v0+z v1+z v2+z v3+z) + hex (0 1 2 3 4 5 6 7) b0 (11 10 1) simpleGrading (1 ( ( 0.1 0.25 41.9 ) ( 0.9 0.75 1 ) ) 1) // b0 (v0-0 v1-0 v2-0 v3-0 v0+z v1+z v2+z v3+z) ); edges @@ -38,49 +38,29 @@ spline 0 1 // spline0 (v0-0 v1-0) ( ( 0 80 0 ) - ( 100 78.0422606518061 0 ) ( 200 72.3606797749979 0 ) - ( 300 63.5114100916989 0 ) ( 400 52.3606797749979 0 ) - ( 500 40 0 ) ( 600 27.6393202250021 0 ) - ( 700 16.4885899083011 0 ) ( 800 7.6393202250021 0 ) - ( 900 1.95773934819386 0 ) ( 1000 0 0 ) - ( 1100 1.95773934819386 0 ) ( 1200 7.6393202250021 0 ) - ( 1300 16.4885899083011 0 ) ( 1400 27.6393202250021 0 ) - ( 1500 40 0 ) ( 1600 52.3606797749979 0 ) - ( 1700 63.5114100916989 0 ) ( 1800 72.3606797749979 0 ) - ( 1900 78.0422606518061 0 ) ( 2000 80 0 ) ) spline 4 5 // spline1 (v0+z v1+z) ( ( 0 80 0.01 ) - ( 100 78.0422606518061 0.01 ) ( 200 72.3606797749979 0.01 ) - ( 300 63.5114100916989 0.01 ) ( 400 52.3606797749979 0.01 ) - ( 500 40 0.01 ) ( 600 27.6393202250021 0.01 ) - ( 700 16.4885899083011 0.01 ) ( 800 7.6393202250021 0.01 ) - ( 900 1.95773934819386 0.01 ) ( 1000 0 0.01 ) - ( 1100 1.95773934819386 0.01 ) ( 1200 7.6393202250021 0.01 ) - ( 1300 16.4885899083011 0.01 ) ( 1400 27.6393202250021 0.01 ) - ( 1500 40 0.01 ) ( 1600 52.3606797749979 0.01 ) - ( 1700 63.5114100916989 0.01 ) ( 1800 72.3606797749979 0.01 ) - ( 1900 78.0422606518061 0.01 ) ( 2000 80 0.01 ) ) ); diff --git a/doc/examples/fluidsimfoam-phill/tests/test_phill.py b/doc/examples/fluidsimfoam-phill/tests/test_phill.py --- a/doc/examples/fluidsimfoam-phill/tests/test_phill.py +++ b/doc/examples/fluidsimfoam-phill/tests/test_phill.py @@ -14,6 +14,8 @@ def test_reproduce_case(): params = Simul.create_default_params() params.output.sub_directory = "tests_fluidsimfoam/phill" + params.block_mesh_dict.nx = 10 + params.block_mesh_dict.ny = 10 sim = Simul(params) check_saved_case(path_saved_case, sim.path_run) # HG changeset patch # User Pooria DANAEIFAR <pouryadanaeifar@gmail.com> # Date 1684249074 -7200 # Tue May 16 16:57:54 2023 +0200 # Node ID 185ec1a1ac2481e359fac05f266300375d41538a # Parent 19ec7f9d8f240024698531e09a6927c636cfcf81 Add script for phill sinusoidal case diff --git a/doc/examples/fluidsimfoam-phill/doc/reproduce_sin_2d.py b/doc/examples/fluidsimfoam-phill/doc/reproduce_sin_2d.py new file mode 100644 --- /dev/null +++ b/doc/examples/fluidsimfoam-phill/doc/reproduce_sin_2d.py @@ -0,0 +1,19 @@ +from fluidsimfoam_phill import Simul + +params = Simul.create_default_params() +params.short_name_type_run = "sin_2d" +params.init_fields.buoyancy_frequency = 0.001 +params.transport_properties.nu = 0.01 +params.transport_properties.pr = 10 +params.control_dict.end_time = 1200000 +params.control_dict.delta_t = 10 +params.block_mesh_dict.lx = 2000 +params.block_mesh_dict.ly = 5000 +params.block_mesh_dict.nx = 20 +params.block_mesh_dict.ny = 50 + +params.output.sub_directory = "examples_fluidsimfoam/phill" + +sim = Simul(params) + +sim.make.exec("run") # HG changeset patch # User Pooria DANAEIFAR <pouryadanaeifar@gmail.com> # Date 1684249273 -7200 # Tue May 16 17:01:13 2023 +0200 # Node ID 4f8e8412e88944b2c2ea0ba3853b560d71c14b2f # Parent 185ec1a1ac2481e359fac05f266300375d41538a Parameterize h_max in output diff --git a/doc/examples/fluidsimfoam-phill/src/fluidsimfoam_phill/output.py b/doc/examples/fluidsimfoam-phill/src/fluidsimfoam_phill/output.py --- a/doc/examples/fluidsimfoam-phill/src/fluidsimfoam_phill/output.py +++ b/doc/examples/fluidsimfoam-phill/src/fluidsimfoam_phill/output.py @@ -129,10 +129,13 @@ @classmethod def _complete_params_block_mesh_dict(cls, params): super()._complete_params_block_mesh_dict(params) - default = {"nx": 20, "ny": 50, "nz": 1} + default = {"nx": 20, "ny": 50, "nz": 1, "h_max": 80} default.update({"lx": 2000, "ly": 5000, "lz": 0.01, "scale": 1}) for key, value in default.items(): - params.block_mesh_dict[key] = value + try: + params.block_mesh_dict[key] = value + except AttributeError: + params.block_mesh_dict._set_attribs({key: value}) def _make_code_block_mesh_dict(self, params): nx = params.block_mesh_dict.nx @@ -143,10 +146,11 @@ ly = params.block_mesh_dict.ly lz = params.block_mesh_dict.lz + h_max = params.block_mesh_dict.h_max + bmd = BlockMeshDict() bmd.set_scale(params.block_mesh_dict.scale) - h_max = 80 basevs = [ Vertex(0, h_max, lz, "v0"), Vertex(lx, h_max, lz, "v1"), @@ -167,7 +171,7 @@ ) dots = [] - h_max = 80 + for dot in range(nx + 1): x_dot = dot * lx / nx y_dot = (h_max / 2) * ( diff --git a/doc/examples/fluidsimfoam-phill/src/fluidsimfoam_phill/templates/fvOptions.jinja b/doc/examples/fluidsimfoam-phill/src/fluidsimfoam_phill/templates/fvOptions.jinja --- a/doc/examples/fluidsimfoam-phill/src/fluidsimfoam_phill/templates/fvOptions.jinja +++ b/doc/examples/fluidsimfoam-phill/src/fluidsimfoam_phill/templates/fvOptions.jinja @@ -32,7 +32,6 @@ } -/* momentumSource { type meanVelocityForce; @@ -42,7 +41,6 @@ { selectionMode all; fields (U); - Ubar (1.0 0 0); + Ubar (0.1 0 0); } } -*/ # HG changeset patch # User Pooria DANAEIFAR <pouryadanaeifar@gmail.com> # Date 1684310878 -7200 # Wed May 17 10:07:58 2023 +0200 # Node ID b5ad286dc895cecfbd1e113f3b291c36a9eabd11 # Parent 4f8e8412e88944b2c2ea0ba3853b560d71c14b2f Update fvoptions and script diff --git a/doc/examples/fluidsimfoam-phill/doc/reproduce_sin_2d.py b/doc/examples/fluidsimfoam-phill/doc/reproduce_sin_2d.py --- a/doc/examples/fluidsimfoam-phill/doc/reproduce_sin_2d.py +++ b/doc/examples/fluidsimfoam-phill/doc/reproduce_sin_2d.py @@ -1,16 +1,25 @@ from fluidsimfoam_phill import Simul params = Simul.create_default_params() + params.short_name_type_run = "sin_2d" + params.init_fields.buoyancy_frequency = 0.001 params.transport_properties.nu = 0.01 params.transport_properties.pr = 10 + params.control_dict.end_time = 1200000 params.control_dict.delta_t = 10 + params.block_mesh_dict.lx = 2000 params.block_mesh_dict.ly = 5000 params.block_mesh_dict.nx = 20 params.block_mesh_dict.ny = 50 +params.block_mesh_dict.h_max = 80 + +params.fv_options.momentum_source.active = "yes" +params.fv_options.momentum_source.mean_velocity_force_coeffs.ubar = "(0.1 0 0)" +params.fv_options.atm_coriolis_u_source1.active = "yes" params.output.sub_directory = "examples_fluidsimfoam/phill" diff --git a/doc/examples/fluidsimfoam-phill/src/fluidsimfoam_phill/output.py b/doc/examples/fluidsimfoam-phill/src/fluidsimfoam_phill/output.py --- a/doc/examples/fluidsimfoam-phill/src/fluidsimfoam_phill/output.py +++ b/doc/examples/fluidsimfoam-phill/src/fluidsimfoam_phill/output.py @@ -7,6 +7,7 @@ BlockMeshDict, ConstantFileHelper, FoamInputFile, + FvOptionsHelper, FvSchemesHelper, VolScalarField, VolVectorField, @@ -38,21 +39,6 @@ return field -code_fv_options = dedent( - r""" -atmCoriolisUSource1 -{ - type atmCoriolisUSource; - atmCoriolisUSourceCoeffs - { - selectionMode all; - Omega (0 7.2921e-5 0); - } -} -""" -) - - class OutputPHill(Output): """Output for the phill solver""" @@ -126,6 +112,34 @@ comments={}, ) + _helper_fv_options = FvOptionsHelper() + _helper_fv_options.add_option( + "momentumSource", + { + "type": "meanVelocityForce", + "active": "no", + "meanVelocityForceCoeffs": { + "selectionMode": "all", + "fields": "(U)", + "Ubar": "(0.1 0 0)", + }, + }, + parameters=["active", "meanVelocityForceCoeffs/Ubar"], + ) + + _helper_fv_options.add_option( + "atmCoriolisUSource1", + { + "type": "atmCoriolisUSource", + "active": "no", + "atmCoriolisUSourceCoeffs": { + "selectionMode": "all", + "Omega": "(0 7.2921e-5 0)", + }, + }, + parameters=["active", "atmCoriolisUSourceCoeffs/Omega"], + ) + @classmethod def _complete_params_block_mesh_dict(cls, params): super()._complete_params_block_mesh_dict(params) diff --git a/doc/examples/fluidsimfoam-phill/src/fluidsimfoam_phill/templates/fvOptions.jinja b/doc/examples/fluidsimfoam-phill/src/fluidsimfoam_phill/templates/fvOptions.jinja deleted file mode 100644 --- a/doc/examples/fluidsimfoam-phill/src/fluidsimfoam_phill/templates/fvOptions.jinja +++ /dev/null @@ -1,46 +0,0 @@ -FoamFile -{ - version 2.0; - format ascii; - class dictionary; - location "constant"; - object fvOptions; -} - -/* -pressureGradient -{ - type vectorSemiImplicitSource; - selectionMode all; - volumeMode specific; - sources - { - U ((0 1.978046e-03 0) 0); - } -} -/* - - -atmCoriolisUSource1 -{ - type atmCoriolisUSource; - atmCoriolisUSourceCoeffs - { - selectionMode all; - Omega (0 7.2921e-5 0); - } -} - - -momentumSource -{ - type meanVelocityForce; - active yes; - - meanVelocityForceCoeffs - { - selectionMode all; - fields (U); - Ubar (0.1 0 0); - } -} diff --git a/doc/examples/fluidsimfoam-phill/tests/saved_cases/case0/constant/fvOptions b/doc/examples/fluidsimfoam-phill/tests/saved_cases/case0/constant/fvOptions --- a/doc/examples/fluidsimfoam-phill/tests/saved_cases/case0/constant/fvOptions +++ b/doc/examples/fluidsimfoam-phill/tests/saved_cases/case0/constant/fvOptions @@ -7,42 +7,25 @@ object fvOptions; } -/* -pressureGradient +momentumSource { - type vectorSemiImplicitSource; - selectionMode all; - volumeMode specific; - sources + type meanVelocityForce; + active no; + meanVelocityForceCoeffs { - U ((0 1.978046e-03 0) 0); + selectionMode all; + fields (U); + Ubar (0.1 0 0); } } -/* - atmCoriolisUSource1 { - type atmCoriolisUSource; + type atmCoriolisUSource; + active no; atmCoriolisUSourceCoeffs { - selectionMode all; - Omega (0 7.2921e-5 0); + selectionMode all; + Omega (0 7.2921e-5 0); } } - - -/* -momentumSource -{ - type meanVelocityForce; - active yes; - - meanVelocityForceCoeffs - { - selectionMode all; - fields (U); - Ubar (1.0 0 0); - } -} -*/ # HG changeset patch # User Pooria DANAEIFAR <pouryadanaeifar@gmail.com> # Date 1684315137 -7200 # Wed May 17 11:18:57 2023 +0200 # Node ID 4e088abdbec5af519ed68da333b98497e77b0c9f # Parent b5ad286dc895cecfbd1e113f3b291c36a9eabd11 Fix phill test (blockmesh problem) diff --git a/doc/examples/fluidsimfoam-phill/src/fluidsimfoam_phill/output.py b/doc/examples/fluidsimfoam-phill/src/fluidsimfoam_phill/output.py --- a/doc/examples/fluidsimfoam-phill/src/fluidsimfoam_phill/output.py +++ b/doc/examples/fluidsimfoam-phill/src/fluidsimfoam_phill/output.py @@ -179,15 +179,14 @@ b0 = bmd.add_hexblock( ("v0-0", "v1-0", "v2-0", "v3-0", "v0+z", "v1+z", "v2+z", "v3+z"), - (nx + 1, ny, nz), + (nx, ny, nz), "b0", SimpleGrading(1, [[0.1, 0.25, 41.9], [0.9, 0.75, 1]], 1), ) dots = [] - - for dot in range(nx + 1): - x_dot = dot * lx / nx + for dot in range(nx): + x_dot = dot * lx / (nx - 1) y_dot = (h_max / 2) * ( 1 - cos(2 * pi * min(abs((x_dot - (lx / 2)) / lx), 1)) ) diff --git a/doc/examples/fluidsimfoam-phill/tests/saved_cases/case0/0/T b/doc/examples/fluidsimfoam-phill/tests/saved_cases/case0/0/T --- a/doc/examples/fluidsimfoam-phill/tests/saved_cases/case0/0/T +++ b/doc/examples/fluidsimfoam-phill/tests/saved_cases/case0/0/T @@ -10,7 +10,7 @@ internalField nonuniform List<scalar> -110 +121 ( 8.332507645259937e-06 7.1306523955147804e-06 @@ -45,83 +45,94 @@ 3.369327217125382e-05 3.5580530071355754e-05 3.671549439347604e-05 - 9.027319062181447e-05 - 8.926503567787971e-05 - 8.759418960244647e-05 - 8.578103975535166e-05 - 8.439745158002038e-05 - 8.388103975535167e-05 - 8.439745158002038e-05 - 8.578103975535166e-05 - 8.759418960244647e-05 - 8.926503567787971e-05 - 9.027319062181447e-05 - 0.00015479816513761465 - 0.00015394495412844036 - 0.00015253109072375126 - 0.00015099694189602445 - 0.00014982568807339448 - 0.00014938837920489294 - 0.00014982568807339448 - 0.00015099694189602445 - 0.00015253109072375126 - 0.00015394495412844036 - 0.00015479816513761465 - 0.00021932313965341484 - 0.00021862385321100912 - 0.00021746890927624868 - 0.00021621304791029562 - 0.00021525484199796125 - 0.0002148970438328236 - 0.00021525484199796125 - 0.00021621304791029562 - 0.00021746890927624868 - 0.00021862385321100912 - 0.00021932313965341484 - 0.00028384811416921505 - 0.0002833037716615698 - 0.0002824057084607543 - 0.00028142915392456676 - 0.00028068297655453616 - 0.00028040468909276245 - 0.00028068297655453616 - 0.00028142915392456676 - 0.0002824057084607543 - 0.0002833037716615698 - 0.00028384811416921505 - 0.0003483720693170234 - 0.0003479826707441386 - 0.00034734352701325174 - 0.0003466452599388379 - 0.00034611213047910293 - 0.00034591233435270126 - 0.00034611213047910293 - 0.0003466452599388379 - 0.00034734352701325174 - 0.0003479826707441386 - 0.0003483720693170234 - 0.0004128970438328236 - 0.0004126625891946992 - 0.00041228032619775734 - 0.00041186136595310904 - 0.0004115402650356778 - 0.00041141997961264014 - 0.0004115402650356778 - 0.00041186136595310904 - 0.00041228032619775734 - 0.0004126625891946992 - 0.0004128970438328236 - 0.0004774220183486238 - 0.0004773425076452598 - 0.0004772181447502548 - 0.0004770774719673802 - 0.00047696839959225276 - 0.0004769276248725789 - 0.00047696839959225276 - 0.0004770774719673802 - 0.0004772181447502548 - 0.0004773425076452598 - 0.0004774220183486238 + 8.624026503567788e-05 + 8.522313965341487e-05 + 8.353516819571864e-05 + 8.170468909276248e-05 + 8.030835881753312e-05 + 7.978725790010192e-05 + 8.030835881753312e-05 + 8.170468909276248e-05 + 8.353516819571864e-05 + 8.522313965341487e-05 + 8.624026503567788e-05 + 0.0001426992864424057 + 0.00014181753312945972 + 0.00014035474006116207 + 0.00013876860346585115 + 0.00013755861365953107 + 0.00013710703363914372 + 0.00013755861365953107 + 0.00013876860346585115 + 0.00014035474006116207 + 0.00014181753312945972 + 0.0001426992864424057 + 0.0001991590214067278 + 0.00019841182466870538 + 0.00019717533129459731 + 0.00019583282364933738 + 0.0001948083588175331 + 0.0001944260958205912 + 0.0001948083588175331 + 0.00019583282364933738 + 0.00019717533129459731 + 0.00019841182466870538 + 0.0001991590214067278 + 0.00025561773700305806 + 0.00025500713557594285 + 0.00025399490316004074 + 0.00025289704383282363 + 0.00025205810397553515 + 0.0002517451580020387 + 0.00025205810397553515 + 0.00025289704383282363 + 0.00025399490316004074 + 0.00025500713557594285 + 0.00025561773700305806 + 0.0003120774719673802 + 0.00031160142711518854 + 0.000310815494393476 + 0.00030996126401630983 + 0.0003093078491335372 + 0.0003090642201834862 + 0.0003093078491335372 + 0.00030996126401630983 + 0.000310815494393476 + 0.00031160142711518854 + 0.0003120774719673802 + 0.0003685361875637105 + 0.00036819571865443423 + 0.0003676350662589194 + 0.00036702446483180426 + 0.0003665586136595311 + 0.0003663843017329255 + 0.0003665586136595311 + 0.00036702446483180426 + 0.0003676350662589194 + 0.00036819571865443423 + 0.0003685361875637105 + 0.0004249959225280326 + 0.0004247900101936798 + 0.0004244556574923547 + 0.0004240886850152905 + 0.0004238083588175331 + 0.000423703363914373 + 0.0004238083588175331 + 0.0004240886850152905 + 0.0004244556574923547 + 0.0004247900101936798 + 0.0004249959225280326 + 0.0004814546381243628 + 0.0004813853211009174 + 0.00048127522935779814 + 0.00048115290519877666 + 0.00048105810397553513 + 0.0004810224260958205 + 0.00048105810397553513 + 0.00048115290519877666 + 0.00048127522935779814 + 0.0004813853211009174 + 0.0004814546381243628 ); boundaryField diff --git a/doc/examples/fluidsimfoam-phill/tests/saved_cases/case0/system/blockMeshDict b/doc/examples/fluidsimfoam-phill/tests/saved_cases/case0/system/blockMeshDict --- a/doc/examples/fluidsimfoam-phill/tests/saved_cases/case0/system/blockMeshDict +++ b/doc/examples/fluidsimfoam-phill/tests/saved_cases/case0/system/blockMeshDict @@ -30,7 +30,7 @@ blocks ( - hex (0 1 2 3 4 5 6 7) b0 (11 10 1) simpleGrading (1 ( ( 0.1 0.25 41.9 ) ( 0.9 0.75 1 ) ) 1) // b0 (v0-0 v1-0 v2-0 v3-0 v0+z v1+z v2+z v3+z) + hex (0 1 2 3 4 5 6 7) b0 (11 11 1) simpleGrading (1 ( ( 0.1 0.25 41.9 ) ( 0.9 0.75 1 ) ) 1) // b0 (v0-0 v1-0 v2-0 v3-0 v0+z v1+z v2+z v3+z) ); edges diff --git a/doc/examples/fluidsimfoam-phill/tests/test_phill.py b/doc/examples/fluidsimfoam-phill/tests/test_phill.py --- a/doc/examples/fluidsimfoam-phill/tests/test_phill.py +++ b/doc/examples/fluidsimfoam-phill/tests/test_phill.py @@ -14,8 +14,8 @@ def test_reproduce_case(): params = Simul.create_default_params() params.output.sub_directory = "tests_fluidsimfoam/phill" - params.block_mesh_dict.nx = 10 - params.block_mesh_dict.ny = 10 + params.block_mesh_dict.nx = 11 + params.block_mesh_dict.ny = 11 sim = Simul(params) check_saved_case(path_saved_case, sim.path_run) # HG changeset patch # User Pooria DANAEIFAR <pouryadanaeifar@gmail.com> # Date 1684327143 -7200 # Wed May 17 14:39:03 2023 +0200 # Node ID 82ef737fdd56ffdf7af73cf16dc9a2a45f6b65c0 # Parent 4e088abdbec5af519ed68da333b98497e77b0c9f Add porosity block to blockmesh diff --git a/doc/examples/fluidsimfoam-phill/src/fluidsimfoam_phill/output.py b/doc/examples/fluidsimfoam-phill/src/fluidsimfoam_phill/output.py --- a/doc/examples/fluidsimfoam-phill/src/fluidsimfoam_phill/output.py +++ b/doc/examples/fluidsimfoam-phill/src/fluidsimfoam_phill/output.py @@ -143,8 +143,15 @@ @classmethod def _complete_params_block_mesh_dict(cls, params): super()._complete_params_block_mesh_dict(params) - default = {"nx": 20, "ny": 50, "nz": 1, "h_max": 80} - default.update({"lx": 2000, "ly": 5000, "lz": 0.01, "scale": 1}) + default = { + "nx": 20, + "ny": 50, + "nz": 1, + "nporosity": 10, + "h_max": 80, + "lporosity": 3000, + } + default.update({"lx": 2000, "ly": 2000, "lz": 0.01, "scale": 1}) for key, value in default.items(): try: params.block_mesh_dict[key] = value @@ -155,10 +162,12 @@ nx = params.block_mesh_dict.nx ny = params.block_mesh_dict.ny nz = params.block_mesh_dict.nz + nporosity = params.block_mesh_dict.nporosity lx = params.block_mesh_dict.lx ly = params.block_mesh_dict.ly lz = params.block_mesh_dict.lz + lp = params.block_mesh_dict.lporosity h_max = params.block_mesh_dict.h_max @@ -169,7 +178,9 @@ Vertex(0, h_max, lz, "v0"), Vertex(lx, h_max, lz, "v1"), Vertex(lx, ly, lz, "v2"), - Vertex(0, ly, lz, "v3"), + Vertex(lx, ly + lp, lz, "v3"), + Vertex(0, ly + lp, lz, "v4"), + Vertex(0, ly, lz, "v5"), ] for v in basevs: @@ -178,12 +189,19 @@ bmd.add_vertex(v.x, v.y, v.z, v.name + "+z") b0 = bmd.add_hexblock( - ("v0-0", "v1-0", "v2-0", "v3-0", "v0+z", "v1+z", "v2+z", "v3+z"), + ("v0-0", "v1-0", "v2-0", "v5-0", "v0+z", "v1+z", "v2+z", "v5+z"), (nx, ny, nz), "b0", SimpleGrading(1, [[0.1, 0.25, 41.9], [0.9, 0.75, 1]], 1), ) + b1 = bmd.add_hexblock( + ("v5-0", "v2-0", "v3-0", "v4-0", "v5+z", "v2+z", "v3+z", "v4+z"), + (nx, nporosity, nz), + "porosity", + SimpleGrading(1, 1, 1), + ) + dots = [] for dot in range(nx): x_dot = dot * lx / (nx - 1) @@ -203,15 +221,22 @@ [Point(dot[0], dot[1], lz) for dot in dots], ) - bmd.add_boundary("wall", "top", [b0.face("n")]) + bmd.add_boundary("wall", "top", [b1.face("n")]) bmd.add_boundary("wall", "bottom", [b0.face("s")]) - bmd.add_cyclic_boundaries("outlet", "inlet", b0.face("e"), b0.face("w")) + bmd.add_cyclic_boundaries( + "outlet", + "inlet", + [b0.face("e"), b1.face("e")], + [b0.face("w"), b1.face("w")], + ) bmd.add_boundary( "empty", "frontandbackplanes", [ b0.face("b"), + b1.face("b"), b0.face("t"), + b1.face("t"), ], ) diff --git a/doc/examples/fluidsimfoam-phill/tests/saved_cases/case0/system/blockMeshDict b/doc/examples/fluidsimfoam-phill/tests/saved_cases/case0/system/blockMeshDict --- a/doc/examples/fluidsimfoam-phill/tests/saved_cases/case0/system/blockMeshDict +++ b/doc/examples/fluidsimfoam-phill/tests/saved_cases/case0/system/blockMeshDict @@ -20,17 +20,22 @@ ( ( 0 80 0 ) // 0 v0-0 ( 2000 80 0 ) // 1 v1-0 - ( 2000 5000 0 ) // 2 v2-0 - ( 0 5000 0 ) // 3 v3-0 - ( 0 80 0.01 ) // 4 v0+z - ( 2000 80 0.01 ) // 5 v1+z - ( 2000 5000 0.01 ) // 6 v2+z - ( 0 5000 0.01 ) // 7 v3+z + ( 2000 2000 0 ) // 2 v2-0 + ( 2000 5000 0 ) // 3 v3-0 + ( 0 5000 0 ) // 4 v4-0 + ( 0 2000 0 ) // 5 v5-0 + ( 0 80 0.01 ) // 6 v0+z + ( 2000 80 0.01 ) // 7 v1+z + ( 2000 2000 0.01 ) // 8 v2+z + ( 2000 5000 0.01 ) // 9 v3+z + ( 0 5000 0.01 ) // 10 v4+z + ( 0 2000 0.01 ) // 11 v5+z ); blocks ( - hex (0 1 2 3 4 5 6 7) b0 (11 11 1) simpleGrading (1 ( ( 0.1 0.25 41.9 ) ( 0.9 0.75 1 ) ) 1) // b0 (v0-0 v1-0 v2-0 v3-0 v0+z v1+z v2+z v3+z) + hex (0 1 2 5 6 7 8 11) b0 (11 11 1) simpleGrading (1 ( ( 0.1 0.25 41.9 ) ( 0.9 0.75 1 ) ) 1) // b0 (v0-0 v1-0 v2-0 v5-0 v0+z v1+z v2+z v5+z) + hex (5 2 3 4 11 8 9 10) porosity (11 10 1) simpleGrading (1 1 1) // porosity (v5-0 v2-0 v3-0 v4-0 v5+z v2+z v3+z v4+z) ); edges @@ -49,7 +54,7 @@ ( 1800 72.3606797749979 0 ) ( 2000 80 0 ) ) - spline 4 5 // spline1 (v0+z v1+z) + spline 6 7 // spline1 (v0+z v1+z) ( ( 0 80 0.01 ) ( 200 72.3606797749979 0.01 ) @@ -72,7 +77,7 @@ type wall; faces ( - (2 3 7 6) // f-b0-n (v2-0 v3-0 v3+z v2+z) + (3 4 10 9) // f-porosity-n (v3-0 v4-0 v4+z v3+z) ); } bottom @@ -80,7 +85,7 @@ type wall; faces ( - (0 1 5 4) // f-b0-s (v0-0 v1-0 v1+z v0+z) + (0 1 7 6) // f-b0-s (v0-0 v1-0 v1+z v0+z) ); } outlet @@ -89,7 +94,8 @@ neighbourPatch inlet; faces ( - (1 2 6 5) // f-b0-e (v1-0 v2-0 v2+z v1+z) + (1 2 8 7) // f-b0-e (v1-0 v2-0 v2+z v1+z) + (2 3 9 8) // f-porosity-e (v2-0 v3-0 v3+z v2+z) ); } inlet @@ -98,7 +104,8 @@ neighbourPatch outlet; faces ( - (0 4 7 3) // f-b0-w (v0-0 v0+z v3+z v3-0) + (0 6 11 5) // f-b0-w (v0-0 v0+z v5+z v5-0) + (5 11 10 4) // f-porosity-w (v5-0 v5+z v4+z v4-0) ); } frontandbackplanes @@ -106,8 +113,10 @@ type empty; faces ( - (0 3 2 1) // f-b0-b (v0-0 v3-0 v2-0 v1-0) - (4 5 6 7) // f-b0-t (v0+z v1+z v2+z v3+z) + (0 5 2 1) // f-b0-b (v0-0 v5-0 v2-0 v1-0) + (5 4 3 2) // f-porosity-b (v5-0 v4-0 v3-0 v2-0) + (6 7 8 11) // f-b0-t (v0+z v1+z v2+z v5+z) + (11 8 9 10) // f-porosity-t (v5+z v2+z v3+z v4+z) ); } ); # HG changeset patch # User Pooria DANAEIFAR <pouryadanaeifar@gmail.com> # Date 1684333820 -7200 # Wed May 17 16:30:20 2023 +0200 # Node ID c52f17c275a4c1966fee28daf37716c228fdac39 # Parent 82ef737fdd56ffdf7af73cf16dc9a2a45f6b65c0 Add porosity to fvOptions diff --git a/doc/examples/fluidsimfoam-phill/src/fluidsimfoam_phill/output.py b/doc/examples/fluidsimfoam-phill/src/fluidsimfoam_phill/output.py --- a/doc/examples/fluidsimfoam-phill/src/fluidsimfoam_phill/output.py +++ b/doc/examples/fluidsimfoam-phill/src/fluidsimfoam_phill/output.py @@ -140,6 +140,30 @@ parameters=["active", "atmCoriolisUSourceCoeffs/Omega"], ) + _helper_fv_options.add_option( + "porosity", + { + "type": "explicitPorositySource", + "explicitPorositySourceCoeffs": { + "selectionMode": "cellZone", + "cellZone": "porosity", + "type": "fixedCoeff", + "active": "yes", + "fixedCoeffCoeffs": { + "alpha": "(500 -1000 -1000)", + "beta": "(0 0 0)", + "rhoRef": "1", + "coordinateSystem": { + "origin": "(0 0 0)", + "e1": "(0.70710678 0.70710678 0)", + "e2": "(0 0 1)", + }, + }, + }, + }, + parameters=["explicitPorositySourceCoeffs/active"], + ) + @classmethod def _complete_params_block_mesh_dict(cls, params): super()._complete_params_block_mesh_dict(params) @@ -147,7 +171,7 @@ "nx": 20, "ny": 50, "nz": 1, - "nporosity": 10, + "ny_porosity": 10, "h_max": 80, "lporosity": 3000, } @@ -162,7 +186,7 @@ nx = params.block_mesh_dict.nx ny = params.block_mesh_dict.ny nz = params.block_mesh_dict.nz - nporosity = params.block_mesh_dict.nporosity + ny_porosity = params.block_mesh_dict.ny_porosity lx = params.block_mesh_dict.lx ly = params.block_mesh_dict.ly @@ -197,7 +221,7 @@ b1 = bmd.add_hexblock( ("v5-0", "v2-0", "v3-0", "v4-0", "v5+z", "v2+z", "v3+z", "v4+z"), - (nx, nporosity, nz), + (nx, ny_porosity, nz), "porosity", SimpleGrading(1, 1, 1), ) diff --git a/doc/examples/fluidsimfoam-phill/tests/saved_cases/case0/0/T b/doc/examples/fluidsimfoam-phill/tests/saved_cases/case0/0/T --- a/doc/examples/fluidsimfoam-phill/tests/saved_cases/case0/0/T +++ b/doc/examples/fluidsimfoam-phill/tests/saved_cases/case0/0/T @@ -12,127 +12,127 @@ List<scalar> 121 ( - 8.332507645259937e-06 - 7.1306523955147804e-06 - 5.128083588175331e-06 - 2.9617635066258914e-06 - 1.3106218144750253e-06 - 6.946819571865443e-07 - 1.3106218144750253e-06 - 2.9617635066258914e-06 - 5.128083588175331e-06 - 7.1306523955147804e-06 - 8.332507645259937e-06 - 1.213058103975535e-05 - 1.093781855249745e-05 - 8.950417940876656e-06 - 6.800489296636085e-06 - 5.1618450560652396e-06 - 4.550550458715596e-06 - 5.1618450560652396e-06 - 6.800489296636085e-06 - 8.950417940876656e-06 - 1.093781855249745e-05 - 1.213058103975535e-05 - 3.671549439347604e-05 - 3.5580530071355754e-05 - 3.369327217125382e-05 - 3.164923547400611e-05 - 3.0090519877675836e-05 - 2.9508970438328233e-05 - 3.0090519877675836e-05 - 3.164923547400611e-05 - 3.369327217125382e-05 - 3.5580530071355754e-05 - 3.671549439347604e-05 - 8.624026503567788e-05 - 8.522313965341487e-05 - 8.353516819571864e-05 - 8.170468909276248e-05 - 8.030835881753312e-05 - 7.978725790010192e-05 - 8.030835881753312e-05 - 8.170468909276248e-05 - 8.353516819571864e-05 - 8.522313965341487e-05 - 8.624026503567788e-05 - 0.0001426992864424057 - 0.00014181753312945972 - 0.00014035474006116207 - 0.00013876860346585115 - 0.00013755861365953107 - 0.00013710703363914372 - 0.00013755861365953107 - 0.00013876860346585115 - 0.00014035474006116207 - 0.00014181753312945972 - 0.0001426992864424057 - 0.0001991590214067278 - 0.00019841182466870538 - 0.00019717533129459731 - 0.00019583282364933738 - 0.0001948083588175331 - 0.0001944260958205912 - 0.0001948083588175331 - 0.00019583282364933738 - 0.00019717533129459731 - 0.00019841182466870538 - 0.0001991590214067278 - 0.00025561773700305806 - 0.00025500713557594285 - 0.00025399490316004074 - 0.00025289704383282363 - 0.00025205810397553515 - 0.0002517451580020387 - 0.00025205810397553515 - 0.00025289704383282363 - 0.00025399490316004074 - 0.00025500713557594285 - 0.00025561773700305806 - 0.0003120774719673802 - 0.00031160142711518854 - 0.000310815494393476 - 0.00030996126401630983 - 0.0003093078491335372 - 0.0003090642201834862 - 0.0003093078491335372 - 0.00030996126401630983 - 0.000310815494393476 - 0.00031160142711518854 - 0.0003120774719673802 - 0.0003685361875637105 - 0.00036819571865443423 - 0.0003676350662589194 - 0.00036702446483180426 - 0.0003665586136595311 - 0.0003663843017329255 - 0.0003665586136595311 - 0.00036702446483180426 - 0.0003676350662589194 - 0.00036819571865443423 - 0.0003685361875637105 - 0.0004249959225280326 - 0.0004247900101936798 - 0.0004244556574923547 - 0.0004240886850152905 - 0.0004238083588175331 - 0.000423703363914373 - 0.0004238083588175331 - 0.0004240886850152905 - 0.0004244556574923547 - 0.0004247900101936798 - 0.0004249959225280326 - 0.0004814546381243628 - 0.0004813853211009174 - 0.00048127522935779814 - 0.00048115290519877666 - 0.00048105810397553513 - 0.0004810224260958205 - 0.00048105810397553513 - 0.00048115290519877666 - 0.00048127522935779814 - 0.0004813853211009174 - 0.0004814546381243628 + 8.052650356778797e-06 + 6.850316004077471e-06 + 4.847533129459734e-06 + 2.68177370030581e-06 + 1.0315800203873598e-06 + 4.1611314984709475e-07 + 1.0315800203873598e-06 + 2.68177370030581e-06 + 4.847533129459734e-06 + 6.850316004077471e-06 + 8.052650356778797e-06 + 1.7855249745158e-05 + 1.6712538226299692e-05 + 1.4811009174311924e-05 + 1.275341488277268e-05 + 1.118532110091743e-05 + 1.0600407747196737e-05 + 1.118532110091743e-05 + 1.275341488277268e-05 + 1.4811009174311924e-05 + 1.6712538226299692e-05 + 1.7855249745158e-05 + 4.5074006116207945e-05 + 4.4096839959225274e-05 + 4.247614678899082e-05 + 4.071916411824668e-05 + 3.9379102956167175e-05 + 3.887900101936799e-05 + 3.9379102956167175e-05 + 4.071916411824668e-05 + 4.247614678899082e-05 + 4.4096839959225274e-05 + 4.5074006116207945e-05 + 8.036289500509684e-05 + 7.960244648318041e-05 + 7.834260958205912e-05 + 7.697594291539245e-05 + 7.593323139653414e-05 + 7.554413863404688e-05 + 7.593323139653414e-05 + 7.697594291539245e-05 + 7.834260958205912e-05 + 7.960244648318041e-05 + 8.036289500509684e-05 + 0.00011565137614678898 + 0.00011510805300713557 + 0.00011420897043832824 + 0.00011323241590214065 + 0.00011248725790010192 + 0.00011220897043832821 + 0.00011248725790010192 + 0.00011323241590214065 + 0.00011420897043832824 + 0.00011510805300713557 + 0.00011565137614678898 + 0.00015094087665647296 + 0.0001506136595310907 + 0.0001500754332313965 + 0.0001494892966360856 + 0.00014904179408766562 + 0.00014887461773700305 + 0.00014904179408766562 + 0.0001494892966360856 + 0.0001500754332313965 + 0.0001506136595310907 + 0.00015094087665647296 + 0.00018622935779816511 + 0.00018611926605504583 + 0.0001859418960244648 + 0.00018574617737003056 + 0.0001855953109072375 + 0.000185539245667686 + 0.0001855953109072375 + 0.00018574617737003056 + 0.0001859418960244648 + 0.00018611926605504583 + 0.00018622935779816511 + 0.00024209989806320078 + 0.00024209989806320078 + 0.00024209989806320078 + 0.00024209989806320078 + 0.00024209989806320078 + 0.00024209989806320078 + 0.00024209989806320078 + 0.00024209989806320078 + 0.00024209989806320078 + 0.00024209989806320078 + 0.00024209989806320078 + 0.00031855249745158 + 0.00031855249745158 + 0.00031855249745158 + 0.00031855249745158 + 0.00031855249745158 + 0.00031855249745158 + 0.00031855249745158 + 0.00031855249745158 + 0.00031855249745158 + 0.00031855249745158 + 0.00031855249745158 + 0.00039500509683995915 + 0.00039500509683995915 + 0.00039500509683995915 + 0.00039500509683995915 + 0.00039500509683995915 + 0.00039500509683995915 + 0.00039500509683995915 + 0.00039500509683995915 + 0.00039500509683995915 + 0.00039500509683995915 + 0.00039500509683995915 + 0.0004714576962283384 + 0.0004714576962283384 + 0.0004714576962283384 + 0.0004714576962283384 + 0.0004714576962283384 + 0.0004714576962283384 + 0.0004714576962283384 + 0.0004714576962283384 + 0.0004714576962283384 + 0.0004714576962283384 + 0.0004714576962283384 ); boundaryField diff --git a/doc/examples/fluidsimfoam-phill/tests/saved_cases/case0/constant/fvOptions b/doc/examples/fluidsimfoam-phill/tests/saved_cases/case0/constant/fvOptions --- a/doc/examples/fluidsimfoam-phill/tests/saved_cases/case0/constant/fvOptions +++ b/doc/examples/fluidsimfoam-phill/tests/saved_cases/case0/constant/fvOptions @@ -29,3 +29,27 @@ Omega (0 7.2921e-5 0); } } + +porosity +{ + type explicitPorositySource; + explicitPorositySourceCoeffs + { + selectionMode cellZone; + cellZone porosity; + type fixedCoeff; + active yes; + fixedCoeffCoeffs + { + alpha (500 -1000 -1000); + beta (0 0 0); + rhoRef 1; + coordinateSystem + { + origin (0 0 0); + e1 (0.70710678 0.70710678 0); + e2 (0 0 1); + } + } + } +} diff --git a/doc/examples/fluidsimfoam-phill/tests/saved_cases/case0/system/blockMeshDict b/doc/examples/fluidsimfoam-phill/tests/saved_cases/case0/system/blockMeshDict --- a/doc/examples/fluidsimfoam-phill/tests/saved_cases/case0/system/blockMeshDict +++ b/doc/examples/fluidsimfoam-phill/tests/saved_cases/case0/system/blockMeshDict @@ -34,8 +34,8 @@ blocks ( - hex (0 1 2 5 6 7 8 11) b0 (11 11 1) simpleGrading (1 ( ( 0.1 0.25 41.9 ) ( 0.9 0.75 1 ) ) 1) // b0 (v0-0 v1-0 v2-0 v5-0 v0+z v1+z v2+z v5+z) - hex (5 2 3 4 11 8 9 10) porosity (11 10 1) simpleGrading (1 1 1) // porosity (v5-0 v2-0 v3-0 v4-0 v5+z v2+z v3+z v4+z) + hex (0 1 2 5 6 7 8 11) b0 (11 7 1) simpleGrading (1 ( ( 0.1 0.25 41.9 ) ( 0.9 0.75 1 ) ) 1) // b0 (v0-0 v1-0 v2-0 v5-0 v0+z v1+z v2+z v5+z) + hex (5 2 3 4 11 8 9 10) porosity (11 4 1) simpleGrading (1 1 1) // porosity (v5-0 v2-0 v3-0 v4-0 v5+z v2+z v3+z v4+z) ); edges diff --git a/doc/examples/fluidsimfoam-phill/tests/test_phill.py b/doc/examples/fluidsimfoam-phill/tests/test_phill.py --- a/doc/examples/fluidsimfoam-phill/tests/test_phill.py +++ b/doc/examples/fluidsimfoam-phill/tests/test_phill.py @@ -15,7 +15,8 @@ params = Simul.create_default_params() params.output.sub_directory = "tests_fluidsimfoam/phill" params.block_mesh_dict.nx = 11 - params.block_mesh_dict.ny = 11 + params.block_mesh_dict.ny = 7 + params.block_mesh_dict.ny_porosity = 4 sim = Simul(params) check_saved_case(path_saved_case, sim.path_run) # HG changeset patch # User Pooria DANAEIFAR <pouryadanaeifar@gmail.com> # Date 1684334867 -7200 # Wed May 17 16:47:47 2023 +0200 # Node ID 59b79dbfe7aef8403d8675a6209e900e8642dad7 # Parent c52f17c275a4c1966fee28daf37716c228fdac39 Fix fvOptions diff --git a/doc/examples/fluidsimfoam-phill/src/fluidsimfoam_phill/output.py b/doc/examples/fluidsimfoam-phill/src/fluidsimfoam_phill/output.py --- a/doc/examples/fluidsimfoam-phill/src/fluidsimfoam_phill/output.py +++ b/doc/examples/fluidsimfoam-phill/src/fluidsimfoam_phill/output.py @@ -43,10 +43,9 @@ """Output for the phill solver""" name_variables = ["U", "p_rgh", "T", "alphat"] - name_system_files = Output.name_system_files + ["blockMeshDict"] + name_system_files = Output.name_system_files + ["blockMeshDict", "fvOptions"] name_constant_files = [ "g", - "fvOptions", "MRFProperties", "transportProperties", "turbulenceProperties", @@ -114,54 +113,43 @@ _helper_fv_options = FvOptionsHelper() _helper_fv_options.add_option( - "momentumSource", - { - "type": "meanVelocityForce", - "active": "no", - "meanVelocityForceCoeffs": { - "selectionMode": "all", - "fields": "(U)", - "Ubar": "(0.1 0 0)", - }, + "meanVelocityForce", + name="momentumSource", + active=False, + coeffs={ + "fields": "(U)", + "Ubar": "(0.1 0 0)", }, - parameters=["active", "meanVelocityForceCoeffs/Ubar"], + parameters=["coeffs/Ubar"], ) _helper_fv_options.add_option( - "atmCoriolisUSource1", - { - "type": "atmCoriolisUSource", - "active": "no", - "atmCoriolisUSourceCoeffs": { - "selectionMode": "all", - "Omega": "(0 7.2921e-5 0)", - }, + "atmCoriolisUSource", + active=False, + coeffs={ + "Omega": "(0 7.2921e-5 0)", }, - parameters=["active", "atmCoriolisUSourceCoeffs/Omega"], + parameters=["coeffs/Omega"], ) _helper_fv_options.add_option( - "porosity", - { - "type": "explicitPorositySource", - "explicitPorositySourceCoeffs": { - "selectionMode": "cellZone", - "cellZone": "porosity", - "type": "fixedCoeff", - "active": "yes", - "fixedCoeffCoeffs": { - "alpha": "(500 -1000 -1000)", - "beta": "(0 0 0)", - "rhoRef": "1", - "coordinateSystem": { - "origin": "(0 0 0)", - "e1": "(0.70710678 0.70710678 0)", - "e2": "(0 0 1)", - }, + "explicitPorositySource", + name="porosity", + cell_zone="porosity", + coeffs={ + "type": "fixedCoeff", + "fixedCoeffCoeffs": { + "alpha": "(500 -1000 -1000)", + "beta": "(0 0 0)", + "rhoRef": "1", + "coordinateSystem": { + "origin": "(0 0 0)", + "e1": "(0.70710678 0.70710678 0)", + "e2": "(0 0 1)", }, }, }, - parameters=["explicitPorositySourceCoeffs/active"], + parameters=["coeffs/alpha"], ) @classmethod diff --git a/doc/examples/fluidsimfoam-phill/tests/saved_cases/case0/constant/fvOptions b/doc/examples/fluidsimfoam-phill/tests/saved_cases/case0/constant/fvOptions deleted file mode 100644 --- a/doc/examples/fluidsimfoam-phill/tests/saved_cases/case0/constant/fvOptions +++ /dev/null @@ -1,55 +0,0 @@ -FoamFile -{ - version 2.0; - format ascii; - class dictionary; - location "constant"; - object fvOptions; -} - -momentumSource -{ - type meanVelocityForce; - active no; - meanVelocityForceCoeffs - { - selectionMode all; - fields (U); - Ubar (0.1 0 0); - } -} - -atmCoriolisUSource1 -{ - type atmCoriolisUSource; - active no; - atmCoriolisUSourceCoeffs - { - selectionMode all; - Omega (0 7.2921e-5 0); - } -} - -porosity -{ - type explicitPorositySource; - explicitPorositySourceCoeffs - { - selectionMode cellZone; - cellZone porosity; - type fixedCoeff; - active yes; - fixedCoeffCoeffs - { - alpha (500 -1000 -1000); - beta (0 0 0); - rhoRef 1; - coordinateSystem - { - origin (0 0 0); - e1 (0.70710678 0.70710678 0); - e2 (0 0 1); - } - } - } -} diff --git a/doc/examples/fluidsimfoam-phill/tests/saved_cases/case0/system/fvOptions b/doc/examples/fluidsimfoam-phill/tests/saved_cases/case0/system/fvOptions new file mode 100644 --- /dev/null +++ b/doc/examples/fluidsimfoam-phill/tests/saved_cases/case0/system/fvOptions @@ -0,0 +1,55 @@ +FoamFile +{ + version 2.0; + format ascii; + class dictionary; + location "system"; + object fvOptions; +} + +momentumSource +{ + type meanVelocityForce; + active no; + selectionMode all; + meanVelocityForceCoeffs + { + fields (U); + Ubar (0.1 0 0); + } +} + +atmCoriolisUSource +{ + type atmCoriolisUSource; + active no; + selectionMode all; + atmCoriolisUSourceCoeffs + { + Omega (0 7.2921e-5 0); + } +} + +porosity +{ + type explicitPorositySource; + active yes; + selectionMode cellZone; + cellZone porosity; + explicitPorositySourceCoeffs + { + type fixedCoeff; + fixedCoeffCoeffs + { + alpha (500 -1000 -1000); + beta (0 0 0); + rhoRef 1; + coordinateSystem + { + origin (0 0 0); + e1 (0.70710678 0.70710678 0); + e2 (0 0 1); + } + } + } +} # HG changeset patch # User paugier <pierre.augier@univ-grenoble-alpes.fr> # Date 1684753152 -7200 # Mon May 22 12:59:12 2023 +0200 # Node ID f05b0758653a70a1f641370eed6146be57070c12 # Parent 59b79dbfe7aef8403d8675a6209e900e8642dad7 Fix phill fvOptions diff --git a/doc/examples/fluidsimfoam-phill/dev/profile_solver.py b/doc/examples/fluidsimfoam-phill/dev/profile_solver.py new file mode 100644 --- /dev/null +++ b/doc/examples/fluidsimfoam-phill/dev/profile_solver.py @@ -0,0 +1,115 @@ +""" + +``` +python profile_solver.py +pip install gprof2dot +gprof2dot -f pstats profile.pstats | dot -Tpng -o profile.png +``` + +Conclusions: + +- creating the default parameters is a bit slow because of underscore and co + (not too bad). + +- there is a real performance issue with the method + `foam_input_files.fields.FieldABC.from_code` when there are calculated boundaryField. + + https://foss.heptapod.net/fluiddyn/fluidsimfoam/-/blob/branch/default/src/fluidsimfoam/foam_input_files/fields.py#L36 + +``` +boundaryField +{ + top + { + type calculated; + value nonuniform List<scalar> +20 +( +50 +150 +250 +350 +450 +550 +650 +750 +850 +950 +1050 +1150 +1250 +1350 +1450 +1550 +1650 +1750 +1850 +1950 +) +; +... +``` + +The issue is actually in fluidsimfoam.operators.Operators.get_cell_coords + +https://foss.heptapod.net/fluiddyn/fluidsimfoam/-/blob/branch/default/src/fluidsimfoam/operators.py#L39 + +where we do + +``` + def get_arr(path): + field = VolScalarField.from_path(path) + return field.get_array() + + path_cy = path_cx.with_name("Cy") + path_cz = path_cx.with_name("Cz") + + return get_arr(path_cx), get_arr(path_cy), get_arr(path_cz) + + +We can instead read only the cell centers written in 0/C. + +``` + +""" + +import cProfile +from time import perf_counter + +from fluidsimfoam_phill import Simul + +t0 = perf_counter() + +params = Simul.create_default_params() +cProfile.runctx( + "params = Simul.create_default_params()", + globals(), + locals(), + "profile_params.pstats", +) + +print(f"params created in {perf_counter() - t0:.2f} s") + +params.output.sub_directory = "examples_fluidsimfoam/phill" +params.short_name_type_run = "sin_2d" + +params.init_fields.buoyancy_frequency = 0.001 +params.transport_properties.nu = 0.01 +params.transport_properties.pr = 10 + +params.control_dict.end_time = 1200000 +params.control_dict.delta_t = 10 + +params.block_mesh_dict.lx = 2000 +params.block_mesh_dict.ly = 5000 +params.block_mesh_dict.nx = 20 +params.block_mesh_dict.ny = 50 +params.block_mesh_dict.h_max = 80 + +params.fv_options.momentum_source.active = True +params.fv_options.momentum_source.ubar = "(0.1 0 0)" +params.fv_options.atm_coriolis_u_source.active = True + +t0 = perf_counter() +cProfile.runctx("sim = Simul(params)", globals(), locals(), "profile.pstats") +print(f"Simulation directory created in {perf_counter() - t0:.2f} s") diff --git a/doc/examples/fluidsimfoam-phill/doc/reproduce_sin_2d.py b/doc/examples/fluidsimfoam-phill/doc/reproduce_sim_2d.py rename from doc/examples/fluidsimfoam-phill/doc/reproduce_sin_2d.py rename to doc/examples/fluidsimfoam-phill/doc/reproduce_sim_2d.py --- a/doc/examples/fluidsimfoam-phill/doc/reproduce_sin_2d.py +++ b/doc/examples/fluidsimfoam-phill/doc/reproduce_sim_2d.py @@ -2,6 +2,7 @@ params = Simul.create_default_params() +params.output.sub_directory = "examples_fluidsimfoam/phill" params.short_name_type_run = "sin_2d" params.init_fields.buoyancy_frequency = 0.001 @@ -17,11 +18,9 @@ params.block_mesh_dict.ny = 50 params.block_mesh_dict.h_max = 80 -params.fv_options.momentum_source.active = "yes" -params.fv_options.momentum_source.mean_velocity_force_coeffs.ubar = "(0.1 0 0)" -params.fv_options.atm_coriolis_u_source1.active = "yes" - -params.output.sub_directory = "examples_fluidsimfoam/phill" +params.fv_options.momentum_source.active = True +params.fv_options.momentum_source.ubar = "(0.1 0 0)" +params.fv_options.atm_coriolis_u_source.active = True sim = Simul(params) diff --git a/doc/examples/fluidsimfoam-phill/src/fluidsimfoam_phill/output.py b/doc/examples/fluidsimfoam-phill/src/fluidsimfoam_phill/output.py --- a/doc/examples/fluidsimfoam-phill/src/fluidsimfoam_phill/output.py +++ b/doc/examples/fluidsimfoam-phill/src/fluidsimfoam_phill/output.py @@ -6,7 +6,6 @@ from fluidsimfoam.foam_input_files import ( BlockMeshDict, ConstantFileHelper, - FoamInputFile, FvOptionsHelper, FvSchemesHelper, VolScalarField, @@ -115,21 +114,21 @@ _helper_fv_options.add_option( "meanVelocityForce", name="momentumSource", - active=False, - coeffs={ + active=True, + default={ "fields": "(U)", "Ubar": "(0.1 0 0)", }, - parameters=["coeffs/Ubar"], + parameters=["Ubar"], ) _helper_fv_options.add_option( "atmCoriolisUSource", active=False, - coeffs={ + default={ "Omega": "(0 7.2921e-5 0)", }, - parameters=["coeffs/Omega"], + parameters=["Omega"], ) _helper_fv_options.add_option( @@ -149,7 +148,7 @@ }, }, }, - parameters=["coeffs/alpha"], + parameters=["fixedCoeffCoeffs/alpha"], ) @classmethod diff --git a/doc/examples/fluidsimfoam-phill/src/fluidsimfoam_phill/solver.py b/doc/examples/fluidsimfoam-phill/src/fluidsimfoam_phill/solver.py --- a/doc/examples/fluidsimfoam-phill/src/fluidsimfoam_phill/solver.py +++ b/doc/examples/fluidsimfoam-phill/src/fluidsimfoam_phill/solver.py @@ -3,11 +3,6 @@ class InfoSolverPHill(InfoSolver): - """Contain the information on a :class:`fluidsimfoam_phill.solver.Simul` - instance. - - """ - def _init_root(self): super()._init_root() self.module_name = "fluidsimfoam_phill.solver" @@ -19,8 +14,6 @@ class SimulPHill(SimulFoam): - """A solver which compiles and runs using a Snakefile.""" - InfoSolver = InfoSolverPHill diff --git a/doc/examples/fluidsimfoam-phill/tests/saved_cases/case0/system/fvOptions b/doc/examples/fluidsimfoam-phill/tests/saved_cases/case0/system/fvOptions --- a/doc/examples/fluidsimfoam-phill/tests/saved_cases/case0/system/fvOptions +++ b/doc/examples/fluidsimfoam-phill/tests/saved_cases/case0/system/fvOptions @@ -10,13 +10,10 @@ momentumSource { type meanVelocityForce; - active no; + active yes; selectionMode all; - meanVelocityForceCoeffs - { - fields (U); - Ubar (0.1 0 0); - } + fields (U); + Ubar (0.1 0 0); } atmCoriolisUSource @@ -24,21 +21,18 @@ type atmCoriolisUSource; active no; selectionMode all; - atmCoriolisUSourceCoeffs - { - Omega (0 7.2921e-5 0); - } + Omega (0 7.2921e-5 0); } porosity { - type explicitPorositySource; - active yes; - selectionMode cellZone; - cellZone porosity; + type explicitPorositySource; + active yes; explicitPorositySourceCoeffs { - type fixedCoeff; + selectionMode cellZone; + cellZone porosity; + type fixedCoeff; fixedCoeffCoeffs { alpha (500 -1000 -1000); # HG changeset patch # User paugier <pierre.augier@univ-grenoble-alpes.fr> # Date 1684753236 -7200 # Mon May 22 13:00:36 2023 +0200 # Node ID f588e61deead69318cb5e0ebfc286378cdeda689 # Parent f05b0758653a70a1f641370eed6146be57070c12 Optimize get_cells_coords and Fields diff --git a/.hgignore b/.hgignore --- a/.hgignore +++ b/.hgignore @@ -17,6 +17,7 @@ *.ipynb_checkpoints* **/*.ipynb *.egg-info/* +**/*.pstats build/* dist/*.tar.gz diff --git a/src/fluidsimfoam/foam_input_files/fields.py b/src/fluidsimfoam/foam_input_files/fields.py --- a/src/fluidsimfoam/foam_input_files/fields.py +++ b/src/fluidsimfoam/foam_input_files/fields.py @@ -33,7 +33,7 @@ cls: str @classmethod - def from_code(cls, code: str): + def from_code(cls, code: str, skip_boundary_field=False): if "nonuniform" not in code: tree = parse(code) return cls(None, None, tree=tree) @@ -45,9 +45,9 @@ ")", index_nonuniform, index_boundaryField ) - code_to_parse = ( - code[:index_nonuniform] + ";\n\n" + code[index_boundaryField:] - ) + code_to_parse = code[:index_nonuniform] + ";\n" + if not skip_boundary_field: + code_to_parse += "\n" + code[index_boundaryField:] tree = parse(code_to_parse) code_data = code[index_opening_par + 1 : index_closing_par].strip() @@ -61,9 +61,11 @@ return cls("", "", tree=tree, values=data) @classmethod - def from_path(cls, path: str or Path): + def from_path(cls, path: str or Path, skip_boundary_field=False): path = Path(path) - field = cls.from_code(path.read_text()) + field = cls.from_code( + path.read_text(), skip_boundary_field=skip_boundary_field + ) field.path = path return field @@ -177,6 +179,10 @@ value = values self.tree.set_child("internalField", value) + def get_components(self): + arr = self.get_array() + return arr[:, 0], arr[:, 1], arr[:, 2] + class VolTensorField(FieldABC): cls = "volTensorField" diff --git a/src/fluidsimfoam/operators.py b/src/fluidsimfoam/operators.py --- a/src/fluidsimfoam/operators.py +++ b/src/fluidsimfoam/operators.py @@ -3,7 +3,7 @@ import shutil from subprocess import PIPE, run -from fluidsimfoam.foam_input_files.fields import VolScalarField +from fluidsimfoam.foam_input_files.fields import VolVectorField class Operators: @@ -14,9 +14,9 @@ assert (sim.output.path_run / "system/blockMeshDict").exists() def get_cells_coords(self): - path_cx = self.sim.path_run / "0/Cx" + path_c = self.sim.path_run / "0/C" - if not path_cx.exists(): + if not path_c.exists(): path_polymesh = self.sim.path_run / "constant/polyMesh/points" if not path_polymesh.exists(): @@ -36,11 +36,5 @@ stdout=PIPE, ) - def get_arr(path): - field = VolScalarField.from_path(path) - return field.get_array() - - path_cy = path_cx.with_name("Cy") - path_cz = path_cx.with_name("Cz") - - return get_arr(path_cx), get_arr(path_cy), get_arr(path_cz) + field = VolVectorField.from_path(path_c, skip_boundary_field=True) + return field.get_components() diff --git a/tests/test_fields.py b/tests/test_fields.py --- a/tests/test_fields.py +++ b/tests/test_fields.py @@ -266,7 +266,14 @@ { upperBoundary { - type cyclic; + type calculated; + value nonuniform List<vector> + 2 + ( + (50 8000 0.005) + (150 8000 0.005) + ) + ; } lowerBoundary { @@ -380,11 +387,19 @@ field_c = VolVectorField.from_code(code_cells_centers) field_cx = VolScalarField.from_code(code_cx) + field_c = VolVectorField.from_code( + code_cells_centers, skip_boundary_field=True + ) + field_cx = VolScalarField.from_code(code_cx, skip_boundary_field=True) + c_values = field_c.get_array() cx_values = field_cx.get_array() assert np.allclose(c_values[:, 0], cx_values) + x, y, z = field_c.get_components() + assert np.allclose(x, cx_values) + def test_tensor(): field = VolTensorField("tensor", "") # HG changeset patch # User paugier <pierre.augier@univ-grenoble-alpes.fr> # Date 1684753567 -7200 # Mon May 22 13:06:07 2023 +0200 # Node ID 465845bc644ac9cf9243322d0cf72a037e0f74c3 # Parent f588e61deead69318cb5e0ebfc286378cdeda689 Phill without MRFProperties diff --git a/doc/examples/fluidsimfoam-phill/src/fluidsimfoam_phill/output.py b/doc/examples/fluidsimfoam-phill/src/fluidsimfoam_phill/output.py --- a/doc/examples/fluidsimfoam-phill/src/fluidsimfoam_phill/output.py +++ b/doc/examples/fluidsimfoam-phill/src/fluidsimfoam_phill/output.py @@ -43,12 +43,7 @@ name_variables = ["U", "p_rgh", "T", "alphat"] name_system_files = Output.name_system_files + ["blockMeshDict", "fvOptions"] - name_constant_files = [ - "g", - "MRFProperties", - "transportProperties", - "turbulenceProperties", - ] + name_constant_files = ["g", "transportProperties", "turbulenceProperties"] _default_control_dict_params = Output._default_control_dict_params.copy() _default_control_dict_params.update( diff --git a/doc/examples/fluidsimfoam-phill/src/fluidsimfoam_phill/templates/MRFProperties.jinja b/doc/examples/fluidsimfoam-phill/src/fluidsimfoam_phill/templates/MRFProperties.jinja deleted file mode 100644 --- a/doc/examples/fluidsimfoam-phill/src/fluidsimfoam_phill/templates/MRFProperties.jinja +++ /dev/null @@ -1,21 +0,0 @@ -FoamFile -{ - version 2.0; - format ascii; - class dictionary; - location "constant"; - object MRFProperties; -} - -/* -MRF1 -{ - active true; - selectionMode cellZone; - cellZone rotor; - - origin (0 0 0); - axis (0 0 1); - omega constant 0.2; -} -*/ \ No newline at end of file diff --git a/doc/examples/fluidsimfoam-phill/tests/saved_cases/case0/constant/MRFProperties b/doc/examples/fluidsimfoam-phill/tests/saved_cases/case0/constant/MRFProperties deleted file mode 100644 --- a/doc/examples/fluidsimfoam-phill/tests/saved_cases/case0/constant/MRFProperties +++ /dev/null @@ -1,21 +0,0 @@ -FoamFile -{ - version 2.0; - format ascii; - class dictionary; - location "constant"; - object MRFProperties; -} - -/* -MRF1 -{ - active true; - selectionMode cellZone; - cellZone rotor; - - origin (0 0 0); - axis (0 0 1); - omega constant 0.2; -} -*/ \ No newline at end of file # HG changeset patch # User paugier <pierre.augier@univ-grenoble-alpes.fr> # Date 1684755687 -7200 # Mon May 22 13:41:27 2023 +0200 # Node ID 024d218df7da6929894e3c1ce08088bf126c41e5 # Parent 465845bc644ac9cf9243322d0cf72a037e0f74c3 Improve constant_files to produce g file diff --git a/doc/examples/fluidsimfoam-phill/src/fluidsimfoam_phill/output.py b/doc/examples/fluidsimfoam-phill/src/fluidsimfoam_phill/output.py --- a/doc/examples/fluidsimfoam-phill/src/fluidsimfoam_phill/output.py +++ b/doc/examples/fluidsimfoam-phill/src/fluidsimfoam_phill/output.py @@ -105,6 +105,13 @@ comments={}, ) + _helper_g = ConstantFileHelper( + "g", + {"value": [0, -9.81, 0]}, + dimension="m/s^2", + cls="uniformDimensionedVectorField", + ) + _helper_fv_options = FvOptionsHelper() _helper_fv_options.add_option( "meanVelocityForce", diff --git a/doc/examples/fluidsimfoam-phill/src/fluidsimfoam_phill/templates/g.jinja b/doc/examples/fluidsimfoam-phill/src/fluidsimfoam_phill/templates/g.jinja deleted file mode 100644 --- a/doc/examples/fluidsimfoam-phill/src/fluidsimfoam_phill/templates/g.jinja +++ /dev/null @@ -1,11 +0,0 @@ -FoamFile -{ - version 2.0; - format ascii; - class uniformDimensionedVectorField; - location "constant"; - object g; -} - -dimensions [0 1 -2 0 0 0 0]; -value (0 -9.81 0); diff --git a/doc/examples/fluidsimfoam-phill/tests/saved_cases/case0/constant/g b/doc/examples/fluidsimfoam-phill/tests/saved_cases/case0/constant/g --- a/doc/examples/fluidsimfoam-phill/tests/saved_cases/case0/constant/g +++ b/doc/examples/fluidsimfoam-phill/tests/saved_cases/case0/constant/g @@ -7,5 +7,11 @@ object g; } -dimensions [0 1 -2 0 0 0 0]; -value (0 -9.81 0); +dimensions [0 1 -2 0 0 0 0]; + +value +( + 0 + -9.81 + 0 +); diff --git a/src/fluidsimfoam/foam_input_files/__init__.py b/src/fluidsimfoam/foam_input_files/__init__.py --- a/src/fluidsimfoam/foam_input_files/__init__.py +++ b/src/fluidsimfoam/foam_input_files/__init__.py @@ -26,7 +26,7 @@ from inflection import underscore -from .ast import Dict, FoamInputFile, List, Value +from .ast import Dict, DimensionSet, FoamInputFile, List, Value from .parser import dump, parse __all__ = [ @@ -47,6 +47,7 @@ "ConstantFileHelper", "BlockMeshDictRectilinear", "FvOptionsHelper", + "DimensionSet", ] diff --git a/src/fluidsimfoam/foam_input_files/ast.py b/src/fluidsimfoam/foam_input_files/ast.py --- a/src/fluidsimfoam/foam_input_files/ast.py +++ b/src/fluidsimfoam/foam_input_files/ast.py @@ -129,7 +129,7 @@ ): child = np.array(child) - if isinstance(child, (type(None), str, Number)): + if isinstance(child, (type(None), str, Number, DimensionSet)): pass elif isinstance(child, dict): child = Dict(child, name=key) @@ -309,6 +309,8 @@ class DimensionSet(list, Node): def __init__(self, foam_units): + if isinstance(foam_units, str): + foam_units = str2foam_units(foam_units) if not all(isinstance(elem, int) for elem in foam_units): raise ValueError("Bad {foam_units = }") super().__init__(foam_units) diff --git a/src/fluidsimfoam/foam_input_files/constant_files.py b/src/fluidsimfoam/foam_input_files/constant_files.py --- a/src/fluidsimfoam/foam_input_files/constant_files.py +++ b/src/fluidsimfoam/foam_input_files/constant_files.py @@ -3,6 +3,7 @@ from copy import deepcopy from fluidsimfoam.foam_input_files import ( + DimensionSet, FileHelper, FoamInputFile, _as_py_name, @@ -19,7 +20,9 @@ default_dimension: str = False, dimensions: dict = None, comments: dict = None, - doc=None, + doc: str = None, + cls: str = "dictionary", + dimension=None, ): self.file_name = file_name self.default = default @@ -27,6 +30,8 @@ self.dimensions = dimensions self.comments = comments self.doc = doc + self.cls = cls + self.dimension = dimension def complete_params(self, params): _complete_params_dict(params, self.file_name, self.default, self.doc) @@ -36,13 +41,16 @@ info={ "version": 2.0, "format": "ascii", - "class": "dictionary", + "class": self.cls, "location": '"constant"', "object": self.file_name, }, comments=self.comments, ) + if self.dimension is not None: + tree.set_child("dimensions", DimensionSet(self.dimension)) + params_file = params[_as_py_name(self.file_name)] default = deepcopy(self.default) diff --git a/src/fluidsimfoam/foam_input_files/fields.py b/src/fluidsimfoam/foam_input_files/fields.py --- a/src/fluidsimfoam/foam_input_files/fields.py +++ b/src/fluidsimfoam/foam_input_files/fields.py @@ -19,7 +19,6 @@ FoamInputFile, List, Value, - str2foam_units, ) DEFAULT_CODE_INCLUDE = '#include "fvCFD.H"' @@ -81,7 +80,7 @@ } if not isinstance(dimension, DimensionSet): - dimension = DimensionSet(str2foam_units(dimension)) + dimension = DimensionSet(dimension) self.tree = FoamInputFile( info, children={"dimensions": dimension, "internalField": None} # HG changeset patch # User paugier <pierre.augier@univ-grenoble-alpes.fr> # Date 1684757118 -7200 # Mon May 22 14:05:18 2023 +0200 # Node ID e8a34c116fe22b22336528daa959056207130023 # Parent 024d218df7da6929894e3c1ce08088bf126c41e5 _update_attribs and phill blockmesh.py diff --git a/doc/examples/fluidsimfoam-phill/src/fluidsimfoam_phill/blockmesh.py b/doc/examples/fluidsimfoam-phill/src/fluidsimfoam_phill/blockmesh.py new file mode 100644 --- /dev/null +++ b/doc/examples/fluidsimfoam-phill/src/fluidsimfoam_phill/blockmesh.py @@ -0,0 +1,104 @@ +from math import cos, pi + +from fluidsimfoam.foam_input_files.blockmesh import ( + BlockMeshDict, + Point, + SimpleGrading, + Vertex, +) + +possible_geometries = ("sinus",) + + +def make_code_blockmesh(bmd_params): + if bmd_params.geometry not in possible_geometries: + raise ValueError( + f"{bmd_params.geometry = } not in {possible_geometries = }" + ) + func = globals()["make_code_" + bmd_params.geometry] + return func(bmd_params) + + +def make_code_sinus(bmd_params): + nx = bmd_params.nx + ny = bmd_params.ny + nz = bmd_params.nz + ny_porosity = bmd_params.ny_porosity + + lx = bmd_params.lx + ly = bmd_params.ly + lz = bmd_params.lz + ly_p = bmd_params.ly_porosity + + h_max = bmd_params.h_max + + bmd = BlockMeshDict() + bmd.set_scale(bmd_params.scale) + + basevs = [ + Vertex(0, h_max, lz, "v0"), + Vertex(lx, h_max, lz, "v1"), + Vertex(lx, ly, lz, "v2"), + Vertex(lx, ly + ly_p, lz, "v3"), + Vertex(0, ly + ly_p, lz, "v4"), + Vertex(0, ly, lz, "v5"), + ] + + for v in basevs: + bmd.add_vertex(v.x, v.y, 0, v.name + "-0") + for v in basevs: + bmd.add_vertex(v.x, v.y, v.z, v.name + "+z") + + b0 = bmd.add_hexblock( + ("v0-0", "v1-0", "v2-0", "v5-0", "v0+z", "v1+z", "v2+z", "v5+z"), + (nx, ny, nz), + "b0", + SimpleGrading(1, [[0.1, 0.25, 41.9], [0.9, 0.75, 1]], 1), + ) + + b1 = bmd.add_hexblock( + ("v5-0", "v2-0", "v3-0", "v4-0", "v5+z", "v2+z", "v3+z", "v4+z"), + (nx, ny_porosity, nz), + "porosity", + SimpleGrading(1, 1, 1), + ) + + dots = [] + for dot in range(nx): + x_dot = dot * lx / (nx - 1) + y_dot = (h_max / 2) * ( + 1 - cos(2 * pi * min(abs((x_dot - (lx / 2)) / lx), 1)) + ) + dots.append([x_dot, y_dot]) + + bmd.add_splineedge( + ["v0-0", "v1-0"], + "spline0", + [Point(dot[0], dot[1], 0) for dot in dots], + ) + bmd.add_splineedge( + ["v0+z", "v1+z"], + "spline1", + [Point(dot[0], dot[1], lz) for dot in dots], + ) + + bmd.add_boundary("wall", "top", [b1.face("n")]) + bmd.add_boundary("wall", "bottom", [b0.face("s")]) + bmd.add_cyclic_boundaries( + "outlet", + "inlet", + [b0.face("e"), b1.face("e")], + [b0.face("w"), b1.face("w")], + ) + bmd.add_boundary( + "empty", + "frontandbackplanes", + [ + b0.face("b"), + b1.face("b"), + b0.face("t"), + b1.face("t"), + ], + ) + + return bmd.format(sort_vortices="as_added") diff --git a/doc/examples/fluidsimfoam-phill/src/fluidsimfoam_phill/output.py b/doc/examples/fluidsimfoam-phill/src/fluidsimfoam_phill/output.py --- a/doc/examples/fluidsimfoam-phill/src/fluidsimfoam_phill/output.py +++ b/doc/examples/fluidsimfoam-phill/src/fluidsimfoam_phill/output.py @@ -1,19 +1,14 @@ -from math import cos, pi -from textwrap import dedent - -from inflection import underscore - from fluidsimfoam.foam_input_files import ( - BlockMeshDict, ConstantFileHelper, FvOptionsHelper, FvSchemesHelper, VolScalarField, VolVectorField, ) -from fluidsimfoam.foam_input_files.blockmesh import Point, SimpleGrading, Vertex from fluidsimfoam.output import Output +from .blockmesh import make_code_blockmesh + def add_default_boundaries(field): for name, type_ in ( @@ -156,104 +151,24 @@ @classmethod def _complete_params_block_mesh_dict(cls, params): super()._complete_params_block_mesh_dict(params) - default = { - "nx": 20, - "ny": 50, - "nz": 1, - "ny_porosity": 10, - "h_max": 80, - "lporosity": 3000, - } - default.update({"lx": 2000, "ly": 2000, "lz": 0.01, "scale": 1}) - for key, value in default.items(): - try: - params.block_mesh_dict[key] = value - except AttributeError: - params.block_mesh_dict._set_attribs({key: value}) + params.block_mesh_dict._update_attribs( + { + "nx": 20, + "ny": 50, + "nz": 1, + "ny_porosity": 10, + "h_max": 80, + "ly_porosity": 3000, + "lx": 2000, + "ly": 2000, + "lz": 0.01, + "scale": 1, + "geometry": "sinus", + } + ) def _make_code_block_mesh_dict(self, params): - nx = params.block_mesh_dict.nx - ny = params.block_mesh_dict.ny - nz = params.block_mesh_dict.nz - ny_porosity = params.block_mesh_dict.ny_porosity - - lx = params.block_mesh_dict.lx - ly = params.block_mesh_dict.ly - lz = params.block_mesh_dict.lz - lp = params.block_mesh_dict.lporosity - - h_max = params.block_mesh_dict.h_max - - bmd = BlockMeshDict() - bmd.set_scale(params.block_mesh_dict.scale) - - basevs = [ - Vertex(0, h_max, lz, "v0"), - Vertex(lx, h_max, lz, "v1"), - Vertex(lx, ly, lz, "v2"), - Vertex(lx, ly + lp, lz, "v3"), - Vertex(0, ly + lp, lz, "v4"), - Vertex(0, ly, lz, "v5"), - ] - - for v in basevs: - bmd.add_vertex(v.x, v.y, 0, v.name + "-0") - for v in basevs: - bmd.add_vertex(v.x, v.y, v.z, v.name + "+z") - - b0 = bmd.add_hexblock( - ("v0-0", "v1-0", "v2-0", "v5-0", "v0+z", "v1+z", "v2+z", "v5+z"), - (nx, ny, nz), - "b0", - SimpleGrading(1, [[0.1, 0.25, 41.9], [0.9, 0.75, 1]], 1), - ) - - b1 = bmd.add_hexblock( - ("v5-0", "v2-0", "v3-0", "v4-0", "v5+z", "v2+z", "v3+z", "v4+z"), - (nx, ny_porosity, nz), - "porosity", - SimpleGrading(1, 1, 1), - ) - - dots = [] - for dot in range(nx): - x_dot = dot * lx / (nx - 1) - y_dot = (h_max / 2) * ( - 1 - cos(2 * pi * min(abs((x_dot - (lx / 2)) / lx), 1)) - ) - dots.append([x_dot, y_dot]) - - bmd.add_splineedge( - ["v0-0", "v1-0"], - "spline0", - [Point(dot[0], dot[1], 0) for dot in dots], - ) - bmd.add_splineedge( - ["v0+z", "v1+z"], - "spline1", - [Point(dot[0], dot[1], lz) for dot in dots], - ) - - bmd.add_boundary("wall", "top", [b1.face("n")]) - bmd.add_boundary("wall", "bottom", [b0.face("s")]) - bmd.add_cyclic_boundaries( - "outlet", - "inlet", - [b0.face("e"), b1.face("e")], - [b0.face("w"), b1.face("w")], - ) - bmd.add_boundary( - "empty", - "frontandbackplanes", - [ - b0.face("b"), - b1.face("b"), - b0.face("t"), - b1.face("t"), - ], - ) - - return bmd.format(sort_vortices="as_added") + return make_code_blockmesh(params.block_mesh_dict) def _make_tree_alphat(self, params): return make_scalar_field("alphat", dimension="m^2/s", values=0) diff --git a/src/fluidsimfoam/params.py b/src/fluidsimfoam/params.py --- a/src/fluidsimfoam/params.py +++ b/src/fluidsimfoam/params.py @@ -102,3 +102,10 @@ return self.__getattribute__(key) except AttributeError: return super().__getitem__(key) + + def _update_attribs(self, attribs): + for key, value in attribs.items(): + try: + self[key] = value + except AttributeError: + self._set_attrib(key, value) # HG changeset patch # User paugier <pierre.augier@univ-grenoble-alpes.fr> # Date 1684757374 -7200 # Mon May 22 14:09:34 2023 +0200 # Node ID 9ea892a20620b127cea9d8e89faba09d336af42d # Parent e8a34c116fe22b22336528daa959056207130023 Simplify phill (remove solver.py) diff --git a/doc/examples/fluidsimfoam-phill/pyproject.toml b/doc/examples/fluidsimfoam-phill/pyproject.toml --- a/doc/examples/fluidsimfoam-phill/pyproject.toml +++ b/doc/examples/fluidsimfoam-phill/pyproject.toml @@ -21,4 +21,4 @@ ] [project.entry-points."fluidsimfoam.solvers"] -phill = "fluidsimfoam_phill.solver" +phill = "fluidsimfoam_phill" diff --git a/doc/examples/fluidsimfoam-phill/src/fluidsimfoam_phill/__init__.py b/doc/examples/fluidsimfoam-phill/src/fluidsimfoam_phill/__init__.py --- a/doc/examples/fluidsimfoam-phill/src/fluidsimfoam_phill/__init__.py +++ b/doc/examples/fluidsimfoam-phill/src/fluidsimfoam_phill/__init__.py @@ -1,3 +1,19 @@ -from fluidsimfoam_phill.solver import Simul +from fluidsimfoam.info import InfoSolver +from fluidsimfoam.solvers.base import SimulFoam __all__ = ["Simul"] + + +class InfoSolverPHill(InfoSolver): + def _init_root(self): + super()._init_root() + self.module_name = "fluidsimfoam_phill" + self.class_name = "Simul" + self.short_name = "phill" + + self.classes.Output.module_name = "fluidsimfoam_phill.output" + self.classes.Output.class_name = "OutputPHill" + + +class Simul(SimulFoam): + InfoSolver = InfoSolverPHill diff --git a/doc/examples/fluidsimfoam-phill/src/fluidsimfoam_phill/solver.py b/doc/examples/fluidsimfoam-phill/src/fluidsimfoam_phill/solver.py deleted file mode 100644 --- a/doc/examples/fluidsimfoam-phill/src/fluidsimfoam_phill/solver.py +++ /dev/null @@ -1,20 +0,0 @@ -from fluidsimfoam.info import InfoSolver -from fluidsimfoam.solvers.base import SimulFoam - - -class InfoSolverPHill(InfoSolver): - def _init_root(self): - super()._init_root() - self.module_name = "fluidsimfoam_phill.solver" - self.class_name = "Simul" - self.short_name = "phill" - - self.classes.Output.module_name = "fluidsimfoam_phill.output" - self.classes.Output.class_name = "OutputPHill" - - -class SimulPHill(SimulFoam): - InfoSolver = InfoSolverPHill - - -Simul = SimulPHill # HG changeset patch # User paugier <pierre.augier@univ-grenoble-alpes.fr> # Date 1684758112 -7200 # Mon May 22 14:21:52 2023 +0200 # Node ID 1af324a49ce5c5746daccbcc66a9b77567ccc149 # Parent 9ea892a20620b127cea9d8e89faba09d336af42d fluidsimfoam.testing.skipif_executable_not_available diff --git a/doc/examples/fluidsimfoam-phill/tests/test_phill.py b/doc/examples/fluidsimfoam-phill/tests/test_phill.py --- a/doc/examples/fluidsimfoam-phill/tests/test_phill.py +++ b/doc/examples/fluidsimfoam-phill/tests/test_phill.py @@ -1,16 +1,11 @@ -import shutil from pathlib import Path -import pytest from fluidsimfoam_phill import Simul -from fluidsimfoam.testing import check_saved_case - -here = Path(__file__).absolute().parent - -path_saved_case = here / "saved_cases/case0" +from fluidsimfoam.testing import check_saved_case, skipif_executable_not_available +@skipif_executable_not_available("postProcess") def test_reproduce_case(): params = Simul.create_default_params() params.output.sub_directory = "tests_fluidsimfoam/phill" @@ -18,15 +13,11 @@ params.block_mesh_dict.ny = 7 params.block_mesh_dict.ny_porosity = 4 sim = Simul(params) - check_saved_case(path_saved_case, sim.path_run) + here = Path(__file__).absolute().parent + check_saved_case(here / "saved_cases/case0", sim.path_run) -path_foam_executable = shutil.which("icoFoam") - - -@pytest.mark.skipif( - path_foam_executable is None, reason="executable icoFoam not available" -) +@skipif_executable_not_available("icoFoam") def test_run(): params = Simul.create_default_params() params.output.sub_directory = "tests_fluidsimfoam/phill" diff --git a/src/fluidsimfoam/testing.py b/src/fluidsimfoam/testing.py --- a/src/fluidsimfoam/testing.py +++ b/src/fluidsimfoam/testing.py @@ -1,10 +1,26 @@ """Testing utilities""" +import shutil from pathlib import Path +import pytest + from fluidsimfoam.foam_input_files import dump, parse +class skipif_executable_not_available: + def __init__(self, command_name): + path_foam_executable = shutil.which("postProcess") + + self.skipif = pytest.mark.skipif( + path_foam_executable is None, + reason=f"executable '{command_name}' not available", + ) + + def __call__(self, func): + return self.skipif(func) + + def check_saved_case(path_saved_case, path_run, files_compare_tree=None): if files_compare_tree is None: files_compare_tree = [] # HG changeset patch # User paugier <pierre.augier@univ-grenoble-alpes.fr> # Date 1684758270 -7200 # Mon May 22 14:24:30 2023 +0200 # Node ID b263fbfb5b199417e297223288e788145cb87ef3 # Parent 1af324a49ce5c5746daccbcc66a9b77567ccc149 Simplify phill README diff --git a/doc/examples/fluidsimfoam-phill/README.md b/doc/examples/fluidsimfoam-phill/README.md --- a/doc/examples/fluidsimfoam-phill/README.md +++ b/doc/examples/fluidsimfoam-phill/README.md @@ -1,109 +1,16 @@ -# Fluidsimfoam solver for periodic hills (phill) +# Fluidsimfoam solver for periodic hill flows (phill) -This [Fluidsimfoam] solver demonstrates how to write a solver for the simulation of the flow over periodic hills (phill). +This [Fluidsimfoam] solver demonstrates how to write a solver for simulations +of the flow over a periodic hill (phill). ## Install + You can install this solver using this command: ```sh pip install fluidsimfoam-phill ``` -## Run -After installing this solver you can use this script to run a phill case. -```sh -python3 doc/examples/scripts/tuto_phill.py -``` -## Customized Run - -The first step to run a simulation is to create a `params` object with default parameters: -```sh -from fluidsimfoam_phill import Simul - -params = Simul.create_default_params() -``` - -## Modifying the parameters - - -Of course, the parameters can be modified. For instance, let's change the default 2D flow over 2D topography to a 3D flow over a 2D topography by just changing the number of elements in the z-direction in the blochMeshDict: - -```sh -params.block_mesh_dict.lz = 0.5 -params.block_mesh_dict.nz = 50 -``` - -Or you can change the subdirectory: - -```sh -params.output.sub_directory = "tests_fluidsimfoam/phill/" -``` -We are able to change other parameters in the controlDict or some other files in order to run different simulations, for instance: -```sh -params.control_dict.end_time = 0.5 -params.control_dict.delta_t = 0.01 -params.control_dict.start_from = 'startTime' -params.turbulence_properties.simulation_type = "RAS" -``` -After you assign or change all parameters you need, you could create the simulation object. - -## Creation of the simulation object and directory - -Now let’s create the simulation object (We usually use the name `sim`): -```sh -sim = Simul(params) -``` -Information is given about the structure of the sim object (which has attributes sim.oper, sim.output and sim.make corresponding to different aspects of the simulation) and about the creation of some files. When you create this object, you have made a directory for your case that contains all necessary directories (`0`, `system`, `constant`) and files (`fvSolution`, `fvSchemes`, `blockMeshDict` and etc). This directory is accessible by using this command: - -```sh -sim.path_run -``` - -Or you can easily see the list of contents of this directory: - -```sh -ls {sim.path_run} -``` -Something like this: -```sh -0/ constant/ info_solver.xml params_simul.xml system/ tasks.py -``` - -## Run Control - -Now, you have the case ready to start the simulation. You can run this case by this command: - -```sh -sim.make.exec("run") -``` -Or if you want to clean this case even polyMesh: -```sh -sim.make.exec("clean") -``` -If you want to see the run command list: - -```sh -sim.make.list() -``` - -```sh -Available tasks: - - block-mesh - clean - funky-set-fields - run - sets-to-zones - topo-set -``` -If you want to use any of these commands like making blockMeshDict you can easily use this: -```sh -sim.make.exec("block-mesh") -``` - - - - For more details, see https://fluidsimfoam.readthedocs.io/en/latest/install.html [fluidsimfoam]: https://foss.heptapod.net/fluiddyn/fluidsimfoam # HG changeset patch # User paugier <pierre.augier@univ-grenoble-alpes.fr> # Date 1684758584 -7200 # Mon May 22 14:29:44 2023 +0200 # Node ID 1ea48215ba4104fe4aec8a8f0b1d46ee7849a891 # Parent b263fbfb5b199417e297223288e788145cb87ef3 Cleanup docstring add_cyclic_boundaries diff --git a/src/fluidsimfoam/foam_input_files/blockmesh/__init__.py b/src/fluidsimfoam/foam_input_files/blockmesh/__init__.py --- a/src/fluidsimfoam/foam_input_files/blockmesh/__init__.py +++ b/src/fluidsimfoam/foam_input_files/blockmesh/__init__.py @@ -309,28 +309,16 @@ return b def add_cyclic_boundaries(self, name0, name1, faces0, faces1): - """In order to add cyclic boundary: - boundary name, neighbour name, boundary face, neighbour face. For example: - add_cyclic_boundaries("outlet", "inlet", b0.face("e"), b0.face("w")) - The result will be like: - outlet - { - type cyclic; - neighbourPatch inlet; - faces - ( - (3 7 15 11) // f-b2-n (v3-0 v3+y v4+y v4-0) - ); - } - inlet - { - type cyclic; - neighbourPatch outlet; - faces - ( - (0 8 12 4) // f-b0-w (v0-0 v7-0 v7+y v0+y) - ); - }""" + """Add 2 cyclic boundaries + + Example + ------- + + 2 cyclic boundaries can be created as follow:: + + add_cyclic_boundaries("outlet", "inlet", b0.face("e"), b0.face("w")) + + """ b0 = self.add_boundary("cyclic", name0, faces0, neighbour=name1) b1 = self.add_boundary("cyclic", name1, faces1, neighbour=name0) return b0, b1 # HG changeset patch # User paugier <pierre.augier@univ-grenoble-alpes.fr> # Date 1684761870 -7200 # Mon May 22 15:24:30 2023 +0200 # Node ID 596a9aeb22765e196bd3e9ad5cf8bf72185cbb6a # Parent 1ea48215ba4104fe4aec8a8f0b1d46ee7849a891 Resimplify tasks.py diff --git a/src/fluidsimfoam/tasks.py b/src/fluidsimfoam/tasks.py --- a/src/fluidsimfoam/tasks.py +++ b/src/fluidsimfoam/tasks.py @@ -26,32 +26,11 @@ @task(block_mesh) -def topo_set(context): - if not Path("system/topoSetDict").exists(): - print("topoSet not found!") - else: - context.run("topoSet") - - -@task(topo_set) -def sets_to_zones(context): - context.run("setsToZones") +def polymesh(context): + """Create the polymesh directory""" -@task(sets_to_zones) -def funky_set_fields(context): - if not Path("system/funkySetFieldsDict").exists(): - print("funkySetFields not found!") - else: - context.run("funkySetFields -time 0") - - -@task(block_mesh) -def polymesh(context): - pass - - -@task(block_mesh) +@task(polymesh) def run(context): """Main target to launch a simulation""" with open("system/controlDict") as file: