The SKIRT project
advanced radiative transfer for astrophysics
CartesianSpatialGrid Class Reference

#include <CartesianSpatialGrid.hpp>

Inheritance diagram for CartesianSpatialGrid:

Public Member Functions

int cellIndex (Position bfr) const override
Position centralPositionInCell (int m) const override
std::unique_ptr< PathSegmentGeneratorcreatePathSegmentGenerator () const override
double diagonal (int m) const override
MeshmeshX () const
MeshmeshY () const
MeshmeshZ () const
int numCells () const override
Position randomPositionInCell (int m) const override
double volume (int m) const override
Public Member Functions inherited from BoxSpatialGrid
Box boundingBox () const override
int dimension () const override
double maxX () const
double maxY () const
double maxZ () const
double minX () const
double minY () const
double minZ () const
Public Member Functions inherited from SpatialGrid
virtual void writeGridPlotFiles (const SimulationItem *probe) const
Public Member Functions inherited from SimulationItem
template<class T>
T * find (bool setup=true) const
template<class T>
T * interface (int levels=-999999, bool setup=true) const
virtual string itemName () const
void setup ()
string typeAndName () const
Public Member Functions inherited from Item
 Item (const Item &)=delete
virtual ~Item ()
void addChild (Item *child)
const vector< Item * > & children () const
virtual void clearItemListProperty (const PropertyDef *property)
void destroyChild (Item *child)
virtual bool getBoolProperty (const PropertyDef *property) const
virtual vector< double > getDoubleListProperty (const PropertyDef *property) const
virtual double getDoubleProperty (const PropertyDef *property) const
virtual string getEnumProperty (const PropertyDef *property) const
virtual int getIntProperty (const PropertyDef *property) const
virtual vector< Item * > getItemListProperty (const PropertyDef *property) const
virtual ItemgetItemProperty (const PropertyDef *property) const
virtual string getStringProperty (const PropertyDef *property) const
int getUtilityProperty (string name) const
virtual void insertIntoItemListProperty (const PropertyDef *property, int index, Item *item)
Itemoperator= (const Item &)=delete
Itemparent () const
virtual void removeFromItemListProperty (const PropertyDef *property, int index)
virtual void setBoolProperty (const PropertyDef *property, bool value)
virtual void setDoubleListProperty (const PropertyDef *property, vector< double > value)
virtual void setDoubleProperty (const PropertyDef *property, double value)
virtual void setEnumProperty (const PropertyDef *property, string value)
virtual void setIntProperty (const PropertyDef *property, int value)
virtual void setItemProperty (const PropertyDef *property, Item *item)
virtual void setStringProperty (const PropertyDef *property, string value)
void setUtilityProperty (string name, int value)
virtual string type () const
Public Member Functions inherited from Box
 Box ()
 Box (double xmin, double ymin, double zmin, double xmax, double ymax, double zmax)
 Box (Vec rmin, Vec rmax)
void cellIndices (int &i, int &j, int &k, Vec r, int nx, int ny, int nz) const
Vec center () const
bool contains (const Box &box) const
bool contains (double x, double y, double z) const
bool contains (Vec r) const
double diagonal () const
void extend (const Box &box)
const Boxextent () const
void extent (double &xmin, double &ymin, double &zmin, double &xmax, double &ymax, double &zmax) const
Vec fracPos (double xfrac, double yfrac, double zfrac) const
Vec fracPos (int xd, int yd, int zd, int xn, int yn, int zn) const
bool intersects (const Box &box) const
bool intersects (Vec r, const Vec k, double &smin, double &smax) const
bool intersects (Vec rc, double r) const
Vec rmax () const
Vec rmin () const
double volume () const
Vec widths () const
double xmax () const
double xmin () const
double xwidth () const
double ymax () const
double ymin () const
double ywidth () const
double zmax () const
double zmin () const
double zwidth () const

Protected Member Functions

 CartesianSpatialGrid ()
