Changeset dfed1c for src/interface/interface.cpp
- Timestamp:
- Nov 22, 2011, 9:22:10 PM (14 years ago)
- Children:
- facba0
- Parents:
- 66f24d
- File:
-
- 1 edited
-
src/interface/interface.cpp (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/interface/interface.cpp
r66f24d rdfed1c 12 12 #endif 13 13 14 #include <algorithm> 14 15 #include <cmath> 15 16 … … 19 20 using namespace VMG; 20 21 21 Interface::Interface(BC boundary, int levelMin_, int levelMax_, vmg_float box_begin_, vmg_float box_end_,22 int coarseningSteps, vmg_floatalpha)22 void Interface::InitInterface(const Vector& box_offset, const vmg_float& box_size, 23 const int& coarseningSteps, const vmg_float& alpha) 23 24 { 24 bc = boundary; 25 levelMin = levelMin_; 26 levelMax = levelMax_; 25 Index size_factor_max = 1; 26 int num_cells; 27 27 28 bool restricted = false;28 const Vector box_center = box_offset + 0.5 * box_size; 29 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) { 30 for (int i=levelMax; i>=levelMin; --i) { 34 31 35 32 global.push_back(GlobalIndices()); 36 33 extent.push_back(SpatialExtent()); 37 34 38 extent.back().SizeFactor() = Helper::intpow(2, static_cast<int>(log(pow(alpha, i+1)) / log(2.0) + 1.0));35 num_cells = Helper::intpow(2, i); 39 36 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); 37 extent.back().SizeFactor() = 1; 38 extent.back().Size() = box_size; 39 extent.back().Begin() = box_offset; 40 extent.back().End() = box_offset + box_size; 41 extent.back().MeshWidth() = box_size / num_cells; 44 42 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(); 43 global.back().SizeGlobal() = num_cells + 1; 44 global.back().SizeLocal() = num_cells + 1; 45 global.back().BeginFinest() = 0; 46 global.back().BeginLocal() = 0; 47 global.back().EndLocal() = num_cells + 1; 48 49 if (i == levelMax) { 50 global.back().SizeFinest() = num_cells + 1; 51 global.back().EndFinest() = num_cells + 1; 52 global.back().BoundaryType() = GlobalMax; 53 }else { 54 global.back().SizeFinest() = (++global.rbegin())->SizeFinest(); 55 global.back().EndFinest() = (++global.rbegin())->SizeFinest(); 56 global.back().BoundaryType() = GlobalCoarsened; 57 } 48 58 49 59 } 50 60 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; 61 for (int i=0; i<3; ++i) 62 if (bc[i] == Periodic) 63 for (unsigned int j=0; j<global.size(); ++j) { 64 global[j].SizeGlobal()[i] -= 1; 65 global[j].SizeFinest()[i] -= Helper::intpow(2, j); 66 global[j].SizeLocal()[i] -= 1; 67 global[j].EndLocal()[i] -= 1; 68 global[j].EndFinest()[i] -= Helper::intpow(2, j); 69 } 102 70 103 71 levelMin = levelMax - global.size() + 1;
Note:
See TracChangeset
for help on using the changeset viewer.
