source: src/base/interface.cpp@ 6e10f33

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

Some work...

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