WARPXM v1.10.0
Loading...
Searching...
No Matches
wxbox.h
Go to the documentation of this file.
1#ifndef wxbox_h
2#define wxbox_h
3
4// WarpX includes
5#include "wxobject.h"
6
7// std includes
8#include <cassert>
9#include <iostream>
10#include <vector>
11#include <string>
12
13// forward declarations
14class WxCryptSet;
15
24template<typename TYPE> class WxBox : public WxObject
25{
26public:
28 {
29 }
30
34 WxBox(unsigned ndims);
35
43 WxBox(unsigned ndims, const TYPE* lower, const TYPE* upper);
44
52 WxBox(unsigned ndims, const TYPE* length);
53
63 WxBox(TYPE s1, TYPE e1);
67 WxBox(TYPE s1, TYPE e1, TYPE s2, TYPE e2);
68
72 WxBox(TYPE s1, TYPE e1, TYPE s2, TYPE e2, TYPE s3, TYPE e3);
73
77 WxBox(TYPE s1, TYPE e1, TYPE s2, TYPE e2, TYPE s3, TYPE e3, TYPE s4, TYPE e4);
78
82 WxBox(const WxBox<TYPE>& b);
84
85 virtual ~WxBox();
86
98 virtual void setup(const WxCryptSet& wxc);
99
106 void resize(const unsigned dim, const TYPE newLength);
107
113 unsigned ndims() const
114 {
115 return _ndims;
116 }
117
124 TYPE lower(unsigned dim) const
125 {
126 return _lower[dim];
127 }
128
135 void lower(unsigned dim, TYPE low)
136 {
137 _lower[dim] = low;
138 _length[dim] = _upper[dim] - _lower[dim];
139 }
140
147 TYPE upper(unsigned dim) const
148 {
149 return _upper[dim];
150 }
151
158 void upper(unsigned dim, TYPE upp)
159 {
160 _upper[dim] = upp;
161 _length[dim] = _upper[dim] - _lower[dim];
162 }
163
170 std::pair<TYPE, TYPE> boundsPair(unsigned dim) const
171 {
172 return std::pair<TYPE, TYPE>(_lower[dim], _upper[dim]);
173 }
174
180 virtual bool isEmpty() const;
181
188 virtual TYPE length(unsigned dim) const
189 {
190 return _length[dim];
191 }
192
198 TYPE area() const;
199
205 TYPE size() const
206 {
207 return area();
208 }
209
215 std::string coordinateString() const;
216
225
234 WxBox<TYPE> extend(const TYPE low[], const TYPE upp[]) const;
235
243 WxBox<TYPE> extend(const TYPE uniformPad[]) const;
244
252 WxBox<TYPE> extend(TYPE uniformPad) const;
253
263 WxBox<TYPE> extDim(TYPE low, TYPE upp) const;
264
272 void extrude(const WxBox& box);
273
282 WxBox<TYPE> reduceDim(unsigned int newDim) const;
283
290 bool operator==(const WxBox<TYPE>& b) const;
291
299 bool contains(const TYPE coord[]) const;
300
308 bool encloses(const WxBox<TYPE>& candidateBox) const;
309
316 bool compareShape(const WxBox<TYPE>& candidateBox) const;
317
321 static const int max_dims = 8;
322
323protected:
324 unsigned _ndims;
326};
327
331template<typename TYPE> bool operator==(const WxBox<TYPE>& wa, const WxBox<TYPE>& wb);
332
333extern template class WxBox<int>;
334extern template class WxBox<float>;
335extern template class WxBox<double>;
336
338#endif // wxbox_h
WxBox represents a n-dimensional box of elements specified by lower coordinates and upper coordinates...
Definition: wxbox.h:25
WxBox(unsigned ndims, const TYPE *lower, const TYPE *upper)
Constucts a box with given 'lower' and 'upper' bounds.
void lower(unsigned dim, TYPE low)
Set lower bound along dimension 'dim'.
Definition: wxbox.h:135
virtual ~WxBox()
virtual TYPE length(unsigned dim) const
Length of edge along dimension 'dim'.
Definition: wxbox.h:188
bool operator==(const WxBox< TYPE > &b) const
Check if this box is equal to one supplied.
WxBox()
Definition: wxbox.h:27
WxBox(TYPE s1, TYPE e1, TYPE s2, TYPE e2, TYPE s3, TYPE e3)
Rank-3 ctor.
WxBox< TYPE > extend(TYPE uniformPad) const
Returns a box which is extended by the given amount along both sides in every dimension.
bool compareShape(const WxBox< TYPE > &candidateBox) const
Check if all side lengths of the supplied box match this one.
std::pair< TYPE, TYPE > boundsPair(unsigned dim) const
Pair of upper and lower bound along dimension 'dim'.
Definition: wxbox.h:170
WxBox(const WxBox< TYPE > &b)
Copy constructor and assignment operators.
unsigned _ndims
Definition: wxbox.h:324
static const int max_dims
Maximum rank box that can be represented.
Definition: wxbox.h:321
bool contains(const TYPE coord[]) const
Check if the box contains the given point.
TYPE area() const
Area of box.
virtual void setup(const WxCryptSet &wxc)
Constructs a box specified in a cryptset.
void extrude(const WxBox &box)
Increases the rank of this box to match that of the supplied box argument.
WxBox< TYPE > extend(const TYPE uniformPad[]) const
Returns a box which is extended by the given amount along both sides in each dimension.
unsigned ndims() const
Dimensionality of box.
Definition: wxbox.h:113
WxBox< TYPE > extend(const TYPE low[], const TYPE upp[]) const
Returns a box which is extended by the given amount along each side in each dimension.
TYPE _lower[max_dims]
Definition: wxbox.h:325
std::string coordinateString() const
String of box coordinates.
WxBox(TYPE s1, TYPE e1)
The following constructors constuct a box with explicit passing of lower s* and upper e* coordinates.
WxBox< TYPE > intersect(const WxBox< TYPE > &box) const
Computes intersection of this box with supplied box.
TYPE upper(unsigned dim) const
Upper bound along dimension 'dim'.
Definition: wxbox.h:147
WxBox< TYPE > reduceDim(unsigned int newDim) const
Returns a new box which has up to new number of dimensions.
TYPE lower(unsigned dim) const
Lower bound along dimension 'dim'.
Definition: wxbox.h:124
TYPE _upper[max_dims]
Definition: wxbox.h:325
WxBox(unsigned ndims, const TYPE *length)
Constucts a box given lengths of each side.
WxBox(TYPE s1, TYPE e1, TYPE s2, TYPE e2)
Rank-2 ctor.
WxBox(unsigned ndims)
Create a 'ndims' dimensional box.
WxBox(TYPE s1, TYPE e1, TYPE s2, TYPE e2, TYPE s3, TYPE e3, TYPE s4, TYPE e4)
Rank-4 ctor.
WxBox & operator=(const WxBox< TYPE > &b)
bool encloses(const WxBox< TYPE > &candidateBox) const
Check if the box encloses the given box.
WxBox< TYPE > extDim(TYPE low, TYPE upp) const
Returns a new box which has one greater dimension than this one.
virtual bool isEmpty() const
Determine if box is empty.
TYPE size() const
Area of box.
Definition: wxbox.h:205
TYPE _length[max_dims]
Definition: wxbox.h:325
void resize(const unsigned dim, const TYPE newLength)
Modify upper indicex based on newly supplied length.
void upper(unsigned dim, TYPE upp)
Set upper bound along dimension 'dim'.
Definition: wxbox.h:158
WxCryptSet extends WxCrypt by providing, in addition to name-value pairs, an set of named WxCryptSets...
Definition: wxcryptset.h:35
WxObject is a base class for WarpX classes which need to go through a creation/destruction cycle with...
Definition: wxobject.h:54
bool operator==(const WxBox< TYPE > &wa, const WxBox< TYPE > &wb)
Returns true if boxes are same.