source: src/base/interface.cpp@ 8180d8

Last change on this file since 8180d8 was 8180d8, checked in by Julian Iseringhausen <julian.iseringhausen@…>, 13 years ago

Merge stashed open boundary stuff.

  • Property mode set to 100644
File size: 5.1 KB
Line 
1/*
2 * vmg - a versatile multigrid solver
3 * Copyright (C) 2012 Institute for Numerical Simulation, University of Bonn
4 *
5 * vmg is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * vmg is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19/**
20 * @file interface.cpp
21 * @author Julian Iseringhausen <isering@ins.uni-bonn.de>
22 * @date Mon Apr 18 12:55:48 2011
23 *
24 * @brief VMG::Interface
25 *
26 */
27
28#ifdef HAVE_CONFIG_H
29#include <config.h>
30#endif
31
32#include <algorithm>
33#include <cmath>
34
35#include "base/helper.hpp"
36#include "base/interface.hpp"
37
38using namespace VMG;
39
40static Index GetGlobalIndex(const Vector& pos, const SpatialExtent& extent, const BT& bt)
41{
42 const Index index = (pos - extent.Begin()) / extent.MeshWidth() + 0.5;
43 return index + (bt == LocallyRefined ? 1 : 0);
44}
45
46void Interface::InitInterface(const Vector& box_offset, const vmg_float& box_size,
47 const int& coarseningSteps, const vmg_float& alpha)
48{
49 int i;
50 Index num_cells, size_factor;
51 Index add_node = Index(bc[0]==Periodic?0:1,
52 bc[1]==Periodic?0:1,
53 bc[2]==Periodic?0:1);
54
55 const Vector box_center = box_offset + 0.5 * box_size;
56
57 /*
58 * Get Extents
59 */
60 for (i=0; i<coarseningSteps; ++i) {
61
62 for (int j=0; j<3; ++j)
63 size_factor[j] = (bc[j] == Open ? Helper::intpow(2, static_cast<int>(log(pow(alpha, i+1)) / log(2.0) + 1.0)) : 1);
64
65 num_cells = Helper::intpow(2,levelMax-i) * size_factor;
66
67 global.push_back(GlobalIndices());
68 extent.push_back(SpatialExtent());
69
70 extent.back().Size() = box_size * static_cast<Vector>(size_factor);
71 extent.back().Begin() = box_center - 0.5 * extent.back().Size();
72 extent.back().End() = extent.back().Begin() + extent.back().Size();
73 extent.back().MeshWidth() = extent.back().Size() / num_cells;
74
75 global.back().LocalSize() = num_cells + add_node;
76 global.back().LocalBegin() = -1 * num_cells / 2;
77 global.back().LocalEnd() = num_cells/2 + add_node;
78
79 global.back().GlobalSizeNew() = global.back().LocalSize();
80 global.back().GlobalBegin() = global.back().LocalBegin();
81 global.back().GlobalEnd() = global.back().LocalEnd();
82
83 global.back().GlobalSizeFinest() = Helper::intpow(2, coarseningSteps)*num_cells + add_node;
84 global.back().GlobalBeginFinest() = -1 * ((Helper::intpow(2, coarseningSteps)*num_cells) / 2);
85 global.back().GlobalEndFinest() = (Helper::intpow(2, coarseningSteps)*num_cells) / 2 + add_node;
86
87 }
88
89 if (coarseningSteps == 0) {
90
91 num_cells = Helper::intpow(2, levelMax);
92
93 global.push_back(GlobalIndices());
94 extent.push_back(SpatialExtent());
95
96 extent.back().Size() = box_size;
97 extent.back().Begin() = box_center - 0.5 * extent.back().Size();
98 extent.back().End() = extent.back().Begin() + extent.back().Size();
99 extent.back().MeshWidth() = extent.back().Size() / num_cells;
100
101 global.back().LocalSize() = num_cells + add_node;
102 global.back().LocalBegin() = -1 * num_cells/2;
103 global.back().LocalEnd() = num_cells/2 + add_node;
104
105 global.back().GlobalSizeNew() = global.back().LocalSize();
106 global.back().GlobalBegin() = global.back().LocalBegin();
107 global.back().GlobalEnd() = global.back().LocalEnd();
108
109 global.back().GlobalSizeFinest() = global.back().LocalSize();
110 global.back().GlobalBeginFinest() = global.back().LocalBegin();
111 global.back().GlobalEndFinest() = global.back().LocalEnd();
112
113 }
114
115 while (global.back().LocalSize().Min() > Helper::intpow(2, levelMin)+1) {
116
117 num_cells /= 2;
118
119 extent.back().Size() = (++extent.rbegin())->Size();
120 extent.back().Begin() = (++extent.rbegin())->Begin();
121 extent.back().End() = (++extent.rbegin())->End();
122 extent.back().MeshWidth() = 2.0 * (++extent.rbegin())->MeshWidth();
123
124 global.back().LocalSize() = num_cells + add_node;
125 global.back().LocalBegin() = -1 * num_cells/2;
126 global.back().LocalEnd() = num_cells/2 + add_node;
127
128 global.back().GlobalSizeNew() = global.back().LocalSize();
129 global.back().GlobalBegin() = global.back().LocalBegin();
130 global.back().GlobalEnd() = global.back().LocalEnd();
131
132 global.back().GlobalSizeFinest() = (++global.rbegin())->GlobalSizeFinest();
133 global.back().GlobalBeginFinest() = (++global.rbegin())->GlobalBeginFinest();
134 global.back().GlobalEndFinest() = (++global.rbegin())->GlobalEndFinest();
135 }
136
137 for (i=global.size()-2; i>=0; --i) {
138 if (global[i].GlobalSizeFinest().Product() >= global[i+1].GlobalSizeFinest().Product()) {
139 global[i].BoundaryType() = GlobalCoarsened;
140 }else {
141 global[i].BoundaryType() = LocallyRefined;
142 global[i+1].BoundaryType() = GlobalMax;
143 break;
144 }
145 }
146
147 levelMin = levelMax - global.size() + 1;
148}
Note: See TracBrowser for help on using the repository browser.