void setupSelfAfter () override
void write_xy (SpatialGridPlotFile *outfile) const override
void write_xyz (SpatialGridPlotFile *outfile) const override
void write_xz (SpatialGridPlotFile *outfile) const override
void write_yz (SpatialGridPlotFile *outfile) const override
Protected Member Functions inherited from BoxSpatialGrid
 BoxSpatialGrid ()
void setupSelfBefore () override
Protected Member Functions inherited from SpatialGrid
 SpatialGrid ()
Randomrandom () const
void setupSelfBefore () override
Protected Member Functions inherited from SimulationItem
 SimulationItem ()
virtual bool offersInterface (const std::type_info &interfaceTypeInfo) const
Protected Member Functions inherited from Item
 Item ()
Protected Member Functions inherited from Box
void setExtent (const Box &extent)
void setExtent (double xmin, double ymin, double zmin, double xmax, double ymax, double zmax)

Private Types

using BaseType
using ItemType

Private Member Functions

Box box (int m) const
int index (int i, int j, int k) const

Private Attributes

Mesh_meshX
Mesh_meshY
Mesh_meshZ
int _Nx
int _Ny
int _Nz
Array _xv
Array _yv
Array _zv

Friends

class ItemRegistry
class MySegmentGenerator

Detailed Description

The CartesianSpatialGrid class is subclass of the BoxSpatialGrid class, and represents three-dimensional spatial grids based on a regular Cartesian grid. Each cell in such a grid is a little cuboid (not necessarily all with the same size or axis ratios).

Constructor & Destructor Documentation

◆ CartesianSpatialGrid()

CartesianSpatialGrid::CartesianSpatialGrid ( )
inlineprotected

Default constructor for concrete Item subclass CartesianSpatialGrid: "a Cartesian spatial grid".

Member Function Documentation

◆ box()

Box CartesianSpatialGrid::box ( int m) const
private

This function calculates the three bin indices \(i\), \(j\) and \(k\) of the cell index \(m\), and then returns the coordinates of the corresponding cell as a Box object. Since the relation between the index and the three bin indices is \(m=k+j\,N_z+i\,N_y\,N_z\), we can use the formulae

\[ \begin{split} i &= \lfloor m/(N_y\,N_z) \rfloor \\ j &= \lfloor (m-i\,N_y\,N_z)/N_z \rfloor \\ k &= m\,{\text{mod}}\,N_z. \end{split} \]

◆ cellIndex()

int CartesianSpatialGrid::cellIndex ( Position bfr) const
overridevirtual

This function returns the index \(m\) of the cell that contains the position \({\bf{r}}\). For a cartesian grid, the function determines the bin indices in the X, Y and Z directions and calculates the correct index based on these indices.

Implements SpatialGrid.

◆ centralPositionInCell()

Position CartesianSpatialGrid::centralPositionInCell ( int m) const
overridevirtual

This function returns the central location from the cell with index \(m\). For a cartesian grid, the function first determines the bin indices \(i\) and \(k\) in the X, Y and Z directions that correspond to the index \(m\). Then the coordinates \(x\), \(y\) and \(z\) are determined using

\[ \begin{split} x &= \frac{x_i + x_{i+1}}{2} \\ y &= \frac{y_j + y_{j+1}}{2} \\ z &= \frac{z_k + z_{k+1}}{2} \end{split} \]

A position with these cartesian coordinates is returned.

Implements SpatialGrid.

◆ createPathSegmentGenerator()

std::unique_ptr< PathSegmentGenerator > CartesianSpatialGrid::createPathSegmentGenerator ( ) const
overridevirtual

This function creates and hands over ownership of a path segment generator (an instance of a PathSegmentGenerator subclass) appropriate for a cartesian grid, implemented as a private PathSegmentGenerator subclass.

The algorithm used to construct the path is fairly straightforward because all cells are cuboids lined up with the coordinate axes and the neighboring cells are easily found by manipulating cell indices.

Implements SpatialGrid.

◆ diagonal()

double CartesianSpatialGrid::diagonal ( int m) const
overridevirtual

This function returns the diagonal of the cell with index \(m\). For a cartesian grid, the function determines the bin indices \(i\), \(j\) and \(k\) corresponding to the X, Y and Z directions. The diagonal is then easily calculated as \(d = \sqrt{ (x_{i+1}-x_i)^2 + (y_{j+1}-y_j)^2 + (z_{k+1}-z_k)^2 }\).

