Commit d43df306 authored by Alexander Kissinger's avatar Alexander Kissinger Committed by Martin Beck
Browse files

[CakeGridCreator] Improved structure of cake grid creator

Improved the structure of cake grid creator:
- Which spacing law to use can now be chosen in the input file
- Extra function for creating vectors of coordinates with spacers. This function can be overwritten by the user if necessary
- Extra function for implementing the grid into the grid factory given the coordinate vectors

Implemented together with MartinB
parent 6e557e93
......@@ -29,6 +29,7 @@
#include <dune/grid/common/gridfactory.hh>
#include <dumux/common/basicproperties.hh>
#include <dumux/common/propertysystem.hh>
namespace Dumux
{
......@@ -89,8 +90,7 @@ private:
* A quadirlateral is a line segment in 1D, a rectangle in 2D and a
* cube in 3D.
*/
template <class TypeTag,
class SpacerRadius = Dumux::LinearSpacer<TypeTag>>
template <class TypeTag>
class CakeGridCreator
{
typedef typename GET_PROP_TYPE(TypeTag, Scalar) Scalar;
......@@ -98,6 +98,7 @@ class CakeGridCreator
typedef Dune::GridFactory<Grid> GridFactory;
typedef std::shared_ptr<Grid> GridPointer;
typedef Dumux::LinearSpacer<TypeTag> SpacerDefault;
typedef typename Dumux::PowerLawSpacer<TypeTag> PowerLawSpacer;
enum { dim = Grid::dimension,
dimWorld = Grid::dimensionworld
......@@ -109,6 +110,9 @@ class CakeGridCreator
angleIdx = 1,
zIdx = 2
};
typedef Dune::BlockVector<Dune::FieldVector<double, dim> > VectorField;
typedef std::array<unsigned int, dim> CellArray;
typedef Dune::FieldVector<typename Grid::ctype, dimWorld> GlobalPosition;
public:
/*!
......@@ -116,43 +120,85 @@ public:
*/
static void makeGrid()
{
if (dim == 2)
if (dim != 3)
{
DUNE_THROW(Dune::NotImplemented, "The CakeGridCreator is not implemented for 1D and 2D.");
}
gridPtr() = CakeGridCreator<TypeTag, SpacerRadius>::createCakeGrid();
VectorField coordinates;;
createVectors(coordinates);
gridPtr() = CakeGridCreator<TypeTag>::createCakeGrid(coordinates);
}
static std::shared_ptr<Grid> createCakeGrid()
static void createVectors(VectorField &coordinates)
{
//Set the coordinate vector
coordinates.resize(1);
coordinates[0] = {0, 0, 0};
coordinates.resize(2);
coordinates[1] = {1, 0, 0};
coordinates.resize(3);
coordinates[2] = {0, 1, 0};
coordinates.resize(4);
coordinates[3] = {1, 1, 0};
coordinates.resize(5);
coordinates[4] = {0, 0, 1};
coordinates.resize(6);
coordinates[5] = {1, 0, 1};
coordinates.resize(7);
coordinates[6] = {0, 1, 1};
coordinates.resize(8);
coordinates[7] = {1, 1, 1};
// The required parameters
typedef Dune::FieldVector<typename Grid::ctype, dimWorld> GlobalPosition;
const GlobalPosition polarCoorMin =
GlobalPosition polarCoorMin;
GlobalPosition polarCoorMax;
CellArray cells;
try {
polarCoorMin =
GET_RUNTIME_PARAM_FROM_GROUP_CSTRING(TypeTag, GlobalPosition, GET_PROP_VALUE(TypeTag, GridParameterGroup).c_str(), PolarCoorMin);
const GlobalPosition polarCoorMax =
polarCoorMax =
GET_RUNTIME_PARAM_FROM_GROUP_CSTRING(TypeTag, GlobalPosition, GET_PROP_VALUE(TypeTag, GridParameterGroup).c_str(), PolarCoorMax);
// The optional parameters (they have a default)
typedef std::array<unsigned int, dim> CellArray;
CellArray cells;
std::fill(cells.begin(), cells.end(), 1);
try { cells = GET_RUNTIME_PARAM_FROM_GROUP_CSTRING(TypeTag, CellArray, GET_PROP_VALUE(TypeTag, GridParameterGroup).c_str(), Cells); }
catch (Dumux::ParameterException &e) { }
cells = GET_RUNTIME_PARAM_FROM_GROUP_CSTRING(TypeTag, CellArray, GET_PROP_VALUE(TypeTag, GridParameterGroup).c_str(), Cells);
}
catch (Dumux::ParameterException &e) {
DUNE_THROW(Dumux::ParameterException, "Please supply the mandatory parameters: "
<< "PolarCoorMin, PolarCoorMax or Cells");
}
SpacerRadius spacerR(polarCoorMin[radiusIdx], polarCoorMax[radiusIdx], cells[radiusIdx]);
//Check the input file whether UsePowerLawSpacerRadius is specified, if yes use type PowerLawSpacer else default type
try {
if(GET_RUNTIME_PARAM_FROM_GROUP_CSTRING(TypeTag, bool, GET_PROP_VALUE(TypeTag, GridParameterGroup).c_str(), UsePowerLawSpacerRadius)){
PowerLawSpacer spacerR(polarCoorMin[radiusIdx], polarCoorMax[radiusIdx], cells[radiusIdx]);
}
else
SpacerDefault spacerR(polarCoorMin[radiusIdx], polarCoorMax[radiusIdx], cells[radiusIdx]);
}
catch (...)
{
SpacerDefault spacerR(polarCoorMin[radiusIdx], polarCoorMax[radiusIdx], cells[radiusIdx]);
}
SpacerDefault spacerAngle(polarCoorMin[angleIdx], polarCoorMax[angleIdx], cells[angleIdx]);
SpacerDefault spacerZ(polarCoorMin[zIdx], polarCoorMax[zIdx], cells[zIdx]);
}
static std::shared_ptr<Grid> createCakeGrid(VectorField &coordinates)
{
GridFactory gf;
Dune::FieldVector<Scalar, dim> pos;
gf.insertVertex({0, 0, 0});
gf.insertVertex({1, 0, 0});
gf.insertVertex({0, 1, 0});
gf.insertVertex({1, 1, 0});
gf.insertVertex({0, 0, 1});
gf.insertVertex({1, 0, 1});
gf.insertVertex({0, 1, 1});
gf.insertVertex({1, 1, 1});
gf.insertVertex(coordinates[0]);
gf.insertVertex(coordinates[1]);
gf.insertVertex(coordinates[2]);
gf.insertVertex(coordinates[3]);
gf.insertVertex(coordinates[4]);
gf.insertVertex(coordinates[5]);
gf.insertVertex(coordinates[6]);
gf.insertVertex(coordinates[7]);
Dune::GeometryType type;
type.makeHexahedron();
......
......@@ -7,11 +7,16 @@ add_dumux_test(test_gridcreator_gmsh test_gridcreator_gmsh test_gridcreator_gmsh
${CMAKE_SOURCE_DIR}/test/references/bifurcation-reference-refined.vtu
${CMAKE_CURRENT_BINARY_DIR}/bifurcation-00001.vtu)
add_dumux_test(test_gridcreator_cake test_gridcreator_cake test_gridcreator_cake.cc
add_dumux_test(test_gridcreator_cake_powerlaw test_gridcreator_cake test_gridcreator_cake.cc
python ${CMAKE_SOURCE_DIR}/bin/runtest.py
--script fuzzy
--command "${CMAKE_CURRENT_BINARY_DIR}/test_gridcreator_cake"
--files ${CMAKE_SOURCE_DIR}/test/references/cake-powerspace-reference.vtu
${CMAKE_CURRENT_BINARY_DIR}/cake-powerspace-00000.vtu
${CMAKE_SOURCE_DIR}/test/references/pieceofcake-linspace-reference.vtu
${CMAKE_CURRENT_BINARY_DIR}/pieceofcake-linspace-00000.vtu)
--files ${CMAKE_SOURCE_DIR}/test/references/cake-powerlaw-reference.vtu
${CMAKE_CURRENT_BINARY_DIR}/cake-00000.vtu)
add_dumux_test(test_gridcreator_pieceofcake_lin test_gridcreator_cake test_gridcreator_cake.cc
python ${CMAKE_SOURCE_DIR}/bin/runtest.py
--script fuzzy
--command "${CMAKE_CURRENT_BINARY_DIR}/test_gridcreator_cake -Grid.PolarCoorMax '1000.0 10.0 1010.0' -Grid.UsePowerLawSpacerRadius false"
--files ${CMAKE_SOURCE_DIR}/test/references/pieceofcake-linspace-reference.vtu
${CMAKE_CURRENT_BINARY_DIR}/pieceofcake-linspace-00000.vtu)
\ No newline at end of file
......@@ -26,6 +26,7 @@
#include <dune/grid/io/file/vtk.hh>
#include <dune/grid/common/mcmgmapper.hh>
#include <dune/common/parallel/mpihelper.hh>
#include <dumux/common/start.hh>
#include <dumux/io/cakegridcreator.hh>
#include <dumux/common/basicproperties.hh>
......@@ -56,28 +57,23 @@ int main(int argc, char** argv)
// Some typedefs
typedef typename TTAG(GridCreatorCakeTest) TypeTag;
typedef typename GET_PROP_TYPE(TypeTag, Grid) Grid;
typedef typename Dumux::LinearSpacer<TypeTag> LinearSpacer;
typedef typename Dumux::CakeGridCreator<TypeTag> GridCreatorLinear;
typedef typename Dumux::PowerLawSpacer<TypeTag> PowerLawSpacer;
typedef typename Dumux::CakeGridCreator<TypeTag, PowerLawSpacer> GridCreatorPowerLaw;
// typedef typename Dumux::GridCreator<TypeTag> GridCreator;
typedef typename Dumux::CakeGridCreator<TypeTag> GridCreator;
// Read the parameters from the input file
typedef typename GET_PROP(TypeTag, ParameterTree) ParameterTree;
//First read parameters from input file
Dune::ParameterTreeParser::readINITree("test_gridcreator_cake.input", ParameterTree::tree());
// Dumux::Parameters::print<TypeTag>();
//Overwrite parameters from input file with command line specified parameters
std::string s = Dumux::readOptions_(argc, argv, ParameterTree::tree());
// Dumux::Parameters::print<TypeTag>();
// Make the grid
GridCreatorLinear::makeGrid();
GridCreatorPowerLaw::makeGrid();
GridCreator::makeGrid();
// construct a vtk output writer and attach the boundaryMakers
Dune::VTKSequenceWriter<Grid::LeafGridView> vtkWriterLinear(GridCreatorLinear::grid().leafGridView(), "pieceofcake-linspace", ".", "");
// vtkWriter.addVertexData(boundaryMarker, "boundaryMarker");
vtkWriterLinear.write(0);
Dune::VTKSequenceWriter<Grid::LeafGridView> vtkWriterPowerLaw(GridCreatorPowerLaw::grid().leafGridView(), "cake-powerspace", ".", "");
// vtkWriter.addVertexData(boundaryMarker, "boundaryMarker");
vtkWriterPowerLaw.write(0);
Dune::VTKSequenceWriter<Grid::LeafGridView> vtkWriter(GridCreator::grid().leafGridView(), "cake", ".", "");
vtkWriter.write(0);
return 0;
}
......
......@@ -2,6 +2,7 @@
PolarCoorMin = 0.1 0.0 1000.0
PolarCoorMax = 1000.0 360.0 1010.0
Cells = 10 4 10
UsePowerLawSpacerRadius = true
[PowerLawSpacer]
Power = 1
\ No newline at end of file
Power = 2
\ No newline at end of file
Supports Markdown
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