https://mooseframework.inl.gov
ComboCutUserObject.C
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 #include "ComboCutUserObject.h"
11 
13 
16 {
18  params.addClassDescription("Combine multiple geometric cut userobjects.");
19  params.addRequiredParam<std::vector<UserObjectName>>(
20  "geometric_cut_userobjects", "Vector of geometric cut userobjects to combine");
21  params.addRequiredParam<std::vector<std::vector<CutSubdomainID>>>(
22  "cut_subdomain_combinations",
23  "Possible combinations of the cut subdomain IDs. The sequence of each combination should "
24  "follow the sequence provided in the geometric_cut_userobjects parameter. Use semicolons to "
25  "separate different combinations.");
26  params.addRequiredParam<std::vector<CutSubdomainID>>(
27  "cut_subdomains", "Resulting combined cut subdomain IDs for each of the combination.");
28 
29  return params;
30 }
31 
33  : GeometricCutUserObject(parameters),
34  _cut_names(getParam<std::vector<UserObjectName>>("geometric_cut_userobjects")),
35  _num_cuts(_cut_names.size()),
36  _cuts(_num_cuts),
37  _keys(getParam<std::vector<std::vector<CutSubdomainID>>>("cut_subdomain_combinations")),
38  _vals(getParam<std::vector<CutSubdomainID>>("cut_subdomains"))
39 {
40  for (unsigned int i = 0; i < _num_cuts; i++)
41  _cuts[i] = &getUserObjectByName<GeometricCutUserObject>(_cut_names[i]);
42 
43  buildMap();
44 }
45 
46 void
48 {
49  for (const auto & combo : _keys)
50  if (combo.size() != _num_cuts)
51  mooseError("Expected multiples of ", _num_cuts, " keys, but got ", combo.size(), " keys.");
52 
53  unsigned int num_combos = _keys.size();
54 
55  if (_vals.size() != num_combos)
56  mooseError("Expected one value for each of the combination, got ",
57  num_combos,
58  " combinations, but got ",
59  _vals.size(),
60  " values.");
61 
62  for (unsigned int i = 0; i < num_combos; i++)
63  _combo_ids.emplace(_keys[i], _vals[i]);
64 }
65 
66 bool
68  std::vector<Xfem::CutEdge> & cut_edges,
69  std::vector<Xfem::CutNode> & cut_nodes) const
70 {
71  unsigned int i_want_to_cut = 0;
72  for (auto cut : _cuts)
73  if (cut->cutElementByGeometry(elem, cut_edges, cut_nodes))
74  i_want_to_cut++;
75 
76  // TODO: Currently we error out if more than one cut userobject wants to do the cutting. We need
77  // to remove this limitation once we add the ability to handle multiple cuts.
78  if (i_want_to_cut > 1)
79  mooseError("More than one GeometricCutUserObject want to cut the same element.");
80 
81  return i_want_to_cut > 0;
82 }
83 
84 bool
86  std::vector<Xfem::CutFace> & cut_faces) const
87 {
88  unsigned int i_want_to_cut = 0;
89  for (auto cut : _cuts)
90  if (cut->cutElementByGeometry(elem, cut_faces))
91  i_want_to_cut++;
92 
93  // TODO: Currently we error out if more than one cut userobject wants to do the cutting. We need
94  // to remove this limitation once we add the ability to handle multiple cuts.
95  if (i_want_to_cut > 1)
96  mooseError("More than one GeometricCutUserObject want to cut the same element.");
97 
98  return i_want_to_cut > 0;
99 }
100 
101 bool
102 ComboCutUserObject::cutFragmentByGeometry(std::vector<std::vector<Point>> & frag_edges,
103  std::vector<Xfem::CutEdge> & cut_edges) const
104 {
105  unsigned int i_want_to_cut = 0;
106  for (auto cut : _cuts)
107  if (cut->cutFragmentByGeometry(frag_edges, cut_edges))
108  i_want_to_cut++;
109 
110  // TODO: Currently we error out if more than one cut userobject wants to do the cutting. We need
111  // to remove this limitation once we add the ability to handle multiple cuts.
112  if (i_want_to_cut > 1)
113  mooseError("More than one GeometricCutUserObject want to cut the same fragment.");
114 
115  return i_want_to_cut > 0;
116 }
117 
118 bool
119 ComboCutUserObject::cutFragmentByGeometry(std::vector<std::vector<Point>> & frag_faces,
120  std::vector<Xfem::CutFace> & cut_faces) const
121 {
122  unsigned int i_want_to_cut = 0;
123  for (auto cut : _cuts)
124  if (cut->cutFragmentByGeometry(frag_faces, cut_faces))
125  i_want_to_cut++;
126 
127  // TODO: Currently we error out if more than one cut userobject wants to do the cutting. We need
128  // to remove this limitation once we add the ability to handle multiple cuts.
129  if (i_want_to_cut > 1)
130  mooseError("More than one GeometricCutUserObject want to cut the same fragment.");
131 
132  return i_want_to_cut > 0;
133 }
134 
137 {
138  std::vector<CutSubdomainID> combo_key;
139  for (auto cut : _cuts)
140  combo_key.push_back(cut->getCutSubdomainID(node));
141 
142  try
143  {
144  CutSubdomainID combo_id = _combo_ids.at(combo_key);
145  return combo_id;
146  }
147  catch (std::out_of_range &)
148  {
149  throw MooseException(name() + ": Unknown cut subdomain combination.");
150  }
151 }
static InputParameters validParams()
Factory constructor, takes parameters so that all derived classes can be built using the same constru...
const std::vector< std::vector< CutSubdomainID > > _keys
Keys read from the input file, to be parsed by buildMap()
std::vector< const GeometricCutUserObject * > _cuts
Vector of points to the GeometricCutUserObjects to be combined.
unsigned int _num_cuts
Number of geometric cuts to be combined.
static InputParameters validParams()
virtual const std::string & name() const
registerMooseObject("XFEMApp", ComboCutUserObject)
void addRequiredParam(const std::string &name, const std::string &doc_string)
unsigned int CutSubdomainID
Definition: XFEMAppTypes.h:18
virtual bool cutElementByGeometry(const Elem *elem, std::vector< Xfem::CutEdge > &cut_edges, std::vector< Xfem::CutNode > &cut_nodes) const override
Loop over all the provided GeometricCutUserObjects, fill the data structures based on each cut that w...
virtual CutSubdomainID getCutSubdomainID(const Node *node) const override
ComboCutUserObject(const InputParameters &parameters)
const std::vector< UserObjectName > _cut_names
Vector of names of GeometricCutUserObjects to be combined.
virtual bool cutFragmentByGeometry(std::vector< std::vector< Point >> &frag_edges, std::vector< Xfem::CutEdge > &cut_edges) const override
Loop over all the provided GeometricCutUserObjects, fill the data structures based on each cut that w...
void buildMap()
Helper function to build the dictionary for composite CutSubdomainID look-up.
void mooseError(Args &&... args) const
void addClassDescription(const std::string &doc_string)
const std::vector< CutSubdomainID > _vals
Values read from the input file, to be parsed by buildMap()
std::map< std::vector< CutSubdomainID >, CutSubdomainID > _combo_ids
The dictionary for composite CutSubdomainID look-up.