Implements SpatialGrid.

◆ index()

int CartesianSpatialGrid::index ( int i,
int j,
int k ) const
private

This function returns the index \(m\) corresponding to the three bin indices \(i\), \(j\) and \(k\). The correspondence is \(m=k+j\,N_z+i\,N_y\,N_z\).

◆ meshX()

Mesh * CartesianSpatialGrid::meshX ( ) const
inline

This function returns the value of the discoverable item property meshX: "the bin distribution in the X direction".

The default value for this property is given by the conditional value expression "LinMesh".

◆ meshY()

Mesh * CartesianSpatialGrid::meshY ( ) const
inline

This function returns the value of the discoverable item property meshY: "the bin distribution in the Y direction".

The default value for this property is given by the conditional value expression "LinMesh".

◆ meshZ()

Mesh * CartesianSpatialGrid::meshZ ( ) const
inline

This function returns the value of the discoverable item property meshZ: "the bin distribution in the Z direction".

The default value for this property is given by the conditional value expression "LinMesh".

◆ numCells()

int CartesianSpatialGrid::numCells ( ) const
overridevirtual

This function returns the number of cells in the grid.

Implements SpatialGrid.

◆ randomPositionInCell()

Position CartesianSpatialGrid::randomPositionInCell ( int m) const
overridevirtual

This function returns a random location from the cell with index \(m\). For a cartesian grid, the function first determines the bin indices \(i\) and \(k\) in the X, Y and Z directions that correspond to the index \(m\). Then random coordinates \(x\), \(y\) and \(z\) are determined using

\[ \begin{split} x &= x_i + {\cal{X}}_1\,(x_{i+1}-x_i) \\ y &= y_j + {\cal{X}}_2\,(y_{j+1}-y_j) \\ z &= z_k + {\cal{X}}_3\, (z_{k+1}-z_k), \end{split} \]

with \({\cal{X}}_1\), \({\cal{X}}_2\) and \({\cal{X}}_3\) three uniform deviates. A position with these cartesian coordinates is returned.

Implements SpatialGrid.

◆ setupSelfAfter()

void CartesianSpatialGrid::setupSelfAfter ( )
overrideprotectedvirtual

This function sets up a number of data members that depend on the Mesh objects configured for this grid.

Reimplemented from SimulationItem.

◆ volume()

double CartesianSpatialGrid::volume ( int m) const
overridevirtual

This function returns the volume of the cell with index \(m\). For a cartesian grid, the function determines the bin indices \(i\), \(j\) and \(k\) corresponding to the X, Y and Z directions. The volume is then easily calculated as \(V = (x_{i+1}-x_i)\, (y_{j+1}-y_j)\, (z_{k+1}-z_k) \).

Implements SpatialGrid.

◆ write_xy()

void CartesianSpatialGrid::write_xy ( SpatialGridPlotFile * outfile) const
overrideprotectedvirtual

This function writes the intersection of the grid structure with the xy plane to the specified SpatialGridPlotFile object.

Reimplemented from SpatialGrid.

◆ write_xyz()

void CartesianSpatialGrid::write_xyz ( SpatialGridPlotFile * outfile) const
overrideprotectedvirtual

This function writes 3D information for all cells in the grid structure to the specified SpatialGridPlotFile object.

Reimplemented from SpatialGrid.

◆ write_xz()

void CartesianSpatialGrid::write_xz ( SpatialGridPlotFile * outfile) const
overrideprotectedvirtual

This function writes the intersection of the grid structure with the xz plane to the specified SpatialGridPlotFile object.

Reimplemented from SpatialGrid.

◆ write_yz()

void CartesianSpatialGrid::write_yz ( SpatialGridPlotFile * outfile) const
overrideprotectedvirtual

This function writes the intersection of the grid structure with the yz plane to the specified SpatialGridPlotFile object.

Reimplemented from SpatialGrid.


The documentation for this class was generated from the following file: