| [de061d] | 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 | * interface_gaussian.cpp | 
|---|
|  | 21 | * | 
|---|
|  | 22 | *  Created on: 19.04.2013 | 
|---|
|  | 23 | *      Author: Julian Iseringhausen | 
|---|
|  | 24 | */ | 
|---|
|  | 25 |  | 
|---|
|  | 26 | #ifdef HAVE_CONFIG_H | 
|---|
|  | 27 | #include <libvmg_config.h> | 
|---|
|  | 28 | #endif | 
|---|
|  | 29 |  | 
|---|
|  | 30 | #include <boost/math/special_functions/erf.hpp> | 
|---|
|  | 31 |  | 
|---|
|  | 32 | #include <cassert> | 
|---|
|  | 33 | #include <cmath> | 
|---|
|  | 34 | #include <iostream> | 
|---|
|  | 35 | #include <limits> | 
|---|
|  | 36 |  | 
|---|
|  | 37 | #include "base/math.hpp" | 
|---|
|  | 38 | #include "grid/grid.hpp" | 
|---|
|  | 39 | #include "grid/multigrid.hpp" | 
|---|
|  | 40 |  | 
|---|
|  | 41 | #include "interface_gaussian.hpp" | 
|---|
|  | 42 |  | 
|---|
|  | 43 | using namespace VMG; | 
|---|
|  | 44 | using VMGInterfaces::InterfaceGaussian; | 
|---|
|  | 45 |  | 
|---|
|  | 46 | void InterfaceGaussian::ImportRightHandSide(Multigrid& multigrid) | 
|---|
|  | 47 | { | 
|---|
|  | 48 | Index i; | 
|---|
|  | 49 | Vector pos; | 
|---|
|  | 50 |  | 
|---|
|  | 51 | Grid& grid = multigrid(multigrid.MaxLevel()); | 
|---|
|  | 52 | grid.Clear(); | 
|---|
|  | 53 |  | 
|---|
|  | 54 | const Vector pos_center = 0.5 * (grid.Extent().Begin() + grid.Extent().End()); | 
|---|
|  | 55 |  | 
|---|
|  | 56 | const Index begin = grid.Local().Begin() + grid.Local().Size() / 4; | 
|---|
|  | 57 | const Index end = grid.Local().End() - grid.Local().Size() / 4; | 
|---|
|  | 58 |  | 
|---|
|  | 59 | for (i.X()=begin.X(); i.X()<end.X(); ++i.X()) | 
|---|
|  | 60 | for (i.Y()=begin.Y(); i.Y()<end.Y(); ++i.Y()) | 
|---|
|  | 61 | for (i.Z()=begin.Z(); i.Z()<end.Z(); ++i.Z()) { | 
|---|
|  | 62 | const vmg_float dist_sqr = std::pow((grid.GetSpatialPos(i) - pos_center).Length(), 2); | 
|---|
|  | 63 | grid(i) = std::exp(-1.0 * dist_sqr / (2.0 * sigma * sigma)) / std::pow(sigma * std::sqrt(2 * VMG::Math::pi), 3); | 
|---|
|  | 64 | } | 
|---|
|  | 65 | } | 
|---|
|  | 66 |  | 
|---|
|  | 67 | void InterfaceGaussian::ExportSolution(Grid& grid) | 
|---|
|  | 68 | { | 
|---|
|  | 69 | Index i; | 
|---|
|  | 70 | vmg_float err_1 = 0.0; | 
|---|
|  | 71 | vmg_float err_2 = 0.0; | 
|---|
|  | 72 | vmg_float err_inf = 0.0; | 
|---|
|  | 73 |  | 
|---|
|  | 74 | const Vector pos_center = 0.5 * (grid.Extent().Begin() + grid.Extent().End()); | 
|---|
|  | 75 |  | 
|---|
|  | 76 | for (i.X()=grid.Local().Begin().X(); i.X()<grid.Local().End().X(); ++i.X()) | 
|---|
|  | 77 | for (i.Y()=grid.Local().Begin().Y(); i.Y()<grid.Local().End().Y(); ++i.Y()) | 
|---|
|  | 78 | for (i.Z()=grid.Local().Begin().Z(); i.Z()<grid.Local().End().Z(); ++i.Z()) { | 
|---|
|  | 79 |  | 
|---|
|  | 80 | const vmg_float dist = (grid.GetSpatialPos(i) - pos_center).Length(); | 
|---|
|  | 81 |  | 
|---|
|  | 82 | if (dist > std::numeric_limits<vmg_float>::epsilon()) { | 
|---|
|  | 83 |  | 
|---|
|  | 84 | const vmg_float err = std::abs(grid.GetVal(i) - 1.0 / (4.0 * VMG::Math::pi * dist) * | 
|---|
|  | 85 | boost::math::erf(dist / (VMG::Math::sqrt2 * sigma))); | 
|---|
|  | 86 |  | 
|---|
|  | 87 | err_1 += err; | 
|---|
|  | 88 | err_2 += err * err; | 
|---|
|  | 89 | err_inf = std::max(err_inf, err); | 
|---|
|  | 90 |  | 
|---|
|  | 91 | } | 
|---|
|  | 92 | } | 
|---|
|  | 93 |  | 
|---|
|  | 94 | err_1 = grid.Extent().MeshWidth().Product() * err_1; | 
|---|
|  | 95 | err_2 = std::sqrt(grid.Extent().MeshWidth().Product() * err_2); | 
|---|
|  | 96 | err_inf = grid.Extent().MeshWidth().Product() * err_inf; | 
|---|
|  | 97 |  | 
|---|
|  | 98 | std::cout << std::scientific << "Error L1-Norm:   " << err_1 << std::endl | 
|---|
|  | 99 | << "Error L2-Norm:   " << err_2 << std::endl | 
|---|
|  | 100 | << "Error Inf-Norm: " << err_inf << std::endl; | 
|---|
|  | 101 | } | 
|---|