The SKIRT project
advanced radiative transfer for astrophysics
StructuredSphereSpatialGrid Class Reference

#include <StructuredSphereSpatialGrid.hpp>

Inheritance diagram for StructuredSphereSpatialGrid:

Public Member Functions

int cellIndex (Position bfr) const override
Position centralPositionInCell (int m) const override
double diagonal (int m) const override
int dimension () const override
MeshmeshAzimuthal () const
MeshmeshPolar () const
MeshmeshRadial () 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 SphereSpatialGrid
Box boundingBox () const override
double maxRadius () const
double minRadius () const
Public Member Functions inherited from SpatialGrid
virtual std::unique_ptr< PathSegmentGeneratorcreatePathSegmentGenerator () const =0
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

 StructuredSphereSpatialGrid ()
bool getCoords (int m, double &rmin, double &thetamin, double &phimin, double &rmax, double &thetamax, double &phimax) const
int index (int i, int j, int k) const
virtual double meshEpsilonScale () const
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
void writeMeridionalStructure (SpatialGridPlotFile *outfile) const
Protected Member Functions inherited from SphereSpatialGrid
 SphereSpatialGrid ()
void setupSelfBefore () override
Protected Member Functions inherited from SpatialGrid
 SpatialGrid ()
Randomrandom () const
Protected Member Functions inherited from SimulationItem
 SimulationItem ()
virtual bool offersInterface (const std::type_info &interfaceTypeInfo) const
Protected Member Functions inherited from Item
 Item ()

Protected Attributes

vector< double > _cellVolume
Array _cosv
Array _cv
double _eps
int _Ncells
int _Nphi
int _Nr
int _Ntheta
Array _phiv
Array _rv
Array _sinv
Array _thetav

Private Types

using BaseType
using ItemType

Private Attributes

Mesh_meshAzimuthal
Mesh_meshPolar
Mesh_meshRadial

Friends

class ItemRegistry

Additional Inherited Members

Static Protected Member Functions inherited from SphereSpatialGrid
static int initPolarGrid (Array &thetav, Array &cosv, const Mesh *mesh)

Detailed Description

StructuredSphereSpatialGrid is an abstract subclass of the SphereSpatialGrid class that represents a fully three-dimensional structured grid based on spherical 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_\theta+1\) polar-inclination grid points \(\theta_j, \,j=0,\ldots,N_\theta\) with \(0=\theta_0\), \(\theta_j<\theta_{j+1}\), and \(\theta_{N_\theta}=\pi\).
  • \(N_\varphi+1\) azimuthal grid points \(\varphi_k, \,k=0,\ldots,N_\varphi\), with \(-\pi=\varphi_0\), \(0<\varphi_{k+1}-\varphi_k\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.
Note
The algorithm used by a path segment generator built on top of this class requires that the xy-plane \(\theta=\pi/2\) is included in the polar grid. If this is not the case, this point is automatically added, increasing the number of polar bins by one.

In total there are \(N_{\text{cells}} = N_r\,N_\theta\,N_\varphi\) cells in the structured grid.

This class provides the structured grid itself, including its geometric queries (cell volume, diagonal, containment, central and random positions, plotting functions), but leaves the path segment generator to concrete subclasses, since this depends heavily on whether anything besides the structured grid (such as embedded clumps) needs to be taken into account. Sphere3DSpatialGrid is a concrete subclass that adds nothing beyond the structured grid itself; ClumpySphericalSpatialGrid is a concrete subclass that superposes a set of spherical clumps on top of it.

Constructor & Destructor Documentation

◆ StructuredSphereSpatialGrid()

StructuredSphereSpatialGrid::StructuredSphereSpatialGrid ( )
inlineprotected

Default constructor for abstract Item subclass StructuredSphereSpatialGrid: "a structured 3D spatial grid in spherical coordinates".

Member Function Documentation

◆ cellIndex()

int StructuredSphereSpatialGrid::cellIndex ( Position bfr) const
overridevirtual

This function returns the index \(m\) of the structured cell that contains the position \({\bf{r}}\), or -1 if the position is outside the grid. It determines the 3D bin indices \(i,j,k\) of the cell containing the position and calculates the correct cell index based on these three numbers.

Implements SpatialGrid.

◆ centralPositionInCell()

Position StructuredSphereSpatialGrid::centralPositionInCell ( int m) const
overridevirtual

This function returns the central location of the structured cell with index \(m\). It determines the 3D bin indices \(i,j,k\) corresponding to the cell index \(m\). The spherical coordinates of the central position are subsequently determined from

\[\begin{split} r &= \frac{r_i + r_{i+1}}{2} \\ \theta &= \frac{\theta_j + \theta_{j+1}}{2} \\ \varphi &= \frac{\varphi_k + \varphi_{k+1}}{2}. \end{split} \]

Implements SpatialGrid.

◆ diagonal()

double StructuredSphereSpatialGrid::diagonal ( int m) const
overridevirtual

This function returns the "diagonal" of the structured cell with index \(m\). It determines the 3D bin indices \(i,j,k\) corresponding to the cell 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,\theta_j,\varphi_k \}\) and \(\{ r_{i+1},\theta_{j+1}, \varphi_{k+1} \}\).

