Skip to content

Commit

Permalink
Merge pull request #27729 from GiudGiud/PR_physics_old_component
Browse files Browse the repository at this point in the history
Add a Physics-using component to current components
  • Loading branch information
GiudGiud authored Jun 19, 2024
2 parents 86fdc6f + a333d03 commit 67db2d8
Show file tree
Hide file tree
Showing 30 changed files with 369 additions and 53 deletions.
2 changes: 1 addition & 1 deletion framework/include/executioners/SolveObject.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class SolveObject : public MooseObject, public PerfGraphInterface, public Postpr
/// Reference to FEProblem
FEProblemBase & _problem;
/// Displaced problem
std::shared_ptr<DisplacedProblem> _displaced_problem;
DisplacedProblem * _displaced_problem;
/// Mesh
MooseMesh & _mesh;
/// Displaced mesh
Expand Down
3 changes: 3 additions & 0 deletions framework/include/problems/DisplacedProblem.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,9 @@ class DisplacedProblem : public SubProblem
virtual unsigned int linearSysNum(const LinearSystemName & sys_name) const override;
virtual unsigned int solverSysNum(const SolverSystemName & sys_name) const override;

/// Get the time integrators from the problem
void addTimeIntegrator();

/**
* Allocate vectors and save old solutions into them.
*/
Expand Down
4 changes: 3 additions & 1 deletion framework/include/utils/InputParameters.h
Original file line number Diff line number Diff line change
Expand Up @@ -837,11 +837,13 @@ class InputParameters : public Parameters
* (1) A local parameter must exist with the same name as common parameter
* (2) Common parameter must valid
* (3) Local parameter must be invalid OR not have been set from its default
* (except if override_default is set)
* (4) Both cannot be private
*/
void applyParameter(const InputParameters & common,
const std::string & common_name,
bool allow_private = false);
bool allow_private = false,
bool override_default = false);
// END APPLY PARAMETER METHODS

