| [de061d] | 1 | /* | 
|---|
|  | 2 | *    vmg - a versatile multigrid solver | 
|---|
|  | 3 | *    Copyright (C) 2012-2013 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   boundary_value_setter.cpp | 
|---|
|  | 21 | * @author Julian Iseringhausen <isering@ins.uni-bonn.de> | 
|---|
|  | 22 | * @date   Mon Apr 15 16:21:40 2013 | 
|---|
|  | 23 | * | 
|---|
|  | 24 | * @brief  Class for setting boundary values with open | 
|---|
|  | 25 | *         boundary conditions. | 
|---|
|  | 26 | * | 
|---|
|  | 27 | */ | 
|---|
|  | 28 |  | 
|---|
|  | 29 | #ifdef HAVE_CONFIG_H | 
|---|
|  | 30 | #include "libvmg_config.h" | 
|---|
|  | 31 | #endif | 
|---|
|  | 32 |  | 
|---|
|  | 33 | #include "comm/comm.hpp" | 
|---|
|  | 34 | #include "discretization/boundary_value_setter.hpp" | 
|---|
|  | 35 | #include "grid/grid.hpp" | 
|---|
|  | 36 | #include "grid/grid_index_translations.hpp" | 
|---|
|  | 37 | #include "grid/multigrid.hpp" | 
|---|
|  | 38 | #include "mg.hpp" | 
|---|
|  | 39 |  | 
|---|
|  | 40 | using namespace VMG; | 
|---|
|  | 41 |  | 
|---|
|  | 42 | void BoundaryValueSetter::ComputeBoundaryValues() | 
|---|
|  | 43 | { | 
|---|
|  | 44 | const Grid& grid_ml = (*MG::GetRhs())(MG::GetRhs()->MaxLevel()); | 
|---|
|  | 45 | Grid& rhs_gml = (*MG::GetRhs())(MG::GetRhs()->GlobalMaxLevel()); | 
|---|
|  | 46 | Grid& sol_gml = (*MG::GetSol())(MG::GetSol()->GlobalMaxLevel()); | 
|---|
|  | 47 |  | 
|---|
|  | 48 | for (std::vector<BoundaryValue>::iterator iter_b = boundary_values.begin(); iter_b != boundary_values.end(); ++iter_b) | 
|---|
|  | 49 | iter_b->Val() = 0.0; | 
|---|
|  | 50 |  | 
|---|
|  | 51 | for (GridIterator iter_g = grid_ml.Iterators().Local().Begin(); iter_g != grid_ml.Iterators().Local().End(); ++iter_g) | 
|---|
|  | 52 | for (std::vector<BoundaryValue>::iterator iter_b = boundary_values.begin(); iter_b != boundary_values.end(); ++iter_b) | 
|---|
|  | 53 | iter_b->Val() += grid_ml.GetVal(*iter_g) * greens_function((iter_b->GetPos() - grid_ml.GetSpatialPos(*iter_g)).Length()); | 
|---|
|  | 54 |  | 
|---|
|  | 55 | std::vector<BoundaryValue> list_bv = MG::GetComm()->CommBoundaryValues(); | 
|---|
|  | 56 |  | 
|---|
|  | 57 | for (std::vector<BoundaryValue>::iterator iter = list_bv.begin(); iter != list_bv.end(); ++iter) { | 
|---|
|  | 58 | const Index i = GridIndexTranslations::GlobalToLocal(rhs_gml, iter->GetIndex()); | 
|---|
|  | 59 | const vmg_float val = grid_ml.Extent().MeshWidth().Product() * iter->Val(); | 
|---|
|  | 60 | rhs_gml(i) = val; | 
|---|
|  | 61 | sol_gml(i) = val; | 
|---|
|  | 62 | } | 
|---|
|  | 63 |  | 
|---|
| [9f1c84] | 64 | // MG::GetComm()->PrintGrid(rhs_gml, "DEBUG GREEN BOUNDARY"); | 
|---|
| [de061d] | 65 | } | 
|---|
|  | 66 |  | 
|---|
|  | 67 | void BoundaryValueSetter::InitBoundaryValueSetter() | 
|---|
|  | 68 | { | 
|---|
|  | 69 | Comm& comm = *MG::GetComm(); | 
|---|
|  | 70 |  | 
|---|
|  | 71 | const Grid& grid = (*MG::GetRhs())(MG::GetRhs()->GlobalMaxLevel()); | 
|---|
|  | 72 |  | 
|---|
|  | 73 | Index begin_local, end_local, i; | 
|---|
|  | 74 | for (int i=0; i<3; ++i) { | 
|---|
|  | 75 | begin_local[i] = grid.Global().GlobalBegin()[i] + (comm.BoundaryConditions()[i] == Open ? 1 : 0); | 
|---|
|  | 76 | end_local[i] = grid.Global().GlobalEnd()[i] - (comm.BoundaryConditions()[i] == Open ? 1 : 0); | 
|---|
|  | 77 | } | 
|---|
|  | 78 |  | 
|---|
|  | 79 | if (comm.BoundaryConditions().X() == Open) { | 
|---|
|  | 80 |  | 
|---|
|  | 81 | i.X() = grid.Global().GlobalBegin().X(); | 
|---|
|  | 82 | for (i.Y() = begin_local.Y(); i.Y() < end_local.Y(); ++i.Y()) | 
|---|
|  | 83 | for (i.Z() = begin_local.Z(); i.Z() < end_local.Z(); ++i.Z()) | 
|---|
|  | 84 | boundary_values.push_back(BoundaryValue(grid, i)); | 
|---|
|  | 85 |  | 
|---|
|  | 86 | i.X() = grid.Global().GlobalEnd().X()-1; | 
|---|
|  | 87 | for (i.Y() = begin_local.Y(); i.Y() < end_local.Y(); ++i.Y()) | 
|---|
|  | 88 | for (i.Z() = begin_local.Z(); i.Z() < end_local.Z(); ++i.Z()) | 
|---|
|  | 89 | boundary_values.push_back(BoundaryValue(grid, i)); | 
|---|
|  | 90 |  | 
|---|
|  | 91 | } | 
|---|
|  | 92 |  | 
|---|
|  | 93 | if (comm.BoundaryConditions().Y() == Open) { | 
|---|
|  | 94 |  | 
|---|
|  | 95 | i.Y() = grid.Global().GlobalBegin().Y(); | 
|---|
|  | 96 | for (i.X() = begin_local.X(); i.X() < end_local.X(); ++i.X()) | 
|---|
|  | 97 | for (i.Z() = begin_local.Z(); i.Z() < end_local.Z(); ++i.Z()) | 
|---|
|  | 98 | boundary_values.push_back(BoundaryValue(grid, i)); | 
|---|
|  | 99 |  | 
|---|
|  | 100 | i.Y() = grid.Global().GlobalEnd().Y() - 1; | 
|---|
|  | 101 | for (i.X() = begin_local.X(); i.X() < end_local.X(); ++i.X()) | 
|---|
|  | 102 | for (i.Z() = begin_local.Z(); i.Z() < end_local.Z(); ++i.Z()) | 
|---|
|  | 103 | boundary_values.push_back(BoundaryValue(grid, i)); | 
|---|
|  | 104 |  | 
|---|
|  | 105 | } | 
|---|
|  | 106 |  | 
|---|
|  | 107 | if (comm.BoundaryConditions().Z() == Open) { | 
|---|
|  | 108 |  | 
|---|
|  | 109 | i.Z() = grid.Global().GlobalBegin().Z(); | 
|---|
|  | 110 | for (i.X() = begin_local.X(); i.X() < end_local.X(); ++i.X()) | 
|---|
|  | 111 | for (i.Y() = begin_local.Y(); i.Y() < end_local.Y(); ++i.Y()) | 
|---|
|  | 112 | boundary_values.push_back(BoundaryValue(grid, i)); | 
|---|
|  | 113 |  | 
|---|
|  | 114 | i.Z() = grid.Global().GlobalEnd().Z() - 1; | 
|---|
|  | 115 | for (i.X() = begin_local.X(); i.X() < end_local.X(); ++i.X()) | 
|---|
|  | 116 | for (i.Y() = begin_local.Y(); i.Y() < end_local.Y(); ++i.Y()) | 
|---|
|  | 117 | boundary_values.push_back(BoundaryValue(grid, i)); | 
|---|
|  | 118 |  | 
|---|
|  | 119 | } | 
|---|
|  | 120 |  | 
|---|
|  | 121 | } | 
|---|
|  | 122 |  | 
|---|
|  | 123 | BoundaryValueSetter::~BoundaryValueSetter() | 
|---|
|  | 124 | { | 
|---|
|  | 125 |  | 
|---|
|  | 126 | } | 
|---|