# BoundingBox¶

This is an introduction to the BoundingBox class. We write a small overarching summary of the class where we define the algorithm/equation/structure reasoning for having this class or where it fits with the rest of the code.

template<int D>
class BoundingBox

Class defining the computational domain.

The computational domain is made up of a collection of D-dimensional boxes on a particular length scale $$n$$. The size of each box is then $$[2^{-n}]^D$$, i.e. higher scale means smaller boxes, and the scale may be negative. The number of boxes can be different in each dimension $$[n_x, n_y, \dots]$$, but they must all be on the same scale (size). Box translations relative to the world origin must be an integer multiple of the given scale size $$2^{-n}$$.

Subclassed by mrcpp::NodeBox< D >

Public Functions

explicit BoundingBox(std::array<int, 2> box)

Constructor for BoundingBox object.

Creates a box with appropriate root scale and scaling factor to fit the given bounds, which applies to all dimensions. Root scale is chosen such that the scaling factor becomes 1 < sfac < 2.

Limitations: Box must be either [0,L] or [-L,L], with L a positive integer. This is the most general constructor, which will create a world with no periodic boundary conditions.

Parameters:

box[in] [lower, upper] bound in all dimensions.

Returns:

New BoundingBox object.

explicit BoundingBox(int n = 0, const std::array<int, D> &l = {}, const std::array<int, D> &nb = {}, const std::array<double, D> &sf = {}, bool pbc = false)

Constructor for BoundingBox object.

Creates a box with given parameters. The parameter n defines the length scale, which, together with sf, determines the unit length of each side of the boxes by $$[2^{-n}]^D$$. The parameter l defines the corner translation of the lower corner of the box relative to the world origin. The parameter nb defines the number of boxes in each dimension. The parameter sf defines the scaling factor, which determines the box translations around the origin, i.e. the amount of boxes around origin. The parameter pbc defines whether the world is periodic or not. In this constructor this value makes all dimensions periodic. This constructor is used for work in periodic systems.

Parameters:
• n[in] Length scale, default 0.

• l[in] Corner translation, default [0, 0, …].

• nb[in] Number of boxes, default [1, 1, …].

• sf[in] Scaling factor, default [1.0, 1.0, …].

• pbc[in] Periodic boundary conditions, default false.

Returns:

New BoundingBox object.

explicit BoundingBox(const NodeIndex<D> &idx, const std::array<int, D> &nb = {}, const std::array<double, D> &sf = {})

Constructor for BoundingBox object.

Creates a box with given parameters. The parameter idx defines the index of the lower corner of the box relative to the world origin. The parameter nb defines the number of boxes in each dimension. The parameter sf defines the scaling factor, which determines the box translations around the origin, i.e. the amount of boxes around origin. This constructor creates a world with no periodic boundary conditions.

Parameters:
• idx[in] index of the lower corner of the box.

• nb[in] Number of boxes, default [1, 1, …].

• sf[in] Scaling factor, default [1.0, 1.0, …].

Returns:

New BoundingBox object.

explicit BoundingBox(const std::array<double, D> &sf, bool pbc = true)

Constructor for BoundingBox object.

Creates a box with given parameters. The parameter sf defines the scaling factor, which determines the box translations around the origin, i.e. the amount of boxes around origin. The parameter pbc defines whether the world is periodic or not. In this constructor this value makes all dimensions periodic. This construtor is used for work in periodic systems.

Parameters:
• sf[in] Scaling factor, default [1.0, 1.0, …].

• pbc[in] Periodic boundary conditions, default true.

BoundingBox(const std::array<double, D> &sf, std::array<bool, D> pbc)

Constructor for BoundingBox object.

Creates a box with given parameters. The parameter sf defines the scaling factor, which determines the box translations around the origin, i.e. the amount of boxes around origin. The parameter pbc defines whether the world is periodic or not. In this constructor this value makes specific dimensions periodic. This is used for work in periodic systems.

Parameters:
• sf[in] Scaling factor, default [1.0, 1.0, …].

• pbc[in] Periodic boundary conditions, default true.

Returns:

New BoundingBox object.

BoundingBox(const BoundingBox<D> &box)

Constructor for BoundingBox object.

Creates a box identical to the input box paramter. This constructor uses all parameters from the other BoundingBox to create a new one.

Parameters:

box[in] Other BoundingBox object.

Returns:

New BoundingBox object.

BoundingBox<D> &operator=(const BoundingBox<D> &box)

Assignment operator overload for BoundingBox object.

Allocates all parameters in this BoundingBox to be that of the other BoundingBox.

Parameters:

box[in] Other BoundingBox object.

Returns:

New BoundingBox object.

NodeIndex<D> getNodeIndex(int bIdx) const

Fetches a NodeIndex object from a given box index.