Implements SpatialGrid.

◆ dimension()

int StructuredSphereSpatialGrid::dimension ( ) const
overridevirtual

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

Implements SpatialGrid.

◆ getCoords()

bool StructuredSphereSpatialGrid::getCoords ( int m,
double & rmin,
double & thetamin,
double & phimin,
double & rmax,
double & thetamax,
double & phimax ) const
protected

This function obtains the spherical coordinates for the corners of the structured cell with index \(m\). It determines the radial, polar and azimuthal bin indices \(i\), \(j\) and \(k\) corresponding to the cell index \(m\) using the formulae

\[ \begin{split} i &= \lfloor m/(N_\theta\,N_\varphi) \rfloor \\ j &= \lfloor m/N_\varphi \rfloor \,\text{mod}\, N_\theta \\ k &= m\,\text{mod}\,N_\varphi. \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 StructuredSphereSpatialGrid::index ( int i,
int j,
int k ) const
protected

This function returns the cell index corresponding to the radial index \(i\), the polar index \(j\), and azimuthal index \(k\). The correspondence is \(m=k+j\,N_\varphi+i\,N_\theta\,N_\varphi\).

◆ meshAzimuthal()

Mesh * StructuredSphereSpatialGrid::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".

◆ meshEpsilonScale()

virtual double StructuredSphereSpatialGrid::meshEpsilonScale ( ) const
protectedvirtual

This function returns the relative-to-maxRadius scale factor used, together with the mesh's own natural scale (the width of the innermost bin or, if there is a hole, the hole's radius), to determine the small epsilon used for progressing a path across a structured cell boundary. The default implementation returns a value that has proven robust for a plain structured grid. A subclass that superposes additional internal geometry (such as embedded clumps) on the structured grid may need to override this with a more conservative (larger) value, since paths in that subclass cross more boundaries of more varied kinds within a given region.

Reimplemented in ClumpySphericalSpatialGrid.

◆ meshPolar()

Mesh * StructuredSphereSpatialGrid::meshPolar ( ) const
inline

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

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

◆ meshRadial()

Mesh * StructuredSphereSpatialGrid::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".

◆ numCells()

int StructuredSphereSpatialGrid::numCells ( ) const
overridevirtual

This function returns the number of cells \(N_r\,N_\theta\,N_\varphi\) in the structured grid.

Implements SpatialGrid.

◆ randomPositionInCell()

Position StructuredSphereSpatialGrid::randomPositionInCell ( int m) const
overridevirtual

This function returns a random location in the structured cell with index \(m\). It determines the 3D bin indices \(i,j,k\) corresponding to the cell index \(m\). Then a random radius \(r\), a random inclination \(\theta\), and a random azimuth \(\varphi\) are determined using

\[ \begin{split} r &= \left( r_i^3 + {\cal{X}}_1\,(r_{i+1}^3-r_i^3) \right)^{1/3} \\ \cos\theta &= \cos\theta_j + {\cal{X}}_2\, (\cos\theta_{j+1}-\cos\theta_j) \\ \varphi &= \varphi_k + {\cal{X}}_3\, (\varphi_{k+1}-\varphi_k), \end{split} \]

with \({\cal{X}}_1\), \({\cal{X}}_2\) and \({\cal{X}}_3\) three uniform deviates.

Implements SpatialGrid.

◆ setupSelfAfter()

void StructuredSphereSpatialGrid::setupSelfAfter ( )
overridevirtual

This function sets up the structured grid. It precomputes and stores cosine values for the polar grid points and sine and cosine values for the azimuthal grid points, and it caches the nominal volume of each structured cell. It further ensures that the grid points conform to the requirements described in the class header.

Reimplemented from SimulationItem.

◆ volume()

double StructuredSphereSpatialGrid::volume ( int m) const
overridevirtual

This function returns the volume of the structured cell with index \(m\), using the nominal volume cached during setup. The volume is calculated as

\[ V = \frac{1}{3} \left(r_{i+1}^3-r_i^3\right) \left(\cos\theta_j-\cos\theta_{j+1}\right) \left(\varphi_{k+1}-\varphi_k\right). \]

.

Implements SpatialGrid.

◆ write_xy()

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

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

Reimplemented from SpatialGrid.

◆ write_xyz()

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

This function writes 3D information for the structured grid to the specified SpatialGridPlotFile object. A subclass that superposes additional geometry on the structured grid may override this function to overlay that geometry, for example by calling this implementation first and then adding its own content.

Reimplemented from SpatialGrid.

◆ write_xz()

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

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

Reimplemented from SpatialGrid.

◆ write_yz()

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

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

Reimplemented from SpatialGrid.

◆ writeMeridionalStructure()

void StructuredSphereSpatialGrid::writeMeridionalStructure ( SpatialGridPlotFile * outfile) const
protected

This function writes the axisymmetric structured-grid lines (spheres and cones) intersected by any meridional plane to the specified SpatialGridPlotFile object. Because the structured grid is itself axisymmetric, this single function serves both the xz and yz views; a subclass overriding write_xz() or write_yz() to overlay additional, non-axisymmetric content can call this function to obtain the structured grid's own contribution.


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