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  NONE
40 };
41 
46 {
47 public:
49 
51 
52  void initialSetup() override;
53  void meshChanged() override;
54  void timestepSetup() override;
55 
56 protected:
74  virtual void
75  modify(const std::unordered_map<dof_id_type, std::pair<SubdomainID, SubdomainID>> & moved_elems);
76 
79 
82 
85 
87  std::unordered_map<BoundaryID, BoundaryName> _moving_boundary_names;
88 
91 
94 
95 private:
97  void createMovingBoundaries(MooseMesh & mesh);
98 
100  const std::unordered_map<dof_id_type, std::pair<SubdomainID, SubdomainID>> & moved_elems,
101  MooseMesh & mesh);
102 
104  void setAncestorsSubdomainIDs(Elem * elem, const SubdomainID subdomain_id);
105 
107  const std::unordered_map<dof_id_type, std::pair<SubdomainID, SubdomainID>> & moved_elems);
108 
109  void gatherMovingBoundaryChangesHelper(const Elem * elem,
110  unsigned short side,
111  const Elem * neigh,
112  unsigned short neigh_side);
113 
115 
116  void prepareVariableForReinitialization(const VariableName & var_name,
117  ReinitStrategy reinit_strategy);
118 
120  void updateAMRMovingBoundary(MooseMesh & mesh);
121 
123  const std::unordered_map<dof_id_type, std::pair<SubdomainID, SubdomainID>> & moved_elems);
124 
127  ConstElemRange & elem_range,
128  ConstBndNodeRange & bnd_node_range);
129 
131  bool nodeIsNewlyReinitialized(dof_id_type node_id) const;
132 
134  void applyIC();
135 
138 
141 
144 
147 
149  void gatherPatchElements(const VariableName & var_name, ReinitStrategy reinit_strategy);
150 
152  void extrapolatePolynomial(const VariableName & var_name);
153 
156  void storeOverriddenDofValues(const VariableName & var_name);
157 
159  void restoreOverriddenDofValues(const VariableName & var_name);
160 
162  std::unordered_map<dof_id_type, std::pair<SubdomainID, SubdomainID>> _moved_elems;
163 
165  int & _t_step_old;
166 
168  bool _restep;
169 
172 
174  std::vector<SubdomainID> _subdomain_ids_to_reinitialize;
175 
178 
180  typedef std::pair<SubdomainID, SubdomainID> SubdomainPair;
181  std::unordered_map<SubdomainPair, BoundaryID> _moving_boundaries;
182 
184  std::unordered_map<dof_id_type, std::unordered_map<unsigned short, BoundaryID>>
186 
188  std::unordered_map<dof_id_type, std::unordered_map<unsigned short, BoundaryID>>
190 
192  std::unordered_map<dof_id_type, std::unordered_map<unsigned short, BoundaryID>>
194 
196  std::unordered_map<dof_id_type, std::unordered_map<unsigned short, BoundaryID>>
198 
200  std::unordered_set<dof_id_type> _reinitialized_elems;
202  std::unique_ptr<ConstElemRange> _reinitialized_elem_range;
203 
205  std::unordered_set<dof_id_type> _semi_local_reinitialized_elems;
206 
208  std::unordered_set<dof_id_type> _reinitialized_nodes;
210  std::unique_ptr<ConstNodeRange> _reinitialized_node_range;
212  std::unique_ptr<ConstBndNodeRange> _reinitialized_bnd_node_range;
213 
219  std::map<VariableName, std::pair<std::vector<dof_id_type>, std::vector<Number>>>
221 
223  std::vector<ReinitStrategy> _reinit_strategy;
224 
226  const std::vector<UserObjectName> _pr_names;
227 
229  std::vector<NodalPatchRecoveryVariable *> _pr;
230 
232  std::vector<VariableName> _reinit_vars;
233 
235  std::map<VariableName, unsigned int> _var_name_to_pr_idx;
236 
243  std::map<unsigned int, std::pair<std::unordered_set<const Elem *>, std::vector<dof_id_type>>>
245 
247  std::map<VariableName, std::vector<dof_id_type>> _patch_elem_ids;
248 
252  int _leaf_max_size = 10;
254  std::vector<Point> _kd_tree_points;
258 
260  std::vector<VariableName> _vars_to_restore_overridden_dofs;
261 };
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:131
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:85
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:93
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.