• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

aurora-multiphysics / aurora / #31

pending completion
#31

push

coveralls-python

web-flow
Update CI (#41)

- Add scripts to build all dependencies and aurora, may be employed by users
- Refactor docker files to use scripts
- Multi-stage docker build to reduce final docker image size
- Add scheduled action to build dependencies and publish docker images
- Scripts to assist with publishing docker images and generating test coverage report
---------
Co-authored-by: Patrick Shriwise <pshriwise@gmail.com>

1138 of 1278 relevant lines covered (89.05%)

354634.23 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/openmc/include/userobject/MoabUserObject.h
1
#pragma once
2

3
// MOOSE includes
4
#include "UserObject.h"
5
#include "MaterialBase.h"
6

7
// MOAB includes
8
#include "moab/Core.hpp"
9
#include "moab/Skinner.hpp"
10
#include "moab/GeomTopoTool.hpp"
11
#include "MBTagConventions.hpp"
12

13
// Libmesh includes
14
#include <libmesh/elem.h>
15
#include <libmesh/enum_io_package.h>
16
#include <libmesh/enum_order.h>
17
#include <libmesh/enum_fe_family.h>
18
#include <libmesh/equation_systems.h>
19
#include <libmesh/system.h>
20
#include <libmesh/mesh_tools.h>
21
#include <libmesh/mesh_function.h>
22

23
/// Convenience struct
24
struct MOABMaterialProperties{
25
  double rel_density;
26
  double temp;
27
};
28

29

30
// Forward Declarations
31
class MoabUserObject;
32

33

34
/**
35
    \brief UserObject class which wraps a moab::Interface pointer.
36

37
    The main role of this class is to bin elements of the mesh
38
    according named variables (presumed temperature and density),
39
    and subsequently perform a skinning operation to find the
40
    surfaces of these local regions.
41
 */
42
class MoabUserObject : public UserObject
43
{
44
 public:
45

46
  MoabUserObject(const InputParameters & parameters);
47

48
  static InputParameters validParams();
49

50
  /// Override MOOSE virtual method to do nothing
51
  virtual void execute(){};
52
  /// Override MOOSE virtual method to do nothing
53
  virtual void initialize(){};
54
  /// Override MOOSE virtual method to do nothing
55
  virtual void finalize(){};
56
  /// Override MOOSE virtual method to do nothing
57
  virtual void threadJoin(const UserObject & /*uo*/){};
58

59
  /// Pass in the FE Problem
60
  void setProblem(FEProblemBase * problem) {
61
    if(problem==nullptr)
62
      throw std::logic_error("Problem passed is null");
63
    _problem_ptr = problem;
64
  } ;
65

66
  /// Check if problem has been set
67
  bool hasProblem(){ return !( _problem_ptr == nullptr ); };
×
68

69
  /// Get a reference to the FE problem
70
  FEProblemBase& problem();
71

72
  /// Initialise MOAB
73
  void initMOAB();
74

75
  /// Intialise objects needed to perform binning of elements
76
  void initBinningData();
77

78
  /// Clear mesh data
79
  void reset();
80

81
  /// Update MOAB with any results from MOOSE
82
  bool update();
83

84
  /// Pass the OpenMC results into the libMesh systems solution
85
  bool setSolution(std::string var_now,std::vector< double > &results, double scaleFactor=1., bool isErr=false, bool normToVol=true);
86

87
  /// Retrieve a list of original material names and properties
88
  void getMaterialProperties(std::vector<std::string>& mat_names_out,
89
                             std::vector<double>& initial_densities,
90
                             std::vector<std::string>& tails,
91
                             std::vector<MOABMaterialProperties>& properties);
92

93
  /// Publically available pointer to MOAB interface
94
  std::shared_ptr<moab::Interface> moabPtr;
95

96
private:
97

98
  // Private types
99

100
  /// Encode the whether the surface normal faces into or out of the volume
101
  enum Sense { BACKWARDS=-1, FORWARDS=1};
102

103
  /// \brief Encode MOAB information about volumes needed when creating surfaces
104
  struct VolData{
105
    moab::EntityHandle vol;
106
    Sense sense;
107
  };
108

109
  // Private methods
110

111
  /// Get a modifyable reference to the underlying libmesh mesh.
112
  MeshBase& mesh();
113

114
  /// Get a modifyable reference to the underlying libmesh equation systems
115
  EquationSystems & systems();
116

117
  /// Get a modifyable reference to the underlying libmesh system
118
  System& system(std::string var_now);
119

120
  // Helper methods to set MOAB database
121

122
  /// Helper method to create MOAB nodes
123
  moab::ErrorCode createNodes(std::map<dof_id_type,moab::EntityHandle>& node_id_to_handle);
124
  /// Helper method to create MOAB elements
125
  void createElems(std::map<dof_id_type,moab::EntityHandle>& node_id_to_handle);
126

127
  /// Helper method to create MOAB tags
128
  moab::ErrorCode createTags();
129

130
  /// Helper method to create MOAB group entity set
131
  moab::ErrorCode createGroup(unsigned int id, std::string name,moab::EntityHandle& group_set);
132

133
  /// Helper method to create MOAB volume entity set
134
  moab::ErrorCode createVol(unsigned int id,moab::EntityHandle& volume_set,moab::EntityHandle group_set);
135

136
  /// Helper method to create MOAB surface entity set
137
  moab::ErrorCode createSurf(unsigned int id,moab::EntityHandle& surface_set, moab::Range& faces,  std::vector<VolData> & voldata);
138

139
  /// Helper method to create MOAB surfaces with no overlaps
140
  moab::ErrorCode createSurfaces(moab::Range& reversed, VolData& voldata, unsigned int& surf_id);
141

142
  /// Create a MOAB surface from a bounding box
143
  moab::ErrorCode createSurfaceFromBox(const BoundingBox& box, VolData& voldata, unsigned int& surf_id, bool normalout, double factor=1.0);
144

145
  /// Create MOAB nodes from a bounding box
146
  moab::ErrorCode createNodesFromBox(const BoundingBox& box,double factor,std::vector<moab::EntityHandle>& vert_handles);
147

148
  /// Create 3 tri faces stemming from one corner of a cude (an open tetrahedron)
149
  moab::ErrorCode createCornerTris(const std::vector<moab::EntityHandle> & verts,
150
                                   unsigned int corner, unsigned int v1,
151
                                   unsigned int v2 ,unsigned int v3,
152
                                   bool normalout, moab::Range &surface_tris);
153

154
  /// Create MOAB tri surface element
155
  moab::ErrorCode createTri(const std::vector<moab::EntityHandle> & vertices,unsigned int v1, unsigned int v2 ,unsigned int v3, moab::Range &surface_tris);
156

157
  /// Add parent-child metadata relating a surface to its volume
158
  moab::ErrorCode updateSurfData(moab::EntityHandle surface_set,VolData data);
159

160
  /// Generic method to set the tags that DAGMC requires
161
  moab::ErrorCode setTags(moab::EntityHandle ent,std::string name, std::string category, unsigned int id, int dim);
162

163
  /// Helper function to wrap moab::tag_set_data for a string
164
  moab::ErrorCode setTagData(moab::Tag tag, moab::EntityHandle ent, std::string data, unsigned int SIZE);
165

166
  /// Helper function to wrap moab::tag_set_data for a generic pointer
167
  moab::ErrorCode setTagData(moab::Tag tag, moab::EntityHandle ent, void* data);
168

169
  /// Return all sets of node indices for sub-tetrahedra if we have a second order mesh
170
  bool getTetSets(ElemType type, std::vector< std::vector<unsigned int> > &perms);
171

172
  /// Build the graveyard (needed by OpenMC)
173
  moab::ErrorCode buildGraveyard(unsigned int & vol_id, unsigned int & surf_id);
174

175
  /// Get the coords of the box back as an array (possibly scaled)
176
  std::vector<Point> boxCoords(const BoundingBox& box, double factor);
177

178
  /// Look for materials in the FE problem
179
  void findMaterials();
180

181
  /// Clear the maps between entity handles and dof ids
182
  void clearElemMaps();
183

184
  /// Add an element to maps
185
  void addElem(dof_id_type id,moab::EntityHandle ent);
186

187
  /// Helper method to set the results in a given system and variable
188
  void setSolution(unsigned int iSysNow, unsigned int iVarNow,std::vector< double > &results, double scaleFactor, bool isErr, bool normToVol);
189

190
  /// Helper method to convert between elem / solution indices
191
  dof_id_type elem_to_soln_index(const Elem& elem,unsigned int iSysNow, unsigned int iVarNow);
192

193
  /// Get a serialised version of solution for a given system
194
  NumericVector<Number>& getSerialisedSolution(libMesh::System* sysPtr);
195

196
  /// Create and save a mesh function for the provided variable
197
  void setMeshFunction(std::string var_name_in);
198

199
  /// Evaluate a mesh function at a point
200
  double evalMeshFunction(std::shared_ptr<MeshFunction> meshFunctionPtr,
201
                          const Point& p);
202

203
  /// Fetch the mesh function associated with a variable
204
  std::shared_ptr<MeshFunction> getMeshFunction(std::string var_name_in);
205

206
  /// Sort elems in to bins of a given temperature
207
  bool sortElemsByResults();
208

209
  /// Group the binned elems into local temperature regions and find their surfaces
210
  bool findSurfaces();
211

212
  /// Group a given bin into local regions
213
  /// NB elems in param is a copy, localElems is a reference
214
  void groupLocalElems(std::set<dof_id_type> elems, std::vector<moab::Range>& localElems);
215

216
  /// Given a value of our variable, find what bin this corresponds to.
217
  int getResultsBin(double value);
218
  /// Find results bin if we have linear binning
219
  inline int getResultsBinLin(double value);
220
    /// Find results bin if we have logarithmic
221
  int getResultsBinLog(double value);
222
  /// Return the bin index of a given relative density
223
  inline int getRelDensityBin(double value);
224

225
  /// Map material, density and temp bin indices onto a linearised index
226
  int getSortBin(int iVarBin, int iDenBin, int iMat,
227
                 int nVarBinsIn, int nDenBinsIn,int nMatsIn);
228
  /// Map material, density and temp bin indices onto a linearised index
229
  /// with default parameters for number of bins
230
  int getSortBin(int iVarBin, int iDenBin, int iMat){
231
    return getSortBin(iVarBin,iDenBin,iMat,nVarBins,nDenBins,nMatBins);
232
  }
233

234
  /// Map density and temp bin indices onto a linearised index
235
  int getMatBin(int iVarBin, int iDenBin, int nVarBinsIn, int nDenBinsIn);
236
  /// Map density and temp bin indices onto a linearised index
237
  /// with default parameters for number of bins
238
  int getMatBin(int iVarBin, int iDenBin){
239
    return getMatBin(iVarBin,iDenBin,nVarBins,nDenBins);
240
  }
241

242
  /// Calculate the variable evaluated at the bin midpoints
243
  void calcMidpoints();
244
  /// Calculate the variable evaluated at the bin midpoints for linear binning
245
  void calcMidpointsLin();
246
  /// Calculate the variable evaluated at the bin midpoints for log binning
247
  void calcMidpointsLog();
248
  /// Calculate the density evaluated at the bin midpoints
249
  void calcDenMidpoints();
250

251
  /// Calculate a generic variable midpoints given binning params
252
  void calcMidpointsLin(double var_min_in, double bin_width_in,int nbins_in,std::vector<double>& midpoints_in);
253

254
  /// Return the centroid position of an element
255
  Point elemCentroid(Elem& elem);
256

257
  /// Clear the containers of elements grouped into bins of constant temp
258
  void resetContainers();
259

260
  /// Clear MOAB entity sets
261
  bool resetMOAB();
262

263
  /// Find the surfaces for the provided range and add to group
264
  bool findSurface(const moab::Range& region,moab::EntityHandle group, unsigned int & vol_id, unsigned int & surf_id,moab::EntityHandle& volume_set);
265

266
  /// Write to file
267
  bool write();
268

269
  /// MPI communication of DOFs of binned elements
270
  void communicateDofSet(std::set<dof_id_type>& dofset);
271

272
  /// Pointer to the feProblem we care about
273
  FEProblemBase * _problem_ptr;
274

275
  /// Pointer to a moab skinner for finding temperature surfaces
276
  std::unique_ptr< moab::Skinner > skinner;
277

278
  /// Pointer for gtt for setting surface sense
279
  std::unique_ptr< moab::GeomTopoTool > gtt;
280

281
  /// Convert MOOSE units to dagmc length units
282
  double lengthscale;
283

284
  /// Convert MOOSE density units to openmc density units
285
  double densityscale;
286

287
  /// Map from libmesh id to MOAB element entity handles
288
  std::map<dof_id_type,std::vector<moab::EntityHandle> > _id_to_elem_handles;
289

290
  /// Save the first tet entity handle
291
  moab::EntityHandle offset;
292

293
  // Data members relating to binning in temperature
294

295
  /// Name of the MOOSE variable
296
  std::string var_name;
297
  /// Whether or not to perform binning
298
  bool binElems;
299
  /// Whether or not to bin in a log scale
300
  bool logscale;
301
  /// Minimum value of our variable
302
  double var_min;
303
  /// Maximum value of our variable for binning on a linear scale
304
  double var_max;
305
  /// Fixed bin width for binning on a linear scale
306
  double bin_width;
307
  /// Minimum power of 10
308
  int powMin;
309
  /// Maximum power of 10
310
  int powMax;
311
  /// Number of variable bins to use
312
  unsigned int nVarBins;
313
  /// Number of powers of 10 to bin in for binning on a log scale
314
  unsigned int nPow;
315
  /// Number of minor divisions for binning on a log scale
316
  unsigned int nMinor;
317
  /// Store the temperature corresponding to the bin mipoint
318
  std::vector<double> midpoints;
319
  /// Store the relative density corresponding to the bin mipoint
320
  std::vector<double> den_midpoints;
321

322
  /// Data members relating to  binning in density
323

324
  /// Name of the MOOSE variable containing the density
325
  std::string den_var_name;
326
  /// Switch to determine if we should bin by material density
327
  bool binByDensity;
328
  /// Minimum relative density diff
329
  double rel_den_min;
330
  /// Max relative density diff
331
  double rel_den_max;
332
  /// Relative density diff bin width
333
  double rel_den_bw;
334
  /// Number of relative density bins
335
  unsigned int nDenBins;
336
  /// Number of distinct subdomains (e.g. vols, mats)
337
  unsigned int nMatBins;
338

339
  /// Container for elems sorted by variable bin and materials
340
  std::vector<std::set<dof_id_type> > sortedElems;
341

342
  /// A map to store mesh functions against their variable name
343
  std::map<std::string, std::shared_ptr<MeshFunction> > meshFunctionPtrs;
344

345
  /// A place to store the entire solution
346
  // N.B. For big problems this is going to be a memory bottleneck
347
  // TODO: We will need to come up with a better solution
348
  // Map is from systems index
349
  std::map<unsigned int, std::unique_ptr<NumericVector<Number> > > serial_solutions;
350

351
  // Materials data
352

353
  /// material names
354
  std::vector<std::string> mat_names;
355
  /// OpenMC material names
356
  std::vector<std::string> openmc_mat_names;
357
  /// all element blocks assigned to mats
358
  std::vector< std::set<SubdomainID> > mat_blocks;
359
  /// vector for initial densities if binning by density
360
  std::vector<double> initialDensities;
361

362
  /// An entitiy handle to represent the set of all tets
363
  moab::EntityHandle meshset;
364

365
  /// Save some topological data: map from surface handle to vol handle and sense
366
  std::map<moab::EntityHandle, std::vector<VolData> > surfsToVols;
367

368
  // Some moab tags
369

370
  /// Tag for dimension for geometry
371
  moab::Tag geometry_dimension_tag;
372
  /// Tag for entitiy set ID
373
  moab::Tag id_tag;
374
  /// Tag for faceting tolerance
375
  moab::Tag faceting_tol_tag;
376
  /// Tag needed by DAGMC
377
  moab::Tag geometry_resabs_tag;
378
  /// Tag for type of entity set
379
  moab::Tag category_tag;
380
  /// Tag for name of entity set
381
  moab::Tag name_tag;
382

383
  /// Const to encode that MOAB tets have 4 nodes
384
  const unsigned int nNodesPerTet = 4;
385

386
  // DagMC settings
387
  /// Faceting tolerence needed by DAGMC
388
  double faceting_tol;
389
  /// Geometry tolerence needed by DAGMC
390
  double geom_tol;
391

392
  /// Scalefactors applied to bounding box for inner surface of graveyard
393
  double scalefactor_inner;
394
  /// Scalefactors applied to bounding box for outer surface of graveyard
395
  double scalefactor_outer;
396

397
  // Settings to control the optional writing of surfaces to file.
398

399
  /// Flag to control whether to save surface skins to file
400
  bool output_skins;
401
  /// Flag to control whether to output the full MOAB mesh database
402
  bool output_full;
403
  /// Base name of skins output file
404
  std::string output_base;
405
  /// Base name of full database output file
406
  std::string output_base_full;
407
  /// Number of times to write to file
408
  unsigned int n_output;
409
  /// Period of writes (skip every n_period -1)
410
  unsigned int n_period;
411
  /// Count number of times file has been written to
412
  unsigned int n_write;
413
  /// Store the number of times writeSurfaces is called
414
  unsigned int n_its;
415

416
  /// Performance timer for initialisation
417
  PerfID _init_timer;
418
  /// Performance timer for update
419
  PerfID _update_timer;
420
  /// Performance timer for setSolution
421
  PerfID _setsolution_timer;
422

423
};
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc