| 1 | /**
|
|---|
| 2 | * @file interface.cpp
|
|---|
| 3 | * @author Julian Iseringhausen <isering@ins.uni-bonn.de>
|
|---|
| 4 | * @date Mon Apr 18 12:55:48 2011
|
|---|
| 5 | *
|
|---|
| 6 | * @brief VMG::Interface
|
|---|
| 7 | *
|
|---|
| 8 | */
|
|---|
| 9 |
|
|---|
| 10 | #ifdef HAVE_CONFIG_H
|
|---|
| 11 | #include <config.h>
|
|---|
| 12 | #endif
|
|---|
| 13 |
|
|---|
| 14 | #include <cmath>
|
|---|
| 15 |
|
|---|
| 16 | #include "base/helper.hpp"
|
|---|
| 17 | #include "interface/interface.hpp"
|
|---|
| 18 |
|
|---|
| 19 | using namespace VMG;
|
|---|
| 20 |
|
|---|
| 21 | Interface::Interface(BC boundary, int levelMin_, int levelMax_, vmg_float box_begin_, vmg_float box_end_,
|
|---|
| 22 | int coarseningSteps, vmg_float alpha)
|
|---|
| 23 | {
|
|---|
| 24 | bc = boundary;
|
|---|
| 25 | levelMin = levelMin_;
|
|---|
| 26 | levelMax = levelMax_;
|
|---|
| 27 |
|
|---|
| 28 | bool restricted = false;
|
|---|
| 29 |
|
|---|
| 30 | const vmg_float box_center = 0.5 * (box_begin_ + box_end_);
|
|---|
| 31 | const vmg_float box_size = box_end_ - box_begin_;
|
|---|
| 32 |
|
|---|
| 33 | for (int i=0; i<coarseningSteps; ++i) {
|
|---|
| 34 |
|
|---|
| 35 | global.push_back(GlobalIndices());
|
|---|
| 36 | extent.push_back(SpatialExtent());
|
|---|
| 37 |
|
|---|
| 38 | extent.back().SizeFactor() = Helper::intpow(2, static_cast<int>(log(pow(alpha, i+1)) / log(2.0) + 1.0));
|
|---|
| 39 |
|
|---|
| 40 | extent.back().Size() = box_size * static_cast<Vector>(extent.back().SizeFactor());
|
|---|
| 41 | extent.back().Begin() = box_center - 0.5 * extent.back().Size();
|
|---|
| 42 | extent.back().End() = extent.back().Begin() + extent.back().Size();
|
|---|
| 43 | extent.back().MeshWidth() = pow(2.0, i-levelMax);
|
|---|
| 44 |
|
|---|
| 45 | global.back().Size() = static_cast<Index>(static_cast<Vector>(extent.back().Size()) / extent.back().MeshWidth() + 0.5) + 1;
|
|---|
| 46 | global.back().Begin() = 0;
|
|---|
| 47 | global.back().End() = global.back().Size();
|
|---|
| 48 |
|
|---|
| 49 | }
|
|---|
| 50 |
|
|---|
| 51 | for (int i=0; i<coarseningSteps; ++i) {
|
|---|
| 52 |
|
|---|
| 53 | if (restricted) {
|
|---|
| 54 | global[i].BoundaryType() = GlobalCoarsened;
|
|---|
| 55 | }else if (extent[i].SizeFactor() == extent.back().SizeFactor()) {
|
|---|
| 56 | global[i].BoundaryType() = GlobalMax;
|
|---|
| 57 | restricted = true;
|
|---|
| 58 | }else {
|
|---|
| 59 | global[i].BoundaryType() = LocallyRefined;
|
|---|
| 60 | }
|
|---|
| 61 |
|
|---|
| 62 | if (i==0) {
|
|---|
| 63 | global[0].AlignmentBegin() = (global[0].Size() - static_cast<int>( pow(2.0, levelMax) + 0.5) - 1) / 2;
|
|---|
| 64 | }else if (global[i].BoundaryType() == LocallyRefined)
|
|---|
| 65 | global[i].AlignmentBegin() = (extent[i].Size() - extent[i-1].Size()) * pow(2.0, levelMax-i-1) + 0.5;
|
|---|
| 66 | else if (global[i].BoundaryType() == GlobalMax)
|
|---|
| 67 | global[i].AlignmentBegin() = (extent[i].Size() - extent[i-1].Size()) * pow(2.0, levelMax-i-1) - 0.5;
|
|---|
| 68 | else
|
|---|
| 69 | global[i].AlignmentBegin() = 0;
|
|---|
| 70 |
|
|---|
| 71 | global[i].AlignmentEnd() = global[i].Size() - global[i].AlignmentBegin();
|
|---|
| 72 | }
|
|---|
| 73 |
|
|---|
| 74 | while (global.size() == 0 || global.back().Size().Max() > Helper::intpow(2,levelMin)+1) {
|
|---|
| 75 |
|
|---|
| 76 | global.push_back(GlobalIndices());
|
|---|
| 77 | extent.push_back(SpatialExtent());
|
|---|
| 78 |
|
|---|
| 79 | extent.back().SizeFactor() = (global.size() > 1 ? (++extent.rbegin())->Size() : 1);
|
|---|
| 80 | extent.back().Size() = (global.size() > 1 ? (++extent.rbegin())->Size() : box_size);
|
|---|
| 81 | extent.back().Begin() = box_center - 0.5 * static_cast<Vector>(extent.back().Size());
|
|---|
| 82 | extent.back().End() = extent.back().Begin() + extent.back().Size();
|
|---|
| 83 | extent.back().MeshWidth() = pow(2.0, static_cast<int>(global.size())-levelMax-1);
|
|---|
| 84 |
|
|---|
| 85 | global.back().Size() = static_cast<Index>(static_cast<Vector>(extent.back().Size()) / extent.back().MeshWidth() + 0.5) + 1;
|
|---|
| 86 | global.back().Begin() = 0;
|
|---|
| 87 | global.back().End() = global.back().Size();
|
|---|
| 88 |
|
|---|
| 89 | if (global.size() > 1)
|
|---|
| 90 | global.back().BoundaryType() = GlobalCoarsened;
|
|---|
| 91 | else
|
|---|
| 92 | global.back().BoundaryType() = GlobalMax;
|
|---|
| 93 |
|
|---|
| 94 | global.back().AlignmentBegin() = 0;
|
|---|
| 95 | global.back().AlignmentEnd() = global.back().Size();
|
|---|
| 96 |
|
|---|
| 97 | }
|
|---|
| 98 |
|
|---|
| 99 | if (boundary == Periodic)
|
|---|
| 100 | for (std::vector<GlobalIndices>::iterator iter=global.begin(); iter!=global.end(); ++iter)
|
|---|
| 101 | iter->Size() -= 1;
|
|---|
| 102 |
|
|---|
| 103 | levelMin = levelMax - global.size() + 1;
|
|---|
| 104 | }
|
|---|