The SKIRT project
advanced radiative transfer for astrophysics
Cylinder3DSpatialGrid Class Reference

#include <Cylinder3DSpatialGrid.hpp>

Inheritance diagram for Cylinder3DSpatialGrid:

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
int dimension () const override
MeshmeshAzimuthal () const
MeshmeshRadial () const
MeshmeshZ () const
int numCells () const override
Position randomPositionInCell (int m) const override
void setupSelfAfter () override
double volume (int m) const override
Public Member Functions inherited from CylinderSpatialGrid
double maxRadius () const
double maxZ () const
double minRadius () 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

Protected Member Functions

 Cylinder3DSpatialGrid ()
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 CylinderSpatialGrid
 CylinderSpatialGrid ()
Box boundingBox () const override
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 ()

Private Types

using BaseType
using ItemType

Private Member Functions

bool getCoords (int m, double &Rmin, double &phimin, double &zmin, double &Rmax, double &phimax, double &zmax) const
int index (int i, int j, int k) const

Private Attributes

Array _cosv
double _eps
bool _hasHole
Mesh_meshAzimuthal
Mesh_meshRadial
Mesh_meshZ
int _Ncells
int _Nphi
int _NR
int _Nz
Array _phiv
Array _Rv
Array _sinv
Array _zv

Friends

class ItemRegistry
class MySegmentGenerator

Detailed Description

The Cylinder3DSpatialGrid class is subclass of the CylinderSpatialGrid class, and represents a fully three-dimensional spatial grid based on cylindrical coordinates. The grid is specified through three sets of grid points:

  • \(N_R+1\) radial grid points \(R_i, \,i=0,\ldots,N_R\), with \(0\le R_\text{min} = R_0\), \(R_i<R_{i+1}\), and \(R_{N_R} = R_\text{max}\).
  • \(N_\varphi+1\) azimuthal grid points \(\varphi_j, \,j=0,\ldots,N_\varphi\), with \(-\pi=\varphi_0\), \(0<\varphi_{j+1}-\varphi_j\le2\pi/3\), and \(\varphi_{N_\varphi}=\pi\). The maximum limit on azimuth bin width is imposed to avoid confusion between the meridional half-planes when detecting cell border limits.
  • \(N_z+1\) vertical grid points \(z_k, \,k=0,\ldots,N_z\), with \(z_\text{min} = z_0\), \(z_i<z_{i+1}\), and \(z_{N_z} = z_\text{max}\).

In total there are \(N_{\text{cells}} = N_R\,N_\varphi\,N_z\) cells in the grid.

Constructor & Destructor Documentation

◆ Cylinder3DSpatialGrid()

Cylinder3DSpatialGrid::Cylinder3DSpatialGrid ( )
inlineprotected

Default constructor for concrete Item subclass Cylinder3DSpatialGrid: "a 3D spatial grid in cylindrical coordinates".

Member Function Documentation

◆ cellIndex()

int Cylinder3DSpatialGrid::cellIndex ( Position bfr) const
overridevirtual

This function returns the index \(m\) of the cell that contains the position \({\bf{r}}\). It determines the indices \(i,j,k\) of the cell containing the position and calculates the correct cell index based on these numbers.

Implements SpatialGrid.

◆ centralPositionInCell()

Position Cylinder3DSpatialGrid::centralPositionInCell ( int m) const
overridevirtual

This function returns the central location of the cell with index \(m\). It determines the 3D bin indices \(i,j,k\) corresponding to the index \(m\), and then calculates the cylindrical coordinates of the central position using

\[ \begin{split} R &= \frac{R_i + R_{i+1}}{2} \\ \varphi &= \frac{\varphi_j + \varphi_{j+1}}{2} \\ z &= \frac{z_k + z_{k+1}}{2} \end{split} \]

Implements SpatialGrid.

◆ createPathSegmentGenerator()

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

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

The ray equation of the path can be written as

\[\begin{cases} x = r_\text{x} + k_\text{x}s \\ y = r_\text{y} + k_\text{y}s \\ z = r_\text{z} + k_\text{z}s \\ \end{cases} \quad \text{with} \;s>0.\]

Intersection with a vertical cylinder centered on the origin with equation \(x^2 +y^2 = R_*^2\) yields a quadratic equation of the form \(s^2+2bs+c=0\) with

\[\begin{aligned} b &= \frac{r_\text{x}k_\text{x} + r_\text{y}k_\text{y}} {k_\text{x}^2 + k_\text{y}^2} \\ c &= \frac{r_\text{x}^2 + r_\text{y}^2 - R_*^2} {k_\text{x}^2 + k_\text{y}^2} \\ \end{aligned}\]

