The SKIRT project
advanced radiative transfer for astrophysics
DisjointWavelengthGrid Class Reference

#include <DisjointWavelengthGrid.hpp>

Inheritance diagram for DisjointWavelengthGrid:

Public Member Functions

int bin (double lambda) const override
vector< int > bins (double lambda) const override
const Arraydlambdav () const
double effectiveWidth (int ell) const override
Array extdlambdav () const
Array extlambdav () const
const Arraylambdav () const
double leftBorder (int ell) const override
int numBins () const override
double rightBorder (int ell) const override
double transmission (int ell, double lambda) const override
double wavelength (int ell) const override
Public Member Functions inherited from WavelengthGrid
Range wavelengthRange () 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

 DisjointWavelengthGrid ()
void setupSelfAfter () override
void setWavelengthBins (const Array &lambdav, double relativeHalfWidth, bool constantWidth=false)
void setWavelengthBorders (const Array &borderv, bool logScale)
void setWavelengthRange (const Array &lambdav, bool logScale)
void setWavelengthSegments (const Array &bordcharv)
void setWavelengthSegments (const vector< double > &borderv, const vector< double > &characv)
Protected Member Functions inherited from WavelengthGrid
 WavelengthGrid ()
Protected Member Functions inherited from SimulationItem
 SimulationItem ()
virtual bool offersInterface (const std::type_info &interfaceTypeInfo) const
virtual void setupSelfBefore ()
Protected Member Functions inherited from Item
 Item ()

Private Types

using BaseType
using ItemType

Private Attributes

Array _borderv
Array _dlambdav
vector< int > _ellv
Array _lambdaleftv
Array _lambdarightv
Array _lambdav

Friends

class ItemRegistry

Detailed Description

DisjointWavelengthGrid is an abstract class that represents wavelength grids with straightforward, non-overlapping bins with constant transmission across each bin.

Specifically, a disjoint wavelength grid consists of non-overlapping but possibly adjacent wavelength bins in increasing wavelength order, with constant maximum transmission within the bins and zero transmission outside of the bins. Each bin is defined by its left and right borders and has a characteristic wavelength that falls inside the bin. The left border is considered to be inside of the bin; the right border is considered to be outside of the bin. Neighboring bins may have a common border but can also be disconnected.

Formally, assuming \(N>0\) bins with zero-based indices, we have

\[\lambda^\mathrm{left}_\ell \le \lambda^\mathrm{c}_\ell < \lambda^\mathrm{right}_\ell, \quad \ell=0\dots N-1 \]

and if \(N>1\), we additionally have

\[ \lambda^\mathrm{right}_\ell \le \lambda^\mathrm{left}_{\ell+1}, \quad \ell=0\dots N-2. \]

Finally, each bin of course has an associated bin width,

\[\lambda^\mathrm{right}_\ell - \lambda^\mathrm{left}_\ell > 0, \quad \ell=0\dots N-1.\]

A DisjointWavelengthGrid subclass is expected to invoke one of the setWavelengthXXX() functions during setup to initialize the wavelength grid. The current implementation offers two such functions: one to specify a consecutive range of adjacent wavelength bins given a list of characteric wavelengths, and another one to specify distinct, nonadjacent wavelength bins given a list of characteric wavelengths and a relative bin width. Other options can be added as the need arises.

Constructor & Destructor Documentation

◆ DisjointWavelengthGrid()

DisjointWavelengthGrid::DisjointWavelengthGrid ( )
inlineprotected

Default constructor for abstract Item subclass DisjointWavelengthGrid: "a wavelength grid with non-overlapping bins".

Member Function Documentation

◆ bin()

int DisjointWavelengthGrid::bin ( double lambda) const
overridevirtual

This function returns the index \(\ell\) of the wavelength bin that contains the specified wavelength \(\lambda\), i.e. for which \(\lambda^\mathrm{left}_\ell <= \lambda < \lambda^\mathrm{right}_\ell\). If \(\lambda\) does not lie inside one of the wavelength bins, the function returns -1.

Implements WavelengthGrid.

◆ bins()

vector< int > DisjointWavelengthGrid::bins ( double lambda) const
overridevirtual

This function returns a single-element list with the index \(\ell\) of the wavelength bin that contains the specified wavelength \(\lambda\), i.e. for which \(\lambda^\mathrm{left}_\ell <= \lambda < \lambda^\mathrm{right}_\ell\). If \(\lambda\) does not lie inside one of the wavelength bins, the function returns an empty list.

Implements WavelengthGrid.

