/*
* 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 num_cells, size_factor;
Index add_node = Index(bc[0]==Periodic?0:1,
bc[1]==Periodic?0:1,
bc[2]==Periodic?0:1);
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)) : 1);
num_cells = Helper::intpow(2,levelMax-i) * size_factor;
global.push_back(GlobalIndices());
extent.push_back(SpatialExtent());
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() = extent.back().Size() / num_cells;
global.back().LocalSize() = num_cells + add_node;
global.back().LocalBegin() = -1 * num_cells / 2;
global.back().LocalEnd() = num_cells/2 + add_node;
global.back().GlobalSizeNew() = global.back().LocalSize();
global.back().GlobalBegin() = global.back().LocalBegin();
global.back().GlobalEnd() = global.back().LocalEnd();
global.back().GlobalSizeFinest() = Helper::intpow(2, coarseningSteps)*num_cells + add_node;
global.back().GlobalBeginFinest() = -1 * ((Helper::intpow(2, coarseningSteps)*num_cells) / 2);
global.back().GlobalEndFinest() = (Helper::intpow(2, coarseningSteps)*num_cells) / 2 + add_node;
}
if (coarseningSteps == 0) {
num_cells = Helper::intpow(2, levelMax);
global.push_back(GlobalIndices());
extent.push_back(SpatialExtent());
extent.back().Size() = box_size;
extent.back().Begin() = box_center - 0.5 * extent.back().Size();
extent.back().End() = extent.back().Begin() + extent.back().Size();
extent.back().MeshWidth() = extent.back().Size() / num_cells;
global.back().LocalSize() = num_cells + add_node;
global.back().LocalBegin() = -1 * num_cells/2;
global.back().LocalEnd() = num_cells/2 + add_node;
global.back().GlobalSizeNew() = global.back().LocalSize();
global.back().GlobalBegin() = global.back().LocalBegin();
global.back().GlobalEnd() = global.back().LocalEnd();
global.back().GlobalSizeFinest() = global.back().LocalSize();
global.back().GlobalBeginFinest() = global.back().LocalBegin();
global.back().GlobalEndFinest() = global.back().LocalEnd();
}
while (global.back().LocalSize().Min() > Helper::intpow(2, levelMin)+1) {
num_cells /= 2;
extent.back().Size() = (++extent.rbegin())->Size();
extent.back().Begin() = (++extent.rbegin())->Begin();
extent.back().End() = (++extent.rbegin())->End();
extent.back().MeshWidth() = 2.0 * (++extent.rbegin())->MeshWidth();
global.back().LocalSize() = num_cells + add_node;
global.back().LocalBegin() = -1 * num_cells/2;
global.back().LocalEnd() = num_cells/2 + add_node;
global.back().GlobalSizeNew() = global.back().LocalSize();
global.back().GlobalBegin() = global.back().LocalBegin();
global.back().GlobalEnd() = global.back().LocalEnd();
global.back().GlobalSizeFinest() = (++global.rbegin())->GlobalSizeFinest();
global.back().GlobalBeginFinest() = (++global.rbegin())->GlobalBeginFinest();
global.back().GlobalEndFinest() = (++global.rbegin())->GlobalEndFinest();
}
for (i=global.size()-2; i>=0; --i) {
if (global[i].GlobalSizeFinest().Product() >= global[i+1].GlobalSizeFinest().Product()) {
global[i].BoundaryType() = GlobalCoarsened;
}else {
global[i].BoundaryType() = LocallyRefined;
global[i+1].BoundaryType() = GlobalMax;
break;
}
}
levelMin = levelMax - global.size() + 1;
}