/*
* vmg - a versatile multigrid solver
* Copyright (C) 2012 Institute for Numerical Simulation, University of Bonn
*
* vmg is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* vmg is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*/
/**
* @file interface.cpp
* @author Julian Iseringhausen
* @date Mon Apr 18 12:55:48 2011
*
* @brief VMG::Interface
*
*/
#ifdef HAVE_CONFIG_H
#include
#endif
#include
#include
#include "base/helper.hpp"
#include "base/interface.hpp"
using namespace VMG;
static Index GetGlobalIndex(const Vector& pos, const SpatialExtent& extent, const BT& bt)
{
const Index index = (pos - extent.Begin()) / extent.MeshWidth() + 0.5;
return index + (bt == LocallyRefined ? 1 : 0);
}
void Interface::InitInterface(const Vector& box_offset, const vmg_float& box_size,
const int& coarseningSteps, const vmg_float& alpha)
{
int i;
Index size_factor;
const Vector box_center = box_offset + 0.5 * box_size;
/*
* Get Extents
*/
for (i=0; i(log(pow(alpha, i+1)) / log(2.0) + 1.0)));
extent.back().Size() = box_size * static_cast(size_factor);
extent.back().Begin() = box_center - 0.5 * extent.back().Size();
extent.back().End() = extent.back().Begin() + extent.back().Size();
extent.back().MeshWidth() = pow(2.0, i-levelMax) * extent.back().Size() / size_factor;
}
if (extent.size() == 0) {
extent.push_back(SpatialExtent());
extent.back().Size() = box_size;
extent.back().Begin() = box_offset;
extent.back().End() = box_offset + box_size;
extent.back().MeshWidth() = box_size / Helper::intpow(2,levelMax);
}
while ((extent.back().Size() / extent.back().MeshWidth()).Min() > Helper::intpow(2,levelMin) + 1) {
extent.push_back(SpatialExtent(extent.back()));
extent.back().MeshWidth() *= 2;
}
/*
* Find GlobalMax
*/
for (std::vector::const_iterator iter=extent.begin(); iter!=extent.end(); ++iter) {
global.push_back(GlobalIndices());
global.back().BoundaryType() = GlobalCoarsened;
}
for (i=global.size()-1; i>=0; --i) {
if (i == 0 || extent[i-1].Size() != extent[i].Size()) {
global[i].BoundaryType() = GlobalMax;
break;
}
}
for (--i; i>=0; --i)
global[i].BoundaryType() = LocallyRefined;
/*
* Compute global grid values
*/
for (i=0; i