forked from idaholab/moose
-
Notifications
You must be signed in to change notification settings - Fork 0
/
SetupMeshAction.C
162 lines (128 loc) · 7.17 KB
/
SetupMeshAction.C
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
/****************************************************************/
/* DO NOT MODIFY THIS HEADER */
/* MOOSE - Multiphysics Object Oriented Simulation Environment */
/* */
/* (c) 2010 Battelle Energy Alliance, LLC */
/* ALL RIGHTS RESERVED */
/* */
/* Prepared by Battelle Energy Alliance, LLC */
/* Under Contract No. DE-AC07-05ID14517 */
/* With the U. S. Department of Energy */
/* */
/* See COPYRIGHT for full restrictions */
/****************************************************************/
#include "SetupMeshAction.h"
#include "MooseApp.h"
#include "MooseMesh.h"
#include "FEProblem.h"
#include "ActionWarehouse.h"
#include "Factory.h"
template<>
InputParameters validParams<SetupMeshAction>()
{
InputParameters params = validParams<MooseObjectAction>();
params.set<std::string>("type") = "FileMesh";
params.addParam<bool>("second_order", false, "Converts a first order mesh to a second order mesh. Note: This is NOT needed if you are reading an actual first order mesh.");
params.addParam<std::vector<SubdomainID> >("block_id", "IDs of the block id/name pairs");
params.addParam<std::vector<SubdomainName> >("block_name", "Names of the block id/name pairs (must correspond with \"block_id\"");
params.addParam<std::vector<BoundaryID> >("boundary_id", "IDs of the boundary id/name pairs");
params.addParam<std::vector<BoundaryName> >("boundary_name", "Names of the boundary id/name pairs (must correspond with \"boundary_id\"");
params.addParam<bool>("construct_side_list_from_node_list", false, "If true, construct side lists from the nodesets in the mesh (i.e. if every node on a give side is in a nodeset then add that side to a sideset");
params.addParam<std::vector<std::string> >("displacements", "The variables corresponding to the x y z displacements of the mesh. If this is provided then the displacements will be taken into account during the computation.");
params.addParam<std::vector<BoundaryName> >("ghosted_boundaries", "Boundaries to be ghosted if using Nemesis");
params.addParam<std::vector<Real> >("ghosted_boundaries_inflation", "If you are using ghosted boundaries you will want to set this value to a vector of amounts to inflate the bounding boxes by. ie if you are running a 3D problem you might set it to '0.2 0.1 0.4'");
params.addParam<unsigned int>("patch_size", 40, "The number of nodes to consider in the NearestNode neighborhood.");
params.addParam<unsigned int>("uniform_refine", 0, "Specify the level of uniform refinement applied to the initial mesh");
params.addParam<bool>("skip_partitioning", false, "If true the mesh won't be partitioned. This may cause large load imbalanced but is currently required if you "
"have a simulation containing uniform refinement, adaptivity and stateful material properties");
// groups
params.addParamNamesToGroup("displacements ghosted_boundaries ghosted_boundaries_inflation patch_size", "Advanced");
params.addParamNamesToGroup("second_order construct_side_list_from_node_list skip_partitioning", "Advanced");
params.addParamNamesToGroup("block_id block_name boundary_id boundary_name", "Add Names");
return params;
}
SetupMeshAction::SetupMeshAction(InputParameters params) :
MooseObjectAction(params)
{
}
void
SetupMeshAction::setupMesh(MooseMesh *mesh)
{
std::vector<BoundaryName> ghosted_boundaries = getParam<std::vector<BoundaryName> >("ghosted_boundaries");
for (unsigned int i=0; i<ghosted_boundaries.size(); i++)
mesh->addGhostedBoundary(mesh->getBoundaryID(ghosted_boundaries[i]));
mesh->setPatchSize(getParam<unsigned int>("patch_size"));
if (isParamValid("ghosted_boundaries_inflation"))
{
std::vector<Real> ghosted_boundaries_inflation = getParam<std::vector<Real> >("ghosted_boundaries_inflation");
mesh->setGhostedBoundaryInflation(ghosted_boundaries_inflation);
}
mesh->ghostGhostedBoundaries();
if (getParam<bool>("second_order"))
mesh->getMesh().all_second_order(true);
#ifdef LIBMESH_ENABLE_AMR
unsigned int level = getParam<unsigned int>("uniform_refine");
// Did they specify extra refinement levels on the command-line?
level += _app.getParam<unsigned int>("refinements");
mesh->setUniformRefineLevel(level);
#endif //LIBMESH_ENABLE_AMR
// Add entity names to the mesh
if (_pars.isParamValid("block_id") && _pars.isParamValid("block_name"))
{
std::vector<SubdomainID> ids = getParam<std::vector<SubdomainID> >("block_id");
std::vector<SubdomainName> names = getParam<std::vector<SubdomainName> >("block_name");
std::set<SubdomainName> seen_it;
if (ids.size() != names.size())
mooseError("You must supply the same number of block ids and names parameters");
for (unsigned int i=0; i<ids.size(); ++i)
{
if (seen_it.find(names[i]) != seen_it.end())
mooseError("The following dynamic block name is not unique: " + names[i]);
seen_it.insert(names[i]);
mesh->setSubdomainName(ids[i], names[i]);
}
}
if (_pars.isParamValid("boundary_id") && _pars.isParamValid("boundary_name"))
{
std::vector<BoundaryID> ids = getParam<std::vector<BoundaryID> >("boundary_id");
std::vector<BoundaryName> names = getParam<std::vector<BoundaryName> >("boundary_name");
std::set<SubdomainName> seen_it;
if (ids.size() != names.size())
mooseError("You must supply the same number of boundary ids and names parameters");
for (unsigned int i=0; i<ids.size(); ++i)
{
if (seen_it.find(names[i]) != seen_it.end())
mooseError("The following dynamic boundary name is not unique: " + names[i]);
mesh->setBoundaryName(ids[i], names[i]);
seen_it.insert(names[i]);
}
}
if (getParam<bool>("construct_side_list_from_node_list"))
mesh->getMesh().get_boundary_info().build_side_list_from_node_list();
// Here we can override the partitioning for special cases
if (getParam<bool>("skip_partitioning"))
mesh->getMesh().skip_partitioning(getParam<bool>("skip_partitioning"));
}
void
SetupMeshAction::act()
{
// Create the mesh object and tell it to build itself
if (_current_task == "setup_mesh")
_mesh = MooseSharedNamespace::static_pointer_cast<MooseMesh>(_factory.create(_type, "mesh", _moose_object_pars));
else if (_current_task == "init_mesh")
{
_mesh->init();
if (isParamValid("displacements"))
{
// Create the displaced mesh
_displaced_mesh = MooseSharedNamespace::static_pointer_cast<MooseMesh>(_factory.create(_type, "displaced_mesh", _moose_object_pars));
_displaced_mesh->init();
std::vector<std::string> displacements = getParam<std::vector<std::string> >("displacements");
if (displacements.size() != _displaced_mesh->dimension())
mooseError("Number of displacements and dimension of mesh MUST be the same!");
}
setupMesh(_mesh.get());
if (_displaced_mesh)
setupMesh(_displaced_mesh.get());
}
}