◆ dlambdav()

const Array & DisjointWavelengthGrid::dlambdav ( ) const
inline

This function returns (a reference to) the list of bin widths in this wavelength grid. In combination with the lambdav() function, it allows easily expressing calculations involving consecutive wavelength grids.

◆ effectiveWidth()

double DisjointWavelengthGrid::effectiveWidth ( int ell) const
overridevirtual

This function returns the width of the wavelength bin corresponding to the index \(\ell\), i.e. \(\lambda^\mathrm{right}_\ell - \lambda^\mathrm{left}_\ell\).

Implements WavelengthGrid.

◆ extdlambdav()

Array DisjointWavelengthGrid::extdlambdav ( ) const

This function returns a list of bin widths in this wavelength grid extended with a zero value on each side. This extended wavelength bin width list can be used, for example, to integrate a function discretized on the extended wavelength grid returned by the extlambdav() function over the wavelength range.

◆ extlambdav()

Array DisjointWavelengthGrid::extlambdav ( ) const

This function returns a list of the characteristic wavelengths in this wavelength grid extended with the outermost bin border point on each side. The list has thus two additional points, one on each side, and as a result covers the complete wavelength range of the grid, including the widths of the outer bins. This extended wavelength list can be used in situations where one needs to calculate/interpolate some function over the complete range of the wavelength grid and not just up to the outermost characteristic wavelengths.

◆ lambdav()

const Array & DisjointWavelengthGrid::lambdav ( ) const
inline

This function returns (a reference to) the list of characteristic wavelengths in this wavelength grid. In combination with the dlambdav() function, it allows easily expressing calculations involving consecutive wavelength grids.

◆ leftBorder()

double DisjointWavelengthGrid::leftBorder ( int ell) const
overridevirtual

This function returns the left border of the wavelength bin corresponding to the index \(\ell\), i.e. \(\lambda^\mathrm{left}_\ell\).

Implements WavelengthGrid.

◆ numBins()

int DisjointWavelengthGrid::numBins ( ) const
overridevirtual

This function returns the number of bins, \(N\), in the grid (or equivalently, the number of characteristic wavelengths).

Implements WavelengthGrid.

◆ rightBorder()

double DisjointWavelengthGrid::rightBorder ( int ell) const
overridevirtual

This function returns the right border of the wavelength bin corresponding to the index \(\ell\), i.e. \(\lambda^\mathrm{right}_\ell\).

Implements WavelengthGrid.

◆ setupSelfAfter()

void DisjointWavelengthGrid::setupSelfAfter ( )
overrideprotectedvirtual

This function verifies that the wavelength bins have been initialized by a subclass calling one of the setWavelengthXXX() functions of this class in their setupSelfBefore() function.

Reimplemented from SimulationItem.

◆ setWavelengthBins()

void DisjointWavelengthGrid::setWavelengthBins ( const Array & lambdav,
double relativeHalfWidth,
bool constantWidth = false )
protected

This function initializes the wavelength grid to a set of distinct, nonadjacent wavelength bins given a list of characteric wavelengths and a relative half bin width. The subclass determines a list of characteric wavelengths and a relative half bin width, and the bin borders and bin widths are automatically calculated from that information by this function. If the specified wavelength list is empty, or if the relative half bin width is not positive, or if the calculated bins overlap, the function throws a fatal error.

Specifically, the function first sorts the specified characteristic wavelengths in ascending order and then calculates the bin borders using \(\lambda^\mathrm{left}_\ell = \lambda^\mathrm{c}_\ell(1-w)\) and \(\lambda^\mathrm{right}_\ell = \lambda^\mathrm{c}_\ell(1+w)\;, \ell=0\dots N-1\), where \(w\) is the specified relative half bin width. If the constantWidth flag is true, the width for the shortest wavelength is used for all bin widths instead. Finally the function trivially calculates the wavelength bin widths from the bin borders.

◆ setWavelengthBorders()

void DisjointWavelengthGrid::setWavelengthBorders ( const Array & borderv,
bool logScale )
protected

This function initializes the wavelength grid to a consecutive range of \(N>0\) adjacent wavelength bins given a list of \(N+1\) wavelength bin borders. The subclass determines a list of bin borders according to some predefined scheme, and the characteristic wavelengths and bin widths are automatically determined from that list by this function. If the specified list has fewer than two bin borders, or if there are duplicate values (which would lead to empty bins), the function throws a fatal error.

The function first sorts the specified wavelength bin borders in ascending order and then calculates the characteristic wavelengths assuming linear scaling (arithmetic mean) or logarithmic scaling (geometric mean) depending on the value of the logScale flag.

◆ setWavelengthRange()

void DisjointWavelengthGrid::setWavelengthRange ( const Array & lambdav,
bool logScale )
protected

This function initializes the wavelength grid to a consecutive range of adjacent wavelength bins given a list of characteric wavelengths. The subclass determines a list of characteric wavelengths according to some predefined scheme, and the bin borders and bin widths are automatically determined from that list by this function. If the specified wavelength list is empty, or if there are duplicate values (which would lead to empty bins), the function throws a fatal error.

The function first sorts the specified characteristic wavelengths in ascending order and then calculates the bin borders assuming linear or logarithmic scaling depending on the value of the logScale flag. The inner border between two consecutive characteristic wavelengths is placed at the mid-point of those two wavelengths (in linear or logarithmic space), and the outer borders at the edges of the wavelength range are placed such that the outer bins have the same width as the respective adjacent bins (in linear or logarithmic space). If the wavelength grid has just a single wavelength, the borders are placed just next to the wavelength to form a narrow bin. Finally, the function trivially calculates the wavelength bin widths from the bin borders.

For linear scaling, the corresponding formulas are trivial. For logarithmic scaling, the formalas in logarithmic space translate easily to equivalent but more efficient formulas in real space. For the inner borders this yields the geometric mean of the two adjacent characteristic wavelengths, i.e. \(\lambda^\mathrm{right}_{\ell-1} = \lambda^\mathrm{left}_\ell = \sqrt{\lambda^\mathrm{c}_{\ell-1}\lambda^\mathrm{c}_\ell}\;, \ell=1\dots N-1\). The leftmost outer border is placed at \(\lambda^\mathrm{left}_0 = \sqrt{(\lambda^\mathrm{c}_{0})^3/\lambda^\mathrm{c}_1}\), and the rightmost outer border is placed at \(\lambda^\mathrm{right}_{N-1} = \sqrt{(\lambda^\mathrm{c}_{N-1})^3/\lambda^\mathrm{c}_{N-2}}\).

If there is just a single wavelength in the grid, the outer borders are placed (for both linear and logarithmic scaling) according to \(\lambda^\mathrm{left}_0 = \lambda^\mathrm{c}_{0}(1-1/1000)\) and \(\lambda^\mathrm{right}_0 = \lambda^\mathrm{c}_{0}(1+1/1000)\).

◆ setWavelengthSegments() [1/2]

void DisjointWavelengthGrid::setWavelengthSegments ( const Array & bordcharv)
protected

This function initializes the wavelength grid from a list of interleaved bin border points and corresponding characteristic wavelengths. (i.e., borders and characteristic wavelengths alternate). The number of values must be uneven and at least three. The list must be in strictly increasing or decreasing order, which means duplicates are not allowed, except that a zero characteristic wavelength indicates a segment that is not part of the grid, i.e. that lies between two non-adjacent bins. In other words, this option allows to (1) arbitrarily place characteristic wavelengths within each bin and (2) to specify intermediate wavelength ranges that are not covered by any bin.

◆ setWavelengthSegments() [2/2]

void DisjointWavelengthGrid::setWavelengthSegments ( const vector< double > & borderv,
const vector< double > & characv )
protected

This function initializes the wavelength grid from a list of bin border points and a corresponding list of characteristic wavelengths. A zero characteristic wavelength indicates a segment that is not part of the grid, i.e. that lies between two non-adjacent bins or beyond the outer grid borders. In other words, the subclass has full control over the placement of bin borders and characteristic wavelengths.

The two lists must have the same size. The borders must be listed in strictly increasing order of wavelength (i.e. there cannot be any duplicates), all nonzero characteristic wavelengths must lie within their corresponding bin, the last characteristic wavelength must be zero, and there must be at least one nonzero characteristic wavelength. If these requirements are violated, the behavior of this function is undefined.

◆ transmission()

double DisjointWavelengthGrid::transmission ( int ell,
double lambda ) const
overridevirtual

This function returns the relative transmission for the wavelength bin corresponding to the index \(\ell\) at the wavelength \(\lambda\). For the present class, it always returns

Implements WavelengthGrid.

◆ wavelength()

double DisjointWavelengthGrid::wavelength ( int ell) const
overridevirtual

This function returns the characteristic wavelength \(\lambda^\mathrm{c}_\ell\) corresponding to the index \(\ell\).

Implements WavelengthGrid.


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