During the adaptive refinement, each original box will contain an increasing number of smaller cells, each of which will be part of a specific node in the tree. These cells are divided adaptivelly. This function returns the NodeIndex object of the cell at the lower back corner of the box object indexed by bIdx. Specialized for D=1 below

Parameters:

bIdx[in] Box index, the index of the box we want to fetch the cell index from.

Returns:

The NodeIndex object of the index given as it is in the Multiresolutoin analysis.

int getBoxIndex(Coord<D> r) const

Fetches the index of a box from a given coordinate.

Specialized for D=1 below

Parameters:

r[in] D-dimensional array representaing a coordinate in the simulation box

Returns:

The index value of the boxes in the position given as it is in the generated world.

int getBoxIndex(NodeIndex<D> nIdx) const

Fetches the index of a box from a given NodeIndex.

During the multiresolution analysis the boxes will be divided into smaller boxes, which means that each individual box will be part of a specific node in the tree. Each node will get its own index value, but will still be part of one of the original boxes of the world. Specialized for D=1 below

Parameters:

nIdx[in] NodeIndex object, representing the node and its index in the adaptive tree.

Returns:

The index value of the boxes in which the NodeIndex object is mapping to.

NodeIndex<1> getNodeIndex(int bIdx) const

Fetches a NodeIndex object from a given box index, specialiced for 1-D.

During the adaptive refinement, each original box will contain an increasing number of smaller cells, each of which will be part of a specific node in the tree. These cells are divided adaptivelly. This function returns the NodeIndex object of the cell at the lower back corner of the box object indexed by bIdx.

Parameters:

bIdx[in] Box index, the index of the box we want to fetch the cell index from.

Returns:

The NodeIndex object of the index given as it is in the Multiresolutoin analysis.

int getBoxIndex(Coord<1> r) const

Fetches the index of a box from a given coordinate, specialized for 1D.

Parameters:

r[in] 1-dimensional array representaing a coordinate in the simulation box

Returns:

The index value of the boxes in the position given as it is in the generated world.

int getBoxIndex(NodeIndex<1> nIdx) const

Fetches the index of a box from a given NodeIndex specialized for 1-D.

During the multiresolution analysis the boxes will be divided into smaller boxes, which means that each individual box will be part of a specific node in the tree. Each node will get its own index value, but will still be part of one of the original boxes of the world.

Parameters:

nIdx[in] NodeIndex object, representing the node and its index in the adaptive tree.

Returns:

The index value of the boxes in which the NodeIndex object is mapping to.

Protected Functions

void setNBoxes(const std::array<int, D> &nb = {})

Sets the number of boxes in each dimension.

For each dimentions D it sets the number of boxes in that dimension in the nBoxes array and the total amount of boxes in the world in the totBoxes variable. This just sets counters for the number of boxes in each dimension.

Parameters:

nb[in] Number of boxes, default [1, 1, …].

void setDerivedParameters()

Computes and sets all derived parameters.

For all parameters that have been initialized in the constructor, this function will compute the necessary derived parameters in each dimension. The unit length is set to sfac $$\cdot 2^{-n}$$ where sfac is the scaling factor (default 1.0) and n is the length scale. The unit length is the base unit which is used for the size and positioning of the boxes around origin. The boxLength is the total length of the box in each dimension, which is the unit length times the number of boxes in that dimension. The lowerBound is computed from the index of the lower corner of the box and the unit length. The upperBound is computed to be the lower corner plus the total length in that dimension.

void setScalingFactors(const std::array<double, D> &sf)

Sets the number of boxes in each dimension.

This checks that the sf variable has sane values before assigning it to the member variable scalingFactor.

Parameters:

sf[in] Scaling factor, default [1.0, 1.0, …].

void setPeriodic(std::array<bool, D> periodic)

Sets which dimensions are periodic.

This fills in the periodic array with the values from the input array.

Parameters:

pbs[in] D-dimensional array holding boolean values for each dimension.

void setPeriodic(bool periodic)

Sets which dimensions are periodic.

this fills in the periodic array with the values from the input.

Parameters:

pbc[in] Boolean which is used to set all dimension to either periodic or not

std::ostream &print(std::ostream &o) const

Prints information about the BoundinBox object.

A function which prints information about the BoundingBox object.

Parameters:

o[in] Output stream variable which will be used to print the information

Returns:

The output stream variable.

Protected Attributes

NodeIndex<D> cornerIndex

Index defining the lower corner of the box.

std::array<int, D> nBoxes = {}

Number of boxes in each dim, last entry total.

std::array<bool, D> periodic = {}

Sets which dimension has Periodic boundary conditions.

Coord<D> unitLengths

1/2^initialScale

Coord<D> boxLengths

Total length (unitLength times nBoxes)

Coord<D> lowerBounds

Box lower bound (not real)

Coord<D> upperBounds

Box upper bound (not real)