Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add convenience constructor for BoundingBox and MRA #179

Merged
merged 3 commits into from
Oct 11, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 48 additions & 2 deletions src/trees/BoundingBox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,52 @@

namespace mrcpp {

/** @returns New BoundingBox object
*
* @param[in] box: [lower, upper] bound in all dimensions
*
* @details 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.
*/
template <int D>
BoundingBox<D>::BoundingBox(std::array<int, 2> box) {
if (box[1] < 1) {
MSG_ERROR("Invalid upper bound: " << box[1]);
box[1] = 1;
MSG_WARN("Setting upper bound: " << box[1]);
}
if (!(box[0] == 0 or box[0] == -box[1])) {
MSG_ERROR("Invalid lower bound: " << box[0]);
box[0] = -box[1];
MSG_WARN("Setting lower bound: " << box[0]);
}
int n = 0;
double size = 1.0 * box[1];
while (size >= 2.0) {
size /= 2.0;
n--;
}
auto l = std::array<int, D>{};
auto nb = std::array<int, D>{};
auto sfac = std::array<double, D>{};
if (box[0] == 0) {
l.fill(0);
nb.fill(1);
} else {
l.fill(-1);
nb.fill(2);
}
sfac.fill(size);
this->cornerIndex = NodeIndex<D>(n, l);
setPeriodic(false);
setNBoxes(nb);
setScalingFactors(sfac);
setDerivedParameters();
}

/** @returns New BoundingBox object
*
* @param[in] n: Length scale, default 0
Expand Down Expand Up @@ -118,7 +164,7 @@ template <int D> void BoundingBox<D>::setDerivedParameters() {
template <int D> void BoundingBox<D>::setScalingFactors(const std::array<double, D> &sf) {
assert(this->totBoxes > 0);
for (auto &x : sf)
if (x == 0.0 and sf != std::array<double, D>{}) MSG_ABORT("The scaling factor cannot be zero in any of the directions");
if (x <= 0.0 and sf != std::array<double, D>{}) MSG_ABORT("Non-positive scaling factor: " << x);
this->scalingFactor = sf;
if (scalingFactor == std::array<double, D>{}) scalingFactor.fill(1.0);
}
Expand Down Expand Up @@ -158,7 +204,7 @@ template <int D> int BoundingBox<D>::getBoxIndex(Coord<D> r) const {
int idx[D];
for (int d = 0; d < D; d++) {
double x = r[d];
if (not this->isPeriodic()) {
if (!this->isPeriodic()) {
if (x < this->lowerBounds[d]) return -1;
if (x >= this->upperBounds[d]) return -1;
}
Expand Down
7 changes: 4 additions & 3 deletions src/trees/BoundingBox.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,10 @@ namespace mrcpp {

template <int D> class BoundingBox {
public:
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);
BoundingBox(const NodeIndex<D> &idx, const std::array<int, D> &nb = {}, const std::array<double, D> &sf = {});
BoundingBox(const std::array<double, D> &sf, bool pbc = true);
explicit BoundingBox(std::array<int, 2> box);
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);
explicit BoundingBox(const NodeIndex<D> &idx, const std::array<int, D> &nb = {}, const std::array<double, D> &sf = {});
explicit BoundingBox(const std::array<double, D> &sf, bool pbc = true);
BoundingBox(const std::array<double, D> &sf, std::array<bool, D> pbc);
BoundingBox(const BoundingBox<D> &box);
BoundingBox<D> &operator=(const BoundingBox<D> &box);
Expand Down
20 changes: 20 additions & 0 deletions src/trees/MultiResolutionAnalysis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,26 @@

namespace mrcpp {

template <int D>
MultiResolutionAnalysis<D>::MultiResolutionAnalysis(std::array<int, 2> bb, int order, int depth)
: maxDepth(depth)
, basis(InterpolatingBasis(order))
, world(bb) {
if (getMaxDepth() > MaxDepth) MSG_ABORT("Beyond MaxDepth");
if (getMaxScale() > MaxScale) MSG_ABORT("Beyond MaxScale");
setupFilter();
}

template <int D>
MultiResolutionAnalysis<D>::MultiResolutionAnalysis(const BoundingBox<D> &bb, int order, int depth)
: maxDepth(depth)
, basis(InterpolatingBasis(order))
, world(bb) {
if (getMaxDepth() > MaxDepth) MSG_ABORT("Beyond MaxDepth");
if (getMaxScale() > MaxScale) MSG_ABORT("Beyond MaxScale");
setupFilter();
}

template <int D>
MultiResolutionAnalysis<D>::MultiResolutionAnalysis(const MultiResolutionAnalysis<D> &mra)
: maxDepth(mra.maxDepth)
Expand Down
2 changes: 2 additions & 0 deletions src/trees/MultiResolutionAnalysis.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ namespace mrcpp {

template <int D> class MultiResolutionAnalysis final {
public:
MultiResolutionAnalysis(std::array<int, 2> bb, int order, int depth = MaxDepth);
MultiResolutionAnalysis(const BoundingBox<D> &bb, int order, int depth = MaxDepth);
MultiResolutionAnalysis(const BoundingBox<D> &bb, const ScalingBasis &sb, int depth = MaxDepth);
MultiResolutionAnalysis(const MultiResolutionAnalysis<D> &mra);
MultiResolutionAnalysis &operator=(const MultiResolutionAnalysis &mra) = delete;
Expand Down