The SKIRT project
advanced radiative transfer for astrophysics
Public Member Functions | Protected Member Functions | Private Types | Private Member Functions | Private Attributes | Friends | List of all members
Sphere3DSpatialGrid Class Reference

#include <Sphere3DSpatialGrid.hpp>

Inheritance diagram for Sphere3DSpatialGrid:
Inheritance graph
[legend]

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
 
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 Box boundingBox () const =0
 
virtual int cellIndex (Position bfr) const =0
 
virtual Position centralPositionInCell (int m) const =0
 
virtual std::unique_ptr< PathSegmentGeneratorcreatePathSegmentGenerator () const =0
 
virtual double diagonal (int m) const =0
 
virtual int dimension () const =0
 
virtual int numCells () const =0
 
virtual Position randomPositionInCell (int m) const =0
 
virtual double volume (int m) 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

 Sphere3DSpatialGrid ()
 
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 SphereSpatialGrid
 SphereSpatialGrid ()
 
void setupSelfBefore () override
 
- Protected Member Functions inherited from SpatialGrid
 SpatialGrid ()
 
Randomrandom () const
 
void setupSelfBefore () override
 
virtual void write_xy (SpatialGridPlotFile *outfile) const
 
virtual void write_xyz (SpatialGridPlotFile *outfile) const
 
virtual void write_xz (SpatialGridPlotFile *outfile) const
 
virtual void write_yz (SpatialGridPlotFile *outfile) const
 
- Protected Member Functions inherited from SimulationItem
 SimulationItem ()
 
virtual bool offersInterface (const std::type_info &interfaceTypeInfo) const
 
virtual void setupSelfAfter ()
 
virtual void setupSelfBefore ()
 
- Protected Member Functions inherited from Item
 Item ()
 

Private Types

using BaseType = SphereSpatialGrid
 
using ItemType = Sphere3DSpatialGrid
 

Private Member Functions

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
 

Private Attributes

Array _cosv
 
Array _cv
 
double _eps
 
Mesh_meshAzimuthal
 
Mesh_meshPolar
 
Mesh_meshRadial
 
int _Ncells
 
int _Nphi
 
int _Nr
 
int _Ntheta
 
Array _phiv
 
Array _rv
 
Array _sinv
 
Array _thetav
 

Friends

class ItemRegistry
 
class MySegmentGenerator
 

Additional Inherited Members

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

Detailed Description

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

Note
The algorithm used by the path segment generator in this class requires that the xy-plane θ=π/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 Ncells=NrNθNφ cells in the grid.

This item type is displayed only if the Boolean expression "Level2" evaluates to true after replacing the names by true or false depending on their presence.

Constructor & Destructor Documentation

◆ Sphere3DSpatialGrid()

Sphere3DSpatialGrid::Sphere3DSpatialGrid ( )
inlineprotected

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

Member Function Documentation

◆ cellIndex()

int Sphere3DSpatialGrid::cellIndex ( Position  bfr) const
overridevirtual

This function returns the index m of the cell that contains the position r. 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 Sphere3DSpatialGrid::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 cell index m. The spherical coordinates of the central position are subsequently determined from

r=ri+ri+12θ=θj+θj+12φ=φk+φk+12.

Implements SpatialGrid.

◆ createPathSegmentGenerator()

std::unique_ptr< PathSegmentGenerator > Sphere3DSpatialGrid::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 spherical grid, implemented as a private PathSegmentGenerator subclass.

We represent the path by its parameter equation x=r+sk, and we assume that k is a unit vector. The two intersection points with a radial boundary sphere x2=r2 are obtained by solving the quadratic equation s2+2(rk)s+(r2r2)=0 for s.

The two intersection points with an angular boundary cone xz2=c2x2 (with c=cosθ) are obtained by solving the quadratic equation (c2kz2)s2+2(c2rkrzkz)s+(c2r2rz2)=0 for s. The intersection points with the reflected cone are always more distant than the other cell boundaries (the requirement to include the xy-plane θ=π/2 in the grid ensures that this is true) and thus these phantom points are automatically ignored.

The intersection point with a meriodonal plane sinφx=cosφy is obtained by

s=rxsinφrycosφkxsinφkycosφ

The requirement that φj+1φj2π/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.

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 Sphere3DSpatialGrid::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 cell index m, and then calculates the distance between the outer/upper and inner/lower corners of the cell, i.e. between the points {ri,θj,φk} and {ri+1,θj+1,φk+1}.

Implements SpatialGrid.

◆ dimension()

int Sphere3DSpatialGrid::dimension ( ) const
overridevirtual

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

Implements SpatialGrid.

◆ getCoords()

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

This function obtains the spherical coordinates for the corners of the 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

i=m/(NθNφ)j=m/NφmodNθk=mmodNφ.

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 Sphere3DSpatialGrid::index ( int  i,
int  j,
int  k 
) const
private

This private function returns the cell index corresponding to the radial index i, the polar index j, and azimuthal index k. The correspondence is m=k+jNφ+iNθNφ.

◆ meshAzimuthal()

Sphere3DSpatialGrid::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" .

◆ meshPolar()

Sphere3DSpatialGrid::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()

Sphere3DSpatialGrid::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 Sphere3DSpatialGrid::numCells ( ) const
overridevirtual

This function returns the number of cells NrNθNφ in the grid.

Implements SpatialGrid.

◆ randomPositionInCell()

Position Sphere3DSpatialGrid::randomPositionInCell ( int  m) const
overridevirtual

This function returns a random location in the 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 θ, and a random azimuth φ are determined using

r=(ri3+X1(ri+13ri3))1/3cosθ=cosθj+X2(cosθj+1cosθj)φ=φk+X3(φk+1φk),

with X1, X2 and X3 three uniform deviates.

Implements SpatialGrid.

◆ setupSelfAfter()

void Sphere3DSpatialGrid::setupSelfAfter ( )
overridevirtual

This function sets up a number of data members. It precomputes and stores cosine values for the polar grid points and sine and cosine values for the azimuthal grid points. It further ensures that the grid points conform to the requirements described in the class header.

Reimplemented from SimulationItem.

◆ volume()

double Sphere3DSpatialGrid::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 cell index m, and then calculates the volume as

V=13(ri+13ri3)(cosθjcosθj+1)(φk+1φk).

Implements SpatialGrid.

◆ write_xy()

void Sphere3DSpatialGrid::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 Sphere3DSpatialGrid::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 Sphere3DSpatialGrid::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 Sphere3DSpatialGrid::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: