19 #include "libmesh/periodic_boundary.h" 33 params.
addParam<std::vector<VariableName>>(
"variable",
34 "Variable(s) to apply periodic boundary conditions " 35 "to; if unset, apply to all field variables.");
60 rm_params.
set<std::string>(
"for_whom") =
"PeriodicBCs";
62 mooseError(
"We should have added periodic boundaries and consequently we should have set the " 71 if (rm_params.areAllRequiredParamsValid())
74 "ElementSideNeighborLayers",
"periodic_bc_ghosting_" +
name(), rm_params);
80 mooseError(
"Invalid initialization of ElementSideNeighborLayers");
89 mooseAssert(
_vars.size(),
"Shouldn't run without variables");
97 std::ostringstream
out;
98 out <<
"Periodicity information for the variables\n";
99 for (
const auto & var_ptr :
_vars)
100 out <<
" - " << var_ptr->name() <<
"\n";
101 out <<
"will only be stored in the system's DoF map, not on the MooseMesh";
111 for (
const auto & var_ptr :
_vars)
113 const auto sys_num = var_ptr->sys().number();
114 for (
const auto component :
make_range(var_ptr->count()))
116 const auto var_num = var_ptr->number() + component;
122 if (is_regular_orthogonal)
126 const auto add_to_dof_map = [&p, &sys_num](
auto & problem)
127 { problem.es().get_system(sys_num).get_dof_map().add_periodic_boundary(p); };
135 std::vector<const MooseVariableFieldBase *>
138 std::vector<VariableName> var_names;
142 var_names = getParam<std::vector<VariableName>>(
"variable");
143 if (var_names.empty())
144 paramError(
"variable",
"No variables are set to apply periodic boundaries to");
145 for (
const auto & var_name : var_names)
147 if (
_problem->hasScalarVariable(var_name))
149 "Variable '" + var_name +
150 "' is a scalar variable and does not support a periodic boundary condition");
151 if (!
_problem->hasVariable(var_name))
152 paramError(
"variable",
"Variable '" + var_name +
"' not found");
153 if (
_problem->getVariable(0, var_name).isFV())
155 "Variable '" + var_name +
156 "' is a finite volume variable and does not support a periodic boundary " 165 if (
_problem->numSolverSystems() > 1)
166 mooseError(
"Parameter 'variable' must be specified when multiple solver systems exist");
167 const auto & nl =
_problem->getNonlinearSystemBase(0);
168 var_names = nl.getVariableNames();
169 var_names.erase(std::remove_if(var_names.begin(),
171 [&nl](
const auto & var_name)
173 return nl.hasScalarVariable(var_name) ||
174 nl.getVariable(0, var_name).isFV();
177 if (var_names.empty())
178 mooseError(
"There are no variables to apply periodic boundaries to");
182 std::vector<const MooseVariableFieldBase *>
vars;
183 vars.reserve(var_names.size());
184 std::optional<unsigned int> used_sys_num;
185 for (
const auto & var_name : var_names)
187 const auto & var =
_problem->getVariable(0, var_name);
188 const auto sys_num = var.sys().number();
192 if (used_sys_num && *used_sys_num != sys_num)
194 "Variables were specified across multiple systems; this is not supported. Use a " 195 "separate [Periodic/BCs] block for each system.");
196 used_sys_num = sys_num;
198 vars.push_back(&var);
void setupPeriodicBoundaries(FEProblemBase &problem)
Sets up the periodic boundaries.
unsigned int size(THREAD_ID tid=0) const
Return how many kernels we store in the current warehouse.
This Action adds a periodic boundary to the problem.
std::shared_ptr< DisplacedProblem > displaced_problem
RelationshipManagerType
Main types of Relationship Managers.
registerMooseAction("MooseApp", AddPeriodicBCAction, "add_periodic_bc")
void paramError(const std::string ¶m, Args... args) const
Emits an error prefixed with the file and line number of the given param (from the input file) along ...
Factory & _factory
The Factory associated with the MooseApp.
std::shared_ptr< MooseObject > create(const std::string &obj_name, const std::string &name, const InputParameters ¶meters, THREAD_ID tid=0, bool print_deprecated=true)
boundary_id_type pairedboundary
InputParameters getValidParams(const std::string &name) const
Get valid parameters for the object.
void addPeriodicVariable(const unsigned int sys_num, const unsigned int var_num, const BoundaryID primary, const BoundaryID secondary)
For "regular orthogonal" meshes, determine if variable var_num is periodic with respect to the primar...
void mooseInfoRepeated(Args &&... args)
Emit an informational message with the given stringified, concatenated args.
std::vector< const MooseVariableFieldBase * > getVariables() const
Helper for getting the variables to which periodic boundary conditions will be applied.
const libMesh::PeriodicBoundaries & getPeriodicBoundaries() const
Get the PeriodicBoundaries map produced in setupPeriodicBoundaries().
virtual void act() override
Method to add objects to the simulation or perform other setup tasks.
std::vector< const MooseVariableFieldBase * > _vars
The variables to apply periodic boundary conditions to.
void set_variable(unsigned int var)
boundary_id_type myboundary
const std::string & name() const
Get the name of the class.
bool addRelationshipManager(std::shared_ptr< RelationshipManager > relationship_manager)
Transfers ownership of a RelationshipManager to the application for lifetime management.
static InputParameters validParams()
void checkPeriodicParams() const
Checks the validity of the periodic boundary condition parameters.
AddPeriodicBCAction(const InputParameters ¶ms)
MooseMesh wraps a libMesh::Mesh object and enhances its capabilities by caching additional data and s...
const std::string & _current_task
The current action (even though we have separate instances for each action)
MooseApp & _app
The MOOSE application this is associated with.
bool isRegularOrthogonal()
Getter to query if the mesh was detected to be regular and orthogonal.
static InputParameters validParams()
void releaseSharedObjects(const MooseObject &moose_object, THREAD_ID tid=0)
Releases any shared resources created as a side effect of creating an object through the Factory::cre...
std::shared_ptr< MooseMesh > & _mesh
RelationshipManagers are used for describing what kinds of non-local resources are needed for an obje...
IntRange< T > make_range(T beg, T end)
void mooseError(Args &&... args) const
Emits an error prefixed with object name and type and optionally a file path to the top-level block p...
static InputParameters validParams()
std::shared_ptr< FEProblemBase > & _problem
Convenience reference to a problem this action works on.
bool isParamValid(const std::string &name) const
Test if the supplied parameter is valid.
MOOSE now contains C++17 code, so give a reasonable error message stating what the user can do to add...
virtual void onSetupPeriodicBoundary(libMesh::PeriodicBoundaryBase &p) override
Overriden method from PeriodicBCHelper that is called on every periodic boundary, in which we will se...