23 #include "libmesh/periodic_boundary.h" 35 params.
addParam<std::vector<std::string>>(
"auto_direction",
36 "If using a generated mesh, you can " 37 "specify just the dimension(s) you " 38 "want to mark as periodic");
40 params.
addParam<BoundaryName>(
"primary",
"Boundary ID associated with the primary boundary.");
41 params.
addParam<BoundaryName>(
"secondary",
"Boundary ID associated with the secondary boundary.");
43 "Vector that translates coordinates on the " 44 "primary boundary to coordinates on the " 45 "secondary boundary.");
46 params.
addParam<std::vector<std::string>>(
"transform_func",
47 "Functions that specify the transformation");
48 params.
addParam<std::vector<std::string>>(
"inv_transform_func",
49 "Functions that specify the inverse transformation");
51 params.
addParam<std::vector<VariableName>>(
52 "variable", {},
"Variable for the periodic boundary condition");
58 :
Action(params), _mesh(nullptr)
67 "Using the automatic periodic boundary detection does not require additional parameters");
70 paramError(
"primary",
"Both a primary and secondary boundary must be specified");
75 const std::vector<VariableName> & var_names)
78 if (
_problem->numSolverSystems() > 1)
79 mooseError(
"Multiple solver systems currently not supported");
82 const std::vector<VariableName> * var_names_ptr;
85 if (var_names.empty())
88 var_names_ptr = &var_names;
91 auto applyPeriodicBC = [&](
unsigned int var_num,
const std::string & var_name)
98 "' will only be stored in the system's DoF map, not on the MooseMesh");
102 for (
const auto & var_name : *var_names_ptr)
108 unsigned int var_num = var.
number();
112 for (
const auto component :
make_range(var.count()))
113 applyPeriodicBC(var_num + component, var_name +
"_" + std::to_string(component));
116 applyPeriodicBC(var_num, var_name);
136 if (!is_orthogonal_mesh)
137 mooseError(
"Could not detect orthogonal dimension ranges for DistributedMesh.");
140 std::vector<std::string> auto_dirs = getParam<std::vector<std::string>>(
"auto_direction");
143 for (
const auto & dir : auto_dirs)
146 if (dir ==
"X" || dir ==
"x")
148 else if (dir ==
"Y" || dir ==
"y")
151 mooseError(
"Cannot wrap 'Y' direction when using a 1D mesh");
154 else if (dir ==
"Z" || dir ==
"z")
157 mooseError(
"Cannot wrap 'Z' direction when using a 1D or 2D mesh");
163 const std::pair<BoundaryID, BoundaryID> * boundary_ids =
169 if (boundary_ids ==
nullptr)
170 mooseError(
"Couldn't auto-detect a paired boundary for use with periodic boundary " 171 "conditions in the '" +
172 dir +
"' direction");
178 for (
const auto i :
make_range(eq.n_systems()))
179 eq.get_system(i).get_dof_map().add_periodic_boundary(p);
183 for (
const auto i :
make_range(deq.n_systems()))
184 deq.get_system(i).get_dof_map().add_periodic_boundary(p);
203 auto rm_params =
_factory.getValidParams(
"ElementSideNeighborLayers");
205 rm_params.set<std::string>(
"for_whom") =
"PeriodicBCs";
207 mooseError(
"We should have added periodic boundaries and consequently we should have set the " 216 if (rm_params.areAllRequiredParamsValid())
219 "ElementSideNeighborLayers",
"periodic_bc_ghosting_" +
name(), rm_params);
222 _factory.releaseSharedObjects(*rm_obj);
225 mooseError(
"Invalid initialization of ElementSideNeighborLayers");
230 auto & nl =
_problem->getNonlinearSystemBase(0);
237 const auto & primary_name = getParam<BoundaryName>(
"primary");
238 const auto & secondary_name = getParam<BoundaryName>(
"secondary");
240 paramError(
"primary",
"Boundary '" + primary_name +
"' does not exist in the mesh");
242 paramError(
"secondary",
"Boundary '" + secondary_name +
"' does not exist in the mesh");
246 RealVectorValue translation = getParam<RealVectorValue>(
"translation");
254 for (
const auto i :
make_range(eq.n_systems()))
255 eq.get_system(i).get_dof_map().add_periodic_boundary(p);
259 for (
const auto i :
make_range(deq.n_systems()))
260 deq.get_system(i).get_dof_map().add_periodic_boundary(p);
263 else if (
getParam<std::vector<std::string>>(
"transform_func") != std::vector<std::string>())
265 std::vector<std::string> inv_fn_names =
266 getParam<std::vector<std::string>>(
"inv_transform_func");
267 std::vector<std::string> fn_names = getParam<std::vector<std::string>>(
"transform_func");
271 if (inv_fn_names == std::vector<std::string>())
272 mooseError(
"You must provide an inv_transform_func for FunctionPeriodicBoundary!");
286 for (
const auto i :
make_range(eq.n_systems()))
287 eq.get_system(i).get_dof_map().add_periodic_boundary(pb, ipb);
291 for (
const auto i :
make_range(deq.n_systems()))
292 deq.get_system(i).get_dof_map().add_periodic_boundary(pb, ipb);
298 "You have to specify either 'auto_direction', 'translation' or 'trans_func' in your " 299 "period boundary section '" +
307 nl.dofMap().get_periodic_boundaries());
const InputParameters & _pars
The object's parameters.
This Action adds a periodic boundary to the problem.
std::shared_ptr< DisplacedProblem > displaced_problem
RelationshipManagerType
Main types of Relationship Managers.
const std::string & _name
The name of this class.
registerMooseAction("MooseApp", AddPeriodicBCAction, "add_periodic_bc")
bool hasBoundaryName(const MeshBase &input_mesh, const BoundaryName &name)
Whether a particular boundary name exists in the mesh.
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 ...
const T & getParam(const std::string &name) const
Retrieve a parameter for the object.
unsigned int number() const
Get variable number coming from libMesh.
Factory & _factory
The Factory associated with the MooseApp.
Periodic boundary for calculation periodic BC on domains where the translation is given by functions...
boundary_id_type pairedboundary
void mooseInfoRepeated(Args &&... args)
Emit an informational message with the given stringified, concatenated args.
The following methods are specializations for using the libMesh::Parallel::packed_range_* routines fo...
bool autoTranslationBoundaries()
This function will automatically add the correct translation vectors for each requested dimension whe...
virtual void act() override
Method to add objects to the simulation or perform other setup tasks.
Nonlinear system to be solved.
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()
virtual std::unique_ptr< Base > create()=0
MeshBase & getMesh()
Accessor for the underlying libMesh Mesh object.
AddPeriodicBCAction(const InputParameters ¶ms)
virtual void set_periodic_boundaries(const PeriodicBoundaries *)
virtual unsigned int dimension() const
Returns MeshBase::mesh_dimension(), (not MeshBase::spatial_dimension()!) of the underlying libMesh me...
MooseMesh wraps a libMesh::Mesh object and enhances its capabilities by caching additional data and s...
const std::pair< BoundaryID, BoundaryID > * getPairedBoundaryMapping(unsigned int component)
This function attempts to return the paired boundary ids for the given component. ...
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.
void setPeriodicVars(libMesh::PeriodicBoundaryBase &p, const std::vector< VariableName > &var_names)
bool isRegularOrthogonal()
Getter to query if the mesh was detected to be regular and orthogonal.
void addPeriodicVariable(unsigned int var_num, BoundaryID primary, BoundaryID secondary)
For "regular orthogonal" meshes, determine if variable var_num is periodic with respect to the primar...
std::shared_ptr< MooseMesh > & _mesh
bool detectOrthogonalDimRanges(Real tol=1e-6)
This routine determines whether the Mesh is a regular orthogonal mesh (i.e.
RelationshipManagers are used for describing what kinds of non-local resources are needed for an obje...
Real dimensionWidth(unsigned int component) const
Returns the width of the requested dimension.
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...
const std::vector< VariableName > & getVariableNames() const
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.
MooseVariableFieldBase & getVariable(THREAD_ID tid, const std::string &var_name) const
Gets a reference to a variable of with specified name.
virtual bool hasScalarVariable(const std::string &var_name) const
virtual bool isDistributedMesh() const
Returns the final Mesh distribution type.
GhostingFunctor & default_ghosting()
BoundaryID getBoundaryID(const BoundaryName &boundary_name) const
Get the associated BoundaryID for the boundary name.