www.mooseframework.org
SetupMeshAction.C
Go to the documentation of this file.
1 /****************************************************************/
2 /* DO NOT MODIFY THIS HEADER */
3 /* MOOSE - Multiphysics Object Oriented Simulation Environment */
4 /* */
5 /* (c) 2010 Battelle Energy Alliance, LLC */
6 /* ALL RIGHTS RESERVED */
7 /* */
8 /* Prepared by Battelle Energy Alliance, LLC */
9 /* Under Contract No. DE-AC07-05ID14517 */
10 /* With the U. S. Department of Energy */
11 /* */
12 /* See COPYRIGHT for full restrictions */
13 /****************************************************************/
14 
15 #include "SetupMeshAction.h"
16 #include "MooseApp.h"
17 #include "MooseMesh.h"
18 #include "FEProblem.h"
19 #include "ActionWarehouse.h"
20 #include "Factory.h"
21 
22 template <>
25 {
27  params.set<std::string>("type") = "FileMesh";
28 
29  params.addParam<bool>("second_order",
30  false,
31  "Converts a first order mesh to a second order "
32  "mesh. Note: This is NOT needed if you are reading "
33  "an actual first order mesh.");
34 
35  params.addParam<std::vector<SubdomainID>>("block_id", "IDs of the block id/name pairs");
36  params.addParam<std::vector<SubdomainName>>(
37  "block_name", "Names of the block id/name pairs (must correspond with \"block_id\"");
38 
39  params.addParam<std::vector<BoundaryID>>("boundary_id", "IDs of the boundary id/name pairs");
40  params.addParam<std::vector<BoundaryName>>(
41  "boundary_name", "Names of the boundary id/name pairs (must correspond with \"boundary_id\"");
42 
43  params.addParam<bool>("construct_side_list_from_node_list",
44  false,
45  "If true, construct side lists from the nodesets in the mesh (i.e. if "
46  "every node on a give side is in a nodeset then add that side to a "
47  "sideset");
48 
49  params.addParam<std::vector<std::string>>(
50  "displacements",
51  "The variables corresponding to the x y z displacements of the mesh. If "
52  "this is provided then the displacements will be taken into account during "
53  "the computation.");
54  params.addParam<std::vector<BoundaryName>>("ghosted_boundaries",
55  "Boundaries to be ghosted if using Nemesis");
56  params.addParam<std::vector<Real>>("ghosted_boundaries_inflation",
57  "If you are using ghosted boundaries you will want to set "
58  "this value to a vector of amounts to inflate the bounding "
59  "boxes by. ie if you are running a 3D problem you might set "
60  "it to '0.2 0.1 0.4'");
61 
62  params.addParam<unsigned int>(
63  "uniform_refine", 0, "Specify the level of uniform refinement applied to the initial mesh");
64  params.addParam<bool>("skip_partitioning",
65  false,
66  "If true the mesh won't be partitioned. This may cause large load "
67  "imbalanced but is currently required if you "
68  "have a simulation containing uniform refinement, adaptivity and stateful "
69  "material properties");
70 
71  // groups
72  params.addParamNamesToGroup("displacements ghosted_boundaries ghosted_boundaries_inflation",
73  "Advanced");
74  params.addParamNamesToGroup("second_order construct_side_list_from_node_list skip_partitioning",
75  "Advanced");
76  params.addParamNamesToGroup("block_id block_name boundary_id boundary_name", "Add Names");
77 
78  return params;
79 }
80 
82 
83 void
85 {
86  std::vector<BoundaryName> ghosted_boundaries =
87  getParam<std::vector<BoundaryName>>("ghosted_boundaries");
88 
89  for (const auto & bnd_name : ghosted_boundaries)
90  mesh->addGhostedBoundary(mesh->getBoundaryID(bnd_name));
91 
92  if (isParamValid("ghosted_boundaries_inflation"))
93  {
94  std::vector<Real> ghosted_boundaries_inflation =
95  getParam<std::vector<Real>>("ghosted_boundaries_inflation");
96  mesh->setGhostedBoundaryInflation(ghosted_boundaries_inflation);
97  }
98 
99  mesh->ghostGhostedBoundaries();
100 
101  if (getParam<bool>("second_order"))
102  mesh->getMesh().all_second_order(true);
103 
104 #ifdef LIBMESH_ENABLE_AMR
105  unsigned int level = getParam<unsigned int>("uniform_refine");
106 
107  // Did they specify extra refinement levels on the command-line?
108  level += _app.getParam<unsigned int>("refinements");
109 
110  mesh->setUniformRefineLevel(level);
111 #endif // LIBMESH_ENABLE_AMR
112 
113  // Add entity names to the mesh
114  if (_pars.isParamValid("block_id") && _pars.isParamValid("block_name"))
115  {
116  std::vector<SubdomainID> ids = getParam<std::vector<SubdomainID>>("block_id");
117  std::vector<SubdomainName> names = getParam<std::vector<SubdomainName>>("block_name");
118  std::set<SubdomainName> seen_it;
119 
120  if (ids.size() != names.size())
121  mooseError("You must supply the same number of block ids and names parameters");
122 
123  for (unsigned int i = 0; i < ids.size(); ++i)
124  {
125  if (seen_it.find(names[i]) != seen_it.end())
126  mooseError("The following dynamic block name is not unique: " + names[i]);
127  seen_it.insert(names[i]);
128  mesh->setSubdomainName(ids[i], names[i]);
129  }
130  }
131  if (_pars.isParamValid("boundary_id") && _pars.isParamValid("boundary_name"))
132  {
133  std::vector<BoundaryID> ids = getParam<std::vector<BoundaryID>>("boundary_id");
134  std::vector<BoundaryName> names = getParam<std::vector<BoundaryName>>("boundary_name");
135  std::set<SubdomainName> seen_it;
136 
137  if (ids.size() != names.size())
138  mooseError("You must supply the same number of boundary ids and names parameters");
139 
140  for (unsigned int i = 0; i < ids.size(); ++i)
141  {
142  if (seen_it.find(names[i]) != seen_it.end())
143  mooseError("The following dynamic boundary name is not unique: " + names[i]);
144  mesh->setBoundaryName(ids[i], names[i]);
145  seen_it.insert(names[i]);
146  }
147  }
148 
149  if (getParam<bool>("construct_side_list_from_node_list"))
150  mesh->getMesh().get_boundary_info().build_side_list_from_node_list();
151 
152  // Here we can override the partitioning for special cases
153  if (getParam<bool>("skip_partitioning"))
154  mesh->getMesh().skip_partitioning(getParam<bool>("skip_partitioning"));
155 }
156 
157 void
159 {
160  // Create the mesh object and tell it to build itself
161  if (_current_task == "setup_mesh")
162  {
164  if (isParamValid("displacements"))
165  _displaced_mesh = _factory.create<MooseMesh>(_type, "displaced_mesh", _moose_object_pars);
166  }
167  else if (_current_task == "init_mesh")
168  {
169  _mesh->init();
170 
171  if (isParamValid("displacements"))
172  {
173  // Initialize the displaced mesh
174  _displaced_mesh->init();
175 
176  std::vector<std::string> displacements = getParam<std::vector<std::string>>("displacements");
177  if (displacements.size() < _displaced_mesh->dimension())
178  mooseError(
179  "Number of displacements must be greater than or equal to the dimension of the mesh!");
180  }
181 
182  setupMesh(_mesh.get());
183 
184  if (_displaced_mesh)
185  setupMesh(_displaced_mesh.get());
186  }
187 }
SetupMeshAction(InputParameters params)
InputParameters validParams< SetupMeshAction >()
std::shared_ptr< MooseObject > create(const std::string &obj_name, const std::string &name, InputParameters parameters, THREAD_ID tid=0, bool print_deprecated=true)
Build an object (must be registered) - THIS METHOD IS DEPRECATED (Use create<T>()) ...
Definition: Factory.C:46
virtual void act() override
void mooseError(Args &&...args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:182
T & set(const std::string &name, bool quiet_mode=false)
Returns a writable reference to the named parameters.
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
Factory & _factory
The Factory associated with the MooseApp.
Definition: Action.h:101
BoundaryID getBoundaryID(const BoundaryName &boundary_name) const
Get the associated BoundaryID for the boundary name.
Definition: MooseMesh.C:929
bool isParamValid(const std::string &name) const
This method returns parameters that have been initialized in one fashion or another, i.e.
InputParameters _pars
Input parameters for the action.
Definition: Action.h:86
MeshBase & getMesh()
Accessor for the underlying libMesh Mesh object.
Definition: MooseMesh.C:2355
void setSubdomainName(SubdomainID subdomain_id, SubdomainName name)
This method returns a writable reference to a subdomain name based on the id parameter.
Definition: MooseMesh.C:1040
std::shared_ptr< MooseMesh > & _displaced_mesh
Definition: Action.h:128
MooseMesh wraps a libMesh::Mesh object and enhances its capabilities by caching additional data and s...
Definition: MooseMesh.h:74
const std::string & _current_task
The current action (even though we have seperate instances for each action)
Definition: Action.h:125
InputParameters validParams< MooseObjectAction >()
void setupMesh(MooseMesh *mesh)
bool isParamValid(const std::string &name) const
Definition: Action.h:80
void setBoundaryName(BoundaryID boundary_id, BoundaryName name)
This method returns a writable reference to a boundary name based on the id parameter.
Definition: MooseMesh.C:1052
const T & getParam(const std::string &name)
Retrieve a parameter for the object.
Definition: MooseApp.h:738
std::shared_ptr< MooseMesh > & _mesh
Definition: Action.h:127
std::string _type
The Object type that is being created.
InputParameters _moose_object_pars
The parameters for the object to be created.
void setGhostedBoundaryInflation(const std::vector< Real > &inflation)
This sets the inflation amount for the bounding box for each partition for use in ghosting boundaries...
Definition: MooseMesh.C:2167
void addParam(const std::string &name, const S &value, const std::string &doc_string)
These methods add an option parameter and a documentation string to the InputParameters object...
void addGhostedBoundary(BoundaryID boundary_id)
This will add the boundary ids to be ghosted to this processor.
Definition: MooseMesh.C:2161
void ghostGhostedBoundaries()
Actually do the ghosting of boundaries that need to be ghosted to this processor. ...
Definition: MooseMesh.C:2243
MooseApp & _app
The MOOSE application this is associated with.
Definition: Action.h:98
void setUniformRefineLevel(unsigned int)
Set uniform refinement level.
Definition: MooseMesh.C:2155
void addParamNamesToGroup(const std::string &space_delim_names, const std::string group_name)
This method takes a space delimited list of parameter names and adds them to the specified group name...