https://mooseframework.inl.gov
ElementSubdomainModifierBase.h
Go to the documentation of this file.
1 //* This file is part of the MOOSE framework
2 //* https://mooseframework.inl.gov
3 //*
4 //* All rights reserved, see COPYRIGHT for full restrictions
5 //* https://github.com/idaholab/moose/blob/master/COPYRIGHT
6 //*
7 //* Licensed under LGPL 2.1, please see LICENSE for details
8 //* https://www.gnu.org/licenses/lgpl-2.1.html
9 
10 #pragma once
11 
12 #include "ElementUserObject.h"
13 #include "NonlinearSystemBase.h"
14 #include "AuxiliarySystem.h"
16 #include "KDTree.h"
17 
33 enum class ReinitStrategy
34 {
35  IC,
39 };
40 
45 {
46 public:
48 
50 
51  void initialSetup() override;
52  void meshChanged() override;
53  void timestepSetup() override;
54 
55 protected:
73  virtual void
74  modify(const std::unordered_map<dof_id_type, std::pair<SubdomainID, SubdomainID>> & moved_elems);
75 
78 
81 
84 
86  std::unordered_map<BoundaryID, BoundaryName> _moving_boundary_names;
87 
90 
93 
94 private:
96  void createMovingBoundaries(MooseMesh & mesh);
97 
99  const std::unordered_map<dof_id_type, std::pair<SubdomainID, SubdomainID>> & moved_elems,
100  MooseMesh & mesh);
101 
103  void setAncestorsSubdomainIDs(Elem * elem, const SubdomainID subdomain_id);
104 
106  const std::unordered_map<dof_id_type, std::pair<SubdomainID, SubdomainID>> & moved_elems);
107 
108  void gatherMovingBoundaryChangesHelper(const Elem * elem,
109  unsigned short side,
110  const Elem * neigh,
111  unsigned short neigh_side);
112 
114 
115  void prepareVariableForReinitialization(const VariableName & var_name,
116  ReinitStrategy reinit_strategy);
117 
119  void updateAMRMovingBoundary(MooseMesh & mesh);
120 
122  const std::unordered_map<dof_id_type, std::pair<SubdomainID, SubdomainID>> & moved_elems);
123 
126  ConstElemRange & elem_range,
127  ConstBndNodeRange & bnd_node_range);
128 
130  bool nodeIsNewlyReinitialized(dof_id_type node_id) const;
131 
133  void applyIC();
134 
137 
140 
143 
146 
148  void gatherPatchElements(const VariableName & var_name, ReinitStrategy reinit_strategy);
149 
151  void extrapolatePolynomial(const VariableName & var_name);
152 
155  void storeOverriddenDofValues(const VariableName & var_name);
156 
158  void restoreOverriddenDofValues(const VariableName & var_name);
159 
161  std::unordered_map<dof_id_type, std::pair<SubdomainID, SubdomainID>> _moved_elems;
162 
164  int & _t_step_old;
165 
167  bool _restep;
168 
171 
173  std::vector<SubdomainID> _subdomain_ids_to_reinitialize;
174 
177 
179  typedef std::pair<SubdomainID, SubdomainID> SubdomainPair;
180  std::unordered_map<SubdomainPair, BoundaryID> _moving_boundaries;
181 
183  std::unordered_map<dof_id_type, std::unordered_map<unsigned short, BoundaryID>>
185 
187  std::unordered_map<dof_id_type, std::unordered_map<unsigned short, BoundaryID>>
189 
191  std::unordered_map<dof_id_type, std::unordered_map<unsigned short, BoundaryID>>
193 
195  std::unordered_map<dof_id_type, std::unordered_map<unsigned short, BoundaryID>>
197 
199  std::unordered_set<dof_id_type> _reinitialized_elems;
201  std::unique_ptr<ConstElemRange> _reinitialized_elem_range;
202 
204  std::unordered_set<dof_id_type> _semi_local_reinitialized_elems;
205 
207  std::unordered_set<dof_id_type> _reinitialized_nodes;
209  std::unique_ptr<ConstNodeRange> _reinitialized_node_range;
211  std::unique_ptr<ConstBndNodeRange> _reinitialized_bnd_node_range;
212 
218  std::map<VariableName, std::pair<std::vector<dof_id_type>, std::vector<Number>>>
220 
222  std::vector<ReinitStrategy> _reinit_strategy;
223 
225  const std::vector<UserObjectName> _pr_names;
226 
228  std::vector<NodalPatchRecoveryVariable *> _pr;
229 
231  std::vector<VariableName> _reinit_vars;
232 
234  std::map<VariableName, unsigned int> _var_name_to_pr_idx;
235 
242  std::map<unsigned int, std::pair<std::unordered_set<const Elem *>, std::vector<dof_id_type>>>
244 
246  std::map<VariableName, std::vector<dof_id_type>> _patch_elem_ids;
247 
251  int _leaf_max_size = 10;
253  std::vector<Point> _kd_tree_points;
257 
259  std::vector<VariableName> _vars_to_restore_overridden_dofs;
260 };
ConstNodeRange & reinitializedNodeRange()
Range of reinitialized nodes.
const std::vector< UserObjectName > _pr_names
Names of the NodalPatchRecoveryVariable user objects.
DisplacedProblem * _displaced_problem
Pointer to the displaced problem.
bool _restep
Whether this is a re-step.
int & _t_step_old
Previous time step number.
std::map< VariableName, unsigned int > _var_name_to_pr_idx
map from variable name to the index of the nodal patch recovery user object in _pr ...
NonlinearSystemBase & _nl_sys
Nonlinear system.
void prepareVariableForReinitialization(const VariableName &var_name, ReinitStrategy reinit_strategy)
std::unordered_set< dof_id_type > _reinitialized_elems
Reinitialized elements.
std::pair< SubdomainID, SubdomainID > SubdomainPair
Moving boundaries associated with each subdomain pair.
std::vector< VariableName > _vars_to_restore_overridden_dofs
List of variable names for which overridden DOF values should be restored.
void initElementStatefulProps()
Reinitialize stateful material properties on range of elements and nodes to be reinitialized.
void gatherPatchElements(const VariableName &var_name, ReinitStrategy reinit_strategy)
Gather patch elements for reinitialized elements based on the reinitialization strategy.
const InputParameters & parameters() const
Get the parameters of the object.
Definition: MooseBase.h:127
std::unordered_map< BoundaryID, BoundaryName > _moving_boundary_names
Boundary names associated with each moving boundary ID.
std::unordered_map< dof_id_type, std::pair< SubdomainID, SubdomainID > > _moved_elems
Cached moved elements for potential restore.
void gatherMovingBoundaryChanges(const std::unordered_map< dof_id_type, std::pair< SubdomainID, SubdomainID >> &moved_elems)
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
std::map< unsigned int, std::pair< std::unordered_set< const Elem * >, std::vector< dof_id_type > > > _evaluable_elems
local evaluable elements before reinitializing the equation systems Key of the map is the system numb...
std::vector< VariableName > _reinit_vars
List of variable names to be initialized for IC.
Base class for a system (of equations)
Definition: SystemBase.h:84
void gatherMovingBoundaryChangesHelper(const Elem *elem, unsigned short side, const Elem *neigh, unsigned short neigh_side)
std::vector< Point > _kd_tree_points
Centroids of all solved elements used for k-d tree construction.
void initialSetup() override
Gets called at the beginning of the simulation before this object is asked to do its job...
bool _skip_restore_subdomain_changes
Skipping restoring the subdomain changes if the timestep is not advanced.
StoredRange< MeshBase::const_element_iterator, const Elem *> ConstElemRange
void updateAMRMovingBoundary(MooseMesh &mesh)
Update boundaries for adaptive mesh from the parent to children elements.
Nonlinear system to be solved.
virtual void modify(const std::unordered_map< dof_id_type, std::pair< SubdomainID, SubdomainID >> &moved_elems)
Modify the element subdomains.
void createMovingBoundaries(MooseMesh &mesh)
Create moving boundaries.
void storeOverriddenDofValues(const VariableName &var_name)
Store values from non-reinitialized DoFs on reinitialized elements Stores the value before re-initial...
ReinitStrategy
Strategies for (re)initializing the solution:
ConstElemRange & reinitializedElemRange()
Range of reinitialized elements.
std::unordered_set< dof_id_type > _semi_local_reinitialized_elems
Semi-local reinitialized elements: ghosted and local reinitialized elements.
void meshChanged() override
Called on this object when the mesh changes.
void setAncestorsSubdomainIDs(Elem *elem, const SubdomainID subdomain_id)
Change the subdomain ID of all ancestor elements.
void applySubdomainChanges(const std::unordered_map< dof_id_type, std::pair< SubdomainID, SubdomainID >> &moved_elems, MooseMesh &mesh)
std::unordered_set< dof_id_type > _reinitialized_nodes
Reinitialized nodes.
MooseMesh wraps a libMesh::Mesh object and enhances its capabilities by caching additional data and s...
Definition: MooseMesh.h:88
StoredRange< MeshBase::const_node_iterator, const Node *> ConstNodeRange
bool subdomainIsReinitialized(SubdomainID id) const
Determine if a subdomain is to be reinitialized.
int _leaf_max_size
KD-tree related members.
std::vector< SubdomainID > _subdomain_ids_to_reinitialize
Reinitialize moved elements whose new subdomain is in this list.
std::map< VariableName, std::pair< std::vector< dof_id_type >, std::vector< Number > > > _overridden_values_on_reinit_elems
A map from variable name to a pair of: (1) a vector of DOF IDs associated with non-reinitialized node...
std::vector< NodalPatchRecoveryVariable * > _pr
Apply initial conditions using polynomial extrapolation.
AuxiliarySystem & _aux_sys
Auxiliary system.
std::unordered_map< dof_id_type, std::unordered_map< unsigned short, BoundaryID > > _add_element_sides
Element sides to be added.
void restoreOverriddenDofValues(const VariableName &var_name)
Restore values to non-reinitialized DoFs on reinitialized elements.
std::unordered_map< dof_id_type, std::unordered_map< unsigned short, BoundaryID > > _remove_element_sides
Element sides to be removed.
void applyMovingBoundaryChanges(MooseMesh &mesh)
bool nodeIsNewlyReinitialized(dof_id_type node_id) const
Determine if a node is newly reinitialized.
std::unique_ptr< ConstBndNodeRange > _reinitialized_bnd_node_range
Range of reinitialized boundary nodes.
std::map< VariableName, std::vector< dof_id_type > > _patch_elem_ids
A map from variable names to their corresponding patch element IDs.
MooseMesh * _displaced_mesh
Displaced mesh.
std::vector< ReinitStrategy > _reinit_strategy
The strategies used to apply IC on newly activated elements, for each variable.
void applyIC()
Reinitialize variables on range of elements and nodes to be reinitialized.
std::unique_ptr< ConstElemRange > _reinitialized_elem_range
Range of reinitialized elements.
Base class for mesh modifiers modifying element subdomains.
void setOldAndOlderSolutions(SystemBase &sys, ConstElemRange &elem_range, ConstBndNodeRange &bnd_node_range)
Set old and older solutions to reinitialized elements and nodes.
void findReinitializedElemsAndNodes(const std::unordered_map< dof_id_type, std::pair< SubdomainID, SubdomainID >> &moved_elems)
void timestepSetup() override
Gets called at the beginning of the timestep before this object is asked to do its job...
std::unique_ptr< ConstNodeRange > _reinitialized_node_range
Range of reinitialized nodes.
std::unordered_map< SubdomainPair, BoundaryID > _moving_boundaries
ConstBndNodeRange & reinitializedBndNodeRange()
Range of reinitialized boundary nodes.
A system that holds auxiliary variables.
double _nearby_distance_threshold
Radius threshold for the k-d tree neighbor search.
std::unordered_map< dof_id_type, std::unordered_map< unsigned short, BoundaryID > > _remove_neighbor_sides
Neighbor sides to be removed.
std::unordered_map< dof_id_type, std::unordered_map< unsigned short, BoundaryID > > _add_neighbor_sides
Neighbor sides to be added.
ElementSubdomainModifierBase(const InputParameters &parameters)
const bool _old_subdomain_reinitialized
Whether to reinitialize moved elements whose old subdomain was in _reinitialize_subdomains.
uint8_t dof_id_type
void extrapolatePolynomial(const VariableName &var_name)
Extrapolate polynomial for the given variable onto the reinitialized elements.