source: src/base/interface.cpp@ e271f0

Last change on this file since e271f0 was fcf7f6, checked in by Julian Iseringhausen <isering@…>, 14 years ago

vmg: Added license files and headers (GPLv3).

git-svn-id: https://svn.version.fz-juelich.de/scafacos/trunk@1812 5161e1c8-67bf-11de-9fd5-51895aff932f

  • Property mode set to 100644
File size: 5.8 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
40void Interface::InitInterface(const Vector& box_offset, const vmg_float& box_size,
41 const int& coarseningSteps, const vmg_float& alpha)
42{
43 int i;
44 Index num_cells = Helper::intpow(2, levelMax);
45 Index size_factor;
46
47 const Vector box_center = box_offset + 0.5 * box_size;
48
49 for (i=0; i<coarseningSteps; ++i) {
50
51 global.push_back(GlobalIndices());
52 extent.push_back(SpatialExtent());
53
54 for (int j=0; j<3; ++j)
55 size_factor[j] = (bc[j] == Periodic ? 1 : Helper::intpow(2, static_cast<int>(log(pow(alpha, i+1)) / log(2.0) + 1.0)));
56
57 extent.back().Size() = box_size * static_cast<Vector>(size_factor);
58 extent.back().Begin() = box_center - 0.5 * extent.back().Size();
59 extent.back().End() = extent.back().Begin() + extent.back().Size();
60 extent.back().MeshWidth() = pow(2.0, i-levelMax);
61
62 num_cells = Helper::intpow(2,levelMax-i) * size_factor;
63
64 global.back().GlobalSize() = num_cells + 1;
65 global.back().LocalSize() = num_cells + 1;
66 global.back().LocalBegin() = 0;
67 global.back().LocalEnd() = num_cells + 1;
68
69 global.back().FinestAbsSize() = Helper::intpow(2,i) * num_cells + 1;
70 global.back().FinestAbsBegin() = ((global.back().FinestAbsSize()-1) * (1-size_factor)) / (2*size_factor);
71 global.back().FinestAbsEnd() = global.back().FinestAbsBegin() + global.back().FinestAbsSize();
72
73 if (i==0)
74 global.back().GlobalFinerBegin() = (num_cells - Helper::intpow(2, levelMax-i))/2;
75 else
76 global.back().GlobalFinerBegin() = (global.back().FinestAbsSize() - (++global.rbegin())->FinestAbsSize()) / Helper::intpow(2,i+1);
77
78 global.back().GlobalFinerEnd() = global.back().GlobalSize() - global.back().GlobalFinerBegin();
79 global.back().GlobalFinerSize() = global.back().GlobalFinerEnd() - global.back().GlobalFinerBegin();
80
81 global.back().LocalFinerBegin() = global.back().GlobalFinerBegin();
82 global.back().LocalFinerEnd() = global.back().GlobalFinerEnd();
83 global.back().LocalFinerSize() = global.back().GlobalFinerSize();
84 }
85
86 while (global.size() == 0 || global.back().GlobalSize().Min() > Helper::intpow(2, levelMin)+1) {
87
88 if (global.size() > 0)
89 num_cells /= 2;
90
91 global.push_back(GlobalIndices());
92 extent.push_back(SpatialExtent());
93
94 if (global.size() == 1) {
95 extent.back().Size() = box_size;
96 extent.back().Begin() = box_offset;
97 extent.back().End() = box_offset + box_size;
98 extent.back().MeshWidth() = box_size / static_cast<Vector>(num_cells);
99 }else {
100 extent.back().Size() = (++extent.rbegin())->Size();
101 extent.back().Begin() = (++extent.rbegin())->Begin();
102 extent.back().End() = (++extent.rbegin())->End();
103 extent.back().MeshWidth() = 2.0 * (++extent.rbegin())->MeshWidth();
104 }
105
106 global.back().GlobalSize() = num_cells + 1;
107 global.back().LocalSize() = num_cells + 1;
108 global.back().LocalBegin() = 0;
109 global.back().LocalEnd() = num_cells + 1;
110
111 if (global.size() == 1) {
112 global.back().FinestAbsBegin() = 0;
113 global.back().FinestAbsEnd() = global.back().GlobalSize();
114 global.back().FinestAbsSize() = global.back().GlobalSize();
115 }else {
116 global.back().FinestAbsBegin() = (++global.rbegin())->FinestAbsBegin();
117 global.back().FinestAbsEnd() = (++global.rbegin())->FinestAbsEnd();
118 global.back().FinestAbsSize() = (++global.rbegin())->FinestAbsSize();
119 }
120
121 global.back().GlobalFinerBegin() = 0;
122 global.back().GlobalFinerEnd() = global.back().GlobalSize();
123 global.back().GlobalFinerSize() = global.back().GlobalSize();
124
125 global.back().LocalFinerBegin() = global.back().GlobalFinerBegin();
126 global.back().LocalFinerEnd() = global.back().GlobalFinerEnd();
127 global.back().LocalFinerSize() = global.back().GlobalFinerSize();
128
129 }
130
131 for (i=0; i<3; ++i)
132 if (bc[i] == Periodic)
133 for (unsigned int j=0; j<global.size(); ++j) {
134 global[j].GlobalSize()[i] -= 1;
135 global[j].FinestAbsSize()[i] -= Helper::intpow(2, j);
136 global[j].FinestAbsEnd()[i] -= Helper::intpow(2, j);
137 global[j].LocalSize()[i] -= 1;
138 global[j].LocalEnd()[i] -= 1;
139 global[j].GlobalFinerSize()[i] -= 1;
140 global[j].GlobalFinerEnd()[i] -= 1;
141 global[j].LocalFinerSize()[i] -= 1;
142 global[j].LocalFinerEnd()[i] -= 1;
143 }
144
145 levelMin = levelMax - global.size() + 1;
146
147 global.back().BoundaryType() = GlobalCoarsened;
148
149 for (i=global.size()-2; i>=0; --i) {
150 if (global[i].FinestAbsSize().Product() >= global[i+1].FinestAbsSize().Product()) {
151 global[i].BoundaryType() = GlobalCoarsened;
152 }else {
153 global[i].BoundaryType() = LocallyRefined;
154 global[i+1].BoundaryType() = GlobalMax;
155 break;
156 }
157 }
158
159 for (; i>=0; --i)
160 global[i].BoundaryType() = LocallyRefined;
161
162 if (global.front().BoundaryType() != LocallyRefined &&
163 global.front().BoundaryType() != GlobalMax)
164 global.front().BoundaryType() = GlobalMax;
165
166}
Note: See TracBrowser for help on using the repository browser.