diff --git a/src/01-basic-application.cc b/src/01-basic-application.cc new file mode 100644 index 0000000000000000000000000000000000000000..155c56ab4ac20494b68fb7d39fe9e916c24bb3a4 --- /dev/null +++ b/src/01-basic-application.cc @@ -0,0 +1,43 @@ +// -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- +// vi: set et ts=4 sw=2 sts=2: + +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + + + +// included standard library headers +#include <iostream> + +// included dune-common headers +#include <dune/common/parallel/mpihelper.hh> +#include <dune/common/exceptions.hh> + + + + +int main(int argc, char** argv) +{ + try{ + // Maybe initialize MPI + Dune::MPIHelper& helper = Dune::MPIHelper::instance(argc, argv); + + // Print process rank + if(Dune::MPIHelper::isFake) + std::cout<< "This is a sequential program." << std::endl; + else + std::cout<<"I am rank "<<helper.rank()<<" of "<<helper.size() + <<" processes!"<<std::endl; + + // Do nothing + + return 0; + } + catch (Dune::Exception &e){ + std::cerr << "Dune reported error: " << e << std::endl; + } + catch (...){ + std::cerr << "Unknown exception thrown!" << std::endl; + } +} diff --git a/src/02-basic-grid-interface.cc b/src/02-basic-grid-interface.cc new file mode 100644 index 0000000000000000000000000000000000000000..74b09ec13ad291eaa44a54b906128cffc4e7aa76 --- /dev/null +++ b/src/02-basic-grid-interface.cc @@ -0,0 +1,80 @@ +// -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- +// vi: set et ts=4 sw=2 sts=2: + +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + + + +// included standard library headers +#include <iostream> +#include <array> + +// included dune-common headers +#include <dune/common/parallel/mpihelper.hh> +#include <dune/common/exceptions.hh> +#include <dune/common/fvector.hh> + +// included dune-grid headers +#include <dune/grid/yaspgrid.hh> +#include <dune/grid/io/file/vtk/vtkwriter.hh> + + + +int main(int argc, char** argv) +{ + try{ + // Maybe initialize MPI + Dune::MPIHelper& helper = Dune::MPIHelper::instance(argc, argv); + + // Print process rank + if(Dune::MPIHelper::isFake) + std::cout<< "This is a sequential program." << std::endl; + else + std::cout<<"I am rank "<<helper.rank()<<" of "<<helper.size() + <<" processes!"<<std::endl; + + // fix grid dimension + const int dim = 2; + + // use the YaspGrid implementation + // YaspGrid = "Yet another structured parallel grid" + using Grid = Dune::YaspGrid<dim>; + + // extension of the domain [0,l] + Dune::FieldVector<double,dim> l(1); + + // start with 10x10x... elements + std::array<int,dim> E; + for(auto& e : E) + e = 2; + + Grid grid(l, E); + +// grid.globalRefine(2); + + auto gridView = grid.leafGridView(); + + int i = 0; + for(const auto& e: Dune::elements(gridView)) + { + ++i; + std::cout << e.geometry().center() << std::endl; + } + std::cout << i << std::endl; + + + using GridView = decltype(gridView); + Dune::VTKWriter<GridView> vtkWriter(gridView); + vtkWriter.write("01-refined-grid"); + + return 0; + } + catch (Dune::Exception &e){ + std::cerr << "Dune reported error: " << e << std::endl; + } + catch (...){ + std::cerr << "Unknown exception thrown!" << std::endl; + } +} diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 046c13da6d6b1a4165ac790106a2ef1c2f00659f..72a1a439c3ec615245369ea6e9c9a33c578778ba 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,2 +1,8 @@ add_executable("dune-fu-tutorial" dune-fu-tutorial.cc) target_link_dune_default_libraries("dune-fu-tutorial") + +add_executable("01-basic-application" 01-basic-application.cc) +target_link_dune_default_libraries("01-basic-application") + +add_executable("02-basic-grid-interface" 02-basic-grid-interface.cc) +target_link_dune_default_libraries("02-basic-grid-interface")