Skip to content
Open
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 geenerator:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
For example, the following member variable stores the pointer to the CSGBase object that is generated by an input mesh geenerator:
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 needed for downstream
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// Holds the output CSGBase object for each mesh generator - including duplicates needed for downstream
/// 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;
};
51 changes: 48 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 @@ -335,21 +343,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 +441,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 cell reference to CSGCell that should be added to universe list
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* @param cell reference to CSGCell that should be added to universe list
* @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
20 changes: 19 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) { 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
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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// Normalize plane coefficients so that a^2 + b^2 + c^2 = 1
/// Normalize plane coefficients so that a^2 + b^2 + c^2 = 1

// is for comments, /// is for docstring

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
17 changes: 16 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,6 +45,16 @@ 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
*
Expand Down
20 changes: 19 additions & 1 deletion framework/include/csg/CSGUniverseList.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,15 @@ 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) { 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 +56,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
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
10 changes: 10 additions & 0 deletions framework/include/csg/CSGZCylinder.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,16 @@ class CSGZCylinder : public CSGSurface
virtual Real evaluateSurfaceEquationAtPoint(const Point & p) const override;

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

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

Expand Down
28 changes: 28 additions & 0 deletions framework/include/utils/CSGUtils.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
//* This file is part of the MOOSE framework
//* https://mooseframework.inl.gov
//*
//* All rights reserved, see COPYRIGHT for full restrictions
//* https://github.com/idaholab/moose/blob/master/COPYRIGHT
//*
//* Licensed under LGPL 2.1, please see LICENSE for details
//* https://www.gnu.org/licenses/lgpl-2.1.html

#pragma once

#include "CSGBase.h"

namespace CSGUtils
{

/**
* Get inner region of given surfaces, defined as the intersection
* of halfspaces of each surface. Here, the halfspace direction is determined based on the origin.
* @param radial_surfaces List of references to surfaces used to define inner region. This should
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* @param radial_surfaces List of references to surfaces used to define inner region. This should
* @param surfaces List of references to surfaces used to define inner region. This should

in this context, may not be radial

* be defined with the minimum number of surfaces to enclose the region
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* be defined with the minimum number of surfaces to enclose the region
* ideally be defined with the minimum number of surfaces needed to enclose the region

* @param origin Point used to determine halfspace direction when defining intersected region
* @return inner region defined by surfaces
*/
CSG::CSGRegion
getInnerRegion(const std::vector<std::reference_wrapper<const CSG::CSGSurface>> & radial_surfaces,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
getInnerRegion(const std::vector<std::reference_wrapper<const CSG::CSGSurface>> & radial_surfaces,
getInnerRegion(const std::vector<std::reference_wrapper<const CSG::CSGSurface>> & surfaces,

const libMesh::Point & origin = Point(0, 0, 0));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const libMesh::Point & origin = Point(0, 0, 0));
const libMesh::Point & origin);

defaults just lead to mistakes

}
Loading