Skip to content
Snippets Groups Projects
Commit be04a447 authored by Christian Engwer's avatar Christian Engwer
Browse files

Merge branch 'feature/yaspgrid-testing' into 'master'

Split YaspGrid tests into more tests and introduce parallel testing

The previous YaspGrid test was a single test which took ages to compile and run.

This branch remodels the Yasp testing suite to achieve the following:

* [x] Split the different parts into separate tests
* [x] Introduce a more sophisticated communication test
* [ ] Test periodic grids
* [x] Do parallel testing through dune_add_test
* [x] Test with -Wall -Werror!!!
* [x] Have tests with and without deprecations!

See merge request !3
parents 137a113b 9518a788
No related branches found
No related tags found
1 merge request!3Split YaspGrid tests into more tests and introduce parallel testing
Pipeline #
Showing with 724 additions and 92 deletions
add_subdirectory(yasp)
dune_add_test(SOURCES geometrygrid-coordfunction-copyconstructor.cc)
dune_add_test(NAME test-geogrid-yaspgrid
......@@ -28,9 +30,6 @@ dune_add_test(SOURCES test-oned.cc
dune_add_test(SOURCES test-mcmg-geogrid.cc)
dune_add_test(SOURCES test-yaspgrid.cc
COMPILE_DEFINITIONS GRIDDIM=2 WORLDDIM=2)
dune_add_test(SOURCES testiteratorranges.cc)
dune_add_test(SOURCES test-hierarchicsearch.cc)
......@@ -102,6 +101,7 @@ endif(ALBERTA_FOUND)
install(FILES basicunitcube.hh
check-albertareader.hh
checkadaptation.hh
checkcomcorrectness.hh
checkcommunicate.hh
checkentitylifetime.hh
checkentityseed.hh
......
// -*- 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 <fstream>
#include <sstream>
#include <unordered_set>
#include <unordered_map>
#include <unistd.h>
#include <dune/common/hash.hh>
#include <dune/common/float_cmp.hh>
#include <dune/grid/common/mcmgmapper.hh>
namespace Dune {
std::size_t hash_value(const PartitionType& pt)
{
return static_cast<std::size_t>(pt);
}
}
DUNE_DEFINE_HASH(DUNE_HASH_TEMPLATE_ARGS(),DUNE_HASH_TYPE(Dune::PartitionType))
namespace Dune {
namespace GridCheck {
struct SymmetryVerifyingDataHandle
: public Dune::CommDataHandleIF<SymmetryVerifyingDataHandle,std::size_t>
{
bool contains(int dim, int codim) const
{
return codim == _codim;
}
bool fixedsize(int dim, int codim) const
{
return _fixed_size;
}
template<typename E>
std::size_t size(const E& e) const
{
return _writes_per_cell;
}
template<typename Buf, typename E>
void gather(Buf& buf, const E& e) const
{
for (std::size_t i = 0; i < _writes_per_cell; ++i)
buf.write(std::size_t(42));
_writes += _writes_per_cell;
}
template<typename Buf, typename E>
void scatter(Buf& buf, const E& e, std::size_t n) const
{
assert(_writes_per_cell == n);
for (std::size_t i = 0; i < _writes_per_cell; ++i)
{
std::size_t tmp = 0;
buf.read(tmp);
assert(tmp == 42);
}
_reads += _writes_per_cell;
}
SymmetryVerifyingDataHandle(int codim, bool fixed_size, std::size_t writes_per_cell)
: _codim(codim)
, _fixed_size(fixed_size)
, _writes_per_cell(writes_per_cell)
, _reads(0)
, _writes(0)
{}
const int _codim;
const bool _fixed_size;
const std::size_t _writes_per_cell;
mutable std::size_t _reads;
mutable std::size_t _writes;
};
template<int dim>
struct CodimLayout
{
bool contains(Dune::GeometryType gt) const
{
return gt.dim() == dim - _codim;
}
int _codim;
};
template<typename GV>
struct CommunicationTestDataHandle
: public Dune::CommDataHandleIF<CommunicationTestDataHandle<GV>,
typename GV::template Codim<0>::Geometry::GlobalCoordinate>
{
bool contains(int dim, int codim) const
{
return codim == _codim;
}
bool fixedsize(int dim, int codim) const
{
return true;
}
template<typename E>
std::size_t size(const E& e) const
{
return 1;
}
template<typename Buf, typename E>
void gather(Buf& buf, const E& e) const
{
assert(_allowed_writes.count(e.partitionType()) > 0);
auto center = e.geometry().center();
buf.write(e.geometry().center());
if (_gv.comm().rank() == 0)
std::cout << "Gathering from entity " << _mapper.index(e) << " at " << e.geometry().center() << std::endl;
++_writes[_mapper.index(e)];
center -= _coords[_mapper.index(e)];
assert(Dune::FloatCmp::eq(center.two_norm(),0.0));
}
template<typename Buf, typename E>
void scatter(Buf& buf, const E& e, std::size_t n) const
{
assert(_allowed_reads.count(e.partitionType()) > 0);
typename E::Geometry::GlobalCoordinate data;
buf.read(data);
++_reads[_mapper.index(e)];
auto center = e.geometry().center();
data -= e.geometry().center();
assert(Dune::FloatCmp::eq(data.two_norm(),0.0));
center -= _coords[_mapper.index(e)];
assert(Dune::FloatCmp::eq(center.two_norm(),0.0));
}
template<int cd, typename Check>
void verify(Dune::Codim<cd> codim, Check check)
{
assert(codim == _codim);
for (const auto& e : entities(_gv,codim))
{
if (_gv.comm().rank() == 0)
std::cout << "Entity of codim " << cd
<< " at " << e.geometry().center()
<< " with partition " << PartitionName(e.partitionType())
<< " and " << _writes[_mapper.index(e)] << " / " << _reads[_mapper.index(e)] << " writes / reads"
<< std::endl;
check(
e.partitionType(),
_allowed_writes.count(e.partitionType()) > 0,
_allowed_reads.count(e.partitionType()) > 0,
_writes[_mapper.index(e)],
_reads[_mapper.index(e)]
);
}
}
CommunicationTestDataHandle(GV gv, int codim, const std::unordered_set<Dune::PartitionType>& allowed_writes, const std::unordered_set<Dune::PartitionType>& allowed_reads, const std::vector<typename GV::template Codim<0>::Geometry::GlobalCoordinate>& coords)
: _gv(gv)
, _codim(codim)
, _mapper(gv,{_codim})
, _allowed_writes(allowed_writes)
, _allowed_reads(allowed_reads)
, _reads(_mapper.size(),0)
, _writes(_mapper.size(),0)
, _coords(coords)
{}
GV _gv;
const int _codim;
Dune::MultipleCodimMultipleGeomTypeMapper<GV,CodimLayout> _mapper;
const std::unordered_set<Dune::PartitionType> _allowed_writes;
const std::unordered_set<Dune::PartitionType> _allowed_reads;
mutable std::vector<std::size_t> _reads;
mutable std::vector<std::size_t> _writes;
const std::vector<typename GV::template Codim<0>::Geometry::GlobalCoordinate>& _coords;
};
template<typename GV, int cd>
void check_communication_correctness_do(GV gv, Codim<cd> codim)
{
if (gv.grid().comm().rank() == 0)
{
std::cout << "Checking codim " << cd << std::endl;
}
std::unordered_map<Dune::PartitionType,std::size_t> count;
Dune::MultipleCodimMultipleGeomTypeMapper<GV,CodimLayout> mapper(gv,{codim});
std::vector<
typename GV::template Codim<0>::Geometry::GlobalCoordinate
> coords(mapper.size());
// start by counting entities by partition type and storing entity positions
for (const auto& e : entities(gv,codim))
{
++count[e.partitionType()];
coords[mapper.index(e)] = e.geometry().center();
}
{
SymmetryVerifyingDataHandle dh_forward(cd,false,3);
gv.communicate(dh_forward,InteriorBorder_InteriorBorder_Interface,ForwardCommunication);
SymmetryVerifyingDataHandle dh_backward(cd,true,3);
gv.communicate(dh_backward,InteriorBorder_InteriorBorder_Interface,BackwardCommunication);
if (count[BorderEntity] > 0)
{
assert(dh_forward._writes == dh_forward._reads);
assert(dh_backward._writes == dh_backward._reads);
assert(dh_forward._writes == dh_backward._writes);
assert(dh_backward._writes == dh_backward._writes);
}
if (gv.grid().comm().size() == 2)
{
if (gv.comm().rank() == 0)
std::cout << "MPI size == 2, checking writes (" << (dh_forward._writes / 3)
<< ") against count of border entities (" << count[BorderEntity] << ")"
<< std::endl;
assert((dh_forward._writes / 3) == count[BorderEntity]);
}
}
{
SymmetryVerifyingDataHandle dh_forward(cd,true,7);
gv.communicate(dh_forward,All_All_Interface,ForwardCommunication);
SymmetryVerifyingDataHandle dh_backward(cd,false,7);
gv.communicate(dh_backward,All_All_Interface,BackwardCommunication);
if (count[BorderEntity] > 0)
{
assert(dh_forward._writes == dh_forward._reads);
assert(dh_backward._writes == dh_backward._reads);
assert(dh_forward._writes == dh_backward._writes);
assert(dh_backward._writes == dh_backward._writes);
}
}
using PTSet = std::unordered_set<PartitionType>;
{
PTSet writers({InteriorEntity,BorderEntity});
PTSet readers({InteriorEntity,BorderEntity,OverlapEntity,FrontEntity,GhostEntity});
CommunicationTestDataHandle<GV> dh(gv,codim,writers,readers,coords);
gv.communicate(dh,InteriorBorder_All_Interface,ForwardCommunication);
}
{
PTSet writers({InteriorEntity,BorderEntity,OverlapEntity,FrontEntity,GhostEntity});
PTSet readers({InteriorEntity,BorderEntity});
CommunicationTestDataHandle<GV> dh(gv,codim,writers,readers,coords);
gv.communicate(dh,InteriorBorder_All_Interface,BackwardCommunication);
}
{
PTSet writers({InteriorEntity,BorderEntity});
PTSet readers({InteriorEntity,BorderEntity});
CommunicationTestDataHandle<GV> dh(gv,codim,writers,readers,coords);
gv.communicate(dh,InteriorBorder_InteriorBorder_Interface,ForwardCommunication);
dh.verify(
codim,
[](PartitionType partition, bool write_allowed, bool read_allowed, std::size_t writes, std::size_t reads)
{
if (partition == BorderEntity)
{
assert(writes > 0);
assert(reads > 0);
assert(writes == reads);
}
else
{
assert(writes == 0);
assert(reads == 0);
}
});
}
}
// Need a forward declaration here
template<typename GV, int cd>
void check_communication_correctness_iter(GV gv, Codim<cd> codim);
// Statically iterate over all codimensions
template<typename GV, int cd>
void check_communication_correctness_iter(GV gv, Codim<cd> codim, std::true_type, std::true_type) {}
template<typename GV, int cd>
void check_communication_correctness_iter(GV gv, Codim<cd> codim, std::false_type, std::true_type) {}
template<typename GV, int cd>
void check_communication_correctness_iter(GV gv, Codim<cd> codim, std::true_type, std::false_type) {
check_communication_correctness_do(gv, codim);
check_communication_correctness_iter (gv, Codim<cd+1>());
}
template<typename GV, int cd>
void check_communication_correctness_iter(GV gv, Codim<cd> codim, std::false_type, std::false_type) {
check_communication_correctness_iter (gv, Codim<cd+1>());
}
template<typename GV, int cd>
void check_communication_correctness_iter(GV gv, Codim<cd> codim) {
check_communication_correctness_iter (gv, codim,
std::integral_constant<bool, Dune::Capabilities::hasEntity<typename GV::Grid, cd>::v>(),
std::integral_constant<bool, cd == GV::dimension + 1>());
}
// Start with codim 0
template<typename GV>
void check_communication_correctness(GV gv)
{
check_communication_correctness_iter (gv, Codim<0>());
}
} // namespace GridCheck
} // namespace Dune
# Add all tests without deprecations
dune_add_test(NAME test-yaspgrid-backuprestore-equidistant
SOURCES test-yaspgrid-backuprestore-equidistant.cc
MPI_RANKS 1 2
TIMEOUT 666
)
dune_add_test(NAME test-yaspgrid-backuprestore-equidistantoffset
SOURCES test-yaspgrid-backuprestore-equidistantoffset.cc
MPI_RANKS 1 2
TIMEOUT 666
)
dune_add_test(NAME test-yaspgrid-backuprestore-tensor
SOURCES test-yaspgrid-backuprestore-tensor.cc
MPI_RANKS 1 2
TIMEOUT 666
)
dune_add_test(NAME test-yaspgrid-tensorgridfactory
SOURCES test-yaspgrid-tensorgridfactory.cc
MPI_RANKS 1 2
TIMEOUT 666
)
dune_add_test(NAME test-yaspgrid-yaspfactory-1d
SOURCES test-yaspgrid-yaspfactory-1d.cc
MPI_RANKS 1 2
TIMEOUT 666
)
dune_add_test(NAME test-yaspgrid-yaspfactory-2d
SOURCES test-yaspgrid-yaspfactory-2d.cc
MPI_RANKS 1 2
TIMEOUT 666
)
dune_add_test(NAME test-yaspgrid-yaspfactory-3d
SOURCES test-yaspgrid-yaspfactory-3d.cc
MPI_RANKS 1 2
TIMEOUT 666
)
// -*- 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 <fstream>
#include <sstream>
#include <dune/common/parallel/mpihelper.hh>
#include <dune/grid/yaspgrid.hh>
#include <dune/grid/yaspgrid/backuprestore.hh>
#include "test-yaspgrid.hh"
int main (int argc , char **argv) {
try {
// Initialize MPI, if present
Dune::MPIHelper::instance(argc, argv);
// check the backup restore facility
check_backuprestore(YaspFactory<2,Dune::EquidistantCoordinates<double,2> >::buildGrid());
// Test again with refinement
check_backuprestore(YaspFactory<2,Dune::EquidistantCoordinates<double,2> >::buildGrid(true, 1));
} catch (Dune::Exception &e) {
std::cerr << e << std::endl;
return 1;
} catch (...) {
std::cerr << "Generic exception!" << std::endl;
return 2;
}
return 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 <fstream>
#include <sstream>
#include <dune/common/parallel/mpihelper.hh>
#include <dune/grid/yaspgrid.hh>
#include <dune/grid/yaspgrid/backuprestore.hh>
#include "test-yaspgrid.hh"
int main (int argc , char **argv) {
try {
// Initialize MPI, if present
Dune::MPIHelper::instance(argc, argv);
// check the backup restore facility
check_backuprestore(YaspFactory<2,Dune::EquidistantOffsetCoordinates<double,2> >::buildGrid());
// Test again with refinement
check_backuprestore(YaspFactory<2,Dune::EquidistantOffsetCoordinates<double,2> >::buildGrid(true, 1));
} catch (Dune::Exception &e) {
std::cerr << e << std::endl;
return 1;
} catch (...) {
std::cerr << "Generic exception!" << std::endl;
return 2;
}
return 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 <fstream>
#include <sstream>
#include <dune/common/parallel/mpihelper.hh>
#include <dune/grid/yaspgrid.hh>
#include <dune/grid/yaspgrid/backuprestore.hh>
#include "test-yaspgrid.hh"
int main (int argc , char **argv) {
try {
// Initialize MPI, if present
Dune::MPIHelper::instance(argc, argv);
// check the backup restore facility
check_backuprestore(YaspFactory<2,Dune::TensorProductCoordinates<double,2> >::buildGrid());
// Test again with refinement
check_backuprestore(YaspFactory<2,Dune::TensorProductCoordinates<double,2> >::buildGrid(true, 1));
} catch (Dune::Exception &e) {
std::cerr << e << std::endl;
return 1;
} catch (...) {
std::cerr << "Generic exception!" << std::endl;
return 2;
}
return 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 <fstream>
#include <sstream>
#include <dune/common/parallel/mpihelper.hh>
#include <dune/grid/yaspgrid.hh>
#include <dune/grid/utility/tensorgridfactory.hh>
#include "test-yaspgrid.hh"
int main (int argc , char **argv) {
try {
// Initialize MPI, if present
Dune::MPIHelper::instance(argc, argv);
// check the factory class for tensorproduct grids
Dune::TensorGridFactory<Dune::YaspGrid<2, Dune::TensorProductCoordinates<double,2> > > factory;
factory.setStart(0,-100.);
factory.fillIntervals(0,10,20.);
factory.fillRange(0, 5, 130.);
factory.geometricFillIntervals(0, 5, 2.0);
factory.geometricFillRange(1,10,100.,1.,false);
factory.fillRange(1,10,200);
factory.geometricFillRange(1,10,250.,1.,true);
factory.fillUntil(1,50,1000.);
factory.createGrid();
} catch (Dune::Exception &e) {
std::cerr << e << std::endl;
return 1;
} catch (...) {
std::cerr << "Generic exception!" << std::endl;
return 2;
}
return 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 <fstream>
#include <sstream>
#include <dune/common/parallel/mpihelper.hh>
#include <dune/grid/yaspgrid.hh>
#include <dune/grid/utility/tensorgridfactory.hh>
#include "test-yaspgrid.hh"
int main (int argc , char **argv) {
try {
// Initialize MPI, if present
Dune::MPIHelper::instance(argc, argv);
check_yasp(YaspFactory<1,Dune::EquidistantCoordinates<double,1> >::buildGrid());
check_yasp(YaspFactory<1,Dune::EquidistantOffsetCoordinates<double,1> >::buildGrid());
check_yasp(YaspFactory<1,Dune::TensorProductCoordinates<double,1> >::buildGrid());
} catch (Dune::Exception &e) {
std::cerr << e << std::endl;
return 1;
} catch (...) {
std::cerr << "Generic exception!" << std::endl;
return 2;
}
return 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 <fstream>
#include <sstream>
#include <dune/common/parallel/mpihelper.hh>
#include <dune/grid/yaspgrid.hh>
#include <dune/grid/utility/tensorgridfactory.hh>
#include "test-yaspgrid.hh"
int main (int argc , char **argv) {
try {
// Initialize MPI, if present
Dune::MPIHelper::instance(argc, argv);
check_yasp(YaspFactory<2,Dune::EquidistantCoordinates<double,2> >::buildGrid(true, 0));
check_yasp(YaspFactory<2,Dune::EquidistantOffsetCoordinates<double,2> >::buildGrid(true, 0));
check_yasp(YaspFactory<2,Dune::TensorProductCoordinates<double,2> >::buildGrid(true, 0));
// In 2D, also test refinement
for (int refineOpt = 0; refineOpt <= 1; ++refineOpt) {
check_yasp(YaspFactory<2,Dune::EquidistantCoordinates<double,2> >::buildGrid(refineOpt == 1, 1));
check_yasp(YaspFactory<2,Dune::EquidistantOffsetCoordinates<double,2> >::buildGrid(refineOpt == 1, 1));
check_yasp(YaspFactory<2,Dune::TensorProductCoordinates<double,2> >::buildGrid(refineOpt == 1, 1));
}
// And periodicity
// check_yasp(YaspFactory<2,Dune::EquidistantCoordinates<double,2> >::buildGrid(true, 0, true));
// check_yasp(YaspFactory<2,Dune::EquidistantOffsetCoordinates<double,2> >::buildGrid(true, 0, true));
// check_yasp(YaspFactory<2,Dune::TensorProductCoordinates<double,2> >::buildGrid(true, 0, true));
} catch (Dune::Exception &e) {
std::cerr << e << std::endl;
return 1;
} catch (...) {
std::cerr << "Generic exception!" << std::endl;
return 2;
}
return 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 <fstream>
#include <sstream>
#include <dune/common/parallel/mpihelper.hh>
#include <dune/grid/yaspgrid.hh>
#include <dune/grid/utility/tensorgridfactory.hh>
#include "test-yaspgrid.hh"
int main (int argc , char **argv) {
try {
// Initialize MPI, if present
Dune::MPIHelper::instance(argc, argv);
check_yasp(YaspFactory<3,Dune::EquidistantCoordinates<double,3> >::buildGrid());
check_yasp(YaspFactory<3,Dune::EquidistantOffsetCoordinates<double,3> >::buildGrid());
check_yasp(YaspFactory<3,Dune::TensorProductCoordinates<double,3> >::buildGrid());
} catch (Dune::Exception &e) {
std::cerr << e << std::endl;
return 1;
} catch (...) {
std::cerr << "Generic exception!" << std::endl;
return 2;
}
return 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 <dune/grid/test/gridcheck.hh>
#include <dune/grid/test/checkcommunicate.hh>
#include <dune/grid/test/checkgeometryinfather.hh>
#include <dune/grid/test/checkintersectionit.hh>
#include <dune/grid/test/checkiterators.hh>
#include <dune/grid/test/checkadaptation.hh>
#include <dune/grid/test/checkpartition.hh>
#include <iostream>
#include <fstream>
#include <sstream>
#include "dune/grid/test/checkcomcorrectness.hh"
#include <dune/common/parallel/mpihelper.hh>
#include <dune/grid/yaspgrid.hh>
#include <dune/grid/yaspgrid/backuprestore.hh>
#include <dune/grid/utility/tensorgridfactory.hh>
#include "gridcheck.hh"
#include "checkcommunicate.hh"
#include "checkgeometryinfather.hh"
#include "checkintersectionit.hh"
#include "checkiterators.hh"
#include "checkadaptation.hh"
#include "checkpartition.hh"
template<int dim, class CC>
struct YaspFactory
......@@ -27,64 +19,99 @@ struct YaspFactory
template<int dim>
struct YaspFactory<dim, Dune::EquidistantCoordinates<double,dim> >
{
static Dune::YaspGrid<dim>* buildGrid()
static Dune::YaspGrid<dim>* buildGrid(
bool keepPhysicalOverlap = true, int refCount = 0, bool periodic = false)
{
std::cout << " using equidistant coordinate container!" << std::endl << std::endl;
Dune::FieldVector<double,dim> Len(1.0);
std::array<int,dim> s;
std::fill(s.begin(), s.end(), 8);
if (dim < 3)
std::fill(s.begin(), s.end(), 8);
else
std::fill(s.begin(), s.end(), 4);
std::bitset<dim> p(0);
p[0] = periodic;
int overlap = 1;
return new Dune::YaspGrid<dim>(Len,s,p,overlap);
auto grid = new Dune::YaspGrid<dim>(Len,s,p,overlap);
grid->refineOptions (keepPhysicalOverlap);
grid->globalRefine (refCount);
return grid;
}
};
template<int dim>
struct YaspFactory<dim, Dune::EquidistantOffsetCoordinates<double,dim> >
{
static Dune::YaspGrid<dim, Dune::EquidistantOffsetCoordinates<double,dim> >* buildGrid()
static Dune::YaspGrid<dim, Dune::EquidistantOffsetCoordinates<double,dim> >* buildGrid(
bool keepPhysicalOverlap = true, int refCount = 0, bool periodic = false)
{
std::cout << " using equidistant coordinate container with non-zero origin!" << std::endl << std::endl;
Dune::FieldVector<double,dim> lowerleft(-1.0);
Dune::FieldVector<double,dim> upperright(1.0);
std::array<int,dim> s;
std::fill(s.begin(), s.end(), 8);
if (dim < 3)
std::fill(s.begin(), s.end(), 8);
else
std::fill(s.begin(), s.end(), 4);
std::bitset<dim> p(0);
p[0] = periodic;
int overlap = 1;
return new Dune::YaspGrid<dim, Dune::EquidistantOffsetCoordinates<double,dim> >(lowerleft,upperright,s,p,overlap);
auto grid = new Dune::YaspGrid<dim, Dune::EquidistantOffsetCoordinates<double,dim> >(lowerleft,upperright,s,p,overlap);
grid->refineOptions (keepPhysicalOverlap);
grid->globalRefine (refCount);
return grid;
}
};
template<int dim>
struct YaspFactory<dim, Dune::TensorProductCoordinates<double,dim> >
{
static Dune::YaspGrid<dim, Dune::TensorProductCoordinates<double,dim> >* buildGrid()
static Dune::YaspGrid<dim, Dune::TensorProductCoordinates<double,dim> >* buildGrid(
bool keepPhysicalOverlap = true, int refCount = 0, bool periodic = false)
{
std::cout << " using tensorproduct coordinate container!" << std::endl << std::endl;
std::bitset<dim> p(0);
p[0] = periodic;
int overlap = 1;
std::array<std::vector<double>,dim> coords;
for (int i=0; i<dim; i++)
{
coords[i].resize(9);
coords[i][0] = -1.0;
coords[i][1] = -0.5;
coords[i][2] = -0.25;
coords[i][3] = -0.125;
coords[i][4] = 0.0;
coords[i][5] = 0.125;
coords[i][6] = 0.25;
coords[i][7] = 0.5;
coords[i][8] = 1.0;
if (dim < 3) {
for (int i=0; i<dim; i++)
{
coords[i].resize(9);
coords[i][0] = -1.0;
coords[i][1] = -0.5;
coords[i][2] = -0.25;
coords[i][3] = -0.125;
coords[i][4] = 0.0;
coords[i][5] = 0.125;
coords[i][6] = 0.25;
coords[i][7] = 0.5;
coords[i][8] = 1.0;
}
} else {
for (int i=0; i<dim; i++)
{
coords[i].resize(7);
coords[i][0] = -1.0;
coords[i][1] = -0.5;
coords[i][2] = -0.25;
coords[i][3] = 0.0;
coords[i][4] = 0.25;
coords[i][5] = 0.5;
coords[i][6] = 1.0;
}
}
return new Dune::YaspGrid<dim, Dune::TensorProductCoordinates<double,dim> >(coords,p,overlap);
auto grid = new Dune::YaspGrid<dim, Dune::TensorProductCoordinates<double,dim> >(coords,p,overlap);
grid->refineOptions (keepPhysicalOverlap);
grid->globalRefine (refCount);
return grid;
}
};
......@@ -92,12 +119,6 @@ template <int dim, class CC>
void check_yasp(Dune::YaspGrid<dim,CC>* grid) {
std::cout << std::endl << "YaspGrid<" << dim << ">";
if (grid == NULL)
grid = YaspFactory<dim,CC>::buildGrid();
gridcheck(*grid);
//grid->globalRefine(2);
gridcheck(*grid);
checkIterators ( grid->leafGridView() );
......@@ -108,6 +129,9 @@ void check_yasp(Dune::YaspGrid<dim,CC>* grid) {
for(int l=0; l<=grid->maxLevel(); ++l)
checkCommunication(*grid,l,Dune::dvverb);
// check communication correctness
Dune::GridCheck::check_communication_correctness(grid->leafGridView());
// check geometry lifetime
checkGeometryLifetime( grid->leafGridView() );
// check the method geometryInFather()
......@@ -173,50 +197,3 @@ void check_backuprestore(Dune::YaspGrid<dim,CC>* grid)
delete grid;
}
int main (int argc , char **argv) {
try {
// Initialize MPI, if present
Dune::MPIHelper::instance(argc, argv);
check_yasp(YaspFactory<1,Dune::EquidistantCoordinates<double,1> >::buildGrid());
check_yasp(YaspFactory<1,Dune::EquidistantOffsetCoordinates<double,1> >::buildGrid());
check_yasp(YaspFactory<1,Dune::TensorProductCoordinates<double,1> >::buildGrid());
check_yasp(YaspFactory<2,Dune::EquidistantCoordinates<double,2> >::buildGrid());
check_yasp(YaspFactory<2,Dune::EquidistantOffsetCoordinates<double,2> >::buildGrid());
check_yasp(YaspFactory<2,Dune::TensorProductCoordinates<double,2> >::buildGrid());
check_yasp(YaspFactory<3,Dune::EquidistantCoordinates<double,3> >::buildGrid());
check_yasp(YaspFactory<3,Dune::EquidistantOffsetCoordinates<double,3> >::buildGrid());
check_yasp(YaspFactory<3,Dune::TensorProductCoordinates<double,3> >::buildGrid());
// check the factory class for tensorproduct grids
Dune::TensorGridFactory<Dune::YaspGrid<2, Dune::TensorProductCoordinates<double,2> > > factory;
factory.setStart(0,-100.);
factory.fillIntervals(0,10,20.);
factory.fillRange(0, 5, 130.);
factory.geometricFillIntervals(0, 5, 2.0);
factory.geometricFillRange(1,10,100.,1.,false);
factory.fillRange(1,10,200);
factory.geometricFillRange(1,10,250.,1.,true);
factory.fillUntil(1,50,1000.);
auto grid = factory.createGrid();
// check the backup restore facility
check_backuprestore(YaspFactory<2,Dune::EquidistantCoordinates<double,2> >::buildGrid());
check_backuprestore(YaspFactory<2,Dune::EquidistantOffsetCoordinates<double,2> >::buildGrid());
check_backuprestore(YaspFactory<2,Dune::TensorProductCoordinates<double,2> >::buildGrid());
} catch (Dune::Exception &e) {
std::cerr << e << std::endl;
return 1;
} catch (...) {
std::cerr << "Generic exception!" << std::endl;
return 2;
}
return 0;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment