Commit c4446c8c authored by Praetorius, Simon's avatar Praetorius, Simon
Browse files

Mesh reader extended to UGGrid, Filesystem-Library added, String utilities added

parent 2ab573aa
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
#include <memory> #include <memory>
#include <string> #include <string>
#include <dune/amdis/common/Utility.hpp>
#include <dune/amdis/Log.hpp> #include <dune/amdis/Log.hpp>
namespace AMDiS namespace AMDiS
...@@ -30,7 +31,7 @@ namespace AMDiS ...@@ -30,7 +31,7 @@ namespace AMDiS
* Must be implemented by sub classes of CreatorInterface. * Must be implemented by sub classes of CreatorInterface.
* Creates a new instance of the sub class of BaseClass. * Creates a new instance of the sub class of BaseClass.
*/ */
virtual std::shared_ptr<BaseClass> create() = 0; virtual shared_ptr<BaseClass> create() = 0;
}; };
/** /**
...@@ -44,9 +45,9 @@ namespace AMDiS ...@@ -44,9 +45,9 @@ namespace AMDiS
{ {
public: public:
virtual std::shared_ptr<BaseClass> create() override virtual shared_ptr<BaseClass> create() override
{ {
AMDIS_ERROR_EXIT("This create method should not be called. Call create(string) instead!"); AMDIS_ERROR_EXIT("Should not be called. Call create(string) instead!");
return {}; return {};
}; };
...@@ -55,7 +56,7 @@ namespace AMDiS ...@@ -55,7 +56,7 @@ namespace AMDiS
* Creates a new instance of the sub class of BaseClass by passing a * Creates a new instance of the sub class of BaseClass by passing a
* string to the constructor. * string to the constructor.
*/ */
virtual std::shared_ptr<BaseClass> create(std::string) = 0; virtual shared_ptr<BaseClass> create(std::string) = 0;
}; };
......
...@@ -45,8 +45,8 @@ namespace AMDiS ...@@ -45,8 +45,8 @@ namespace AMDiS
dir = "output"; dir = "output";
Parameters::get(base + "->output directory", dir); Parameters::get(base + "->output directory", dir);
vtkWriter = std::make_shared<Dune::VTKWriter<MeshView>>(meshView); vtkWriter = make_shared<Dune::VTKWriter<MeshView>>(meshView);
vtkSeqWriter = std::make_shared<Dune::VTKSequenceWriter<MeshView>>(vtkWriter, filename, dir, ""); vtkSeqWriter = make_shared<Dune::VTKSequenceWriter<MeshView>>(vtkWriter, filename, dir, "");
} }
...@@ -125,8 +125,8 @@ namespace AMDiS ...@@ -125,8 +125,8 @@ namespace AMDiS
private: private:
MeshView const& meshView; MeshView const& meshView;
std::shared_ptr<Dune::VTKWriter<MeshView>> vtkWriter; shared_ptr<Dune::VTKWriter<MeshView>> vtkWriter;
std::shared_ptr<Dune::VTKSequenceWriter<MeshView>> vtkSeqWriter; shared_ptr<Dune::VTKSequenceWriter<MeshView>> vtkSeqWriter;
std::vector<std::string> names; std::vector<std::string> names;
std::array<std::vector<double>, nComponents> data_vectors; std::array<std::vector<double>, nComponents> data_vectors;
......
...@@ -13,55 +13,68 @@ ...@@ -13,55 +13,68 @@
#include <dune/grid/uggrid.hh> #include <dune/grid/uggrid.hh>
#include <dune/grid/yaspgrid.hh> #include <dune/grid/yaspgrid.hh>
#include "Initfile.hpp" #include <dune/grid/albertagrid/albertareader.hh>
#include "Log.hpp" #include <dune/grid/io/file/gmshreader.hh>
#include <dune/amdis/Initfile.hpp>
#include <dune/amdis/Log.hpp>
#include <dune/amdis/common/Filesystem.hpp>
namespace AMDiS namespace AMDiS
{ {
struct _albertagrid {}; namespace tag
struct _uggrid {};
struct _yaspgrid {};
struct _unknowngrid {};
template <class Grid>
struct MeshTagImpl
{ {
using type = _unknowngrid; struct albertagrid {};
}; struct uggrid {};
struct yaspgrid {};
template <class Grid> struct unknowngrid {};
using MeshTag = typename MeshTagImpl<Grid>::type;
} // end namespace tag
// specialization for some grid types from DUNE namespace Impl
#if HAVE_ALBERTA
template <int dim, int dimworld>
struct MeshTagImpl<Dune::AlbertaGrid<dim, dimworld>>
{ {
using type = _albertagrid; template <class Grid>
}; struct MeshTag
{
using type = tag::unknowngrid;
};
// specialization for some grid types from DUNE
#if HAVE_ALBERTA
template <int dim, int dimworld>
struct MeshTag<Dune::AlbertaGrid<dim, dimworld>>
{
using type = tag::albertagrid;
};
#endif #endif
#if HAVE_UG #if HAVE_UG
template <int dim> template <int dim>
struct MeshTagImpl<Dune::UGGrid<dim>> struct MeshTag<Dune::UGGrid<dim>>
{ {
using type = _uggrid; using type = tag::uggrid;
}; };
#endif #endif
template <int dim, class Coordinates>
struct MeshTag<Dune::YaspGrid<dim, Coordinates>>
{
using type = tag::yaspgrid;
};
} // end namespace Impl
template <int dim, class Coordinates> template <class Grid>
struct MeshTagImpl<Dune::YaspGrid<dim, Coordinates>> using MeshTag_t = typename Impl::MeshTag<Grid>::type;
{
using type = _yaspgrid;
};
/// A creator class for meshes. Each mesh needs different way of initialization
template <class Grid> template <class Grid>
class MeshCreator class MeshCreator
{ {
static std::unique_ptr<Grid> create(std::string meshName) static unique_ptr<Grid> create(std::string meshName)
{ {
AMDIS_ERROR_EXIT("Not yet implemented"); AMDIS_ERROR_EXIT("Creator not yet implemented for this mesh type.");
} }
}; };
...@@ -71,7 +84,7 @@ namespace AMDiS ...@@ -71,7 +84,7 @@ namespace AMDiS
{ {
using Grid = Dune::AlbertaGrid<dim, dimworld>; using Grid = Dune::AlbertaGrid<dim, dimworld>;
static std::unique_ptr<Grid> create(std::string meshName) static unique_ptr<Grid> create(std::string meshName)
{ {
std::string macro_filename = ""; std::string macro_filename = "";
Parameters::get(meshName + "->macro file name", macro_filename); Parameters::get(meshName + "->macro file name", macro_filename);
...@@ -79,18 +92,53 @@ namespace AMDiS ...@@ -79,18 +92,53 @@ namespace AMDiS
// TODO: if filename_extension is ".2d" or ".3d" read it directly from file // TODO: if filename_extension is ".2d" or ".3d" read it directly from file
// otherwise use a factory method // otherwise use a factory method
return std::make_unique<Grid>(macro_filename); return make_unique<Grid>(macro_filename);
} }
}; };
#endif #endif
#if HAVE_UG
template <int dim>
struct MeshCreator<Dune::UGGrid<dim>>
{
using Grid = Dune::UGGrid<dim>;
static unique_ptr<Grid> create(std::string meshName)
{
std::string filename = "";
Parameters::get(meshName + "->macro file name", filename);
if (!filename.empty()) {
Path fn(filename);
auto ext = fn.extension();
#if HAVE_ALBERTA
if (ext == "1d" || ext == "2d" || ext == "3d") {
Dune::GridFactory<Grid> factory;
Dune::AlbertaReader<Grid> reader;
reader.readGrid(filename, factory);
return unique_ptr<Grid>{factory.createGrid()};
}
#endif
if (ext == "msh") {
Dune::GmshReader<Grid> reader;
return unique_ptr<Grid>{reader.read(filename)};
}
} else {
AMDIS_ERROR_EXIT("Construction of UGGrid without filename not yet implemented!");
}
}
};
#endif
template <int dim, class T> template <int dim, class T>
struct MeshCreator<Dune::YaspGrid<dim, Dune::EquidistantCoordinates<T,dim>>> struct MeshCreator<Dune::YaspGrid<dim, Dune::EquidistantCoordinates<T,dim>>>
{ {
using Grid = Dune::YaspGrid<dim, Dune::EquidistantCoordinates<T,dim>>; using Grid = Dune::YaspGrid<dim, Dune::EquidistantCoordinates<T,dim>>;
static std::unique_ptr<Grid> create(std::string meshName) static unique_ptr<Grid> create(std::string meshName)
{ {
Dune::FieldVector<double, dim> L; L = 1.0; // extension of the domain Dune::FieldVector<double, dim> L; L = 1.0; // extension of the domain
Parameters::get(meshName + "->dimension", L); Parameters::get(meshName + "->dimension", L);
...@@ -102,7 +150,7 @@ namespace AMDiS ...@@ -102,7 +150,7 @@ namespace AMDiS
// TODO: add more parameters for yasp-grid (see constructor) // TODO: add more parameters for yasp-grid (see constructor)
return std::make_unique<Grid>(L, s); return make_unique<Grid>(L, s);
} }
}; };
...@@ -112,7 +160,7 @@ namespace AMDiS ...@@ -112,7 +160,7 @@ namespace AMDiS
{ {
using Grid = Dune::YaspGrid<dim, Dune::EquidistantOffsetCoordinates<T, dim>>; using Grid = Dune::YaspGrid<dim, Dune::EquidistantOffsetCoordinates<T, dim>>;
static std::unique_ptr<Grid> create(std::string meshName) static unique_ptr<Grid> create(std::string meshName)
{ {
Dune::FieldVector<double, dim> lowerleft; // Lower left corner of the domain Dune::FieldVector<double, dim> lowerleft; // Lower left corner of the domain
Dune::FieldVector<double, dim> upperright; // Upper right corner of the domain Dune::FieldVector<double, dim> upperright; // Upper right corner of the domain
...@@ -124,7 +172,7 @@ namespace AMDiS ...@@ -124,7 +172,7 @@ namespace AMDiS
// TODO: add more parameters for yasp-grid (see constructor) // TODO: add more parameters for yasp-grid (see constructor)
return std::make_unique<Grid>(lowerleft, upperright, s); return make_unique<Grid>(lowerleft, upperright, s);
} }
}; };
......
...@@ -30,9 +30,9 @@ namespace AMDiS ...@@ -30,9 +30,9 @@ namespace AMDiS
} }
template <class... Args> template <class... Args>
static std::shared_ptr<Self> zot(Args&&... args) static shared_ptr<Self> zot(Args&&... args)
{ {
auto op = std::make_shared<Self>(); auto op = make_shared<Self>();
op->addZOT(std::forward<Args>(args)...); op->addZOT(std::forward<Args>(args)...);
return op; return op;
} }
...@@ -59,9 +59,9 @@ namespace AMDiS ...@@ -59,9 +59,9 @@ namespace AMDiS
} }
template <class... Args> template <class... Args>
static std::shared_ptr<Self> fot(Args&&... args) static shared_ptr<Self> fot(Args&&... args)
{ {
auto op = std::make_shared<Self>(); auto op = make_shared<Self>();
op->addFOT(std::forward<Args>(args)...); op->addFOT(std::forward<Args>(args)...);
return op; return op;
} }
...@@ -86,9 +86,9 @@ namespace AMDiS ...@@ -86,9 +86,9 @@ namespace AMDiS
} }
template <class... Args> template <class... Args>
static std::shared_ptr<Self> sot(Args&&... args) static shared_ptr<Self> sot(Args&&... args)
{ {
auto op = std::make_shared<Self>(); auto op = make_shared<Self>();
op->addSOT(std::forward<Args>(args)...); op->addSOT(std::forward<Args>(args)...);
return op; return op;
} }
...@@ -97,7 +97,7 @@ namespace AMDiS ...@@ -97,7 +97,7 @@ namespace AMDiS
/// Calls \ref zot(), \ref for() or \ref sot(), depending on template /// Calls \ref zot(), \ref for() or \ref sot(), depending on template
/// parameter \p Order. /// parameter \p Order.
template <size_t Order, class... Args> template <size_t Order, class... Args>
static std::shared_ptr<Self> create(Args&&... args) static shared_ptr<Self> create(Args&&... args)
{ {
return create(index_<Order>{}, std::forward<Args>(args)...); return create(index_<Order>{}, std::forward<Args>(args)...);
} }
...@@ -180,19 +180,19 @@ namespace AMDiS ...@@ -180,19 +180,19 @@ namespace AMDiS
Self& addSOTImpl(Term const& term, const index_<I>, const index_<J>); Self& addSOTImpl(Term const& term, const index_<I>, const index_<J>);
template <class... Args> template <class... Args>
static std::shared_ptr<Self> create(index_<0>, Args&&... args) static shared_ptr<Self> create(index_<0>, Args&&... args)
{ {
return zot(std::forward<Args>(args)...); return zot(std::forward<Args>(args)...);
} }
template <class... Args> template <class... Args>
static std::shared_ptr<Self> create(index_<1>, Args&&... args) static shared_ptr<Self> create(index_<1>, Args&&... args)
{ {
return fot(std::forward<Args>(args)...); return fot(std::forward<Args>(args)...);
} }
template <class... Args> template <class... Args>
static std::shared_ptr<Self> create(index_<2>, Args&&... args) static shared_ptr<Self> create(index_<2>, Args&&... args)
{ {
return sot(std::forward<Args>(args)...); return sot(std::forward<Args>(args)...);
} }
......
...@@ -76,7 +76,7 @@ namespace AMDiS ...@@ -76,7 +76,7 @@ namespace AMDiS
ProblemType& problemStat; ProblemType& problemStat;
/// Solution of the last timestep. /// Solution of the last timestep.
std::shared_ptr<SystemVectorType> oldSolution; shared_ptr<SystemVectorType> oldSolution;
}; };
......
...@@ -43,7 +43,7 @@ namespace AMDiS ...@@ -43,7 +43,7 @@ namespace AMDiS
// create oldSolution // create oldSolution
std::vector<std::string> componentNames(size, name + "_uOld"); std::vector<std::string> componentNames(size, name + "_uOld");
oldSolution = std::make_shared<SystemVectorType>(*problemStat.getFeSpaces(), componentNames); oldSolution = make_shared<SystemVectorType>(*problemStat.getFeSpaces(), componentNames);
} }
} }
......
...@@ -102,12 +102,12 @@ namespace AMDiS ...@@ -102,12 +102,12 @@ namespace AMDiS
double* factor = NULL, double* factor = NULL,
double* estFactor = NULL); double* estFactor = NULL);
void addMatrixOperator(std::shared_ptr<OperatorType> op, void addMatrixOperator(shared_ptr<OperatorType> op,
int i, int j, int i, int j,
double* factor = NULL, double* factor = NULL,
double* estFactor = NULL); double* estFactor = NULL);
void addMatrixOperator(std::map< std::pair<int,int>, std::shared_ptr<OperatorType> > ops); void addMatrixOperator(std::map< std::pair<int,int>, shared_ptr<OperatorType> > ops);
/// Adds an operator to \ref rhs. /// Adds an operator to \ref rhs.
void addVectorOperator(OperatorType& op, void addVectorOperator(OperatorType& op,
...@@ -115,12 +115,12 @@ namespace AMDiS ...@@ -115,12 +115,12 @@ namespace AMDiS
double* factor = NULL, double* factor = NULL,
double* estFactor = NULL); double* estFactor = NULL);
void addVectorOperator(std::shared_ptr<OperatorType> op, void addVectorOperator(shared_ptr<OperatorType> op,
int i, int i,
double* factor = NULL, double* factor = NULL,
double* estFactor = NULL); double* estFactor = NULL);
void addVectorOperator(std::map< int, std::shared_ptr<OperatorType> > ops); void addVectorOperator(std::map< int, shared_ptr<OperatorType> > ops);
/// Adds a Dirichlet boundary condition /// Adds a Dirichlet boundary condition
...@@ -219,7 +219,7 @@ namespace AMDiS ...@@ -219,7 +219,7 @@ namespace AMDiS
"No mesh name specified for '" << name << "->mesh'!"); "No mesh name specified for '" << name << "->mesh'!");
mesh = MeshCreator<Mesh>::create(meshName); mesh = MeshCreator<Mesh>::create(meshName);
meshView = std::make_shared<MeshView>(mesh->leafGridView()); meshView = make_shared<MeshView>(mesh->leafGridView());
AMDIS_MSG("Create mesh:"); AMDIS_MSG("Create mesh:");
AMDIS_MSG("#elements = " << mesh->size(0)); AMDIS_MSG("#elements = " << mesh->size(0));
...@@ -230,16 +230,16 @@ namespace AMDiS ...@@ -230,16 +230,16 @@ namespace AMDiS
void createFeSpaces() void createFeSpaces()
{ {
feSpaces = std::make_shared<FeSpaces>(constructTuple<FeSpaces>(*meshView)); feSpaces = make_shared<FeSpaces>(constructTuple<FeSpaces>(*meshView));
} }
void createMatricesAndVectors() void createMatricesAndVectors()
{ {
systemMatrix = std::make_shared<SystemMatrixType>(*feSpaces); systemMatrix = make_shared<SystemMatrixType>(*feSpaces);
solution = std::make_shared<SystemVectorType>(*feSpaces, componentNames); solution = make_shared<SystemVectorType>(*feSpaces, componentNames);
auto rhsNames = std::vector<std::string>(nComponents, "rhs"); auto rhsNames = std::vector<std::string>(nComponents, "rhs");
rhs = std::make_shared<SystemVectorType>(*feSpaces, rhsNames); rhs = make_shared<SystemVectorType>(*feSpaces, rhsNames);
} }
void createSolver() void createSolver()
...@@ -255,7 +255,7 @@ namespace AMDiS ...@@ -255,7 +255,7 @@ namespace AMDiS
void createFileWriter() void createFileWriter()
{ {
filewriter = std::make_shared<FileWriter<Traits>>(name + "->output", filewriter = make_shared<FileWriter<Traits>>(name + "->output",
*meshView, *meshView,
componentNames); componentNames);
} }
...@@ -271,13 +271,13 @@ namespace AMDiS ...@@ -271,13 +271,13 @@ namespace AMDiS
bool getElementMatrix(RowView const& rowView, bool getElementMatrix(RowView const& rowView,
ColView const& colView, ColView const& colView,
ElementMatrix& elementMatrix, ElementMatrix& elementMatrix,
std::list<std::shared_ptr<OperatorType>>& operators, std::list<shared_ptr<OperatorType>>& operators,
std::list<double*> const& factors); std::list<double*> const& factors);
template <class RowView> template <class RowView>
bool getElementVector(RowView const& rowView, bool getElementVector(RowView const& rowView,
ElementVector& elementVector, ElementVector& elementVector,
std::list<std::shared_ptr<OperatorType>>& operators, std::list<shared_ptr<OperatorType>>& operators,
std::list<double*> const& factors); std::list<double*> const& factors);
...@@ -311,49 +311,57 @@ namespace AMDiS ...@@ -311,49 +311,57 @@ namespace AMDiS
std::vector<std::string> componentNames; std::vector<std::string> componentNames;
/// Mesh of this problem. /// Mesh of this problem.
std::shared_ptr<Mesh> mesh; // TODO: generalize to multi-mesh problems shared_ptr<Mesh> mesh; // TODO: generalize to multi-mesh problems
/// Name of the mesh /// Name of the mesh
std::string meshName; std::string meshName;
/// A gridView object /// A gridView object
std::shared_ptr<MeshView> meshView; shared_ptr<MeshView> meshView;
/// Pointer to the meshes for the different problem components /// Pointer to the meshes for the different problem components
std::vector<Mesh*> componentMeshes; std::vector<Mesh*> componentMeshes;
/// FE spaces of this problem. /// FE spaces of this problem.
std::shared_ptr<FeSpaces> feSpaces; // eventuell const shared_ptr<FeSpaces> feSpaces; // eventuell const
/// A FileWriter object /// A FileWriter object
std::shared_ptr<FileWriter<Traits>> filewriter; shared_ptr<FileWriter<Traits>> filewriter;
/// An object of the linearSolver Interface /// An object of the linearSolver Interface