www.mooseframework.org
XFEMMarkerUserObject.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 "XFEMMarkerUserObject.h"
9 
10 #include "XFEM.h"
11 #include "MooseMesh.h"
12 
13 #include "libmesh/parallel_algebra.h"
14 #include "libmesh/parallel.h"
15 
16 template <>
17 InputParameters
19 {
20  InputParameters params = validParams<ElementUserObject>();
21  params.addParam<std::vector<BoundaryName>>(
22  "initiate_on_boundary",
23  "Permit cracks to initiate in elements adjacent to specified boundaries");
24  params.addParam<bool>("secondary_cracks", false, "should secondary cracks be allowed");
25  return params;
26 }
27 
28 XFEMMarkerUserObject::XFEMMarkerUserObject(const InputParameters & parameters)
29  : ElementUserObject(parameters),
30  _mesh(_subproblem.mesh()),
31  _secondary_cracks(getParam<bool>("secondary_cracks"))
32 {
33  FEProblemBase * fe_problem = dynamic_cast<FEProblemBase *>(&_subproblem);
34  if (fe_problem == NULL)
35  mooseError("Problem casting _subproblem to FEProblemBase in XFEMMarkerUserObject");
36  _xfem = MooseSharedNamespace::dynamic_pointer_cast<XFEM>(fe_problem->getXFEM());
37  if (_xfem == NULL)
38  mooseError("Problem casting to XFEM in XFEMMarkerUserObject");
39  if (isNodal())
40  mooseError("XFEMMarkerUserObject can only be run on an element variable");
41 
42  if (isParamValid("initiate_on_boundary"))
43  {
44  std::vector<BoundaryName> initiation_boundary_names =
45  getParam<std::vector<BoundaryName>>("initiate_on_boundary");
46  _initiation_boundary_ids = _mesh.getBoundaryIDs(initiation_boundary_names, true);
47  }
48 }
49 
50 void
52 {
53  _marked_elems.clear();
55  .clear(); // mark the fragment which has secondary crack growing from the primary crack
56  _marked_elem_sides.clear();
57 }
58 
59 void
61 {
62  RealVectorValue direction;
63  bool isCut = _xfem->isElemCut(_current_elem);
64  bool isCTE = _xfem->isElemAtCrackTip(_current_elem);
65  bool isOnBoundary = false;
66  unsigned int boundarySide = 99999;
67  unsigned int _current_eid = _current_elem->id();
68  std::map<unsigned int, RealVectorValue>::iterator mit;
69  mit = _marked_elems.find(_current_eid);
70 
71  for (unsigned int i = 0; i < _initiation_boundary_ids.size(); ++i)
72  {
73  if (_mesh.isBoundaryElem(_current_eid, _initiation_boundary_ids[i]))
74  {
75  isOnBoundary = true;
76  boundarySide = _mesh.sideWithBoundaryID(_current_elem, _initiation_boundary_ids[i]);
77  }
78  }
79 
80  if (isCTE && doesElementCrack(direction))
81  {
82  if (mit != _marked_elems.end())
83  {
84  mooseError("ERROR: element ", _current_eid, " already marked for crack growth.");
85  }
86  _marked_elems[_current_eid] = direction;
87  }
88  else if (isOnBoundary && doesElementCrack(direction))
89  {
90  if (mit != _marked_elems.end())
91  {
92  mooseError("ERROR: element ", _current_eid, " already marked for crack growth.");
93  }
94  _marked_elems[_current_eid] = direction;
95  _marked_elem_sides[_current_eid] = boundarySide;
96  }
97  else if (isCut && _secondary_cracks && doesElementCrack(direction))
98  {
99  if (mit != _marked_elems.end())
100  {
101  mooseError("ERROR: element ", _current_eid, " already marked for crack growth.");
102  }
103  _marked_elems[_current_eid] = direction;
104  _marked_frags.insert(_current_eid);
105  }
106 }
107 
108 void
109 XFEMMarkerUserObject::threadJoin(const UserObject & y)
110 {
111  const XFEMMarkerUserObject & xmuo = dynamic_cast<const XFEMMarkerUserObject &>(y);
112 
113  for (std::map<unsigned int, RealVectorValue>::const_iterator mit = xmuo._marked_elems.begin();
114  mit != xmuo._marked_elems.end();
115  ++mit)
116  {
117  _marked_elems[mit->first] = mit->second; // TODO do error checking for duplicates here too
118  }
119 
120  for (std::set<unsigned int>::const_iterator mit = xmuo._marked_frags.begin();
121  mit != xmuo._marked_frags.end();
122  ++mit)
123  {
124  _marked_frags.insert(*mit); // TODO do error checking for duplicates here too
125  }
126 
127  for (std::map<unsigned int, unsigned int>::const_iterator mit = xmuo._marked_elem_sides.begin();
128  mit != xmuo._marked_elem_sides.end();
129  ++mit)
130  {
131  _marked_elem_sides[mit->first] = mit->second; // TODO do error checking for duplicates here too
132  }
133 }
134 
135 void
137 {
138  _communicator.set_union(_marked_elems);
139  _communicator.set_union(_marked_frags);
140  _communicator.set_union(_marked_elem_sides);
141 
142  _xfem->clearStateMarkedElems();
143  std::map<unsigned int, RealVectorValue>::iterator mit;
144  for (mit = _marked_elems.begin(); mit != _marked_elems.end(); ++mit)
145  {
146  if (_marked_elem_sides.find(mit->first) != _marked_elem_sides.end())
147  {
148  _xfem->addStateMarkedElem(mit->first, mit->second, _marked_elem_sides[mit->first]);
149  }
150  else if (_marked_frags.find(mit->first) != _marked_frags.end())
151  {
152  _xfem->addStateMarkedFrag(mit->first, mit->second);
153  }
154  else
155  {
156  _xfem->addStateMarkedElem(mit->first, mit->second);
157  }
158  }
159  _marked_elems.clear();
160  _marked_frags.clear();
161  _marked_elem_sides.clear();
162 }
163 
164 bool
165 XFEMMarkerUserObject::doesElementCrack(RealVectorValue & direction)
166 {
167  direction(1) = 1.0;
168  return true;
169 }
std::set< unsigned int > _marked_frags
virtual bool doesElementCrack(RealVectorValue &direction)
std::map< unsigned int, RealVectorValue > _marked_elems
std::vector< BoundaryID > _initiation_boundary_ids
MooseSharedPointer< XFEM > _xfem
XFEMMarkerUserObject(const InputParameters &parameters)
Factory constructor, takes parameters so that all derived classes can be built using the same constru...
This is the XFEM class.
Definition: XFEM.h:60
InputParameters validParams< XFEMMarkerUserObject >()
Coupled auxiliary value.
std::map< unsigned int, unsigned int > _marked_elem_sides
virtual void threadJoin(const UserObject &y)