www.mooseframework.org
XFEMAction.C
Go to the documentation of this file.
1 /****************************************************************/
2 /* MOOSE - Multiphysics Object Oriented Simulation Environment */
3 /* */
4 /* All contents are licensed under LGPL V2.1 */
5 /* See LICENSE for full restrictions */
6 /****************************************************************/
7 
8 #include "XFEMAction.h"
9 
10 // MOOSE includes
11 #include "FEProblem.h"
12 #include "DisplacedProblem.h"
13 #include "NonlinearSystem.h"
14 #include "Executioner.h"
15 #include "MooseEnum.h"
16 #include "Parser.h"
17 #include "Factory.h"
18 
19 #include "GeometricCutUserObject.h"
20 #include "CrackFrontDefinition.h"
21 
22 #include "libmesh/transient_system.h"
23 #include "libmesh/string_to_enum.h"
24 
25 // XFEM includes
26 #include "XFEM.h"
27 #include "XFEMElementPairLocator.h"
28 
29 template <>
30 InputParameters
32 {
33  InputParameters params = validParams<Action>();
34 
35  params.addParam<std::vector<UserObjectName>>(
36  "geometric_cut_userobjects",
37  "List of names of GeometricCutUserObjects with cut info and methods");
38  params.addParam<std::string>("qrule", "volfrac", "XFEM quadrature rule to use");
39  params.addParam<bool>("output_cut_plane", false, "Output the XFEM cut plane and volume fraction");
40  params.addParam<bool>("use_crack_growth_increment", false, "Use fixed crack growth increment");
41  params.addParam<Real>("crack_growth_increment", 0.1, "Crack growth increment");
42  params.addParam<bool>("use_crack_tip_enrichment", false, "Use crack tip enrichment functions");
43  params.addParam<UserObjectName>("crack_front_definition",
44  "The CrackFrontDefinition user object name (only "
45  "needed if 'use_crack_tip_enrichment=true')");
46  params.addParam<std::vector<VariableName>>("displacements",
47  "Names of displacement variables (only "
48  "needed if 'use_crack_tip_enrichment=true')");
49  params.addParam<std::vector<VariableName>>("enrichment_displacements",
50  "Names of enrichment displacement variables (only "
51  "needed if 'use_crack_tip_enrichment=true')");
52  params.addParam<std::vector<BoundaryName>>("cut_off_boundary",
53  "Boundary that contains all nodes for which "
54  "enrichment DOFs should be fixed away from crack tip "
55  "(only needed if 'use_crack_tip_enrichment=true')");
56  params.addParam<Real>("cut_off_radius",
57  "The cut off radius of crack tip enrichment functions (only needed if "
58  "'use_crack_tip_enrichment=true')");
59  return params;
60 }
61 
62 XFEMAction::XFEMAction(InputParameters params)
63  : Action(params),
64  _geom_cut_userobjects(getParam<std::vector<UserObjectName>>("geometric_cut_userobjects")),
65  _xfem_qrule(getParam<std::string>("qrule")),
66  _xfem_cut_plane(false),
67  _xfem_use_crack_growth_increment(getParam<bool>("use_crack_growth_increment")),
68  _xfem_crack_growth_increment(getParam<Real>("crack_growth_increment")),
69  _use_crack_tip_enrichment(getParam<bool>("use_crack_tip_enrichment"))
70 {
71  _order = "CONSTANT";
72  _family = "MONOMIAL";
73  if (isParamValid("output_cut_plane"))
74  _xfem_cut_plane = getParam<bool>("output_cut_plane");
75 
77  {
78  if (isParamValid("crack_front_definition"))
79  _crack_front_definition = getParam<UserObjectName>("crack_front_definition");
80  else
81  mooseError("To add crack tip enrichment, crack_front_definition must be provided.");
82 
83  if (isParamValid("displacements"))
84  _displacements = getParam<std::vector<VariableName>>("displacements");
85  else
86  mooseError("To add crack tip enrichment, displacements must be provided.");
87 
88  if (isParamValid("enrichment_displacements"))
89  {
90  _enrich_displacements = getParam<std::vector<VariableName>>("enrichment_displacements");
91  if (_enrich_displacements.size() != 8 && _displacements.size() == 2)
92  mooseError("The number of enrichment displacements should be total 8 for 2D.");
93  else if (_enrich_displacements.size() != 12 && _displacements.size() == 3)
94  mooseError("The number of enrichment displacements should be total 12 for 3D.");
95  }
96  else
97  mooseError("To add crack tip enrichment, enrichment_displacements must be provided.");
98 
99  if (isParamValid("cut_off_boundary"))
100  _cut_off_bc = getParam<std::vector<BoundaryName>>("cut_off_boundary");
101  else
102  mooseError("To add crack tip enrichment, cut_off_boundary must be provided.");
103 
104  if (isParamValid("cut_off_radius"))
105  _cut_off_radius = getParam<Real>("cut_off_radius");
106  else
107  mooseError("To add crack tip enrichment, cut_off_radius must be provided.");
108  }
109 }
110 
111 void
113 {
114 
115  MooseSharedPointer<XFEMInterface> xfem_interface = _problem->getXFEM();
116  if (xfem_interface == NULL)
117  {
118  _pars.set<FEProblemBase *>("_fe_problem_base") = &*_problem;
119  MooseSharedPointer<XFEM> new_xfem(new XFEM(_pars));
120  _problem->initXFEM(new_xfem);
121  xfem_interface = _problem->getXFEM();
122  }
123 
124  MooseSharedPointer<XFEM> xfem = MooseSharedNamespace::dynamic_pointer_cast<XFEM>(xfem_interface);
125  if (xfem == NULL)
126  mooseError("dynamic cast of xfem object failed");
127 
128  if (_current_task == "setup_xfem")
129  {
130  xfem->setXFEMQRule(_xfem_qrule);
131 
133 
134  MooseSharedPointer<XFEMElementPairLocator> new_xfem_epl(new XFEMElementPairLocator(xfem, 0));
135  _problem->geomSearchData().addElementPairLocator(0, new_xfem_epl);
136 
137  if (_problem->getDisplacedProblem() != NULL)
138  {
139  MooseSharedPointer<XFEMElementPairLocator> new_xfem_epl2(
140  new XFEMElementPairLocator(xfem, 0, true));
141  _problem->getDisplacedProblem()->geomSearchData().addElementPairLocator(0, new_xfem_epl2);
142  }
143 
144  // Pull in geometric cut user objects by name (getUserObjectByName)
145  // Send to XFEM and store in vector of GeometricCutUserObjects (addGeometricCut)
146  for (unsigned int i = 0; i < _geom_cut_userobjects.size(); ++i)
147  {
148  const UserObject * uo = &(_problem->getUserObjectBase(_geom_cut_userobjects[i]));
149  xfem->addGeometricCut(dynamic_cast<const GeometricCutUserObject *>(uo));
150  }
151  }
152  else if (_current_task == "add_variable" && _use_crack_tip_enrichment)
153  {
154  for (const auto & enrich_disp : _enrich_displacements)
155  _problem->addVariable(enrich_disp,
156  FEType(Utility::string_to_enum<Order>("FIRST"),
157  Utility::string_to_enum<FEFamily>("LAGRANGE")),
158  1.0);
159  }
160  else if (_current_task == "add_kernel" && _use_crack_tip_enrichment)
161  {
162  for (unsigned int i = 0; i < _enrich_displacements.size(); ++i)
163  {
164  InputParameters params = _factory.getValidParams("CrackTipEnrichmentStressDivergenceTensors");
165  params.set<NonlinearVariableName>("variable") = _enrich_displacements[i];
166  params.set<unsigned int>("component") = i / 4;
167  params.set<unsigned int>("enrichment_component") = i % 4;
168  params.set<UserObjectName>("crack_front_definition") = _crack_front_definition;
169  params.set<std::vector<VariableName>>("enrichment_displacements") = _enrich_displacements;
170  params.set<std::vector<VariableName>>("displacements") = _displacements;
171  _problem->addKernel(
172  "CrackTipEnrichmentStressDivergenceTensors", _enrich_displacements[i], params);
173  }
174  }
175  else if (_current_task == "add_bc" && _use_crack_tip_enrichment)
176  {
177  for (unsigned int i = 0; i < _enrich_displacements.size(); ++i)
178  {
179  InputParameters params = _factory.getValidParams("CrackTipEnrichmentCutOffBC");
180  params.set<NonlinearVariableName>("variable") = _enrich_displacements[i];
181  params.set<Real>("value") = 0;
182  params.set<std::vector<BoundaryName>>("boundary") = _cut_off_bc;
183  params.set<Real>("cut_off_radius") = _cut_off_radius;
184  params.set<UserObjectName>("crack_front_definition") = _crack_front_definition;
185  _problem->addBoundaryCondition(
186  "CrackTipEnrichmentCutOffBC", _enrich_displacements[i], params);
187  }
188  }
189  else if (_current_task == "add_aux_variable" && _xfem_cut_plane)
190  {
191  _problem->addAuxVariable(
192  "xfem_cut_origin_x",
193  FEType(Utility::string_to_enum<Order>(_order), Utility::string_to_enum<FEFamily>(_family)));
194  _problem->addAuxVariable(
195  "xfem_cut_origin_y",
196  FEType(Utility::string_to_enum<Order>(_order), Utility::string_to_enum<FEFamily>(_family)));
197  _problem->addAuxVariable(
198  "xfem_cut_origin_z",
199  FEType(Utility::string_to_enum<Order>(_order), Utility::string_to_enum<FEFamily>(_family)));
200  _problem->addAuxVariable(
201  "xfem_cut_normal_x",
202  FEType(Utility::string_to_enum<Order>(_order), Utility::string_to_enum<FEFamily>(_family)));
203  _problem->addAuxVariable(
204  "xfem_cut_normal_y",
205  FEType(Utility::string_to_enum<Order>(_order), Utility::string_to_enum<FEFamily>(_family)));
206  _problem->addAuxVariable(
207  "xfem_cut_normal_z",
208  FEType(Utility::string_to_enum<Order>(_order), Utility::string_to_enum<FEFamily>(_family)));
209 
210  _problem->addAuxVariable(
211  "xfem_cut2_origin_x",
212  FEType(Utility::string_to_enum<Order>(_order), Utility::string_to_enum<FEFamily>(_family)));
213  _problem->addAuxVariable(
214  "xfem_cut2_origin_y",
215  FEType(Utility::string_to_enum<Order>(_order), Utility::string_to_enum<FEFamily>(_family)));
216  _problem->addAuxVariable(
217  "xfem_cut2_origin_z",
218  FEType(Utility::string_to_enum<Order>(_order), Utility::string_to_enum<FEFamily>(_family)));
219  _problem->addAuxVariable(
220  "xfem_cut2_normal_x",
221  FEType(Utility::string_to_enum<Order>(_order), Utility::string_to_enum<FEFamily>(_family)));
222  _problem->addAuxVariable(
223  "xfem_cut2_normal_y",
224  FEType(Utility::string_to_enum<Order>(_order), Utility::string_to_enum<FEFamily>(_family)));
225  _problem->addAuxVariable(
226  "xfem_cut2_normal_z",
227  FEType(Utility::string_to_enum<Order>(_order), Utility::string_to_enum<FEFamily>(_family)));
228 
229  _problem->addAuxVariable(
230  "xfem_volfrac",
231  FEType(Utility::string_to_enum<Order>(_order), Utility::string_to_enum<FEFamily>(_family)));
232  }
233  else if (_current_task == "add_aux_kernel" && _xfem_cut_plane)
234  {
235  InputParameters params = _factory.getValidParams("XFEMVolFracAux");
236  params.set<MultiMooseEnum>("execute_on") = "timestep_begin";
237  params.set<AuxVariableName>("variable") = "xfem_volfrac";
238  _problem->addAuxKernel("XFEMVolFracAux", "xfem_volfrac", params);
239 
240  params = _factory.getValidParams("XFEMCutPlaneAux");
241  params.set<MultiMooseEnum>("execute_on") = "timestep_end";
242 
243  // first cut plane
244  params.set<unsigned int>("plane_id") = 0;
245 
246  params.set<AuxVariableName>("variable") = "xfem_cut_origin_x";
247  params.set<MooseEnum>("quantity") = "origin_x";
248  _problem->addAuxKernel("XFEMCutPlaneAux", "xfem_cut_origin_x", params);
249 
250  params.set<AuxVariableName>("variable") = "xfem_cut_origin_y";
251  params.set<MooseEnum>("quantity") = "origin_y";
252  _problem->addAuxKernel("XFEMCutPlaneAux", "xfem_cut_origin_y", params);
253 
254  params.set<AuxVariableName>("variable") = "xfem_cut_origin_z";
255  params.set<MooseEnum>("quantity") = "origin_z";
256  _problem->addAuxKernel("XFEMCutPlaneAux", "xfem_cut_origin_z", params);
257 
258  params.set<AuxVariableName>("variable") = "xfem_cut_normal_x";
259  params.set<MooseEnum>("quantity") = "normal_x";
260  _problem->addAuxKernel("XFEMCutPlaneAux", "xfem_cut_normal_x", params);
261 
262  params.set<AuxVariableName>("variable") = "xfem_cut_normal_y";
263  params.set<MooseEnum>("quantity") = "normal_y";
264  _problem->addAuxKernel("XFEMCutPlaneAux", "xfem_cut_normal_y", params);
265 
266  params.set<AuxVariableName>("variable") = "xfem_cut_normal_z";
267  params.set<MooseEnum>("quantity") = "normal_z";
268  _problem->addAuxKernel("XFEMCutPlaneAux", "xfem_cut_normal_z", params);
269 
270  // second cut plane
271  params.set<unsigned int>("plane_id") = 1;
272 
273  params.set<AuxVariableName>("variable") = "xfem_cut2_origin_x";
274  params.set<MooseEnum>("quantity") = "origin_x";
275  _problem->addAuxKernel("XFEMCutPlaneAux", "xfem_cut2_origin_x", params);
276 
277  params.set<AuxVariableName>("variable") = "xfem_cut2_origin_y";
278  params.set<MooseEnum>("quantity") = "origin_y";
279  _problem->addAuxKernel("XFEMCutPlaneAux", "xfem_cut2_origin_y", params);
280 
281  params.set<AuxVariableName>("variable") = "xfem_cut2_origin_z";
282  params.set<MooseEnum>("quantity") = "origin_z";
283  _problem->addAuxKernel("XFEMCutPlaneAux", "xfem_cut2_origin_z", params);
284 
285  params.set<AuxVariableName>("variable") = "xfem_cut2_normal_x";
286  params.set<MooseEnum>("quantity") = "normal_x";
287  _problem->addAuxKernel("XFEMCutPlaneAux", "xfem_cut2_normal_x", params);
288 
289  params.set<AuxVariableName>("variable") = "xfem_cut2_normal_y";
290  params.set<MooseEnum>("quantity") = "normal_y";
291  _problem->addAuxKernel("XFEMCutPlaneAux", "xfem_cut2_normal_y", params);
292 
293  params.set<AuxVariableName>("variable") = "xfem_cut2_normal_z";
294  params.set<MooseEnum>("quantity") = "normal_z";
295  _problem->addAuxKernel("XFEMCutPlaneAux", "xfem_cut2_normal_z", params);
296  }
297 }
UserObjectName _crack_front_definition
Definition: XFEMAction.h:35
bool _xfem_use_crack_growth_increment
Definition: XFEMAction.h:32
Real _cut_off_radius
Definition: XFEMAction.h:39
This is the XFEM class.
Definition: XFEM.h:60
InputParameters validParams< XFEMAction >()
Definition: XFEMAction.C:31
std::string _order
Definition: XFEMAction.h:29
std::string _xfem_qrule
Definition: XFEMAction.h:28
virtual void act()
Definition: XFEMAction.C:112
bool _use_crack_tip_enrichment
Definition: XFEMAction.h:34
std::vector< VariableName > _enrich_displacements
Definition: XFEMAction.h:36
XFEMAction(InputParameters params)
Definition: XFEMAction.C:62
std::vector< VariableName > _displacements
Definition: XFEMAction.h:37
bool _xfem_cut_plane
Definition: XFEMAction.h:31
std::vector< BoundaryName > _cut_off_bc
Definition: XFEMAction.h:38
Real _xfem_crack_growth_increment
Definition: XFEMAction.h:33
std::vector< UserObjectName > _geom_cut_userobjects
Definition: XFEMAction.h:27
std::string _family
Definition: XFEMAction.h:30