Commit f2efbafa authored by Robert K's avatar Robert K

[feature][periodic] added test to test correctness of periodic

neighbors.
parent b7d70208
......@@ -9,6 +9,7 @@ set(EXTRA_TESTS
test-adaptivity
test-fromtogridfactory
test-iterators
test-periodic
test-twists
test-hierarchic
test-ball-projection
......
......@@ -4,7 +4,8 @@ set(DGFS
cube-testgrid-2-2.dgf
cube-testgrid-2-3.dgf
grid2d_str1d.dgf
periodic.dgf
periodic2.dgf
periodic3.dgf
sphere.dgf
simplex-testgrid-2-2.dgf
simplex-testgrid-2-3.dgf
......
DGF
INTERVAL
0 0 % lower left corner
1 1 % upper right corner
8 8 % number of cells in each direction
#
PERIODICFACETRANSFORMATION
1 0, 0 1 + 1 0 % make periodic in x-direction
1 0, 0 1 + 0 1 % make periodic in y-direction
#
BOUNDARYDOMAIN
DEFAULT 1
#
GRIDPARAMETER
OVERLAP 0
#
#
// -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
// vi: set et ts=4 sw=2 sts=2:
#include "config.h"
#include <iostream>
#include <memory>
#include <sstream>
#include <string>
#include <vector>
#include <dune/common/parallel/mpihelper.hh>
#include <dune/alugrid/grid.hh>
#include <dune/alugrid/dgf.hh>
#include <dune/grid/io/file/vtk/vtkwriter.hh>
using namespace Dune;
template <class GridView>
void checkPeriodic( const GridView& gv )
{
for(const auto& elem : Dune::elements( gv ) )
{
for( const auto& intersection : Dune::intersections( gv, elem ))
{
// check periodic boundary
if( intersection.neighbor() && intersection.boundary() )
{
const auto& inside = intersection.inside();
const auto& outside = intersection.outside();
auto centerInside = intersection.geometryInInside().center();
auto centerOutside = intersection.geometryInOutside().center();
auto gIn = inside.geometry().global ( centerInside );
auto gOut = outside.geometry().global ( centerOutside );
auto diff = gIn - gOut;
if( std::abs(diff.two_norm() - 1.0 ) > 1e-12 )
{
std::cout << gIn << " " << gOut << " " << diff << std::endl;
DUNE_THROW(Dune::InvalidStateException,"Centers of periodic boundary differ");
}
}
}
}
}
int main( int argc, char** argv )
try
{
static const int dim = 2;
auto& mpiHelper = MPIHelper::instance( argc, argv );
const int rank = mpiHelper.rank();
std::string filename = "dgf/periodic" + std::to_string( dim ) + ".dgf";
if( argc > 1 )
{
filename = std::string(argv[1]);
}
using GridType = Dune::ALUGrid<dim, dim, Dune::cube, Dune::nonconforming>;
Dune::GridPtr< GridType > gridPtr( filename );
GridType& grid = *gridPtr;
grid.loadBalance();
checkPeriodic( grid.leafGridView() );
for( int i=0; i<3; ++i )
{
grid.globalRefine( 1 );
checkPeriodic( grid.leafGridView() );
}
Dune::VTKWriter<typename GridType::LeafGridView> vtkWriter( grid.leafGridView());
vtkWriter.write( "periodic-out" );
return 0;
}
catch ( Dune::Exception &e )
{
std::cerr << e << std::endl;
return 1;
}
catch (std::exception &e) {
std::cerr << e.what() << std::endl;
return 1;
}
catch ( ... )
{
std::cerr << "Generic exception!" << std::endl;
return 2;
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment