diff --git a/Makefile b/Makefile index 3a792393..4c6713fb 100644 --- a/Makefile +++ b/Makefile @@ -46,6 +46,7 @@ RDG := no RICHARDS := no STOCHASTIC_TOOLS := no TENSOR_MECHANICS := no +THERMAL_HYDRAULICS := no XFEM := no include $(MOOSE_DIR)/modules/modules.mk diff --git a/include/actions/AddFoamBCAction.h b/include/actions/AddFoamBCAction.h index cc90072b..84853b3d 100644 --- a/include/actions/AddFoamBCAction.h +++ b/include/actions/AddFoamBCAction.h @@ -1,7 +1,9 @@ #pragma once #include "InputParameters.h" -#include "MooseObjectAction.h" +#include "FoamProblem.h" + +#include class AddFoamBCAction : public MooseObjectAction { @@ -15,4 +17,7 @@ class AddFoamBCAction : public MooseObjectAction protected: // Create AuxVariable associated with new-style BCs void createAuxVariable(); + + // Create Receiver for Postprocessor-based BCs + void createReceiver(FoamProblem & problem); }; diff --git a/include/bcs/FoamBCBase.h b/include/bcs/FoamBCBase.h index 11b865ee..69fbfcb6 100644 --- a/include/bcs/FoamBCBase.h +++ b/include/bcs/FoamBCBase.h @@ -7,6 +7,9 @@ #include #include #include +#include "VariadicTable.h" + +typedef VariadicTable BCInfoTable; class FoamBCBase : public MooseObject, public Coupleable { @@ -26,7 +29,10 @@ class FoamBCBase : public MooseObject, public Coupleable // returns the name of the foam boundaries the BC applies to std::vector boundary() const { return _boundary; }; - virtual void initialSetup(); + virtual void initialSetup() = 0; + + // Add information about BC to table + virtual void addInfoRow(BCInfoTable & table) = 0; protected: // OpenFOAM variable which this BC is to be imposed on diff --git a/include/bcs/FoamFixedGradientBC.h b/include/bcs/FoamFixedGradientBC.h index 97041d43..0672b563 100644 --- a/include/bcs/FoamFixedGradientBC.h +++ b/include/bcs/FoamFixedGradientBC.h @@ -1,9 +1,9 @@ #pragma once -#include "FoamBCBase.h" +#include "FoamVariableBCBase.h" #include "InputParameters.h" -class FoamFixedGradientBC : public FoamBCBase +class FoamFixedGradientBC : public FoamVariableBCBase { public: // Validate input file parameters diff --git a/include/bcs/FoamFixedGradientPostprocessorBC.h b/include/bcs/FoamFixedGradientPostprocessorBC.h new file mode 100644 index 00000000..5f35fd37 --- /dev/null +++ b/include/bcs/FoamFixedGradientPostprocessorBC.h @@ -0,0 +1,19 @@ +#pragma once + +#include "FoamPostprocessorBCBase.h" +#include "InputParameters.h" + +class FoamFixedGradientPostprocessorBC : public FoamPostprocessorBCBase +{ +public: + static InputParameters validParams(); + + FoamFixedGradientPostprocessorBC(const InputParameters & params); + + // impose boundary condition + virtual void imposeBoundaryCondition() override; + +protected: + // name of diffusivity coefficient used to divide flux + std::string _diffusivity_coefficient; +}; diff --git a/include/bcs/FoamFixedValueBC.h b/include/bcs/FoamFixedValueBC.h index 70a9f865..00932728 100644 --- a/include/bcs/FoamFixedValueBC.h +++ b/include/bcs/FoamFixedValueBC.h @@ -1,9 +1,9 @@ #pragma once -#include "FoamBCBase.h" +#include "FoamVariableBCBase.h" #include "InputParameters.h" -class FoamFixedValueBC : public FoamBCBase +class FoamFixedValueBC : public FoamVariableBCBase { public: // Validate input file parameters diff --git a/include/bcs/FoamFixedValuePostprocessorBC.h b/include/bcs/FoamFixedValuePostprocessorBC.h new file mode 100644 index 00000000..57010a45 --- /dev/null +++ b/include/bcs/FoamFixedValuePostprocessorBC.h @@ -0,0 +1,14 @@ +#pragma once + +#include "FoamPostprocessorBCBase.h" + +class FoamFixedValuePostprocessorBC : public FoamPostprocessorBCBase +{ +public: + static InputParameters validParams(); + + FoamFixedValuePostprocessorBC(const InputParameters & params); + + // Impose boundary conditions (to be called from FoamProblem class) + virtual void imposeBoundaryCondition() override; +}; diff --git a/include/bcs/FoamMassFlowRateInletBC.h b/include/bcs/FoamMassFlowRateInletBC.h new file mode 100644 index 00000000..741b2b6e --- /dev/null +++ b/include/bcs/FoamMassFlowRateInletBC.h @@ -0,0 +1,17 @@ +#include "FoamPostprocessorBCBase.h" +#include "InputParameters.h" +#include "MooseTypes.h" +#include "PostprocessorInterface.h" + +class FoamMassFlowRateInletBC : public FoamPostprocessorBCBase +{ +public: + static InputParameters validParams(); + + FoamMassFlowRateInletBC(const InputParameters & params); + + virtual void imposeBoundaryCondition() override; + +protected: + const Real _scale_factor; +}; diff --git a/include/bcs/FoamPostprocessorBCBase.h b/include/bcs/FoamPostprocessorBCBase.h new file mode 100644 index 00000000..be37f63d --- /dev/null +++ b/include/bcs/FoamPostprocessorBCBase.h @@ -0,0 +1,27 @@ +#pragma once + +#include "FoamBCBase.h" +#include "InputParameters.h" +#include "MooseTypes.h" +#include "PostprocessorInterface.h" + +class FoamPostprocessorBCBase : public FoamBCBase, public PostprocessorInterface +{ +public: + static InputParameters validParams(); + + explicit FoamPostprocessorBCBase(const InputParameters & params); + + // returns the moose AuxVariable imposed on OpenFOAM + VariableName moosePostprocessor() const { return _pp_name; } + + virtual void initialSetup() {}; + + virtual void addInfoRow(BCInfoTable & table); + +protected: + const PostprocessorName _pp_name; + + // Pointer to Moose variable used to impose BC + const PostprocessorValue & _pp_value; +}; diff --git a/include/bcs/FoamVariableBCBase.h b/include/bcs/FoamVariableBCBase.h new file mode 100644 index 00000000..ccc2bce7 --- /dev/null +++ b/include/bcs/FoamVariableBCBase.h @@ -0,0 +1,29 @@ +#pragma once + +#include "FoamBCBase.h" +#include "InputParameters.h" + +class FoamVariableBCBase : public FoamBCBase +{ +public: + static InputParameters validParams(); + + explicit FoamVariableBCBase(const InputParameters & params); + + // returns the moose AuxVariable imposed on OpenFOAM + VariableName mooseVariable() const { return _moose_var->name(); } + + virtual void initialSetup(); + + virtual void addInfoRow(BCInfoTable & table); + +protected: + // Get the value of the MOOSE variable at an element + Real variableValueAtElement(const libMesh::Elem & elem); + + // Get the data vector of the MOOSE field on a subdomain + std::vector getMooseVariableArray(int subdomainId); + + // Pointer to Moose variable used to impose BC + MooseVariableFieldBase * _moose_var; +}; diff --git a/include/mesh/FoamMesh.h b/include/mesh/FoamMesh.h index 5e9ffd93..45dac203 100644 --- a/include/mesh/FoamMesh.h +++ b/include/mesh/FoamMesh.h @@ -60,12 +60,19 @@ class FoamMesh : public MooseMesh return _foam_mesh.foundObject(name); } + // Returns the patch array for field and subdomain + template + Foam::fvPatchField & getBCField(SubdomainID subdomain, Foam::word const & field) + { + return const_cast &>( + _foam_mesh.boundary()[subdomain].lookupPatchField(field)); + } + // Returns the gradient BC array for field and subdomain template Foam::Field & getGradientBCField(SubdomainID subdomain, Foam::word const & field) { - auto & var = const_cast &>( - _foam_mesh.boundary()[subdomain].lookupPatchField(field)); + auto & var = getBCField(subdomain, field); return Foam::refCast>(var).gradient(); } diff --git a/include/util/hippoUtils.h b/include/util/hippoUtils.h index de43b41d..fa13e0f7 100644 --- a/include/util/hippoUtils.h +++ b/include/util/hippoUtils.h @@ -13,5 +13,20 @@ copyParamFromParam(InputParameters & dst, const InputParameters & src, const std if (src.isParamValid(name_in)) dst.set(name_in) = src.get(name_in); } + +template +inline std::string +listFromVector(std::vector vec, StrType sep = ", ") +{ + if (vec.size() == 0) + return std::string(); + else if (vec.size() == 1) + return vec.at(0); + + std::string str; + auto binary_op = [&](const std::string & acc, const std::string & it) { return acc + sep + it; }; + std::accumulate(vec.begin(), vec.end(), str, binary_op); + return str; +} } } diff --git a/src/actions/AddFoamBCAction.C b/src/actions/AddFoamBCAction.C index f2ffce49..84767518 100644 --- a/src/actions/AddFoamBCAction.C +++ b/src/actions/AddFoamBCAction.C @@ -7,6 +7,17 @@ registerMooseAction("hippoApp", AddFoamBCAction, "add_foam_bc"); +namespace +{ +inline bool +findParamKey(const InputParameters & params, const std::string & key) +{ + return std::find_if(params.begin(), + params.end(), + [&](const auto & param) { return param.first == key; }) != params.end(); +} +} + InputParameters AddFoamBCAction::validParams() { @@ -27,9 +38,13 @@ AddFoamBCAction::act() mooseError("FoamBCs system can only be used with FoamProblem."); // Do not create aux variable if variable provided. - if (!_moose_object_pars.isParamSetByUser("v")) + if (findParamKey(_moose_object_pars, "v") && !_moose_object_pars.isParamSetByUser("v")) createAuxVariable(); + // Create receiver if pp not provided and pp is an allowed parameter + if (findParamKey(_moose_object_pars, "pp") && !_moose_object_pars.isParamSetByUser("pp")) + createReceiver(*foam_problem); + foam_problem->addObject(_type, _name, _moose_object_pars, false); } } @@ -56,3 +71,12 @@ AddFoamBCAction::createAuxVariable() std::static_pointer_cast(_action_factory.create(class_name, name(), action_params)); _awh.addActionBlock(action); } + +void +AddFoamBCAction::createReceiver(FoamProblem & problem) +{ + auto params = _factory.getValidParams("Receiver"); + + Hippo::internal::copyParamFromParam(params, _moose_object_pars, "default"); + problem.addPostprocessor("Receiver", name(), params); +} diff --git a/src/bcs/FoamBCBase.C b/src/bcs/FoamBCBase.C index b2879f11..5ab066a4 100644 --- a/src/bcs/FoamBCBase.C +++ b/src/bcs/FoamBCBase.C @@ -14,16 +14,6 @@ #include #include -namespace -{ -// Private function to check if variables are constant monomials -inline bool -is_constant_monomial(const MooseVariableFieldBase & var) -{ - return var.order() == libMesh::Order::CONSTANT && var.feType().family == FEFamily::MONOMIAL; -} -} - InputParameters FoamBCBase::validParams() { @@ -32,13 +22,8 @@ FoamBCBase::validParams() "Name of a Foam field. e.g. T (temperature) U (velocity)."); params.addParam>("boundary", "Boundaries that the boundary condition applies to."); - - params.addParam( - "v", - "Optional variable to use in BC. This allows existing AuxVariables to be" - " used rather than creating a new one under the hood."); - // Get desired parameters from Variable objects - params.transferParam>(MooseVariable::validParams(), "initial_condition"); + params.addRequiredParam("foam_variable", + "Name of a Foam field. e.g. T (temperature) U (velocity)."); params.registerSystemAttributeName("FoamBC"); params.registerBase("FoamBC"); @@ -50,7 +35,6 @@ FoamBCBase::FoamBCBase(const InputParameters & params) : MooseObject(params), Coupleable(this, false), _foam_variable(params.get("foam_variable")), - _moose_var(nullptr), _boundary(params.get>("boundary")) { auto * problem = dynamic_cast(&_c_fe_problem); @@ -60,7 +44,8 @@ FoamBCBase::FoamBCBase(const InputParameters & params) _mesh = &problem->mesh(); // check that the foam variable exists - if (!_mesh->foamHasObject(_foam_variable)) + if (!params.isPrivate("foam_variable") && + !_mesh->foamHasObject(_foam_variable)) mooseError("There is no OpenFOAM field named '", _foam_variable, "'"); // check that the boundary is in the FoamMesh @@ -75,45 +60,3 @@ FoamBCBase::FoamBCBase(const InputParameters & params) if (_boundary.empty()) _boundary = all_subdomain_names; } - -void -FoamBCBase::initialSetup() -{ - // Check variable exists - auto var_name = parameters().isParamValid("v") ? parameters().get("v") : _name; - if (!_c_fe_problem.hasVariable(var_name)) - mooseError("Variable '", var_name, "' doesn't exist"); - - THREAD_ID tid = parameters().get("_tid"); - _moose_var = &_c_fe_problem.getVariable(tid, var_name); - - // Check variable is constant monomial in case it is provided. - if (!is_constant_monomial(*_moose_var)) - mooseError("Variable '", var_name, "' must be a constant monomial."); -} - -Real -FoamBCBase::variableValueAtElement(const libMesh::Elem * elem) -{ - auto & sys = _moose_var->sys(); - auto dof = elem->dof_number(sys.number(), _moose_var->number(), 0); - return sys.solution()(dof); -} - -std::vector -FoamBCBase::getMooseVariableArray(int subdomain_id) -{ - size_t patch_count = _mesh->getPatchCount(subdomain_id); - size_t patch_offset = _mesh->getPatchOffset(subdomain_id); - - std::vector var_array(patch_count); - for (size_t j = 0; j < patch_count; ++j) - { - auto elem = patch_offset + j; - auto elem_ptr = _mesh->getElemPtr(elem + _mesh->rank_element_offset); - assert(elem_ptr); - var_array[j] = variableValueAtElement(elem_ptr); - } - - return var_array; -} diff --git a/src/bcs/FoamFixedGradientBC.C b/src/bcs/FoamFixedGradientBC.C index 7434d077..120bb6b7 100644 --- a/src/bcs/FoamFixedGradientBC.C +++ b/src/bcs/FoamFixedGradientBC.C @@ -10,7 +10,7 @@ registerMooseObject("hippoApp", FoamFixedGradientBC); InputParameters FoamFixedGradientBC::validParams() { - auto params = FoamBCBase::validParams(); + auto params = FoamVariableBCBase::validParams(); params.addClassDescription("A FoamBC that imposes a fixed gradient dirichlet boundary condition " "on the OpenFOAM simulation"); params.addParam("diffusivity_coefficient", @@ -20,7 +20,7 @@ FoamFixedGradientBC::validParams() } FoamFixedGradientBC::FoamFixedGradientBC(const InputParameters & parameters) - : FoamBCBase(parameters), + : FoamVariableBCBase(parameters), _diffusivity_coefficient(parameters.get("diffusivity_coefficient")) { // check that the diffusivity coefficient is a OpenFOAM scalar field diff --git a/src/bcs/FoamFixedGradientPostprocessorBC.C b/src/bcs/FoamFixedGradientPostprocessorBC.C new file mode 100644 index 00000000..91b3dfaf --- /dev/null +++ b/src/bcs/FoamFixedGradientPostprocessorBC.C @@ -0,0 +1,66 @@ +#include "FoamFixedGradientPostprocessorBC.h" +#include "PstreamReduceOps.H" +#include "Registry.h" +#include + +registerMooseObject("hippoApp", FoamFixedGradientPostprocessorBC); + +InputParameters +FoamFixedGradientPostprocessorBC::validParams() +{ + auto params = FoamPostprocessorBCBase::validParams(); + params.addParam("diffusivity_coefficient", + "", + "OpenFOAM scalar field name to be specified if 'v' is " + "a flux rather than a gradient"); + return params; +} + +FoamFixedGradientPostprocessorBC::FoamFixedGradientPostprocessorBC(const InputParameters & params) + : FoamPostprocessorBCBase(params), + _diffusivity_coefficient(params.get("diffusivity_coefficient")) +{ + // check that the diffusivity coefficient is a OpenFOAM scalar field + if (!_diffusivity_coefficient.empty() && + !_mesh->fvMesh().foundObject(_diffusivity_coefficient)) + mooseError( + "Diffusivity coefficient '", _diffusivity_coefficient, "' not a Foam volScalarField"); +} + +void +FoamFixedGradientPostprocessorBC::imposeBoundaryCondition() +{ + auto & foam_mesh = _mesh->fvMesh(); + + // Get subdomains this FoamBC acts on + auto subdomains = _mesh->getSubdomainIDs(_boundary); + for (auto subdomain : subdomains) + { + auto & boundary = foam_mesh.boundary()[subdomain]; + // Get underlying field from OpenFOAM boundary patch. + auto & foam_gradient = + _mesh->getGradientBCField(subdomain, _foam_variable); + + // If diffusivity_coefficient is specified grad array is a flux, so result + // must be divided by it + if (!_diffusivity_coefficient.empty()) + { + // Get the underlying diffusivity field + auto & coeff = foam_mesh.boundary()[subdomain].lookupPatchField( + _diffusivity_coefficient); + + // Calculate the bulk value of the diffusivity coefficient + auto area = boundary.magSf(); + auto total_area = Foam::returnReduce(Foam::sum(area), Foam::sumOp()); + auto coeff_bulk = + Foam::returnReduce(Foam::sum(coeff * area), Foam::sumOp()) / total_area; + + // set gradient + std::fill(foam_gradient.begin(), foam_gradient.end(), _pp_value / coeff_bulk); + } + else // if no diffusivity coefficient grad_array is just the gradient so fill + { + std::fill(foam_gradient.begin(), foam_gradient.end(), _pp_value); + } + } +} diff --git a/src/bcs/FoamFixedValueBC.C b/src/bcs/FoamFixedValueBC.C index 11c74268..29c7b0dc 100644 --- a/src/bcs/FoamFixedValueBC.C +++ b/src/bcs/FoamFixedValueBC.C @@ -1,36 +1,35 @@ #include "FoamFixedValueBC.h" #include "InputParameters.h" #include "MooseTypes.h" +#include registerMooseObject("hippoApp", FoamFixedValueBC); InputParameters FoamFixedValueBC::validParams() { - auto params = FoamBCBase::validParams(); + auto params = FoamVariableBCBase::validParams(); params.addClassDescription("A FoamBC that imposes a fixed value dirichlet boundary condition " "on the OpenFOAM simulation"); return params; } -FoamFixedValueBC::FoamFixedValueBC(const InputParameters & parameters) : FoamBCBase(parameters) {} +FoamFixedValueBC::FoamFixedValueBC(const InputParameters & parameters) + : FoamVariableBCBase(parameters) +{ +} void FoamFixedValueBC::imposeBoundaryCondition() { - auto & foam_mesh = _mesh->fvMesh(); - // Get subdomains this FoamBC acts on - // TODO: replace with BoundaryRestriction member functions once FoamMesh is updated auto subdomains = _mesh->getSubdomainIDs(_boundary); for (auto subdomain : subdomains) { std::vector && var_array = getMooseVariableArray(subdomain); // Get underlying field from OpenFOAM boundary patch - auto & foam_var = const_cast &>( - foam_mesh.boundary()[subdomain].lookupPatchField( - _foam_variable)); + auto & foam_var = _mesh->getBCField(subdomain, _foam_variable); assert(var_array.size() == static_cast(foam_var.size())); diff --git a/src/bcs/FoamFixedValuePosprocessorBC.C b/src/bcs/FoamFixedValuePosprocessorBC.C new file mode 100644 index 00000000..03958d0d --- /dev/null +++ b/src/bcs/FoamFixedValuePosprocessorBC.C @@ -0,0 +1,29 @@ +#include "FoamFixedValuePostprocessorBC.h" +#include "Registry.h" + +registerMooseObject("hippoApp", FoamFixedValuePostprocessorBC); + +InputParameters +FoamFixedValuePostprocessorBC::validParams() +{ + return FoamPostprocessorBCBase::validParams(); +} + +FoamFixedValuePostprocessorBC::FoamFixedValuePostprocessorBC(const InputParameters & params) + : FoamPostprocessorBCBase(params) +{ +} + +void +FoamFixedValuePostprocessorBC::imposeBoundaryCondition() +{ + // Get subdomains this FoamBC acts on + auto subdomains = _mesh->getSubdomainIDs(_boundary); + for (auto subdomain : subdomains) + { + // Get underlying field from OpenFOAM boundary patch + auto & foam_var = _mesh->getBCField(subdomain, _foam_variable); + + std::fill(foam_var.begin(), foam_var.end(), _pp_value); + } +} diff --git a/src/bcs/FoamMassFlowRateInletBC.C b/src/bcs/FoamMassFlowRateInletBC.C new file mode 100644 index 00000000..925cd424 --- /dev/null +++ b/src/bcs/FoamMassFlowRateInletBC.C @@ -0,0 +1,44 @@ +#include "FoamMassFlowRateInletBC.h" +#include "InputParameters.h" +#include "MooseTypes.h" +#include "PstreamReduceOps.H" +#include "Registry.h" + +registerMooseObject("hippoApp", FoamMassFlowRateInletBC); + +InputParameters +FoamMassFlowRateInletBC::validParams() +{ + auto params = FoamPostprocessorBCBase::validParams(); + + params.addParam("scale_factor", 1., "Scale factor multiply mass flow rate pp by."); + params.suppressParameter("foam_variable"); + params.set("foam_variable") = "U"; + + return params; +} + +FoamMassFlowRateInletBC::FoamMassFlowRateInletBC(const InputParameters & params) + : FoamPostprocessorBCBase(params), _scale_factor(params.get("scale_factor")) +{ +} + +void +FoamMassFlowRateInletBC::imposeBoundaryCondition() +{ + auto & foam_mesh = _mesh->fvMesh(); + + // Get subdomains this FoamBC acts on + // TODO: replace with BoundaryRestriction member functions once FoamMesh is updated + auto subdomains = _mesh->getSubdomainIDs(_boundary); + for (auto subdomain : subdomains) + { + auto & boundary_patch = foam_mesh.boundary()[subdomain]; + + auto & U_var = const_cast &>( + boundary_patch.lookupPatchField("U")); + auto & rho = boundary_patch.lookupPatchField("rho"); + Real area = Foam::returnReduce(Foam::sum(boundary_patch.magSf()), Foam::sumOp()); + U_var == -_scale_factor * _pp_value * boundary_patch.nf() / (rho * area); + } +} diff --git a/src/bcs/FoamPostprocessorBCBase.C b/src/bcs/FoamPostprocessorBCBase.C new file mode 100644 index 00000000..7deb88b2 --- /dev/null +++ b/src/bcs/FoamPostprocessorBCBase.C @@ -0,0 +1,39 @@ +#include "FoamBCBase.h" +#include "FoamPostprocessorBCBase.h" +#include "hippoUtils.h" + +#include "InputParameters.h" +#include "MooseTypes.h" +#include "PostprocessorInterface.h" +#include "Receiver.h" + +InputParameters +FoamPostprocessorBCBase::validParams() +{ + auto params = FoamBCBase::validParams(); + + params.addParam("pp", "optional postprocessor to be used in BC"); + params.transferParam(Receiver::validParams(), "default"); + + return params; +} + +FoamPostprocessorBCBase::FoamPostprocessorBCBase(const InputParameters & params) + : FoamBCBase(params), + PostprocessorInterface(this), + _pp_name((params.isParamSetByUser("pp")) ? params.get("pp") : _name), + _pp_value(getPostprocessorValueByName(_pp_name)) +{ + if (params.isParamSetByUser("pp") && params.isParamSetByUser("default")) + mooseWarning("'pp' and 'default' should not both be set. 'default' ignored."); +} + +void +FoamPostprocessorBCBase::addInfoRow(BCInfoTable & table) +{ + table.addRow(name(), + type(), + foamVariable(), + moosePostprocessor(), + Hippo::internal::listFromVector(boundary())); +} diff --git a/src/bcs/FoamVariableBCBase.C b/src/bcs/FoamVariableBCBase.C new file mode 100644 index 00000000..bd88208e --- /dev/null +++ b/src/bcs/FoamVariableBCBase.C @@ -0,0 +1,85 @@ + +#include "FoamVariableBCBase.h" +#include "hippoUtils.h" + +#include "FEProblemBase.h" + +namespace +{ +// Private function to check if variables are constant monomials +inline bool +is_constant_monomial(const MooseVariableFieldBase & var) +{ + return var.order() == libMesh::Order::CONSTANT && var.feType().family == FEFamily::MONOMIAL; +} +} + +InputParameters +FoamVariableBCBase::validParams() +{ + InputParameters params = FoamBCBase::validParams(); + + params.addParam( + "v", + "Optional variable to use in BC. This allows existing AuxVariables to be" + " used rather than creating a new one under the hood."); + // Get desired parameters from Variable objects + params.transferParam>(MooseVariable::validParams(), "initial_condition"); + + return params; +} + +FoamVariableBCBase::FoamVariableBCBase(const InputParameters & params) + : FoamBCBase(params), _moose_var(nullptr) +{ +} + +void +FoamVariableBCBase::initialSetup() +{ + // Check variable exists + auto var_name = parameters().isParamValid("v") ? parameters().get("v") : _name; + if (!_c_fe_problem.hasVariable(var_name)) + mooseError("Variable '", var_name, "' doesn't exist"); + + THREAD_ID tid = parameters().get("_tid"); + _moose_var = &_c_fe_problem.getVariable(tid, var_name); + + // Check variable is constant monomial in case it is provided. + if (!is_constant_monomial(*_moose_var)) + mooseError("Variable '", var_name, "' must be a constant monomial."); +} + +void +FoamVariableBCBase::addInfoRow(BCInfoTable & table) +{ + // List info about BC + table.addRow( + name(), type(), foamVariable(), mooseVariable(), Hippo::internal::listFromVector(boundary())); +} + +Real +FoamVariableBCBase::variableValueAtElement(const libMesh::Elem & elem) +{ + auto & sys = _moose_var->sys(); + auto dof = elem.dof_number(sys.number(), _moose_var->number(), 0); + return sys.solution()(dof); +} + +std::vector +FoamVariableBCBase::getMooseVariableArray(int subdomainId) +{ + size_t patch_count = _mesh->getPatchCount(subdomainId); + size_t patch_offset = _mesh->getPatchOffset(subdomainId); + + std::vector var_array(patch_count); + for (size_t j = 0; j < patch_count; ++j) + { + auto elem = patch_offset + j; + const auto elem_ptr = _mesh->getElemPtr(elem + _mesh->rank_element_offset); + assert(elem_ptr); + var_array[j] = variableValueAtElement(*elem_ptr); + } + + return var_array; +} diff --git a/src/problems/FoamProblem.C b/src/problems/FoamProblem.C index d1c470f9..e15f2afb 100644 --- a/src/problems/FoamProblem.C +++ b/src/problems/FoamProblem.C @@ -1,47 +1,27 @@ -#include "Attributes.h" -#include "ExternalProblem.h" +#include "FoamVariableField.h" #include "FoamMesh.h" #include "FoamProblem.h" #include "FoamSolver.h" -#include "VariadicTable.h" -#include "word.H" +#include "hippoUtils.h" -#include -#include -#include -#include -#include -#include "FoamVariableField.h" +#include "Attributes.h" +#include "ExternalProblem.h" +#include "VariadicTable.h" +#include "MooseTypes.h" #include "InputParameters.h" #include "VariadicTable.h" + #include +#include #include #include #include - #include #include -registerMooseObject("hippoApp", FoamProblem); +#include -namespace -{ -// Create comma separated list from vector -template -inline std::string -listFromVector(std::vector vec, StrType sep = ", ") -{ - if (vec.size() == 0) - return std::string(); - else if (vec.size() == 1) - return vec.at(0); - - std::string str; - auto binary_op = [&](const std::string & acc, const std::string & it) { return acc + sep + it; }; - std::accumulate(vec.begin(), vec.end(), str, binary_op); - return str; -} -} +registerMooseObject("hippoApp", FoamProblem); InputParameters FoamProblem::validParams() @@ -154,7 +134,7 @@ FoamProblem::verifyFoamBCs() "FoamBC name", "Type", "Foam variable", - "Moose variable", + "Moose variable/postprocessor", "Boundaries", }); @@ -172,11 +152,7 @@ FoamProblem::verifyFoamBCs() auto && boundary = bc->boundary(); used_bcs.insert(used_bcs.end(), boundary.begin(), boundary.end()); // List info about BC - vt.addRow(bc->name(), - bc->type(), - bc->foamVariable(), - bc->mooseVariable(), - listFromVector(boundary)); + bc->addInfoRow(vt); } } @@ -198,7 +174,7 @@ FoamProblem::verifyFoamBCs() unused_bcs.push_back(bc); } if (unused_bcs.size() > 0) - vt.addRow("", "UnusedBoundaries", "", "", listFromVector(unused_bcs)); + vt.addRow("", "UnusedBoundaries", "", "", Hippo::internal::listFromVector(unused_bcs)); } vt.print(_console); } @@ -223,7 +199,7 @@ FoamProblem::verifyFoamPostprocessors() if (fpp) { _foam_postprocessor.push_back(fpp); - vt.addRow(fpp->name(), fpp->type(), listFromVector(fpp->blocks())); + vt.addRow(fpp->name(), fpp->type(), Hippo::internal::listFromVector(fpp->blocks())); } } diff --git a/test/include/bcs/FoamTestBC.h b/test/include/bcs/FoamTestBC.h index 28cd2a91..0ae3cf71 100644 --- a/test/include/bcs/FoamTestBC.h +++ b/test/include/bcs/FoamTestBC.h @@ -1,10 +1,10 @@ -#include "FoamBCBase.h" +#include "FoamVariableBCBase.h" #include "InputParameters.h" -class FoamTestBC : public FoamBCBase +class FoamTestBC : public FoamVariableBCBase { public: - explicit FoamTestBC(const InputParameters & params) : FoamBCBase(params) {}; + explicit FoamTestBC(const InputParameters & params) : FoamVariableBCBase(params) {}; void imposeBoundaryCondition() {}; }; diff --git a/test/tests/bcs/fixed_gradient_pp/foam/0/T b/test/tests/bcs/fixed_gradient_pp/foam/0/T new file mode 100644 index 00000000..6da637de --- /dev/null +++ b/test/tests/bcs/fixed_gradient_pp/foam/0/T @@ -0,0 +1,52 @@ +/*--------------------------------*- C++ -*----------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | Website: https://openfoam.org + \\ / A nd | Version: 10 + \\/ M anipulation | +\*---------------------------------------------------------------------------*/ +FoamFile +{ + format ascii; + class volScalarField; + location "0"; + object T; +} +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +dimensions [0 0 0 1 0 0 0]; + +internalField uniform 0.; + +boundaryField +{ + left + { + type fixedValue; + value uniform 0.; + } + right + { + type fixedGradient; + gradient uniform 1.; + } + top + { + type zeroGradient; + } + front + { + type zeroGradient; + } + bottom + { + type zeroGradient; + } + back + { + type zeroGradient; + } +} + + +// ************************************************************************* // diff --git a/test/tests/bcs/fixed_gradient_pp/foam/constant/physicalProperties b/test/tests/bcs/fixed_gradient_pp/foam/constant/physicalProperties new file mode 100644 index 00000000..6dab7b1c --- /dev/null +++ b/test/tests/bcs/fixed_gradient_pp/foam/constant/physicalProperties @@ -0,0 +1,51 @@ +/*--------------------------------*- C++ -*----------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | Website: https://openfoam.org + \\ / A nd | Version: 10 + \\/ M anipulation | +\*---------------------------------------------------------------------------*/ +FoamFile +{ + format ascii; + class dictionary; + location "constant"; + object physicalProperties; +} +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +thermoType +{ + type heSolidThermo; + mixture pureMixture; + transport constIsoSolid; + thermo eConst; + equationOfState rhoConst; + specie specie; + energy sensibleInternalEnergy; +} + +mixture +{ + specie + { + molWeight 1; + } + thermodynamics + { + Cv 1; // Specific heat capacity [J/(kg·K)] + Hf 1; // Heat of formation [J/kg] + Tref 0; + } + transport + { + kappa 2.; // Thermal conductivity [W/(m·K)] + } + equationOfState + { + rho 1; // Density [kg/m^3] + } +} + + +// ************************************************************************* // diff --git a/test/tests/bcs/fixed_gradient_pp/foam/system/blockMeshDict b/test/tests/bcs/fixed_gradient_pp/foam/system/blockMeshDict new file mode 100644 index 00000000..face9ea6 --- /dev/null +++ b/test/tests/bcs/fixed_gradient_pp/foam/system/blockMeshDict @@ -0,0 +1,85 @@ +FoamFile +{ + version 2.0; + format ascii; + class dictionary; + object blockMeshDict; +} + +vertices +( + ( 0.0 0.0 0.0 ) + ( 10.0 0.0 0.0 ) + ( 10.0 1.0 0.0 ) + ( 0.0 1.0 0.0 ) + + ( 0.0 0.0 1.0) + ( 10.0 0.0 1.0) + ( 10.0 1.0 1.0) + ( 0.0 1.0 1.0) +); + +blocks +( + hex (0 1 2 3 4 5 6 7) (50 1 1) simpleGrading (25 1 1) +); + +boundary +( + + // interface + left + { + type wall; + faces + ( + (4 7 3 0) + ); + } + + right + { + type wall; + faces + ( + (6 5 1 2) + ); + } + + top + { + type wall; + faces + ( + (2 3 7 6) + ); + } + + front + { + type wall; + faces + ( + (3 2 1 0) + ); + } + + bottom + { + type wall; + faces + ( + (0 1 5 4) + ); + } + + back + { + type wall; + faces + ( + (4 5 6 7) + ); + } + +); diff --git a/test/tests/bcs/fixed_gradient_pp/foam/system/controlDict b/test/tests/bcs/fixed_gradient_pp/foam/system/controlDict new file mode 100644 index 00000000..89301ab0 --- /dev/null +++ b/test/tests/bcs/fixed_gradient_pp/foam/system/controlDict @@ -0,0 +1,44 @@ +/*--------------------------------*- C++ -*----------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | Website: https://openfoam.org + \\ / A nd | Version: 10 + \\/ M anipulation | +\*---------------------------------------------------------------------------*/ +FoamFile +{ + format ascii; + class dictionary; + object controlDict; +} +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +solver bcTestSolver; + +startFrom startTime; + +startTime 0; + +stopAt endTime; + +endTime 32.; + +deltaT 1.; + +writeControl timeStep; + +writeInterval 1; + +writeFormat ascii; + +writePrecision 20; + +writeCompression off; + +timeFormat general; + +timePrecision 20; + +runTimeModifiable true; + +// ************************************************************************* // diff --git a/test/tests/bcs/fixed_gradient_pp/foam/system/fvSchemes b/test/tests/bcs/fixed_gradient_pp/foam/system/fvSchemes new file mode 100644 index 00000000..a24aaf80 --- /dev/null +++ b/test/tests/bcs/fixed_gradient_pp/foam/system/fvSchemes @@ -0,0 +1,46 @@ +/*--------------------------------*- C++ -*----------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | Website: https://openfoam.org + \\ / A nd | Version: 12 + \\/ M anipulation | +\*---------------------------------------------------------------------------*/ +FoamFile +{ + format ascii; + class dictionary; + object fvSchemes; +} +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +ddtSchemes +{ + default Euler; +} + +gradSchemes +{ + default Gauss linear; +} + +divSchemes +{ + default Gauss linear; +} + +laplacianSchemes +{ + default Gauss linear corrected; +} + +interpolationSchemes +{ + default linear; +} + +snGradSchemes +{ + default corrected; +} + +// ************************************************************************* // diff --git a/test/tests/bcs/fixed_gradient_pp/foam/system/fvSolution b/test/tests/bcs/fixed_gradient_pp/foam/system/fvSolution new file mode 100644 index 00000000..639b272d --- /dev/null +++ b/test/tests/bcs/fixed_gradient_pp/foam/system/fvSolution @@ -0,0 +1,49 @@ +/*--------------------------------*- C++ -*----------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | Website: https://openfoam.org + \\ / A nd | Version: 12 + \\/ M anipulation | +\*---------------------------------------------------------------------------*/ +FoamFile +{ + format ascii; + class dictionary; + object fvSolution; +} +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +solvers +{ + rho + { + solver diagonal; + } + + rhoFinal + { + $rho; + } + + + e + { + solver PBiCGStab; + preconditioner DIC; + tolerance 1e-15; + relTol 1e-15; + } + + eFinal + { + $e; + tolerance 1e-15; + relTol 1e-15; + } +} + +PIMPLE +{ +} + +// ************************************************************************* // diff --git a/test/tests/bcs/fixed_gradient_pp/main.i b/test/tests/bcs/fixed_gradient_pp/main.i new file mode 100644 index 00000000..cce2ed4a --- /dev/null +++ b/test/tests/bcs/fixed_gradient_pp/main.i @@ -0,0 +1,56 @@ +[Mesh] + type = FoamMesh + case = 'foam' + foam_patch = 'left right' +[] + +[Variables] + [dummy] + family = MONOMIAL + order = CONSTANT + initial_condition = 999 + [] +[] + +[FoamBCs] + [T_value] + type=FoamFixedValuePostprocessorBC + foam_variable = T + default = 0. + boundary = 'left' + [] + [T_flux] + type=FoamFixedGradientPostprocessorBC + foam_variable = T + boundary = 'right' + diffusivity_coefficient = kappa + pp = T_flux + [] +[] + +[Postprocessors] + [T_flux] + type = ParsedPostprocessor + expression = '2*t' + use_t = true + execute_on = 'INITIAL TIMESTEP_BEGIN' + [] +[] + +[Problem] + type = FoamProblem +[] + +[Executioner] + type = Transient + end_time = 32 + [TimeSteppers] + [foam] + type = FoamControlledTimeStepper + [] + [] +[] + +[Outputs] + exodus = true +[] diff --git a/test/tests/bcs/fixed_gradient_pp/test.py b/test/tests/bcs/fixed_gradient_pp/test.py new file mode 100644 index 00000000..98b48ce7 --- /dev/null +++ b/test/tests/bcs/fixed_gradient_pp/test.py @@ -0,0 +1,29 @@ +"""Tests for imposing BCs in OpenFOAM using MOOSE input file syntax""" + +import unittest +import fluidfoam as ff +import numpy as np + +from read_hippo_data import get_foam_times # pylint: disable=E0401 + + +class TestFoamBCFixedGradient(unittest.TestCase): + """Test class for imposing fixed value BCs in Hippo.""" + + def test_fixed_gradient_x(self): + """Test case for imposing fixed value.""" + case_dir = "foam/" + times = get_foam_times(case_dir, string=True)[1:] + + for time in times: + coords = dict(zip(("x", "y", "z"), ff.readof.readmesh(case_dir))) + + temp = ff.readof.readscalar(case_dir, time, "T") + + temp_ref = coords["x"] * np.float64(time) + + temp_diff_max = np.argmax(abs(temp - temp_ref)) + assert np.allclose(temp_ref, temp, rtol=1e-7, atol=1e-12), ( + f"Max diff ({time}): {abs(temp - temp_ref).max()} " + f"{temp[temp_diff_max]} {temp_ref[temp_diff_max]}" + ) diff --git a/test/tests/bcs/fixed_gradient_pp/tests b/test/tests/bcs/fixed_gradient_pp/tests new file mode 100644 index 00000000..ba30399b --- /dev/null +++ b/test/tests/bcs/fixed_gradient_pp/tests @@ -0,0 +1,39 @@ +[Tests] + [foam_bc_fixed_gradient_pp] + [setup] + type = RunCommand + command = 'bash -c "foamCleanCase -case foam && blockMesh -case foam"' + [] + [diffusivity_coeff_err] + type = RunException + input = main.i + prereq = foam_bc_fixed_gradient_pp/setup + expect_err = "Diffusivity coefficient 'kappa1' not a Foam volScalarField" + cli_args = 'FoamBCs/T_flux/diffusivity_coefficient=kappa1' + allow_warnings = true + [] + [run] + type = RunApp + input = main.i + prereq = foam_bc_fixed_gradient_pp/setup + allow_warnings = true + [] + [verify] + type = PythonUnitTest + input = test.py + prereq = foam_bc_fixed_gradient_pp/run + [] + [run_no_kappa] + type = RunApp + input = main.i + cli_args = "FoamBCs/T_flux/diffusivity_coefficient='' Postprocessors/T_flux/expression='t'" + prereq = foam_bc_fixed_gradient_pp/verify + allow_warnings = true + [] + [verify_no_kappa] + type = PythonUnitTest + input = test.py + prereq = foam_bc_fixed_gradient_pp/run_no_kappa + [] + [] +[] diff --git a/test/tests/bcs/fixed_value_pp/foam/0/T b/test/tests/bcs/fixed_value_pp/foam/0/T new file mode 100644 index 00000000..65a14be8 --- /dev/null +++ b/test/tests/bcs/fixed_value_pp/foam/0/T @@ -0,0 +1,56 @@ +/*--------------------------------*- C++ -*----------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | Website: https://openfoam.org + \\ / A nd | Version: 10 + \\/ M anipulation | +\*---------------------------------------------------------------------------*/ +FoamFile +{ + format ascii; + class volScalarField; + location "0"; + object T; +} +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +dimensions [0 0 0 1 0 0 0]; + +internalField uniform 0.1; + +boundaryField +{ + left + { + type fixedValue; + value uniform 0.; + } + right + { + type fixedValue; + value uniform 0.; + } + top + { + type fixedValue; + value uniform 0.; + } + bottom + { + type fixedValue; + value uniform 0.; + } + back + { + type fixedValue; + value uniform 0.; + } + front + { + type fixedValue; + value uniform 0.; + } +} + + +// ************************************************************************* // diff --git a/test/tests/bcs/fixed_value_pp/foam/constant/physicalProperties b/test/tests/bcs/fixed_value_pp/foam/constant/physicalProperties new file mode 100644 index 00000000..96a14c15 --- /dev/null +++ b/test/tests/bcs/fixed_value_pp/foam/constant/physicalProperties @@ -0,0 +1,51 @@ +/*--------------------------------*- C++ -*----------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | Website: https://openfoam.org + \\ / A nd | Version: 10 + \\/ M anipulation | +\*---------------------------------------------------------------------------*/ +FoamFile +{ + format ascii; + class dictionary; + location "constant"; + object physicalProperties; +} +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +thermoType +{ + type heSolidThermo; + mixture pureMixture; + transport constIsoSolid; + thermo eConst; + equationOfState rhoConst; + specie specie; + energy sensibleInternalEnergy; +} + +mixture +{ + specie + { + molWeight 1; + } + thermodynamics + { + Cv 1; // Specific heat capacity [J/(kg·K)] + Hf 1; // Heat of formation [J/kg] + Tref 0; + } + transport + { + kappa 1; // Thermal conductivity [W/(m·K)] + } + equationOfState + { + rho 1; // Density [kg/m^3] + } +} + + +// ************************************************************************* // diff --git a/test/tests/bcs/fixed_value_pp/foam/system/blockMeshDict b/test/tests/bcs/fixed_value_pp/foam/system/blockMeshDict new file mode 100644 index 00000000..face9ea6 --- /dev/null +++ b/test/tests/bcs/fixed_value_pp/foam/system/blockMeshDict @@ -0,0 +1,85 @@ +FoamFile +{ + version 2.0; + format ascii; + class dictionary; + object blockMeshDict; +} + +vertices +( + ( 0.0 0.0 0.0 ) + ( 10.0 0.0 0.0 ) + ( 10.0 1.0 0.0 ) + ( 0.0 1.0 0.0 ) + + ( 0.0 0.0 1.0) + ( 10.0 0.0 1.0) + ( 10.0 1.0 1.0) + ( 0.0 1.0 1.0) +); + +blocks +( + hex (0 1 2 3 4 5 6 7) (50 1 1) simpleGrading (25 1 1) +); + +boundary +( + + // interface + left + { + type wall; + faces + ( + (4 7 3 0) + ); + } + + right + { + type wall; + faces + ( + (6 5 1 2) + ); + } + + top + { + type wall; + faces + ( + (2 3 7 6) + ); + } + + front + { + type wall; + faces + ( + (3 2 1 0) + ); + } + + bottom + { + type wall; + faces + ( + (0 1 5 4) + ); + } + + back + { + type wall; + faces + ( + (4 5 6 7) + ); + } + +); diff --git a/test/tests/bcs/fixed_value_pp/foam/system/controlDict b/test/tests/bcs/fixed_value_pp/foam/system/controlDict new file mode 100644 index 00000000..cb155c26 --- /dev/null +++ b/test/tests/bcs/fixed_value_pp/foam/system/controlDict @@ -0,0 +1,44 @@ +/*--------------------------------*- C++ -*----------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | Website: https://openfoam.org + \\ / A nd | Version: 10 + \\/ M anipulation | +\*---------------------------------------------------------------------------*/ +FoamFile +{ + format ascii; + class dictionary; + object controlDict; +} +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +solver bcTestSolver; + +startFrom startTime; + +startTime 0; + +stopAt endTime; + +endTime 0.32; + +deltaT 0.01; + +writeControl timeStep; + +writeInterval 1; + +writeFormat ascii; + +writePrecision 20; + +writeCompression off; + +timeFormat general; + +timePrecision 20; + +runTimeModifiable true; + +// ************************************************************************* // diff --git a/test/tests/bcs/fixed_value_pp/foam/system/fvSchemes b/test/tests/bcs/fixed_value_pp/foam/system/fvSchemes new file mode 100644 index 00000000..0e534821 --- /dev/null +++ b/test/tests/bcs/fixed_value_pp/foam/system/fvSchemes @@ -0,0 +1,46 @@ +/*--------------------------------*- C++ -*----------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | Website: https://openfoam.org + \\ / A nd | Version: 12 + \\/ M anipulation | +\*---------------------------------------------------------------------------*/ +FoamFile +{ + format ascii; + class dictionary; + object fvSchemes; +} +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +ddtSchemes +{ + default Euler; +} + +gradSchemes +{ + default Gauss linear; +} + +divSchemes +{ + default Gauss linear; +} + +laplacianSchemes +{ + default Gauss linear corrected; +} + +interpolationSchemes +{ + default linear; +} + +snGradSchemes +{ + default corrected; +} + +// ************************************************************************* // diff --git a/test/tests/bcs/fixed_value_pp/foam/system/fvSolution b/test/tests/bcs/fixed_value_pp/foam/system/fvSolution new file mode 100644 index 00000000..59db6a2a --- /dev/null +++ b/test/tests/bcs/fixed_value_pp/foam/system/fvSolution @@ -0,0 +1,61 @@ +/*--------------------------------*- C++ -*----------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | Website: https://openfoam.org + \\ / A nd | Version: 12 + \\/ M anipulation | +\*---------------------------------------------------------------------------*/ +FoamFile +{ + format ascii; + class dictionary; + object fvSolution; +} +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +solvers +{ + rho + { + solver diagonal; + } + + rhoFinal + { + $rho; + } + + + e + { + solver PBiCGStab; + preconditioner DIC; + tolerance 1e-8; + relTol 1e-8; + } + + eFinal + { + $e; + tolerance 1e-8; + relTol 1e-8; + } +} + +PIMPLE +{ + momentumPredictor yes; + pRefCell 0; + pRefValue 0; +} + +relaxationFactors +{ + equations + { + h 1; + U 1; + } +} + +// ************************************************************************* // diff --git a/test/tests/bcs/fixed_value_pp/main.i b/test/tests/bcs/fixed_value_pp/main.i new file mode 100644 index 00000000..c49df10a --- /dev/null +++ b/test/tests/bcs/fixed_value_pp/main.i @@ -0,0 +1,77 @@ +[Mesh] + type = FoamMesh + case = 'foam' + foam_patch = 'left right bottom top back front' +[] + +[Variables] + [dummy] + family = MONOMIAL + order = CONSTANT + initial_condition = 999 + [] +[] + +[FoamBCs] + [temp1] + type=FoamFixedValuePostprocessorBC + foam_variable = T + boundary = 'left right top' # test boundary restrictions + pp = T_bc1 + [] + [temp2] + type=FoamFixedValuePostprocessorBC + foam_variable = T + boundary = 'bottom front back' # test boundary restrictions + pp = T_bc2 + [] +[] + +[FoamVariables] + [T_shadow] + type = FoamVariableField + foam_variable = 'T' + [] + [e_shadow] + type = FoamVariableField + foam_variable = 'e' + [] + [whf_shadow] + type = FoamFunctionObject + foam_variable = 'wallHeatFlux' + [] +[] + +[Postprocessors] + [T_bc1] + type=ParsedPostprocessor + expression = '0.05 + t' + use_t = true + execute_on='TIMESTEP_BEGIN INITIAL' + [] + [T_bc2] + type=ParsedPostprocessor + expression = '0.05 + 2*t' + use_t = true + execute_on='TIMESTEP_BEGIN INITIAL' + [] +[] + +[Problem] + type = FoamProblem + # Take the boundary temperature from OpenFOAM and set it on the MOOSE mesh. +[] + +[Executioner] + type = Transient + end_time = 0.32 + [TimeSteppers] + [foam] + type = FoamControlledTimeStepper + [] + [] +[] + +[Outputs] + exodus = true +[] diff --git a/test/tests/bcs/fixed_value_pp/test.py b/test/tests/bcs/fixed_value_pp/test.py new file mode 100644 index 00000000..a42a0eed --- /dev/null +++ b/test/tests/bcs/fixed_value_pp/test.py @@ -0,0 +1,30 @@ +"""Tests for imposing BCs in OpenFOAM using MOOSE input file syntax""" + +import unittest +import fluidfoam as ff +import numpy as np + +from read_hippo_data import get_foam_times # pylint: disable=E0401 + + +class TestFoamBCFixedValuePostprocessor(unittest.TestCase): + """Test class for imposing fixed value BCs in Hippo using postprocessors.""" + + def test_fixed_value(self): + """Test case for imposing fixed value.""" + case_dir = "foam/" + boundaries = ["top", "bottom", "front", "back", "left", "right"] + times = get_foam_times(case_dir, string=True)[1:] + + for time in times: + for boundary in boundaries: + temp = ff.readof.readscalar(case_dir, time, "T", boundary=boundary) + + scale = 1.0 if boundary in ("left", "right", "top") else 2.0 + temp_ref = 0.05 + scale * np.float64(time) + + temp_diff_max = np.argmax(abs(temp - temp_ref)) + assert np.allclose(temp_ref, temp, rtol=1e-7, atol=1e-12), ( + f"Max diff {boundary} ({time}): {abs(temp - temp_ref).max()} " + f"{temp[temp_diff_max]} {temp_ref[temp_diff_max]}" + ) diff --git a/test/tests/bcs/fixed_value_pp/tests b/test/tests/bcs/fixed_value_pp/tests new file mode 100644 index 00000000..002cd453 --- /dev/null +++ b/test/tests/bcs/fixed_value_pp/tests @@ -0,0 +1,19 @@ +[Tests] + [foam_bc_action_test] + [setup] + type = RunCommand + command = 'bash -c "foamCleanCase -case foam && blockMesh -case foam"' + [] + [run] + type = RunApp + input = main.i + prereq = foam_bc_action_test/setup + allow_warnings = true + [] + [verify] + type = PythonUnitTest + input = test.py + prereq = foam_bc_action_test/run + [] + [] +[] diff --git a/test/tests/bcs/laplace_fixed_gradient/tests b/test/tests/bcs/laplace_fixed_gradient/tests index ab7bf175..5166c3b1 100644 --- a/test/tests/bcs/laplace_fixed_gradient/tests +++ b/test/tests/bcs/laplace_fixed_gradient/tests @@ -23,5 +23,17 @@ input = test.py prereq = foam_bc_fixed_gradient/run [] + [run_no_kappa] + type = RunApp + input = main.i + cli_args = "FoamBCs/T_flux/diffusivity_coefficient='' AuxKernels/T_flux/expression='t'" + prereq = foam_bc_fixed_gradient/verify + allow_warnings = true + [] + [verify_no_kappa] + type = PythonUnitTest + input = test.py + prereq = foam_bc_fixed_gradient/run_no_kappa + [] [] [] diff --git a/test/tests/bcs/mass_flow_rate/foam/0/T b/test/tests/bcs/mass_flow_rate/foam/0/T new file mode 100644 index 00000000..f8312bb2 --- /dev/null +++ b/test/tests/bcs/mass_flow_rate/foam/0/T @@ -0,0 +1,56 @@ +/*--------------------------------*- C++ -*----------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | Website: https://openfoam.org + \\ / A nd | Version: 10 + \\/ M anipulation | +\*---------------------------------------------------------------------------*/ +FoamFile +{ + format ascii; + class volScalarField; + location "0"; + object T; +} +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +dimensions [0 0 0 1 0 0 0]; + +internalField uniform 0.1; + +boundaryField +{ + left + { + type calculated; + value uniform 0.; + } + right + { + type calculated; + value uniform 0.; + } + top + { + type calculated; + value uniform 0.; + } + bottom + { + type calculated; + value uniform 0.; + } + back + { + type calculated; + value uniform 0.; + } + front + { + type calculated; + value uniform 0.; + } +} + + +// ************************************************************************* // diff --git a/test/tests/bcs/mass_flow_rate/foam/0/U b/test/tests/bcs/mass_flow_rate/foam/0/U new file mode 100644 index 00000000..d23654bb --- /dev/null +++ b/test/tests/bcs/mass_flow_rate/foam/0/U @@ -0,0 +1,31 @@ +/*--------------------------------*- C++ -*----------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | Website: https://openfoam.org + \\ / A nd | Version: 12 + \\/ M anipulation | +\*---------------------------------------------------------------------------*/ +FoamFile +{ + format ascii; + class volVectorField; + location "0"; + object U; +} +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +dimensions [ 0 1 -1 0 0 0 0 ]; + +internalField uniform (2 -1 0); + +boundaryField +{ + + ".*" + { + type fixedValue; + value $internalField; + } +} + +// ************************************************************************* // diff --git a/test/tests/bcs/mass_flow_rate/foam/0/p b/test/tests/bcs/mass_flow_rate/foam/0/p new file mode 100644 index 00000000..0d00fc2f --- /dev/null +++ b/test/tests/bcs/mass_flow_rate/foam/0/p @@ -0,0 +1,30 @@ +/*--------------------------------*- C++ -*----------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | Website: https://openfoam.org + \\ / A nd | Version: 12 + \\/ M anipulation | +\*---------------------------------------------------------------------------*/ +FoamFile +{ + format ascii; + class volScalarField; + location "0"; + object p; +} +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +dimensions [ 1 -1 -2 0 0 0 0 ]; + +internalField uniform 0; + +boundaryField +{ + ".*" + { + type calculated; + value $internalField; + } +} + +// ************************************************************************* // diff --git a/test/tests/bcs/mass_flow_rate/foam/0/p_rgh b/test/tests/bcs/mass_flow_rate/foam/0/p_rgh new file mode 100644 index 00000000..cfc89a8c --- /dev/null +++ b/test/tests/bcs/mass_flow_rate/foam/0/p_rgh @@ -0,0 +1,30 @@ +/*--------------------------------*- C++ -*----------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | Website: https://openfoam.org + \\ / A nd | Version: 12 + \\/ M anipulation | +\*---------------------------------------------------------------------------*/ +FoamFile +{ + format ascii; + class volScalarField; + location "0"; + object p_rgh; +} +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +dimensions [ 1 -1 -2 0 0 0 0 ]; + +internalField uniform 0; + +boundaryField +{ + ".*" + { + type fixedValue; + value $internalField; + } +} + +// ************************************************************************* // diff --git a/test/tests/bcs/mass_flow_rate/foam/0/rho b/test/tests/bcs/mass_flow_rate/foam/0/rho new file mode 100644 index 00000000..d30a04dc --- /dev/null +++ b/test/tests/bcs/mass_flow_rate/foam/0/rho @@ -0,0 +1,56 @@ +/*--------------------------------*- C++ -*----------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | Website: https://openfoam.org + \\ / A nd | Version: 12 + \\/ M anipulation | +\*---------------------------------------------------------------------------*/ +FoamFile +{ + format ascii; + class volScalarField; + location "0"; + object rho; +} +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +dimensions [1 -3 0 0 0 0 0]; + +internalField uniform 1; + +boundaryField +{ + left + { + type calculated; + value uniform 1; + } + right + { + type calculated; + value uniform 1; + } + top + { + type calculated; + value uniform 1; + } + front + { + type calculated; + value uniform 1; + } + bottom + { + type calculated; + value uniform 1; + } + back + { + type calculated; + value uniform 1; + } +} + + +// ************************************************************************* // diff --git a/test/tests/bcs/mass_flow_rate/foam/constant/g b/test/tests/bcs/mass_flow_rate/foam/constant/g new file mode 100644 index 00000000..8af96f3a --- /dev/null +++ b/test/tests/bcs/mass_flow_rate/foam/constant/g @@ -0,0 +1,21 @@ +/*--------------------------------*- C++ -*----------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | Website: https://openfoam.org + \\ / A nd | Version: 10 + \\/ M anipulation | +\*---------------------------------------------------------------------------*/ +FoamFile +{ + format ascii; + class uniformDimensionedVectorField; + location "constant"; + object g; +} +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +dimensions [0 1 -2 0 0 0 0]; +value (0 0 0); + + +// ************************************************************************* // diff --git a/test/tests/bcs/mass_flow_rate/foam/constant/momentumTransport b/test/tests/bcs/mass_flow_rate/foam/constant/momentumTransport new file mode 100644 index 00000000..0416f1a9 --- /dev/null +++ b/test/tests/bcs/mass_flow_rate/foam/constant/momentumTransport @@ -0,0 +1,18 @@ +/*--------------------------------*- C++ -*----------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | Website: https://openfoam.org + \\ / A nd | Version: 10 + \\/ M anipulation | +\*---------------------------------------------------------------------------*/ +FoamFile +{ + format ascii; + class dictionary; + object RASProperties; +} +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +simulationType laminar; + +// ************************************************************************* // diff --git a/test/tests/bcs/mass_flow_rate/foam/constant/physicalProperties b/test/tests/bcs/mass_flow_rate/foam/constant/physicalProperties new file mode 100644 index 00000000..8a4c6a29 --- /dev/null +++ b/test/tests/bcs/mass_flow_rate/foam/constant/physicalProperties @@ -0,0 +1,52 @@ +/*--------------------------------*- C++ -*----------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | Website: https://openfoam.org + \\ / A nd | Version: 10 + \\/ M anipulation | +\*---------------------------------------------------------------------------*/ +FoamFile +{ + format ascii; + class dictionary; + location "constant"; + object physicalProperties; +} +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +thermoType +{ + type heRhoThermo; + mixture pureMixture; + transport const; + thermo hConst; + equationOfState rhoConst; + specie specie; + energy sensibleEnthalpy; +} + +mixture +{ + specie + { + molWeight 1; + } + thermodynamics + { + Cp 1; // Specific heat capacity [J/(kg·K)] + Hf 1; // Heat of formation [J/kg] + Tref 0; + } + transport + { + kappa 1; // Thermal conductivity [W/(m·K)] + mu 1.; + } + equationOfState + { + rho 0.5; // Density [kg/m^3] + } +} + + +// ************************************************************************* // diff --git a/test/tests/bcs/mass_flow_rate/foam/system/blockMeshDict b/test/tests/bcs/mass_flow_rate/foam/system/blockMeshDict new file mode 100644 index 00000000..1adab343 --- /dev/null +++ b/test/tests/bcs/mass_flow_rate/foam/system/blockMeshDict @@ -0,0 +1,85 @@ +FoamFile +{ + version 2.0; + format ascii; + class dictionary; + object blockMeshDict; +} + +vertices +( + ( 0.0 0.0 0.0 ) + ( 10.0 0.0 0.0 ) + ( 10.0 1.0 0.0 ) + ( 0.0 1.0 0.0 ) + + ( 0.0 0.0 1.0) + ( 10.0 0.0 1.0) + ( 10.0 1.0 1.0) + ( 0.0 1.0 1.0) +); + +blocks +( + hex (0 1 2 3 4 5 6 7) (50 2 2) simpleGrading (25 1 1) +); + +boundary +( + + // interface + left + { + type wall; + faces + ( + (4 7 3 0) + ); + } + + right + { + type wall; + faces + ( + (6 5 1 2) + ); + } + + top + { + type wall; + faces + ( + (2 3 7 6) + ); + } + + front + { + type wall; + faces + ( + (3 2 1 0) + ); + } + + bottom + { + type wall; + faces + ( + (0 1 5 4) + ); + } + + back + { + type wall; + faces + ( + (4 5 6 7) + ); + } + +); diff --git a/test/tests/bcs/mass_flow_rate/foam/system/controlDict b/test/tests/bcs/mass_flow_rate/foam/system/controlDict new file mode 100644 index 00000000..4e2baf59 --- /dev/null +++ b/test/tests/bcs/mass_flow_rate/foam/system/controlDict @@ -0,0 +1,44 @@ +/*--------------------------------*- C++ -*----------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | Website: https://openfoam.org + \\ / A nd | Version: 10 + \\/ M anipulation | +\*---------------------------------------------------------------------------*/ +FoamFile +{ + format ascii; + class dictionary; + object controlDict; +} +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +solver postprocessorTestSolver; + +startFrom startTime; + +startTime 0; + +stopAt endTime; + +endTime 0.32; + +deltaT 0.01; + +writeControl timeStep; + +writeInterval 1; + +writeFormat ascii; + +writePrecision 20; + +writeCompression off; + +timeFormat general; + +timePrecision 20; + +runTimeModifiable true; + +// ************************************************************************* // diff --git a/test/tests/bcs/mass_flow_rate/foam/system/decomposeParDict b/test/tests/bcs/mass_flow_rate/foam/system/decomposeParDict new file mode 100644 index 00000000..0204a6b9 --- /dev/null +++ b/test/tests/bcs/mass_flow_rate/foam/system/decomposeParDict @@ -0,0 +1,42 @@ +/*--------------------------------*- C++ -*----------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | Website: https://openfoam.org + \\ / A nd | Version: 10 + \\/ M anipulation | +\*---------------------------------------------------------------------------*/ +FoamFile +{ + format ascii; + class dictionary; + location "system"; + object decomposeParDict; +} +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +numberOfSubdomains 2; + +method simple; + +simpleCoeffs +{ + n (2 1 1); +} + +hierarchicalCoeffs +{ + n (1 1 1); + order xyz; +} + +manualCoeffs +{ + dataFile ""; +} + +distributed no; + +roots ( ); + + +// ************************************************************************* // diff --git a/test/tests/bcs/mass_flow_rate/foam/system/fvSchemes b/test/tests/bcs/mass_flow_rate/foam/system/fvSchemes new file mode 100644 index 00000000..787f3b83 --- /dev/null +++ b/test/tests/bcs/mass_flow_rate/foam/system/fvSchemes @@ -0,0 +1,51 @@ +/*--------------------------------*- C++ -*----------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | Website: https://openfoam.org + \\ / A nd | Version: 12 + \\/ M anipulation | +\*---------------------------------------------------------------------------*/ +FoamFile +{ + format ascii; + class dictionary; + object fvSchemes; +} +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +ddtSchemes +{ + default Euler; +} + +gradSchemes +{ + default Gauss linear; +} + +divSchemes +{ + default none; + + div(phi,U) Gauss linear; + div(phi,K) Gauss linear; + div(phi,h) Gauss linear; + div(((rho*nuEff)*dev2(T(grad(U))))) Gauss linear; +} + +laplacianSchemes +{ + default Gauss linear corrected; +} + +interpolationSchemes +{ + default linear; +} + +snGradSchemes +{ + default corrected; +} + +// ************************************************************************* // diff --git a/test/tests/bcs/mass_flow_rate/foam/system/fvSolution b/test/tests/bcs/mass_flow_rate/foam/system/fvSolution new file mode 100644 index 00000000..61143b21 --- /dev/null +++ b/test/tests/bcs/mass_flow_rate/foam/system/fvSolution @@ -0,0 +1,61 @@ +/*--------------------------------*- C++ -*----------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | Website: https://openfoam.org + \\ / A nd | Version: 12 + \\/ M anipulation | +\*---------------------------------------------------------------------------*/ +FoamFile +{ + format ascii; + class dictionary; + object fvSolution; +} +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +solvers +{ + rho + { + solver diagonal; + } + + rhoFinal + { + $rho; + } + + + "(U|h|p_rgh)" + { + solver PBiCGStab; + preconditioner DILU; + tolerance 1e-8; + relTol 1e-8; + } + + "(U|h|p_rgh)Final" + { + $U; + tolerance 1e-8; + relTol 1e-8; + } +} + +PIMPLE +{ + momentumPredictor yes; + pRefCell 0; + pRefValue 0; +} + +relaxationFactors +{ + equations + { + h 1; + U 1; + } +} + +// ************************************************************************* // diff --git a/test/tests/bcs/mass_flow_rate/gold/main_out.csv b/test/tests/bcs/mass_flow_rate/gold/main_out.csv new file mode 100644 index 00000000..bb1c32b8 --- /dev/null +++ b/test/tests/bcs/mass_flow_rate/gold/main_out.csv @@ -0,0 +1,34 @@ +time,m_dot,pp +0,0,0 +0.01,-0.01,0.01 +0.02,-0.02,0.02 +0.03,-0.03,0.03 +0.04,-0.04,0.04 +0.05,-0.05,0.05 +0.06,-0.06,0.06 +0.07,-0.07,0.07 +0.08,-0.08,0.08 +0.09,-0.09,0.09 +0.1,-0.1,0.1 +0.11,-0.11,0.11 +0.12,-0.12,0.12 +0.13,-0.13,0.13 +0.14,-0.14,0.14 +0.15,-0.15,0.15 +0.16,-0.16,0.16 +0.17,-0.17,0.17 +0.18,-0.18,0.18 +0.19,-0.19,0.19 +0.2,-0.2,0.2 +0.21,-0.21,0.21 +0.22,-0.22,0.22 +0.23,-0.23,0.23 +0.24,-0.24,0.24 +0.25,-0.25,0.25 +0.26,-0.26,0.26 +0.27,-0.27,0.27 +0.28,-0.28,0.28 +0.29,-0.29,0.29 +0.3,-0.3,0.3 +0.31,-0.31,0.31 +0.32,-0.32,0.32 diff --git a/test/tests/bcs/mass_flow_rate/main.i b/test/tests/bcs/mass_flow_rate/main.i new file mode 100644 index 00000000..43fc5346 --- /dev/null +++ b/test/tests/bcs/mass_flow_rate/main.i @@ -0,0 +1,48 @@ +[Mesh] + type = FoamMesh + case = 'foam' + foam_patch = 'left right bottom top back front' +[] + +[FoamBCs] + [temp1] + type=FoamMassFlowRateInletBC + boundary = 'left' # test boundary restrictions + pp = pp + [] +[] + +[Postprocessors] + [pp] + type = ParsedPostprocessor + expression = 't' + use_t = true + execute_on = TIMESTEP_BEGIN + [] + [m_dot] + type = FoamSideAdvectiveFluxIntegral + boundary = left + foam_scalar = rho + [] +[] + + +[Problem] + type = FoamProblem + # Take the boundary temperature from OpenFOAM and set it on the MOOSE mesh. +[] + +[Executioner] + type = Transient + end_time = 0.32 + [TimeSteppers] + [foam] + type = FoamControlledTimeStepper + [] + [] +[] + +[Outputs] + exodus = true + csv=true +[] diff --git a/test/tests/bcs/mass_flow_rate/tests b/test/tests/bcs/mass_flow_rate/tests new file mode 100644 index 00000000..68cf4430 --- /dev/null +++ b/test/tests/bcs/mass_flow_rate/tests @@ -0,0 +1,15 @@ +[Tests] + [mass_flow_rate] + [setup] + type = RunCommand + command = 'bash -c "foamCleanCase -case foam && blockMesh -case foam"' + [] + [run] + type = CSVDiff + input = main.i + prereq = mass_flow_rate/setup + csvdiff = main_out.csv + allow_warnings = true + [] + [] +[] diff --git a/test/tests/bcs/receiver_pp/foam/0/T b/test/tests/bcs/receiver_pp/foam/0/T new file mode 100644 index 00000000..6da637de --- /dev/null +++ b/test/tests/bcs/receiver_pp/foam/0/T @@ -0,0 +1,52 @@ +/*--------------------------------*- C++ -*----------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | Website: https://openfoam.org + \\ / A nd | Version: 10 + \\/ M anipulation | +\*---------------------------------------------------------------------------*/ +FoamFile +{ + format ascii; + class volScalarField; + location "0"; + object T; +} +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +dimensions [0 0 0 1 0 0 0]; + +internalField uniform 0.; + +boundaryField +{ + left + { + type fixedValue; + value uniform 0.; + } + right + { + type fixedGradient; + gradient uniform 1.; + } + top + { + type zeroGradient; + } + front + { + type zeroGradient; + } + bottom + { + type zeroGradient; + } + back + { + type zeroGradient; + } +} + + +// ************************************************************************* // diff --git a/test/tests/bcs/receiver_pp/foam/constant/physicalProperties b/test/tests/bcs/receiver_pp/foam/constant/physicalProperties new file mode 100644 index 00000000..6dab7b1c --- /dev/null +++ b/test/tests/bcs/receiver_pp/foam/constant/physicalProperties @@ -0,0 +1,51 @@ +/*--------------------------------*- C++ -*----------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | Website: https://openfoam.org + \\ / A nd | Version: 10 + \\/ M anipulation | +\*---------------------------------------------------------------------------*/ +FoamFile +{ + format ascii; + class dictionary; + location "constant"; + object physicalProperties; +} +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +thermoType +{ + type heSolidThermo; + mixture pureMixture; + transport constIsoSolid; + thermo eConst; + equationOfState rhoConst; + specie specie; + energy sensibleInternalEnergy; +} + +mixture +{ + specie + { + molWeight 1; + } + thermodynamics + { + Cv 1; // Specific heat capacity [J/(kg·K)] + Hf 1; // Heat of formation [J/kg] + Tref 0; + } + transport + { + kappa 2.; // Thermal conductivity [W/(m·K)] + } + equationOfState + { + rho 1; // Density [kg/m^3] + } +} + + +// ************************************************************************* // diff --git a/test/tests/bcs/receiver_pp/foam/system/blockMeshDict b/test/tests/bcs/receiver_pp/foam/system/blockMeshDict new file mode 100644 index 00000000..face9ea6 --- /dev/null +++ b/test/tests/bcs/receiver_pp/foam/system/blockMeshDict @@ -0,0 +1,85 @@ +FoamFile +{ + version 2.0; + format ascii; + class dictionary; + object blockMeshDict; +} + +vertices +( + ( 0.0 0.0 0.0 ) + ( 10.0 0.0 0.0 ) + ( 10.0 1.0 0.0 ) + ( 0.0 1.0 0.0 ) + + ( 0.0 0.0 1.0) + ( 10.0 0.0 1.0) + ( 10.0 1.0 1.0) + ( 0.0 1.0 1.0) +); + +blocks +( + hex (0 1 2 3 4 5 6 7) (50 1 1) simpleGrading (25 1 1) +); + +boundary +( + + // interface + left + { + type wall; + faces + ( + (4 7 3 0) + ); + } + + right + { + type wall; + faces + ( + (6 5 1 2) + ); + } + + top + { + type wall; + faces + ( + (2 3 7 6) + ); + } + + front + { + type wall; + faces + ( + (3 2 1 0) + ); + } + + bottom + { + type wall; + faces + ( + (0 1 5 4) + ); + } + + back + { + type wall; + faces + ( + (4 5 6 7) + ); + } + +); diff --git a/test/tests/bcs/receiver_pp/foam/system/controlDict b/test/tests/bcs/receiver_pp/foam/system/controlDict new file mode 100644 index 00000000..89301ab0 --- /dev/null +++ b/test/tests/bcs/receiver_pp/foam/system/controlDict @@ -0,0 +1,44 @@ +/*--------------------------------*- C++ -*----------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | Website: https://openfoam.org + \\ / A nd | Version: 10 + \\/ M anipulation | +\*---------------------------------------------------------------------------*/ +FoamFile +{ + format ascii; + class dictionary; + object controlDict; +} +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +solver bcTestSolver; + +startFrom startTime; + +startTime 0; + +stopAt endTime; + +endTime 32.; + +deltaT 1.; + +writeControl timeStep; + +writeInterval 1; + +writeFormat ascii; + +writePrecision 20; + +writeCompression off; + +timeFormat general; + +timePrecision 20; + +runTimeModifiable true; + +// ************************************************************************* // diff --git a/test/tests/bcs/receiver_pp/foam/system/fvSchemes b/test/tests/bcs/receiver_pp/foam/system/fvSchemes new file mode 100644 index 00000000..a24aaf80 --- /dev/null +++ b/test/tests/bcs/receiver_pp/foam/system/fvSchemes @@ -0,0 +1,46 @@ +/*--------------------------------*- C++ -*----------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | Website: https://openfoam.org + \\ / A nd | Version: 12 + \\/ M anipulation | +\*---------------------------------------------------------------------------*/ +FoamFile +{ + format ascii; + class dictionary; + object fvSchemes; +} +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +ddtSchemes +{ + default Euler; +} + +gradSchemes +{ + default Gauss linear; +} + +divSchemes +{ + default Gauss linear; +} + +laplacianSchemes +{ + default Gauss linear corrected; +} + +interpolationSchemes +{ + default linear; +} + +snGradSchemes +{ + default corrected; +} + +// ************************************************************************* // diff --git a/test/tests/bcs/receiver_pp/foam/system/fvSolution b/test/tests/bcs/receiver_pp/foam/system/fvSolution new file mode 100644 index 00000000..639b272d --- /dev/null +++ b/test/tests/bcs/receiver_pp/foam/system/fvSolution @@ -0,0 +1,49 @@ +/*--------------------------------*- C++ -*----------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | Website: https://openfoam.org + \\ / A nd | Version: 12 + \\/ M anipulation | +\*---------------------------------------------------------------------------*/ +FoamFile +{ + format ascii; + class dictionary; + object fvSolution; +} +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +solvers +{ + rho + { + solver diagonal; + } + + rhoFinal + { + $rho; + } + + + e + { + solver PBiCGStab; + preconditioner DIC; + tolerance 1e-15; + relTol 1e-15; + } + + eFinal + { + $e; + tolerance 1e-15; + relTol 1e-15; + } +} + +PIMPLE +{ +} + +// ************************************************************************* // diff --git a/test/tests/bcs/receiver_pp/main.i b/test/tests/bcs/receiver_pp/main.i new file mode 100644 index 00000000..cd1da1a7 --- /dev/null +++ b/test/tests/bcs/receiver_pp/main.i @@ -0,0 +1,48 @@ +[Mesh] + type = FoamMesh + case = 'foam' + foam_patch = 'left right' +[] + +[Variables] + [dummy] + family = MONOMIAL + order = CONSTANT + initial_condition = 999 + [] +[] + +[FoamBCs] + [T_value] + type=FoamFixedValuePostprocessorBC + foam_variable = T + default = 0. + boundary = 'left' + [] + [T_flux] + type=FoamFixedGradientPostprocessorBC + foam_variable = T + boundary = 'right' + diffusivity_coefficient = kappa + default=2 + [] +[] + + +[Problem] + type = FoamProblem +[] + +[Executioner] + type = Transient + end_time = 1 + [TimeSteppers] + [foam] + type = FoamControlledTimeStepper + [] + [] +[] + +[Outputs] + exodus = true +[] diff --git a/test/tests/bcs/receiver_pp/test.py b/test/tests/bcs/receiver_pp/test.py new file mode 100644 index 00000000..98b48ce7 --- /dev/null +++ b/test/tests/bcs/receiver_pp/test.py @@ -0,0 +1,29 @@ +"""Tests for imposing BCs in OpenFOAM using MOOSE input file syntax""" + +import unittest +import fluidfoam as ff +import numpy as np + +from read_hippo_data import get_foam_times # pylint: disable=E0401 + + +class TestFoamBCFixedGradient(unittest.TestCase): + """Test class for imposing fixed value BCs in Hippo.""" + + def test_fixed_gradient_x(self): + """Test case for imposing fixed value.""" + case_dir = "foam/" + times = get_foam_times(case_dir, string=True)[1:] + + for time in times: + coords = dict(zip(("x", "y", "z"), ff.readof.readmesh(case_dir))) + + temp = ff.readof.readscalar(case_dir, time, "T") + + temp_ref = coords["x"] * np.float64(time) + + temp_diff_max = np.argmax(abs(temp - temp_ref)) + assert np.allclose(temp_ref, temp, rtol=1e-7, atol=1e-12), ( + f"Max diff ({time}): {abs(temp - temp_ref).max()} " + f"{temp[temp_diff_max]} {temp_ref[temp_diff_max]}" + ) diff --git a/test/tests/bcs/receiver_pp/tests b/test/tests/bcs/receiver_pp/tests new file mode 100644 index 00000000..01645088 --- /dev/null +++ b/test/tests/bcs/receiver_pp/tests @@ -0,0 +1,39 @@ +[Tests] + [receiver_pp] + [setup] + type = RunCommand + command = 'bash -c "foamCleanCase -case foam && blockMesh -case foam"' + [] + [diffusivity_coeff_err] + type = RunException + input = main.i + prereq = receiver_pp/setup + expect_err = "Diffusivity coefficient 'kappa1' not a Foam volScalarField" + cli_args = 'FoamBCs/T_flux/diffusivity_coefficient=kappa1' + allow_warnings = true + [] + [run] + type = RunApp + input = main.i + prereq = receiver_pp/setup + allow_warnings = true + [] + [verify] + type = PythonUnitTest + input = test.py + prereq = receiver_pp/run + [] + [run_no_kappa] + type = RunApp + input = main.i + cli_args = "FoamBCs/T_flux/diffusivity_coefficient='' FoamBCs/T_flux/default=1" + prereq = receiver_pp/verify + allow_warnings = true + [] + [verify_no_kappa] + type = PythonUnitTest + input = test.py + prereq = receiver_pp/run_no_kappa + [] + [] +[]