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

[CakeGridCreator] Include dummy test

- Test for cake grid creator
- Cake grid creator class which a builds a hexahedron element, without algorithm
- Class for linear spacer, without algorithm
- Class for power spacer, without algorithm
- Program is comilable and running, only the algorithms remain to be implemented
parent 874146ba
// -*- mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
// vi: set et ts=4 sw=4 sts=4:
/*****************************************************************************
* See the file COPYING for full copying permissions. *
* *
* This program 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 2 of the License, or *
* (at your option) any later version. *
* *
* This program 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 <http://www.gnu.org/licenses/>. *
*****************************************************************************/
/*!
* \file
*
* \brief Provides a grid creator which a regular grid made of
* quadrilaterals.
*/
#ifndef DUMUX_CAKE_GRID_CREATOR_HH
#define DUMUX_CAKE_GRID_CREATOR_HH
//#include <dune/grid/utility/structuredgridfactory.hh>
#include <dune/grid/common/gridfactory.hh>
#include <dumux/common/basicproperties.hh>
namespace Dumux
{
namespace Properties
{
NEW_PROP_TAG(Scalar);
NEW_PROP_TAG(Grid);
}
template <class TypeTag>
class LinearSpacer
{
public:
typedef typename GET_PROP_TYPE(TypeTag, Scalar) Scalar;
LinearSpacer(Scalar noOfPoints, Scalar length, Scalar offSet)
: noOfPoints_(noOfPoints), length_(length), offSet_(offSet)
{
}
void createSpacing() const
{
DUNE_THROW(Dune::NotImplemented, "Linear spacer not implemented yet.");
}
private:
Scalar noOfPoints_;
Scalar length_;
Scalar offSet_;
};
template <class TypeTag>
class PowerLawSpacer
{
typedef typename GET_PROP_TYPE(TypeTag, Scalar) Scalar;
public:
PowerLawSpacer(Scalar noOfPoints, Scalar length, Scalar offSet)
: noOfPoints_(noOfPoints), length_(length), offSet_(offSet)
{
power_ = GET_RUNTIME_PARAM_FROM_GROUP(TypeTag, Scalar, PowerLawSpacer, Power);
}
void createSpacing() const
{
DUNE_THROW(Dune::NotImplemented, "Power law spacer not implemented yet.");
}
private:
Scalar power_;
Scalar noOfPoints_;
Scalar length_;
Scalar offSet_;
};
/*!
* \brief Provides a grid creator which a regular grid made of
* quadrilaterals.
*
* 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>>
class CakeGridCreator
{
typedef typename GET_PROP_TYPE(TypeTag, Scalar) Scalar;
typedef typename GET_PROP_TYPE(TypeTag, Grid) Grid;
typedef Dune::GridFactory<Grid> GridFactory;
typedef std::shared_ptr<Grid> GridPointer;
typedef Dumux::LinearSpacer<TypeTag> SpacerDefault;
enum { dim = Grid::dimension };
public:
/*!
* \brief Create the Grid
*/
static void makeGrid()
{
if (dim == 2)
{
DUNE_THROW(Dune::NotImplemented, "The CakeGridCreator is not implemented for 1D and 2D.");
}
// //Get the necessary parameters from the parameter file
// Scalar outerRadius = GET_RUNTIME_PARAM_FROM_GROUP(TypeTag, Scalar, Grid, OuterRadius);
// Scalar wellRadius = GET_RUNTIME_PARAM_FROM_GROUP(TypeTag, Scalar, Grid, WellRadius);
// int noOfCellsR = GET_RUNTIME_PARAM_FROM_GROUP(TypeTag, int, Grid, NoOfCellsR);
// Scalar angle = GET_RUNTIME_PARAM_FROM_GROUP(TypeTag, Scalar, Grid, Angle);
// int noOfSlice = GET_RUNTIME_PARAM_FROM_GROUP(TypeTag, int, Grid, NoOfSlice);
// Scalar height = GET_RUNTIME_PARAM_FROM_GROUP(TypeTag, Scalar, Grid, Height);
// Scalar bOR = GET_RUNTIME_PARAM_FROM_GROUP(TypeTag, Scalar, Grid, BOR);
// int noOfCellsHeight = GET_RUNTIME_PARAM_FROM_GROUP(TypeTag, int, Grid, NoOfCellsHeight);
// SpacerRadius spacerR(noOfCellsR, outerRadius, wellRadius);
// SpacerDefault spacerAngle(noOfSlice, angle, 0.0);
// SpacerDefault spacerZ(noOfCellsHeight, height, bOR);
// Dune::shared_ptr<Grid> gridp(gf.createGrid());
gridPtr() = CakeGridCreator<TypeTag, SpacerRadius>::createCakeGrid();
// gridPtr() = Dune::StructuredGridFactory<Grid>::createCubeGrid(lowerLeft, upperRight, cellRes);
}
static std::shared_ptr<Grid> createCakeGrid()
{
GridFactory gf;
Dune::FieldVector<Scalar, dim> pos;
pos[0] = 0; pos[1] = 0; pos[2] = 0; gf.insertVertex(pos);
pos[0] = 1; pos[1] = 0; pos[2] = 0; gf.insertVertex(pos);
pos[0] = 0; pos[1] = 1; pos[2] = 0; gf.insertVertex(pos);
pos[0] = 1; pos[1] = 1; pos[2] = 0; gf.insertVertex(pos);
pos[0] = 0; pos[1] = 0; pos[2] = 1; gf.insertVertex(pos);
pos[0] = 1; pos[1] = 0; pos[2] = 1; gf.insertVertex(pos);
pos[0] = 0; pos[1] = 1; pos[2] = 1; gf.insertVertex(pos);
pos[0] = 1; pos[1] = 1; pos[2] = 1; gf.insertVertex(pos);
Dune::GeometryType type;
type.makeHexahedron();
std::vector<unsigned int> vid(8);
vid[0] = 0; vid[1] = 1; vid[2] = 2; vid[3] = 3;
vid[4] = 4; vid[5] = 5; vid[6] = 6; vid[7] = 7;
gf.insertElement(type, vid);
return std::shared_ptr<Grid>(gf.createGrid());
}
/*!
* \brief Returns a reference to the grid.
*/
static Grid &grid()
{
return *gridPtr();
}
/*!
* \brief Distributes the grid on all processes of a parallel
* computation.
*/
static void loadBalance()
{
gridPtr()->loadBalance();
}
/*!
* \brief Returns a reference to the shared pointer to the grid.
*/
static GridPointer &gridPtr()
{
static GridPointer cakeGrid;
return cakeGrid;
}
};
}
#endif
......@@ -6,3 +6,12 @@ add_dumux_test(test_gridcreator_gmsh test_gridcreator_gmsh test_gridcreator_gmsh
${CMAKE_CURRENT_BINARY_DIR}/bifurcation-00000.vtu
${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
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)
/*****************************************************************************
* See the file COPYING for full copying permissions. *
* *
* This program 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 2 of the License, or *
* (at your option) any later version. *
* *
* This program 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 <http://www.gnu.org/licenses/>. *
*****************************************************************************/
/*!
* \file
*
* \brief Test for gmsh interface of the grid creator
*/
#include "config.h"
#include <iostream>
#include <dune/common/parametertreeparser.hh>
#include <dune/geometry/referenceelements.hh>
#include <dune/grid/io/file/vtk.hh>
#include <dune/grid/common/mcmgmapper.hh>
#include <dune/common/parallel/mpihelper.hh>
#include <dumux/io/cakegridcreator.hh>
#include <dumux/common/basicproperties.hh>
namespace Dumux
{
namespace Properties
{
NEW_TYPE_TAG(GridCreatorCakeTest, INHERITS_FROM(NumericModel));
// Set the grid type
#if HAVE_DUNE_ALUGRID
SET_TYPE_PROP(GridCreatorCakeTest, Grid, Dune::ALUGrid<3, 3, Dune::cube, Dune::conforming>);
#elif HAVE_UG
SET_TYPE_PROP(GridCreatorCakeTest, Grid, Dune::UGGrid<3>);
#else
SET_TYPE_PROP(GridCreatorCakeTest, Grid, Dune::YaspGrid<3>);
#endif
}
}
int main(int argc, char** argv)
{
#if HAVE_DUNE_ALUGRID
try {
// initialize MPI, finalize is done automatically on exit
Dune::MPIHelper::instance(argc, 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;
// Read the parameters from the input file
typedef typename GET_PROP(TypeTag, ParameterTree) ParameterTree;
Dune::ParameterTreeParser::readINITree("test_gridcreator_cake.input", ParameterTree::tree());
// Make the grid
GridCreatorLinear::makeGrid();
GridCreatorPowerLaw::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);
return 0;
}
catch (Dumux::ParameterException &e) {
typedef typename TTAG(GridCreatorCakeTest) TypeTag;
Dumux::Parameters::print<TypeTag>();
std::cerr << e << ". Abort!\n";
return 1;
}
catch (Dune::Exception &e) {
std::cerr << "Dune reported error: " << e << std::endl;
return 3;
}
catch (...) {
std::cerr << "Unknown exception thrown!\n";
return 4;
}
#else
#warning "You need to have ALUGrid or UGGrid installed to run this test."
std::cerr << "You need to have ALUGrid or UGGrid installed to run this test\n";
return 77;
#endif
} //closing main
//} //closing namespace dumux
[Grid]
OuterRadius = 1000
WellRadius = 0.1
NoOfCellsR = 10
Angle = 360
NoOfSlice = 4
Height = 10
BOR = 1000;
NoOfCellsHeight = 10
[PowerLawSpacer]
Power = 1
<?xml version="1.0"?>
<VTKFile type="UnstructuredGrid" version="0.1" byte_order="LittleEndian">
<UnstructuredGrid>
<Piece NumberOfCells="1" NumberOfPoints="8">
<Points>
<DataArray type="Float32" Name="Coordinates" NumberOfComponents="3" format="ascii">
0 0 0 1 0 0 0 1 0 1 1 0
0 0 1 1 0 1 0 1 1 1 1 1
</DataArray>
</Points>
<Cells>
<DataArray type="Int32" Name="connectivity" NumberOfComponents="1" format="ascii">
0 1 3 2 4 5 7 6
</DataArray>
<DataArray type="Int32" Name="offsets" NumberOfComponents="1" format="ascii">
8
</DataArray>
<DataArray type="UInt8" Name="types" NumberOfComponents="1" format="ascii">
12
</DataArray>
</Cells>
</Piece>
</UnstructuredGrid>
</VTKFile>
<?xml version="1.0"?>
<VTKFile type="UnstructuredGrid" version="0.1" byte_order="LittleEndian">
<UnstructuredGrid>
<Piece NumberOfCells="1" NumberOfPoints="8">
<Points>
<DataArray type="Float32" Name="Coordinates" NumberOfComponents="3" format="ascii">
0 0 0 1 0 0 0 1 0 1 1 0
0 0 1 1 0 1 0 1 1 1 1 1
</DataArray>
</Points>
<Cells>
<DataArray type="Int32" Name="connectivity" NumberOfComponents="1" format="ascii">
0 1 3 2 4 5 7 6
</DataArray>
<DataArray type="Int32" Name="offsets" NumberOfComponents="1" format="ascii">
8
</DataArray>
<DataArray type="UInt8" Name="types" NumberOfComponents="1" format="ascii">
12
</DataArray>
</Cells>
</Piece>
</UnstructuredGrid>
</VTKFile>
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