Intersection with a meridional plane with equation \(\sin\varphi_* x = \cos\varphi_* y\) yields

\[ s = -\;\frac{r_\text{x}\sin\varphi_* - r_\text{y}\cos\varphi_*} {k_\text{x}\sin\varphi_* - k_\text{y}\cos\varphi_*} \]

The requirement that \(\varphi_{j+1}-\varphi_j\le2\pi/3\) ensures that the intersection point with the reflected half-plane is always more distant than the other cell boundaries thus that phantom point is automatically ignored.

Intersection with a horizontal plane with equation \(z=z_*\) easily yields \(s = (z_*-r_\text{z})/k_\text{z}\).

The segment generator progresses the starting point of the path through the grid along the path's direction. For each step along the way, it calculates the distances to the intersections with all candidate borders of the current cell, and then selects the nearest intersection point.

Implements SpatialGrid.

◆ diagonal()

double Cylinder3DSpatialGrid::diagonal ( int m) const
overridevirtual

This function returns the "diagonal" of the cell with index \(m\). It determines the 3D bin indices \(i,j,k\) corresponding to the index \(m\), and then calculates the distance between the outer/upper and inner/lower corners of the cell, i.e. between the points \(\{ R_i,\varphi_j,z_k \}\) and \(\{ R_{i+1},\varphi_{j+1},z_{k+1} \}\).

Implements SpatialGrid.

◆ dimension()

int Cylinder3DSpatialGrid::dimension ( ) const
overridevirtual

This function returns the dimension of the grid, which is 3.

Implements SpatialGrid.

◆ getCoords()

bool Cylinder3DSpatialGrid::getCoords ( int m,
double & Rmin,
double & phimin,
double & zmin,
double & Rmax,
double & phimax,
double & zmax ) const
private

This function obtains the cylindrical coordinates for the corners of the cell with index \(m\). It determines the 3D bin indices \(i,j,k\) corresponding to the index \(m\) using the formulae

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

If all of the resulting bin indices are within range, the function stores the corresponding cell corner coordinates in the provided arguments and returns true. If any of the indices are out of range, the function returns false and the contents of the provided arguments remains unchanged.

◆ index()

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

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

◆ meshAzimuthal()

Mesh * Cylinder3DSpatialGrid::meshAzimuthal ( ) const
inline

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

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

◆ meshRadial()

Mesh * Cylinder3DSpatialGrid::meshRadial ( ) const
inline

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

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

◆ meshZ()

Mesh * Cylinder3DSpatialGrid::meshZ ( ) const
inline

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

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

◆ numCells()

int Cylinder3DSpatialGrid::numCells ( ) const
overridevirtual

This function returns the number of cells \(N_R\,N_\varphi\,N_z\) in the grid.

Implements SpatialGrid.

◆ randomPositionInCell()

Position Cylinder3DSpatialGrid::randomPositionInCell ( int m) const
overridevirtual

This function returns a random position in the cell with index \(m\). It determines the 3D bin indices \(i,j,k\) corresponding to the index \(m\), and then generates the cylindrical coordinates of a random position using

\[ \begin{split} R &= \sqrt{R_i^2 + {\cal{X}}_1\,(R_{i+1}^2-R_i^2)} \\ \varphi &= \varphi_j + {\cal{X}}_2\, (\varphi_{j+1}-\varphi_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.

Implements SpatialGrid.

◆ setupSelfAfter()

void Cylinder3DSpatialGrid::setupSelfAfter ( )
overridevirtual

This function sets up a number of data members that depend on the Mesh objects configured for this grid. It precomputes and stores sine and cosine values for the azimuthal grid points, and verifies that the azimuth bins are not too wide.

Reimplemented from SimulationItem.

◆ volume()

double Cylinder3DSpatialGrid::volume ( int m) const
overridevirtual

This function returns the volume of the cell with index \(m\). It determines the 3D bin indices \(i,j,k\) corresponding to the index \(m\), and then calculates the volume as \(\frac{1}{2} (R_{i+1}^2-R_i^2) (\varphi_{j+1}-\varphi_j) (z_{k+1}-z_k)\).

Implements SpatialGrid.

◆ write_xy()

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

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

Reimplemented from SpatialGrid.

◆ write_xyz()

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

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

Reimplemented from SpatialGrid.

◆ write_xz()

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

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

Reimplemented from SpatialGrid.

◆ write_yz()

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

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

Reimplemented from SpatialGrid.


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