Cardinal
MoabSkinner.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include "GeneralUserObject.h"
4 #include "MaterialBase.h"
5 #include "MooseMesh.h"
6 
7 #include "moab/Core.hpp"
8 #include "moab/Skinner.hpp"
9 #include "moab/GeomTopoTool.hpp"
10 #include "MBTagConventions.hpp"
11 
19 class MoabSkinner : public GeneralUserObject
20 {
21 public:
22  MoabSkinner(const InputParameters & parameters);
23 
24  static InputParameters validParams();
25 
26  virtual void execute() override;
27 
28  virtual void initialize() override;
29 
30  virtual void finalize() override;
31 
32  virtual void threadJoin(const UserObject & /* uo */) override {}
33 
39  virtual moab::ErrorCode check(const moab::ErrorCode input) const;
40 
41  std::string materialName(const unsigned int & block, const unsigned int & density, const unsigned int & temp) const;
42 
44  virtual void update();
45 
51  virtual void setMaterialNames(std::vector<std::string> names) { _material_names = names; }
52 
57  unsigned int nBins() const;
58 
64  virtual unsigned int getTemperatureBin(const Elem * const elem) const;
65 
71  virtual unsigned int getDensityBin(const Elem * const elem) const;
72 
78  virtual unsigned int getSubdomainBin(const Elem * const elem) const
79  {
80  return _blocks.at(elem->subdomain_id());
81  }
82 
87  virtual void setScaling(const Real & scale) { _scaling = scale; }
88 
93  virtual void setVerbosity(const bool & verbose) { _verbose = verbose; }
94 
99  virtual void makeDependentOnExternalAction() { _standalone = false; }
100 
107  unsigned int getAuxiliaryVariableNumber(const std::string & name,
108  const std::string & param_name) const;
109 
111  void reset();
112 
120  virtual unsigned int getBin(const unsigned int & temp_bin,
121  const unsigned int & density_bin,
122  const unsigned int & subdomain_bin) const;
123 
128  virtual const bool & hasGraveyard() const { return _build_graveyard; }
129 
134  void setGraveyard(bool build);
135 
141  virtual unsigned int nDensityBins() const { return _n_density_bins; }
142 
147  virtual bool hasDensitySkinning() const { return _bin_by_density; }
148 
153  const std::shared_ptr<moab::Interface> & moabPtr() const { return _moab; }
154 
155 protected:
156  std::unique_ptr<NumericVector<Number>> _serialized_solution;
157 
159  std::shared_ptr<moab::Interface> _moab;
160 
162  bool _verbose;
163 
165  const std::string & _temperature_name;
166 
168  const Real & _temperature_min;
169 
171  const Real & _temperature_max;
172 
174  const unsigned int & _n_temperature_bins;
175 
178 
180  const bool _bin_by_density;
181 
184  std::vector<std::string> _material_names;
185 
187  const Real & _faceting_tol;
188 
190  const Real & _geom_tol;
191 
194 
197 
199  const bool & _output_skins;
200 
202  const bool & _output_full;
203 
209 
211  const bool & _use_displaced;
212 
214  Real _scaling;
215 
217  unsigned int _n_write;
218 
221 
223  enum Sense
224  {
225  BACKWARDS = -1,
227  };
228 
230  struct VolData
231  {
232  moab::EntityHandle vol;
234  };
235 
237  MooseMesh & getMooseMesh();
244  void createMOABElems();
245 
247  virtual void createTags();
248 
255  void createGroup(const unsigned int & id, const std::string & name, moab::EntityHandle & group_set);
256 
258  void createVol(const unsigned int & id, moab::EntityHandle & volume_set, moab::EntityHandle group_set);
259 
261  void createSurf(const unsigned int & id,
262  moab::EntityHandle & surface_set,
263  moab::Range & faces,
264  const std::vector<VolData> & voldata);
265 
267  void createSurfaces(moab::Range & reversed, VolData & voldata, unsigned int & surf_id);
268 
272  void createSurfaceFromBox(const BoundingBox & box,
273  const VolData & voldata,
274  unsigned int & surf_id,
275  bool normalout,
276  const Real & factor);
277 
284  std::vector<moab::EntityHandle> createNodesFromBox(const BoundingBox & box,
285  const Real & factor) const;
286 
288  void createCornerTris(const std::vector<moab::EntityHandle> & verts,
289  unsigned int corner,
290  unsigned int v1,
291  unsigned int v2,
292  unsigned int v3,
293  bool normalout,
294  moab::Range & surface_tris);
295 
297  moab::EntityHandle createTri(const std::vector<moab::EntityHandle> & vertices,
298  unsigned int v1,
299  unsigned int v2,
300  unsigned int v3);
301 
303  void updateSurfData(moab::EntityHandle surface_set, const VolData & data);
304 
306  void
307  setTags(moab::EntityHandle ent, std::string name, std::string category, unsigned int id, int dim);
308 
310  void setTagData(moab::Tag tag, moab::EntityHandle ent, std::string data, unsigned int SIZE);
311 
313  void setTagData(moab::Tag tag, moab::EntityHandle ent, void * data);
314 
319  const std::vector<std::vector<unsigned int>> & getTetSets(ElemType type) const;
320 
333  void buildGraveyard(unsigned int & vol_id, unsigned int & surf_id);
334 
336  virtual void findBlocks();
337 
339  virtual void sortElemsByResults();
340 
342  void findSurfaces();
343 
346  void groupLocalElems(std::set<dof_id_type> elems, std::vector<moab::Range> & localElems);
347 
349  bool resetMOAB();
350 
352  void findSurface(const moab::Range & region,
353  moab::EntityHandle group,
354  unsigned int & vol_id,
355  unsigned int & surf_id,
356  moab::EntityHandle & volume_set);
357 
359  virtual void write();
360 
362  std::unique_ptr<moab::Skinner> skinner;
363 
365  std::unique_ptr<moab::GeomTopoTool> gtt;
366 
368  std::map<dof_id_type, std::vector<moab::EntityHandle>> _id_to_elem_handles;
369 
371  moab::EntityHandle offset;
372 
374  std::string _density_name;
375 
378 
381 
384 
386  unsigned int _n_density_bins;
387 
389  unsigned int _n_block_bins;
390 
392  std::vector<std::set<dof_id_type>> _elem_bins;
393 
395  std::map<SubdomainID, unsigned int> _blocks;
396 
398  moab::EntityHandle _all_tets;
399 
401  std::map<moab::EntityHandle, std::vector<VolData>> surfsToVols;
402 
405 
407  moab::Tag id_tag;
408 
410  moab::Tag faceting_tol_tag;
411 
414 
416  moab::Tag category_tag;
417 
419  moab::Tag name_tag;
420 
422  std::vector<Real> _temperature_bin_bounds;
423 
425  std::vector<Real> _density_bin_bounds;
426 
428  std::vector<std::vector<unsigned int>> _tet4_nodes;
429 
434  std::vector<std::vector<unsigned int>> _tet10_nodes;
435 
437  unsigned int _temperature_var_num;
438 
440  unsigned int _density_var_num;
441 
443  const unsigned int NODES_PER_MOAB_TET = 4;
444 
446  const Real BIN_TOLERANCE = 1e-6;
447 };
const Real _temperature_bin_width
Temperature bin width.
Definition: MoabSkinner.h:177
std::vector< std::string > _material_names
Definition: MoabSkinner.h:184
virtual void makeDependentOnExternalAction()
Definition: MoabSkinner.h:99
void createSurfaces(moab::Range &reversed, VolData &voldata, unsigned int &surf_id)
Helper method to create MOAB surfaces with no overlaps.
const std::vector< std::vector< unsigned int > > & getTetSets(ElemType type) const
std::shared_ptr< moab::Interface > _moab
MOAB interface.
Definition: MoabSkinner.h:159
const Real & _temperature_min
Lower bound of temperature bins.
Definition: MoabSkinner.h:168
unsigned int _density_var_num
Auxiliary variable number for density.
Definition: MoabSkinner.h:440
const Real & _temperature_max
Upper bound of temperature bins.
Definition: MoabSkinner.h:171
bool _standalone
Whether this class runs by itself, or is controlled by an external class.
Definition: MoabSkinner.h:220
std::map< moab::EntityHandle, std::vector< VolData > > surfsToVols
Save some topological data: map from surface handle to vol handle and sense.
Definition: MoabSkinner.h:401
virtual void write()
Write MOAB volume and/or skin meshes to file.
static InputParameters validParams()
std::string materialName(const unsigned int &block, const unsigned int &density, const unsigned int &temp) const
virtual unsigned int getTemperatureBin(const Elem *const elem) const
void findSurface(const moab::Range &region, moab::EntityHandle group, unsigned int &vol_id, unsigned int &surf_id, moab::EntityHandle &volume_set)
Find the surfaces for the provided range and add to group.
virtual void initialize() override
bool _verbose
Whether to print diagnostic information.
Definition: MoabSkinner.h:162
void createSurfaceFromBox(const BoundingBox &box, const VolData &voldata, unsigned int &surf_id, bool normalout, const Real &factor)
std::string _density_name
Name of the MOOSE variable containing the density.
Definition: MoabSkinner.h:374
virtual void update()
Perform the skinning operation.
std::vector< std::set< dof_id_type > > _elem_bins
Mapping from total bin ID to a set of elements sorted into that bin.
Definition: MoabSkinner.h:392
void createSurf(const unsigned int &id, moab::EntityHandle &surface_set, moab::Range &faces, const std::vector< VolData > &voldata)
Helper method to create MOAB surface entity set.
void findSurfaces()
Group the binned elems into local temperature regions and find their surfaces.
unsigned int _n_block_bins
Number of block bins.
Definition: MoabSkinner.h:389
std::vector< Real > _density_bin_bounds
Bounds of the density bins.
Definition: MoabSkinner.h:425
unsigned int _n_density_bins
Number of density bins.
Definition: MoabSkinner.h:386
virtual void threadJoin(const UserObject &) override
Definition: MoabSkinner.h:32
virtual void finalize() override
std::unique_ptr< moab::GeomTopoTool > gtt
Topology tool for setting surface sense.
Definition: MoabSkinner.h:365
MoabSkinner(const InputParameters &parameters)
void setTagData(moab::Tag tag, moab::EntityHandle ent, std::string data, unsigned int SIZE)
Helper function to wrap moab::tag_set_data for a string.
unsigned int nBins() const
Definition: MoabSkinner.h:225
void groupLocalElems(std::set< dof_id_type > elems, std::vector< moab::Range > &localElems)
Real _density_bin_width
Density bin width.
Definition: MoabSkinner.h:383
void createMOABElems()
moab::EntityHandle createTri(const std::vector< moab::EntityHandle > &vertices, unsigned int v1, unsigned int v2, unsigned int v3)
Create MOAB tri surface element.
virtual unsigned int getBin(const unsigned int &temp_bin, const unsigned int &density_bin, const unsigned int &subdomain_bin) const
virtual void setScaling(const Real &scale)
Definition: MoabSkinner.h:87
const std::shared_ptr< moab::Interface > & moabPtr() const
Definition: MoabSkinner.h:153
moab::Tag name_tag
Tag for name of entity set.
Definition: MoabSkinner.h:419
virtual bool hasDensitySkinning() const
Definition: MoabSkinner.h:147
const std::string & _temperature_name
Name of the temperature variable.
Definition: MoabSkinner.h:165
moab::Tag geometry_dimension_tag
Tag for dimension for geometry.
Definition: MoabSkinner.h:404
void createGroup(const unsigned int &id, const std::string &name, moab::EntityHandle &group_set)
virtual unsigned int nDensityBins() const
Definition: MoabSkinner.h:141
moab::Tag id_tag
Tag for entitiy set ID.
Definition: MoabSkinner.h:407
const bool & _use_displaced
Whether the skinned mesh should be generated from a displaced mesh.
Definition: MoabSkinner.h:211
Definition: CardinalEnums.h:206
unsigned int getAuxiliaryVariableNumber(const std::string &name, const std::string &param_name) const
std::unique_ptr< NumericVector< Number > > _serialized_solution
Definition: MoabSkinner.h:156
const bool & _output_skins
Whether to output the MOAB mesh skins to a .h5m file.
Definition: MoabSkinner.h:199
virtual void setVerbosity(const bool &verbose)
Definition: MoabSkinner.h:93
int dim()
std::map< dof_id_type, std::vector< moab::EntityHandle > > _id_to_elem_handles
Map from libmesh id to MOAB element entity handles.
Definition: MoabSkinner.h:368
MooseMesh & getMooseMesh()
Moose mesh.
const Real & _graveyard_scale_outer
Multiplier on bounding box for outer surface of graveyard.
Definition: MoabSkinner.h:196
const bool & _output_full
Whether to output the MOAB mesh to a .h5m file.
Definition: MoabSkinner.h:202
std::unique_ptr< moab::Skinner > skinner
Moab skinner for finding temperature surfaces.
Definition: MoabSkinner.h:362
void createCornerTris(const std::vector< moab::EntityHandle > &verts, unsigned int corner, unsigned int v1, unsigned int v2, unsigned int v3, bool normalout, moab::Range &surface_tris)
Create 3 tri faces stemming from one corner of a cude (an open tetrahedron)
Real _scaling
Length multiplier to get from [Mesh] units into OpenMC's centimeters.
Definition: MoabSkinner.h:214
moab::Tag geometry_resabs_tag
Tag needed by DAGMC.
Definition: MoabSkinner.h:413
std::vector< std::vector< unsigned int > > _tet4_nodes
Node ordering for a TET4 MOAB element, based on libMesh node numberings.
Definition: MoabSkinner.h:428
Sense
Encode the whether the surface normal faces into or out of the volume.
Definition: MoabSkinner.h:223
void buildGraveyard(unsigned int &vol_id, unsigned int &surf_id)
Build a graveyard volume around the domain.
std::vector< moab::EntityHandle > createNodesFromBox(const BoundingBox &box, const Real &factor) const
moab::Tag faceting_tol_tag
Tag for faceting tolerance.
Definition: MoabSkinner.h:410
void createVol(const unsigned int &id, moab::EntityHandle &volume_set, moab::EntityHandle group_set)
Helper method to create MOAB volume entity set.
unsigned int _n_write
Count number of times output files have been written.
Definition: MoabSkinner.h:217
moab::EntityHandle offset
Save the first tet entity handle.
Definition: MoabSkinner.h:371
virtual unsigned int getSubdomainBin(const Elem *const elem) const
Definition: MoabSkinner.h:78
Sense sense
Definition: MoabSkinner.h:233
moab::EntityHandle _all_tets
Entity handle to represent the set of all tets.
Definition: MoabSkinner.h:398
const Real & _graveyard_scale_inner
Multiplier on bounding box for inner surface of graveyard.
Definition: MoabSkinner.h:193
virtual moab::ErrorCode check(const moab::ErrorCode input) const
Definition: MoabSkinner.h:226
std::map< SubdomainID, unsigned int > _blocks
Blocks in the [Mesh].
Definition: MoabSkinner.h:395
virtual void sortElemsByResults()
Sort all the elements in the [Mesh] into bins for temperature, density, and subdomain.
const unsigned int & _n_temperature_bins
Number of temperature bins.
Definition: MoabSkinner.h:174
virtual void setMaterialNames(std::vector< std::string > names)
Definition: MoabSkinner.h:51
bool resetMOAB()
Clear MOAB entity sets.
const Real & _geom_tol
Geometry tolerence needed by DAGMC.
Definition: MoabSkinner.h:190
void setTags(moab::EntityHandle ent, std::string name, std::string category, unsigned int id, int dim)
Generic method to set the tags that DAGMC requires.
virtual unsigned int getDensityBin(const Elem *const elem) const
Real _density_max
Upper bound of density bins.
Definition: MoabSkinner.h:380
Skins the [Mesh] according to individual bins for temperature, density, and subdomain ID.
Definition: MoabSkinner.h:19
virtual void findBlocks()
Store a mapping from [Mesh] subdomain IDs to an index, to be used for binning by block ID.
moab::EntityHandle vol
Definition: MoabSkinner.h:232
std::vector< std::vector< unsigned int > > _tet10_nodes
Definition: MoabSkinner.h:434
bool _build_graveyard
Definition: MoabSkinner.h:208
moab::Tag category_tag
Tag for type of entity set.
Definition: MoabSkinner.h:416
const bool _bin_by_density
Whether elements are binned by density (in addition to temperature and block)
Definition: MoabSkinner.h:180
const Real BIN_TOLERANCE
Tolerance to use for comparing values to bin bounds.
Definition: MoabSkinner.h:446
const Real & _faceting_tol
Faceting tolerence needed by DAGMC.
Definition: MoabSkinner.h:187
void setGraveyard(bool build)
virtual void execute() override
virtual const bool & hasGraveyard() const
Definition: MoabSkinner.h:128
Encode MOAB information about volumes needed when creating surfaces.
Definition: MoabSkinner.h:230
Real _density_min
Lower bound of density bins.
Definition: MoabSkinner.h:377
void updateSurfData(moab::EntityHandle surface_set, const VolData &data)
Add parent-child metadata relating a surface to its volume.
void reset()
Clear mesh data.
const unsigned int NODES_PER_MOAB_TET
Number of nodes per MOAB tet (which are first order, so TET4)
Definition: MoabSkinner.h:443
std::vector< Real > _temperature_bin_bounds
Bounds of the temperature bins.
Definition: MoabSkinner.h:422
virtual void createTags()
Helper method to create MOAB tags.
unsigned int _temperature_var_num
Auxiliary variable number for temperature.
Definition: MoabSkinner.h:437