Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions framework/doc/content/source/csg/CSGBase.md
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,17 @@ For all methods listed below, a unique pointer to the `CSGBase` object(s) create
- `getCSGBaseByName`: get the `CSGBase` object given a `MeshGeneratorName`
- `getCSGBasesByName`: get all `CSGBase` objects given a list of `MeshGeneratorName`s

For example:
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.

For example, the following member variable stores the pointer to the CSGBase object that is generated by an input mesh generator:

!listing TestCSGAxialSurfaceMeshGenerator.h start=Holds the generated CSGBase object end=_build_csg include-end=true

This variable is initialized in the constructor as:

!listing TestCSGAxialSurfaceMeshGenerator.C start=getCSGBase end=getCSGBase include-end=true

Finally, in the `generateCSG()` method, `std::move` is called on the member variable to transfer ownership to the current mesh generator

!listing TestCSGAxialSurfaceMeshGenerator.C start=get the existing CSGBase end=csg_obj include-end=true

Expand Down Expand Up @@ -306,4 +316,4 @@ To run the above example, use `--allow-test-objects`:

```shell
./moose_test-opt --allow-test-objects --csg-only -i tests/csg/csg_only_chained.i
```
```
4 changes: 4 additions & 0 deletions framework/doc/content/source/csg/CSGSurface.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ To help determine the sign of these half-spaces, each surface type should have a
The type of surface must be set for `_surface_type` in the surface constructor.
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.

### Creating a Surface Clone

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.

## Example

Below shows how `CSGSphere` is implemented as an example.
Expand Down
4 changes: 2 additions & 2 deletions framework/include/base/MeshGeneratorSystem.h
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,6 @@ class MeshGeneratorSystem : public PerfGraphInterface, public libMesh::ParallelO
/// Whether mesh generator system is running in CSG-only mode
bool _csg_only;

/// Holds the output CSGBase object for each mesh generator
std::map<std::string, std::unique_ptr<CSG::CSGBase>> _csg_base_output;
/// 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)
std::map<std::string, std::list<std::unique_ptr<CSG::CSGBase>>> _csg_base_outputs;
};
57 changes: 54 additions & 3 deletions framework/include/csg/CSGBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,19 @@ class CSGBase
*/
CSGBase();

/**
* Copy constructor
*/
CSGBase(const CSGBase & other_base);

/**
* Destructor
*/
~CSGBase();

/// Create a deep copy of this CSGBase instance
std::unique_ptr<CSGBase> clone() const { return std::make_unique<CSGBase>(*this); }

/**
* @brief add a unique surface pointer to this base instance
*
Expand Down Expand Up @@ -310,6 +318,12 @@ class CSGBase
*/
nlohmann::json generateOutput() const;

/// Operator overload for checking if two CSGBase objects are equal
bool operator==(const CSGBase & other) const;

/// Operator overload for checking if two CSGBase objects are not equal
bool operator!=(const CSGBase & other) const;

private:
/**
* @brief Get a Surface object by name.
Expand All @@ -335,21 +349,42 @@ class CSGBase
std::vector<std::string> & linked_universe_names) const;

/**
* @brief Get the CSGSurfaceList object
* @brief Get a const reference to the CSGSurfaceList object
*
* @return CSGSurfaceList
*/
const CSGSurfaceList & getSurfaceList() const { return _surface_list; }

/**
* @brief Get a non-const reference to the CSGSurfaceList object
*
* @return CSGSurfaceList
*/
CSGSurfaceList & getSurfaceList() { return _surface_list; }

/**
* @brief Get the CSGCellList object
* @brief Get a const reference to the CSGCellList object
*
* @return CSGCellList
*/
const CSGCellList & getCellList() const { return _cell_list; }

/**
* @brief Get a non-const reference to the CSGCellList object
*
* @return CSGCellList
*/
CSGCellList & getCellList() { return _cell_list; }

/**
* @brief Get the CSGUniverseList object
* @brief Get a const reference to the CSGUniverseList object
*
* @return CSGUniverseList
*/
const CSGUniverseList & getUniverseList() const { return _universe_list; }

/**
* @brief Get a non-const reference to the CSGUniverseList object
*
* @return CSGUniverseList
*/
Expand Down Expand Up @@ -412,6 +447,22 @@ class CSGBase
// check that universe being accessed is a part of this CSGBase instance
bool checkUniverseInBase(const CSGUniverse & universe) const;

/**
* @brief Add a new cell to the cell list based on a cell reference.
* This method is called by the copy constructor of CSGBase
*
* @param cell reference to CSGCell that should be added to cell list
*/
const CSGCell & addCellToList(const CSGCell & cell);

/**
* @brief Add a new universe to the universe list based on a universe reference.
* This method is called by the copy constructor of CSGBase
*
* @param univ reference to CSGUniverse that should be added to universe list
*/
const CSGUniverse & addUniverseToList(const CSGUniverse & univ);

/// List of surfaces associated with CSG object
CSGSurfaceList _surface_list;

Expand Down
26 changes: 25 additions & 1 deletion framework/include/csg/CSGCellList.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,30 @@ class CSGCellList
addUniverseCell(const std::string & name, const CSGUniverse & univ, const CSGRegion & region);

/**
* @brief Get map of all names to cells in cell list
* @brief return whether cell with given name exists in cell list
*
* @param name name of cell
* @return true if cell name exists, false otherwise
*/
bool hasCell(const std::string & name) const { return _cells.find(name) != _cells.end(); }

/**
* @brief Get non-const map of all names to cells in cell list
*
* @return map of all names to CSGCell pointers
*/
std::unordered_map<std::string, std::unique_ptr<CSGCell>> & getCellListMap() { return _cells; }

/**
* @brief Get const map of all names to cells in cell list
*
* @return map of all names to CSGCell pointers
*/
const std::unordered_map<std::string, std::unique_ptr<CSGCell>> & getCellListMap() const
{
return _cells;
}

/**
* @brief Get all the cells in CSGBase instance
*
Expand Down Expand Up @@ -103,6 +121,12 @@ class CSGCellList
*/
void renameCell(const CSGCell & cell, const std::string & name);

/// Operator overload for checking if two CSGCellList objects are equal
bool operator==(const CSGCellList & other) const;

/// Operator overload for checking if two CSGCellList objects are not equal
bool operator!=(const CSGCellList & other) const;

/// Mapping of cell names to pointers of stored cell objects
std::unordered_map<std::string, std::unique_ptr<CSGCell>> _cells;

Expand Down
13 changes: 13 additions & 0 deletions framework/include/csg/CSGPlane.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,22 @@ class CSGPlane : public CSGSurface
virtual Real evaluateSurfaceEquationAtPoint(const Point & p) const override;

protected:
/**
* @brief create clone of CSGPlane object
*
* @return std::unordered_map<CSGSurface> unique_ptr to cloned plane
*/
virtual std::unique_ptr<CSGSurface> clone() const override
{
return std::make_unique<CSGPlane>(_name, _a, _b, _c, _d);
}

// calculate the equivalent coeffients (aX + bY + cZ = d) from 3 points on a plane
void coeffsFromPoints(const Point & p1, const Point & p2, const Point & p3);

/// Normalize plane coefficients so that a^2 + b^2 + c^2 = 1
void normalizePlaneCoefficients();

/// Value of a in equation of plane
Real _a;

Expand Down
10 changes: 10 additions & 0 deletions framework/include/csg/CSGSphere.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,16 @@ class CSGSphere : public CSGSurface
virtual Real evaluateSurfaceEquationAtPoint(const Point & p) const override;

protected:
/**
* @brief create clone of CSGSphere object
*
* @return std::unordered_map<CSGSurface> unique_ptr to cloned sphere
*/
virtual std::unique_ptr<CSGSurface> clone() const override
{
return std::make_unique<CSGSphere>(_name, Point(_x0, _y0, _z0), _r);
}

// check that radius is positive
void checkRadius() const;

Expand Down
7 changes: 7 additions & 0 deletions framework/include/csg/CSGSurface.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,13 @@ class CSGSurface
bool operator!=(const CSGSurface & other) const;

protected:
/**
* @brief Create clone of current surface, to be implemented by derived class
*
* @return unique_ptr to cloned surface
*/
virtual std::unique_ptr<CSGSurface> clone() const = 0; // Pure virtual function

// set the name of the surface - intentionally not public because
// name needs to be managed at the CSGSurfaceList level
void setName(const std::string & name) { _name = name; }
Expand Down
34 changes: 33 additions & 1 deletion framework/include/csg/CSGSurfaceList.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,18 @@ class CSGSurfaceList
*/
CSGSurfaceList();

/**
* Copy constructor
*/
CSGSurfaceList(const CSGSurfaceList & other_surface_list);

/**
* Destructor
*/
virtual ~CSGSurfaceList() = default;

/**
* @brief Get map of all names to surfaces in surface list
* @brief Get non-const map of all names to surfaces in surface list
*
* @return map of all names to CSGSurface pointers
*/
Expand All @@ -40,13 +45,34 @@ class CSGSurfaceList
return _surfaces;
}

/**
* @brief Get const map of all names to surfaces in surface list
*
* @return map of all names to CSGSurface pointers
*/
const std::unordered_map<std::string, std::unique_ptr<CSGSurface>> & getSurfaceListMap() const
{
return _surfaces;
}

/**
* @brief Get list of references to all surfaces in surface list
*
* @return list of references to surfaces
*/
std::vector<std::reference_wrapper<const CSGSurface>> getAllSurfaces() const;

/**
* @brief return whether surface with given name exists in surface list
*
* @param name name of surface
* @return true if surface name exists, false otherwise
*/
bool hasSurface(const std::string & name) const
{
return _surfaces.find(name) != _surfaces.end();
}

/**
* @brief Get a surface by name
*
Expand All @@ -73,6 +99,12 @@ class CSGSurfaceList
*/
void renameSurface(const CSGSurface & surface, const std::string & name);

/// Operator overload for checking if two CSGSurfaceList objects are equal
bool operator==(const CSGSurfaceList & other) const;

/// Operator overload for checking if two CSGSurfaceList objects are not equal
bool operator!=(const CSGSurfaceList & other) const;

/// Mapping of surface names to pointers of stored surface objects
std::unordered_map<std::string, std::unique_ptr<CSGSurface>> _surfaces;

Expand Down
29 changes: 28 additions & 1 deletion framework/include/csg/CSGUniverseList.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,18 @@ class CSGUniverseList
CSGUniverse & addUniverse(const std::string & name);

/**
* @brief Get map of all names to universes in universe list
* @brief return whether universe with given name exists in universe list
*
* @param name name of universe
* @return true if universe name exists, false otherwise
*/
bool hasUniverse(const std::string & name) const
{
return _universes.find(name) != _universes.end();
}

/**
* @brief Get non-const map of all names to universes in universe list
*
* @return map of all names to CSGUniverse pointers
*/
Expand All @@ -48,6 +59,16 @@ class CSGUniverseList
return _universes;
}

/**
* @brief Get const map of all names to universes in universe list
*
* @return map of all names to CSGUniverse pointers
*/
const std::unordered_map<std::string, std::unique_ptr<CSGUniverse>> & getUniverseListMap() const
{
return _universes;
}

/**
* @brief Get all the universes in CSGBase instance
*
Expand Down Expand Up @@ -87,6 +108,12 @@ class CSGUniverseList
*/
void renameUniverse(const CSGUniverse & universe, const std::string & name);

/// Operator overload for checking if two CSGUniverseList objects are equal
bool operator==(const CSGUniverseList & other) const;

/// Operator overload for checking if two CSGUniverseList objects are not equal
bool operator!=(const CSGUniverseList & other) const;

/// Mapping of universe names to pointers of stored universe objects
std::unordered_map<std::string, std::unique_ptr<CSGUniverse>> _universes;

Expand Down
10 changes: 10 additions & 0 deletions framework/include/csg/CSGXCylinder.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,16 @@ class CSGXCylinder : public CSGSurface
virtual Real evaluateSurfaceEquationAtPoint(const Point & p) const override;

protected:
/**
* @brief create clone of CSGXCylinder object
*
* @return std::unordered_map<CSGSurface> unique_ptr to cloned x-cylinder
*/
virtual std::unique_ptr<CSGSurface> clone() const override
{
return std::make_unique<CSGXCylinder>(_name, _y0, _z0, _r);
}

// check that radius is positive
void checkRadius() const;

Expand Down
10 changes: 10 additions & 0 deletions framework/include/csg/CSGYCylinder.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,16 @@ class CSGYCylinder : public CSGSurface
virtual Real evaluateSurfaceEquationAtPoint(const Point & p) const override;

protected:
/**
* @brief create clone of CSGYCylinder object
*
* @return std::unordered_map<CSGSurface> unique_ptr to cloned y-cylinder
*/
virtual std::unique_ptr<CSGSurface> clone() const override
{
return std::make_unique<CSGYCylinder>(_name, _x0, _z0, _r);
}

// check that radius is positive
void checkRadius() const;

Expand Down
Loading