source: src/base/interface.cpp@ f57182

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

Open boundary conditions.

Conflicts:

lib/vmg/src/Makefile.am
lib/vmg/src/base/factory.cpp
lib/vmg/test/unit_test/library/dirichlet_fas_lr_mpi.cpp

  • Property mode set to 100644
File size: 5.9 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 size_factor;
51
52 const Vector box_center = box_offset + 0.5 * box_size;
53
54 /*
55 * Get Extents
56 */
57 for (i=0; i<coarseningSteps; ++i) {
58 extent.push_back(SpatialExtent());
59 for (int j=0; j<3; ++j)
60 size_factor[j] = (bc[j] == Periodic ? 1 : Helper::intpow(2, static_cast<int>(log(pow(alpha, i+1)) / log(2.0) + 1.0)));
61
62 extent.back().Size() = box_size * static_cast<Vector>(size_factor);
63 extent.back().Begin() = box_center - 0.5 * extent.back().Size();
64 extent.back().End() = extent.back().Begin() + extent.back().Size();
65 extent.back().MeshWidth() = pow(2.0, i-levelMax) * extent.back().Size() / size_factor;
66 }
67
68 if (extent.size() == 0) {
69 extent.push_back(SpatialExtent());
70 extent.back().Size() = box_size;
71 extent.back().Begin() = box_offset;
72 extent.back().End() = box_offset + box_size;
73 extent.back().MeshWidth() = box_size / Helper::intpow(2,levelMax);
74 }
75
76 while ((extent.back().Size() / extent.back().MeshWidth()).Min() > Helper::intpow(2,levelMin) + 1) {
77 extent.push_back(SpatialExtent(extent.back()));
78 extent.back().MeshWidth() *= 2;
79 }
80
81 /*
82 * Find GlobalMax
83 */
84 for (std::vector<SpatialExtent>::const_iterator iter=extent.begin(); iter!=extent.end(); ++iter) {
85 global.push_back(GlobalIndices());
86 global.back().BoundaryType() = GlobalCoarsened;
87 }
88
89 for (i=global.size()-1; i>=0; --i) {
90 if (i == 0 || extent[i-1].Size() != extent[i].Size()) {
91 global[i].BoundaryType() = GlobalMax;
92 break;
93 }
94 }
95 for (--i; i>=0; --i)
96 global[i].BoundaryType() = LocallyRefined;
97
98 /*
99 * Compute global grid values
100 */
101 for (i=0; i<global.size(); ++i) {
102
103 const Index num_cells = extent[i].Size() / extent[i].MeshWidth() + 0.5;
104
105 for (int j=0; j<3; ++j) {
106
107 if (bc[j] == Dirichlet || bc[j] == Open) {
108 /*
109 * Dirichlet
110 */
111
112 if (global[i].BoundaryType() == LocallyRefined) {
113 /*
114 * Locally Refined
115 */
116
117 global[i].GlobalSize()[j] = num_cells[j] + 3;
118
119 if (i == 0) {
120 global[i].GlobalFinerBegin()[j] = GetGlobalIndex(box_offset, extent[i], global[i].BoundaryType())[j];
121 global[i].GlobalFinerEnd()[j] = GetGlobalIndex(box_offset + box_size, extent[i], global[i].BoundaryType())[j] + 1;
122 global[i].GlobalFinerSize()[j] = global[i].GlobalFinerEnd()[j] - global[i].GlobalFinerBegin()[j];
123 } else {
124 global[i].GlobalFinerBegin()[j] = GetGlobalIndex(extent[i-1].Begin(), extent[i], global[i].BoundaryType())[j];
125 global[i].GlobalFinerEnd()[j] = GetGlobalIndex(extent[i-1].End(), extent[i], global[i].BoundaryType())[j] + 1;
126 global[i].GlobalFinerSize()[j] = global[i].GlobalFinerEnd()[j] - global[i].GlobalFinerBegin()[j];
127 }
128
129 } else if (global[i].BoundaryType() == GlobalMax) {
130 /*
131 * Global Max
132 */
133
134 global[i].GlobalSize()[j] = num_cells[j] + 1;
135
136 if (i == 0) {
137 global[i].GlobalFinerBegin()[j] = 0;
138 global[i].GlobalFinerEnd()[j] = num_cells[j] + 1;
139 global[i].GlobalFinerSize()[j] = num_cells[j] + 1;
140 } else {
141 global[i].GlobalFinerBegin()[j] = GetGlobalIndex(extent[i-1].Begin(), extent[i], global[i].BoundaryType())[j];
142 global[i].GlobalFinerEnd()[j] = GetGlobalIndex(extent[i-1].End(), extent[i], global[i].BoundaryType())[j] + 1;
143 global[i].GlobalFinerSize()[j] = global[i].GlobalFinerEnd()[j] - global[i].GlobalFinerBegin()[j];
144 }
145
146 } else {
147 /*
148 * Global Coarsened
149 */
150
151 global[i].GlobalSize()[j] = num_cells[j] + 1;
152
153 global[i].GlobalFinerBegin()[j] = 0;
154 global[i].GlobalFinerEnd()[j] = num_cells[j] + 1;
155 global[i].GlobalFinerSize()[j] = num_cells[j] + 1;
156
157 }
158
159 } else if (bc[j] == Periodic) {
160 /*
161 * Periodic
162 */
163
164 global[i].GlobalSize()[j] = num_cells[j];
165
166 global[i].GlobalFinerBegin()[j] = 0;
167 global[i].GlobalFinerEnd()[j] = num_cells[j];
168 global[i].GlobalFinerSize()[j] = num_cells[j];
169
170 }
171 }
172
173 global[i].LocalBegin() = 0;
174 global[i].LocalEnd() = global[i].GlobalSize();
175 global[i].LocalSize() = global[i].GlobalSize();
176
177 global[i].LocalFinerBegin() = global[i].GlobalFinerBegin();
178 global[i].LocalFinerEnd() = global[i].GlobalFinerEnd();
179 global[i].LocalFinerSize() = global[i].GlobalFinerSize();
180
181 }
182
183 levelMin = levelMax - global.size() + 1;
184
185}
Note: See TracBrowser for help on using the repository browser.