Skip to content

Commit b79a48d

Browse files
authored
Merge pull request #31782 from shikhar413/pin_mg_to_csg
Implement generateCSG method for PinMeshGenerator
2 parents b581629 + 6159314 commit b79a48d

File tree

56 files changed

+2548
-53
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+2548
-53
lines changed

framework/doc/content/source/csg/CSGBase.md

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,17 @@ For all methods listed below, a unique pointer to the `CSGBase` object(s) create
225225
- `getCSGBaseByName`: get the `CSGBase` object given a `MeshGeneratorName`
226226
- `getCSGBasesByName`: get all `CSGBase` objects given a list of `MeshGeneratorName`s
227227
228-
For example:
228+
These functions should be called from the constructor of the MeshGenerator, so that the MeshGenerator system can properly define the dependency tree of all mesh generators in the input file. The returned CSGBase pointers can be stored in a member variable and updated in the `generateCSG()` method in order to make any changes to the CSGBase object.
229+
230+
For example, the following member variable stores the pointer to the CSGBase object that is generated by an input mesh generator:
231+
232+
!listing TestCSGAxialSurfaceMeshGenerator.h start=Holds the generated CSGBase object end=_build_csg include-end=true
233+
234+
This variable is initialized in the constructor as:
235+
236+
!listing TestCSGAxialSurfaceMeshGenerator.C start=getCSGBase end=getCSGBase include-end=true
237+
238+
Finally, in the `generateCSG()` method, `std::move` is called on the member variable to transfer ownership to the current mesh generator
229239
230240
!listing TestCSGAxialSurfaceMeshGenerator.C start=get the existing CSGBase end=csg_obj include-end=true
231241
@@ -306,4 +316,4 @@ To run the above example, use `--allow-test-objects`:
306316
307317
```shell
308318
./moose_test-opt --allow-test-objects --csg-only -i tests/csg/csg_only_chained.i
309-
```
319+
```

framework/doc/content/source/csg/CSGSurface.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ To help determine the sign of these half-spaces, each surface type should have a
2727
The type of surface must be set for `_surface_type` in the surface constructor.
2828
It is recommended that this be done based on the class name using `MooseUtils::prettyCppType<SurfaceClassName>()` so that the surface type automatically matches the class that created it.
2929

30+
### Creating a Surface Clone
31+
32+
In order to make sure that clones of CSGBase objects are created properly, each derived `CSGSurface` type must implement a `clone()` method, which returns a `std::unique_ptr<CSGSurface>` from the given surface instance. This can typically be done by calling `std::make_unique` on the constructor for the derived surface type.
33+
3034
## Example
3135

3236
Below shows how `CSGSphere` is implemented as an example.

framework/include/base/MeshGeneratorSystem.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,6 @@ class MeshGeneratorSystem : public PerfGraphInterface, public libMesh::ParallelO
290290
/// Whether mesh generator system is running in CSG-only mode
291291
bool _csg_only;
292292

293-
/// Holds the output CSGBase object for each mesh generator
294-
std::map<std::string, std::unique_ptr<CSG::CSGBase>> _csg_base_output;
293+
/// Holds the output CSGBase object for each mesh generator - including duplicates when needed by multiple downstream generators (key is MG name, value list is duplicates)
294+
std::map<std::string, std::list<std::unique_ptr<CSG::CSGBase>>> _csg_base_outputs;
295295
};

framework/include/csg/CSGBase.h

Lines changed: 54 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,19 @@ class CSGBase
3434
*/
3535
CSGBase();
3636

37+
/**
38+
* Copy constructor
39+
*/
40+
CSGBase(const CSGBase & other_base);
41+
3742
/**
3843
* Destructor
3944
*/
4045
~CSGBase();
4146

47+
/// Create a deep copy of this CSGBase instance
48+
std::unique_ptr<CSGBase> clone() const { return std::make_unique<CSGBase>(*this); }
49+
4250
/**
4351
* @brief add a unique surface pointer to this base instance
4452
*
@@ -310,6 +318,12 @@ class CSGBase
310318
*/
311319
nlohmann::json generateOutput() const;
312320

321+
/// Operator overload for checking if two CSGBase objects are equal
322+
bool operator==(const CSGBase & other) const;
323+
324+
/// Operator overload for checking if two CSGBase objects are not equal
325+
bool operator!=(const CSGBase & other) const;
326+
313327
private:
314328
/**
315329
* @brief Get a Surface object by name.
@@ -335,21 +349,42 @@ class CSGBase
335349
std::vector<std::string> & linked_universe_names) const;
336350

337351
/**
338-
* @brief Get the CSGSurfaceList object
352+
* @brief Get a const reference to the CSGSurfaceList object
353+
*
354+
* @return CSGSurfaceList
355+
*/
356+
const CSGSurfaceList & getSurfaceList() const { return _surface_list; }
357+
358+
/**
359+
* @brief Get a non-const reference to the CSGSurfaceList object
339360
*
340361
* @return CSGSurfaceList
341362
*/
342363
CSGSurfaceList & getSurfaceList() { return _surface_list; }
343364

344365
/**
345-
* @brief Get the CSGCellList object
366+
* @brief Get a const reference to the CSGCellList object
367+
*
368+
* @return CSGCellList
369+
*/
370+
const CSGCellList & getCellList() const { return _cell_list; }
371+
372+
/**
373+
* @brief Get a non-const reference to the CSGCellList object
346374
*
347375
* @return CSGCellList
348376
*/
349377
CSGCellList & getCellList() { return _cell_list; }
350378

351379
/**
352-
* @brief Get the CSGUniverseList object
380+
* @brief Get a const reference to the CSGUniverseList object
381+
*
382+
* @return CSGUniverseList
383+
*/
384+
const CSGUniverseList & getUniverseList() const { return _universe_list; }
385+
386+
/**
387+
* @brief Get a non-const reference to the CSGUniverseList object
353388
*
354389
* @return CSGUniverseList
355390
*/
@@ -412,6 +447,22 @@ class CSGBase
412447
// check that universe being accessed is a part of this CSGBase instance
413448
bool checkUniverseInBase(const CSGUniverse & universe) const;
414449

450+
/**
451+
* @brief Add a new cell to the cell list based on a cell reference.
452+
* This method is called by the copy constructor of CSGBase
453+
*
454+
* @param cell reference to CSGCell that should be added to cell list
455+
*/
456+
const CSGCell & addCellToList(const CSGCell & cell);
457+
458+
/**
459+
* @brief Add a new universe to the universe list based on a universe reference.
460+
* This method is called by the copy constructor of CSGBase
461+
*
462+
* @param univ reference to CSGUniverse that should be added to universe list
463+
*/
464+
const CSGUniverse & addUniverseToList(const CSGUniverse & univ);
465+
415466
/// List of surfaces associated with CSG object
416467
CSGSurfaceList _surface_list;
417468

framework/include/csg/CSGCellList.h

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,12 +65,30 @@ class CSGCellList
6565
addUniverseCell(const std::string & name, const CSGUniverse & univ, const CSGRegion & region);
6666

6767
/**
68-
* @brief Get map of all names to cells in cell list
68+
* @brief return whether cell with given name exists in cell list
69+
*
70+
* @param name name of cell
71+
* @return true if cell name exists, false otherwise
72+
*/
73+
bool hasCell(const std::string & name) const { return _cells.find(name) != _cells.end(); }
74+
75+
/**
76+
* @brief Get non-const map of all names to cells in cell list
6977
*
7078
* @return map of all names to CSGCell pointers
7179
*/
7280
std::unordered_map<std::string, std::unique_ptr<CSGCell>> & getCellListMap() { return _cells; }
7381

82+
/**
83+
* @brief Get const map of all names to cells in cell list
84+
*
85+
* @return map of all names to CSGCell pointers
86+
*/
87+
const std::unordered_map<std::string, std::unique_ptr<CSGCell>> & getCellListMap() const
88+
{
89+
return _cells;
90+
}
91+
7492
/**
7593
* @brief Get all the cells in CSGBase instance
7694
*
@@ -103,6 +121,12 @@ class CSGCellList
103121
*/
104122
void renameCell(const CSGCell & cell, const std::string & name);
105123

124+
/// Operator overload for checking if two CSGCellList objects are equal
125+
bool operator==(const CSGCellList & other) const;
126+
127+
/// Operator overload for checking if two CSGCellList objects are not equal
128+
bool operator!=(const CSGCellList & other) const;
129+
106130
/// Mapping of cell names to pointers of stored cell objects
107131
std::unordered_map<std::string, std::unique_ptr<CSGCell>> _cells;
108132

framework/include/csg/CSGPlane.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,22 @@ class CSGPlane : public CSGSurface
6767
virtual Real evaluateSurfaceEquationAtPoint(const Point & p) const override;
6868

6969
protected:
70+
/**
71+
* @brief create clone of CSGPlane object
72+
*
73+
* @return std::unordered_map<CSGSurface> unique_ptr to cloned plane
74+
*/
75+
virtual std::unique_ptr<CSGSurface> clone() const override
76+
{
77+
return std::make_unique<CSGPlane>(_name, _a, _b, _c, _d);
78+
}
79+
7080
// calculate the equivalent coeffients (aX + bY + cZ = d) from 3 points on a plane
7181
void coeffsFromPoints(const Point & p1, const Point & p2, const Point & p3);
7282

83+
/// Normalize plane coefficients so that a^2 + b^2 + c^2 = 1
84+
void normalizePlaneCoefficients();
85+
7386
/// Value of a in equation of plane
7487
Real _a;
7588

framework/include/csg/CSGSphere.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,16 @@ class CSGSphere : public CSGSurface
6262
virtual Real evaluateSurfaceEquationAtPoint(const Point & p) const override;
6363

6464
protected:
65+
/**
66+
* @brief create clone of CSGSphere object
67+
*
68+
* @return std::unordered_map<CSGSurface> unique_ptr to cloned sphere
69+
*/
70+
virtual std::unique_ptr<CSGSurface> clone() const override
71+
{
72+
return std::make_unique<CSGSphere>(_name, Point(_x0, _y0, _z0), _r);
73+
}
74+
6575
// check that radius is positive
6676
void checkRadius() const;
6777

framework/include/csg/CSGSurface.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,13 @@ class CSGSurface
101101
bool operator!=(const CSGSurface & other) const;
102102

103103
protected:
104+
/**
105+
* @brief Create clone of current surface, to be implemented by derived class
106+
*
107+
* @return unique_ptr to cloned surface
108+
*/
109+
virtual std::unique_ptr<CSGSurface> clone() const = 0; // Pure virtual function
110+
104111
// set the name of the surface - intentionally not public because
105112
// name needs to be managed at the CSGSurfaceList level
106113
void setName(const std::string & name) { _name = name; }

framework/include/csg/CSGSurfaceList.h

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,18 @@ class CSGSurfaceList
2525
*/
2626
CSGSurfaceList();
2727

28+
/**
29+
* Copy constructor
30+
*/
31+
CSGSurfaceList(const CSGSurfaceList & other_surface_list);
32+
2833
/**
2934
* Destructor
3035
*/
3136
virtual ~CSGSurfaceList() = default;
3237

3338
/**
34-
* @brief Get map of all names to surfaces in surface list
39+
* @brief Get non-const map of all names to surfaces in surface list
3540
*
3641
* @return map of all names to CSGSurface pointers
3742
*/
@@ -40,13 +45,34 @@ class CSGSurfaceList
4045
return _surfaces;
4146
}
4247

48+
/**
49+
* @brief Get const map of all names to surfaces in surface list
50+
*
51+
* @return map of all names to CSGSurface pointers
52+
*/
53+
const std::unordered_map<std::string, std::unique_ptr<CSGSurface>> & getSurfaceListMap() const
54+
{
55+
return _surfaces;
56+
}
57+
4358
/**
4459
* @brief Get list of references to all surfaces in surface list
4560
*
4661
* @return list of references to surfaces
4762
*/
4863
std::vector<std::reference_wrapper<const CSGSurface>> getAllSurfaces() const;
4964

65+
/**
66+
* @brief return whether surface with given name exists in surface list
67+
*
68+
* @param name name of surface
69+
* @return true if surface name exists, false otherwise
70+
*/
71+
bool hasSurface(const std::string & name) const
72+
{
73+
return _surfaces.find(name) != _surfaces.end();
74+
}
75+
5076
/**
5177
* @brief Get a surface by name
5278
*
@@ -73,6 +99,12 @@ class CSGSurfaceList
7399
*/
74100
void renameSurface(const CSGSurface & surface, const std::string & name);
75101

102+
/// Operator overload for checking if two CSGSurfaceList objects are equal
103+
bool operator==(const CSGSurfaceList & other) const;
104+
105+
/// Operator overload for checking if two CSGSurfaceList objects are not equal
106+
bool operator!=(const CSGSurfaceList & other) const;
107+
76108
/// Mapping of surface names to pointers of stored surface objects
77109
std::unordered_map<std::string, std::unique_ptr<CSGSurface>> _surfaces;
78110

framework/include/csg/CSGUniverseList.h

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,18 @@ class CSGUniverseList
3939
CSGUniverse & addUniverse(const std::string & name);
4040

4141
/**
42-
* @brief Get map of all names to universes in universe list
42+
* @brief return whether universe with given name exists in universe list
43+
*
44+
* @param name name of universe
45+
* @return true if universe name exists, false otherwise
46+
*/
47+
bool hasUniverse(const std::string & name) const
48+
{
49+
return _universes.find(name) != _universes.end();
50+
}
51+
52+
/**
53+
* @brief Get non-const map of all names to universes in universe list
4354
*
4455
* @return map of all names to CSGUniverse pointers
4556
*/
@@ -48,6 +59,16 @@ class CSGUniverseList
4859
return _universes;
4960
}
5061

62+
/**
63+
* @brief Get const map of all names to universes in universe list
64+
*
65+
* @return map of all names to CSGUniverse pointers
66+
*/
67+
const std::unordered_map<std::string, std::unique_ptr<CSGUniverse>> & getUniverseListMap() const
68+
{
69+
return _universes;
70+
}
71+
5172
/**
5273
* @brief Get all the universes in CSGBase instance
5374
*
@@ -87,6 +108,12 @@ class CSGUniverseList
87108
*/
88109
void renameUniverse(const CSGUniverse & universe, const std::string & name);
89110

111+
/// Operator overload for checking if two CSGUniverseList objects are equal
112+
bool operator==(const CSGUniverseList & other) const;
113+
114+
/// Operator overload for checking if two CSGUniverseList objects are not equal
115+
bool operator!=(const CSGUniverseList & other) const;
116+
90117
/// Mapping of universe names to pointers of stored universe objects
91118
std::unordered_map<std::string, std::unique_ptr<CSGUniverse>> _universes;
92119

0 commit comments

Comments
 (0)