/**
Expand Down
4 changes: 2 additions & 2 deletions framework/src/actions/CreateDisplacedProblemAction.C
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ CreateDisplacedProblemAction::act()
"We should be adding geometric rms so early that we haven't set our MeshBase yet");

_mesh->allowRemoteElementRemoval(false);
// Displaced mesh should not exist yet
mooseAssert(!_displaced_mesh, "Displaced mesh should not exist yet");
}

if (_current_task == "add_algebraic_rm")
Expand Down Expand Up @@ -163,7 +163,7 @@ CreateDisplacedProblemAction::act()
addProxyAlgebraicRelationshipManagers(undisplaced_aux, displaced_aux);
addProxyAlgebraicRelationshipManagers(displaced_aux, undisplaced_aux);

// Add geoemtric ghosting (which only acts through the mesh) through the single auxiliary
// Add geometric ghosting (which only acts through the mesh) through the single auxiliary
// system as opposed to duplicating the effort through potentially multiple nonlinear systems
addProxyGeometricRelationshipManagers(undisplaced_aux, displaced_aux);
addProxyGeometricRelationshipManagers(displaced_aux, undisplaced_aux);
Expand Down
7 changes: 4 additions & 3 deletions framework/src/base/Moose.C
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,10 @@ addActionTypes(Syntax & syntax)
"(create_problem_custom)"
"(create_problem_default)"
"(create_problem_complete)"
"(init_physics)"
"(init_displaced_problem)" // Problem must be init-ed before we start adding functors
"(add_function)" // Functions can depend on scalar variables & PPs, but this dependence can be
// added on initialSetup() rather than construction
"(init_physics)" // Components add their blocks to Physics, and components need functions at initialization
"(setup_postprocessor_data)"
"(setup_time_integrator)"
"(setup_executioner)"
Expand All @@ -316,13 +319,11 @@ addActionTypes(Syntax & syntax)
"(check_integrity_early)"
"(check_integrity_early_physics)"
"(setup_predictor)"
"(init_displaced_problem)"
"(add_aux_variable, add_variable, add_elemental_field_variable,"
" add_external_aux_variables)"
"(add_mortar_variable)"
"(setup_variable_complete)"
"(setup_quadrature)"
"(add_function)"
"(add_periodic_bc)"
"(add_user_object)"
"(add_distribution)"
Expand Down
2 changes: 1 addition & 1 deletion framework/src/executioners/SolveObject.C
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ SolveObject::SolveObject(Executioner & ex)
_executioner(ex),
_problem(*getCheckedPointerParam<FEProblemBase *>(
"_fe_problem_base", "This might happen if you don't have a mesh")),
_displaced_problem(_problem.getDisplacedProblem()),
_displaced_problem(_problem.getDisplacedProblem().get()),
_mesh(_problem.mesh()),
_displaced_mesh(_displaced_problem ? &_displaced_problem->mesh() : nullptr),
_solver_sys(_problem.numNonlinearSystems()
Expand Down
12 changes: 12 additions & 0 deletions framework/src/physics/PhysicsBase.C
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,18 @@ PhysicsBase::addRelationshipManagers(Moose::RelationshipManagerType input_rm_typ
void
PhysicsBase::initializePhysics()
{
// Annoying edge case. We cannot use ANY_BLOCK_ID for kernels and variables since errors got added
// downstream for using it, we cannot leave it empty as that sets all objects to not live on any
// block
if (isParamSetByUser("block") && _blocks.empty())
paramError("block",
"Empty block restriction is not supported. Comment out the Physics if you are "
"trying to disable it.");

// Components should have added their blocks already.
if (_blocks.empty())
_blocks.push_back("ANY_BLOCK_ID");

mooseAssert(_mesh, "We should have a mesh to find the dimension");
if (_blocks.size())
_dim = _mesh->getBlocksMaxDimension(_blocks);
Expand Down
13 changes: 9 additions & 4 deletions framework/src/problems/DisplacedProblem.C
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,6 @@ DisplacedProblem::DisplacedProblem(const InputParameters & parameters)

for (unsigned int i = 0; i < n_threads; ++i)
_assembly[i].emplace_back(std::make_unique<Assembly>(*displaced_nl, i));

displaced_nl->addTimeIntegrator(
_mproblem.getNonlinearSystemBase(nl_sys_num).getSharedTimeIntegrator());
}

_nl_solution.resize(_displaced_solver_systems.size(), nullptr);
Expand All @@ -80,7 +77,6 @@ DisplacedProblem::DisplacedProblem(const InputParameters & parameters)
_mproblem.getAuxiliarySystem(),
"displaced_" + _mproblem.getAuxiliarySystem().name(),
Moose::VAR_AUXILIARY);
_displaced_aux->addTimeIntegrator(_mproblem.getAuxiliarySystem().getSharedTimeIntegrator());

// // Generally speaking, the mesh is prepared for use, and consequently remote elements are deleted
// // well before our Problem(s) are constructed. Historically, in MooseMesh we have a bunch of
Expand Down Expand Up @@ -195,6 +191,15 @@ DisplacedProblem::initAdaptivity()
{
}

void
DisplacedProblem::addTimeIntegrator()
{
for (const auto nl_sys_num : make_range(_mproblem.numNonlinearSystems()))
_displaced_solver_systems[nl_sys_num]->addTimeIntegrator(
_mproblem.getNonlinearSystemBase(nl_sys_num).getSharedTimeIntegrator());
_displaced_aux->addTimeIntegrator(_mproblem.getAuxiliarySystem().getSharedTimeIntegrator());
}

void
DisplacedProblem::saveOldSolutions()
{
Expand Down
4 changes: 4 additions & 0 deletions framework/src/problems/FEProblemBase.C
Original file line number Diff line number Diff line change
Expand Up @@ -6341,6 +6341,10 @@ FEProblemBase::addTimeIntegrator(const std::string & type,
if (!nl->hasVector(tag_udotdot) && uDotDotRequested())
nl->associateVectorToTag(*nl->solutionUDotDot(), tag_udotdot);
}

if (_displaced_problem)
// Time integrator does not exist when displaced problem is created.
_displaced_problem->addTimeIntegrator();
}

void
Expand Down
5 changes: 3 additions & 2 deletions framework/src/utils/InputParameters.C
Original file line number Diff line number Diff line change
Expand Up @@ -1027,7 +1027,8 @@ InputParameters::applyCoupledVar(const InputParameters & common, const std::stri
void
InputParameters::applyParameter(const InputParameters & common,
const std::string & common_name,
bool allow_private)
bool allow_private,
bool override_default)
{
// Disable the display of deprecated message when applying common parameters, this avoids a dump
// of messages
Expand All @@ -1044,7 +1045,7 @@ InputParameters::applyParameter(const InputParameters & common,
// Extract the properties from the common parameter
const bool common_exist = common._values.find(common_name) != common._values.end();
const bool common_priv = allow_private ? false : common.isPrivate(common_name);
const bool common_valid = common.isParamValid(common_name);
const bool common_valid = common.isParamValid(common_name) || override_default;

/* In order to apply a common parameter 4 statements must be satisfied
* (1) A local parameter must exist with the same name as the common parameter
Expand Down
15 changes: 12 additions & 3 deletions framework/src/variables/MooseVariableFE.C
Original file line number Diff line number Diff line change
Expand Up @@ -1144,9 +1144,12 @@ template <typename OutputType>
typename MooseVariableFE<OutputType>::DotType
MooseVariableFE<OutputType>::evaluateDot(const ElemQpArg & elem_qp, const StateArg & state) const
{
mooseAssert(_time_integrator && _time_integrator->dt(),
mooseAssert(_time_integrator,
"A time derivative is being requested but we do not have a time integrator so we'll "
"have no idea how to compute it");
mooseAssert(_time_integrator->dt(),
"A time derivative is being requested but the time integrator wants to perform a 0s "
"time step");
evaluateOnElement(elem_qp, state, /*query_cache=*/true);
const auto qp = elem_qp.qp;
mooseAssert(qp < _current_elem_qp_functor_dot.size(),
Expand All @@ -1158,9 +1161,12 @@ template <typename OutputType>
typename MooseVariableFE<OutputType>::DotType
MooseVariableFE<OutputType>::evaluateDot(const ElemArg & elem_arg, const StateArg & state) const
{
mooseAssert(_time_integrator && _time_integrator->dt(),
mooseAssert(_time_integrator,
"A time derivative is being requested but we do not have a time integrator so we'll "
"have no idea how to compute it");
mooseAssert(_time_integrator->dt(),
"A time derivative is being requested but the time integrator wants to perform a 0s "
"time step");
const QMonomial qrule(elem_arg.elem->dim(), CONSTANT);
// We can use whatever we want for the point argument since it won't be used
const ElemQpArg elem_qp_arg{elem_arg.elem, /*qp=*/0, &qrule, Point(0, 0, 0)};
Expand All @@ -1172,9 +1178,12 @@ template <typename OutputType>
typename MooseVariableFE<OutputType>::GradientType
MooseVariableFE<OutputType>::evaluateGradDot(const ElemArg & elem_arg, const StateArg & state) const
{
mooseAssert(_time_integrator && _time_integrator->dt(),
mooseAssert(_time_integrator,
"A time derivative is being requested but we do not have a time integrator so we'll "
"have no idea how to compute it");
mooseAssert(_time_integrator->dt(),
"A time derivative is being requested but the time integrator wants to perform a 0s "
"time step");
const QMonomial qrule(elem_arg.elem->dim(), CONSTANT);
// We can use whatever we want for the point argument since it won't be used
const ElemQpArg elem_qp_arg{elem_arg.elem, /*qp=*/0, &qrule, Point(0, 0, 0)};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,21 @@ class SaturationDensityFunction : public Function, public FunctionInterface

SaturationDensityFunction(const InputParameters & parameters);

// To retrieve the fluid properties
virtual void initialSetup() override;

using Function::value;
virtual Real value(Real t, const Point & p) const override;

protected:
/// Temperature function
const Function & _T_fn;
/// 2-phase fluid properties object
const TwoPhaseFluidProperties & _fp_2phase;
const TwoPhaseFluidProperties * _fp_2phase;
/// Single-phase liquid properties
const SinglePhaseFluidProperties & _fp_liquid;
const SinglePhaseFluidProperties * _fp_liquid;
/// Single-phase vapor properties
const SinglePhaseFluidProperties & _fp_vapor;
const SinglePhaseFluidProperties * _fp_vapor;
/// Set true to use liquid phase; else vapor phase
const bool _use_liquid;
};
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ class SaturationPressureFunction : public Function, public FunctionInterface

SaturationPressureFunction(const InputParameters & parameters);

// To retrieve the fluid properties
virtual void initialSetup() override;

using Function::value;
virtual Real value(Real t, const Point & p) const override;
virtual RealVectorValue gradient(Real t, const Point & p) const override;
Expand All @@ -32,5 +35,5 @@ class SaturationPressureFunction : public Function, public FunctionInterface
/// Temperature function
const Function & _T_fn;
/// 2-phase fluid properties object
const TwoPhaseFluidProperties & _fp_2phase;
const TwoPhaseFluidProperties * _fp_2phase;
};
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ class SaturationTemperatureFunction : public Function, public FunctionInterface

SaturationTemperatureFunction(const InputParameters & parameters);

// To retrieve the fluid properties
virtual void initialSetup() override;

using Function::value;
virtual Real value(Real t, const Point & p) const override;
virtual RealVectorValue gradient(Real t, const Point & p) const override;
Expand All @@ -32,5 +35,5 @@ class SaturationTemperatureFunction : public Function, public FunctionInterface
/// Pressure function
const Function & _p_fn;
/// 2-phase fluid properties object
const TwoPhaseFluidProperties & _fp_2phase;
const TwoPhaseFluidProperties * _fp_2phase;
};
2 changes: 1 addition & 1 deletion modules/fluid_properties/src/base/FluidPropertiesApp.C
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ associateSyntaxInner(Syntax & syntax, ActionFactory & /*action_factory*/)
registerMooseObjectTask("add_fluid_properties", FluidProperties, false);
registerMooseObjectTask("add_fp_output", Output, false);

syntax.addDependency("add_fluid_properties", "init_displaced_problem");
// Fluid properties depend on variables
syntax.addDependency("add_aux_variable", "add_fluid_properties");
syntax.addDependency("add_variable", "add_fluid_properties");
syntax.addDependency("add_elemental_field_variable", "add_fluid_properties");
Expand Down
17 changes: 11 additions & 6 deletions modules/fluid_properties/src/functions/SaturationDensityFunction.C
Original file line number Diff line number Diff line change
Expand Up @@ -32,21 +32,26 @@ SaturationDensityFunction::SaturationDensityFunction(const InputParameters & par
FunctionInterface(this),

_T_fn(getFunction("T")),
_fp_2phase(getUserObject<TwoPhaseFluidProperties>("fp_2phase")),
_fp_liquid(getUserObjectByName<SinglePhaseFluidProperties>(_fp_2phase.getLiquidName())),
_fp_vapor(getUserObjectByName<SinglePhaseFluidProperties>(_fp_2phase.getVaporName())),
_use_liquid(getParam<bool>("use_liquid"))
{
}

void
SaturationDensityFunction::initialSetup()
{
_fp_2phase = &getUserObject<TwoPhaseFluidProperties>("fp_2phase");
_fp_liquid = &getUserObjectByName<SinglePhaseFluidProperties>(_fp_2phase->getLiquidName());
_fp_vapor = &getUserObjectByName<SinglePhaseFluidProperties>(_fp_2phase->getVaporName());
}

Real
SaturationDensityFunction::value(Real t, const Point & point) const
{
const Real T = _T_fn.value(t, point);
const Real p = _fp_2phase.p_sat(T);
const Real p = _fp_2phase->p_sat(T);

if (_use_liquid)
return _fp_liquid.rho_from_p_T(p, T);
return _fp_liquid->rho_from_p_T(p, T);
else
return _fp_vapor.rho_from_p_T(p, T);
return _fp_vapor->rho_from_p_T(p, T);
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,19 +30,24 @@ SaturationPressureFunction::SaturationPressureFunction(const InputParameters & p
: Function(parameters),
FunctionInterface(this),

_T_fn(getFunction("T")),
_fp_2phase(getUserObject<TwoPhaseFluidProperties>("fp_2phase"))
_T_fn(getFunction("T"))
{
}

void
SaturationPressureFunction::initialSetup()
{
_fp_2phase = &getUserObject<TwoPhaseFluidProperties>("fp_2phase");
}

Real
SaturationPressureFunction::value(Real t, const Point & point) const
{
return _fp_2phase.p_sat(_T_fn.value(t, point));
return _fp_2phase->p_sat(_T_fn.value(t, point));
}

RealVectorValue
SaturationPressureFunction::gradient(Real t, const Point & point) const
{
return _T_fn.gradient(t, point) / _fp_2phase.dT_sat_dp(value(t, point));
return _T_fn.gradient(t, point) / _fp_2phase->dT_sat_dp(value(t, point));
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,19 +30,24 @@ SaturationTemperatureFunction::SaturationTemperatureFunction(const InputParamete
: Function(parameters),
FunctionInterface(this),

_p_fn(getFunction("p")),
_fp_2phase(getUserObject<TwoPhaseFluidProperties>("fp_2phase"))
_p_fn(getFunction("p"))
{
}

void
SaturationTemperatureFunction::initialSetup()
{
_fp_2phase = &getUserObject<TwoPhaseFluidProperties>("fp_2phase");
}

Real
SaturationTemperatureFunction::value(Real t, const Point & point) const
{
return _fp_2phase.T_sat(_p_fn.value(t, point));
return _fp_2phase->T_sat(_p_fn.value(t, point));
}

RealVectorValue
SaturationTemperatureFunction::gradient(Real t, const Point & point) const
{
return _fp_2phase.dT_sat_dp(_p_fn.value(t, point)) * _p_fn.gradient(t, point);
return _fp_2phase->dT_sat_dp(_p_fn.value(t, point)) * _p_fn.gradient(t, point);
}
5 changes: 3 additions & 2 deletions modules/navier_stokes/include/base/NSFVBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -1171,6 +1171,9 @@ template <class BaseType>
void
NSFVBase<BaseType>::addNSVariables()
{
// We use finite volume variables
getProblem().needFV();

// Determine which variables to add
processVariables();

Expand Down Expand Up @@ -3051,8 +3054,6 @@ template <class BaseType>
void
NSFVBase<BaseType>::processMesh()
{
getProblem().needFV();

_blocks = getBlocks();

// If the user doesn't define a block name we go with the default
Expand Down
Loading

0 comments on commit 67db2d8

Please sign in to comment.