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
RevLine 
[fcf7f6]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
[48b662]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
[dfed1c]32#include <algorithm>
[48b662]33#include <cmath>
34
35#include "base/helper.hpp"
[f003a9]36#include "base/interface.hpp"
[48b662]37
38using namespace VMG;
39
[f57182]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
[dfed1c]46void Interface::InitInterface(const Vector& box_offset, const vmg_float& box_size,
47 const int& coarseningSteps, const vmg_float& alpha)
[48b662]48{
[ac6d04]49 int i;
50 Index size_factor;
[48b662]51
[dfed1c]52 const Vector box_center = box_offset + 0.5 * box_size;
[48b662]53
[f57182]54 /*
55 * Get Extents
56 */
[ac6d04]57 for (i=0; i<coarseningSteps; ++i) {
[48b662]58 extent.push_back(SpatialExtent());
[ac6d04]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)));
[48b662]61
[ac6d04]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();
[f57182]65 extent.back().MeshWidth() = pow(2.0, i-levelMax) * extent.back().Size() / size_factor;
66 }
[48b662]67
[f57182]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 }
[48b662]75
[f57182]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 }
[ac6d04]80
[f57182]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 }
[ac6d04]88
[f57182]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;
[ac6d04]97
[f57182]98 /*
99 * Compute global grid values
100 */
101 for (i=0; i<global.size(); ++i) {
[ac6d04]102
[f57182]103 const Index num_cells = extent[i].Size() / extent[i].MeshWidth() + 0.5;
[ac6d04]104
[f57182]105 for (int j=0; j<3; ++j) {
[ac6d04]106
[f57182]107 if (bc[j] == Dirichlet || bc[j] == Open) {
108 /*
109 * Dirichlet
110 */
[ac6d04]111
[f57182]112 if (global[i].BoundaryType() == LocallyRefined) {
113 /*
114 * Locally Refined
115 */
[ac6d04]116
[f57182]117 global[i].GlobalSize()[j] = num_cells[j] + 3;
[48b662]118
[f57182]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 }
[ac6d04]128
[f57182]129 } else if (global[i].BoundaryType() == GlobalMax) {
130 /*
131 * Global Max
132 */
[ac6d04]133
[f57182]134 global[i].GlobalSize()[j] = num_cells[j] + 1;
[ac6d04]135
[f57182]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 }
[48b662]145
[f57182]146 } else {
147 /*
148 * Global Coarsened
149 */
[48b662]150
[f57182]151 global[i].GlobalSize()[j] = num_cells[j] + 1;
[ac6d04]152
[f57182]153 global[i].GlobalFinerBegin()[j] = 0;
154 global[i].GlobalFinerEnd()[j] = num_cells[j] + 1;
155 global[i].GlobalFinerSize()[j] = num_cells[j] + 1;
[ac6d04]156
[f57182]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 }
[ac6d04]171 }
172
[f57182]173 global[i].LocalBegin() = 0;
174 global[i].LocalEnd() = global[i].GlobalSize();
175 global[i].LocalSize() = global[i].GlobalSize();
[ac6d04]176
[f57182]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;
[ac6d04]184
[48b662]185}
Note: See TracBrowser for help on using the repository browser.