Skip to content
Snippets Groups Projects
Commit d1234317 authored by Praetorius, Simon's avatar Praetorius, Simon
Browse files

added legacy vtkfunctions

parent a23ecf47
No related branches found
No related tags found
No related merge requests found
#pragma once
#include "vtklocalfunctioninterface.hh"
namespace Dune { namespace experimental
{
/// Type erasure for dune-functions LocalFunction interface
template <class GridView, class LocalFunction>
class LocalFunctionWrapper final
: public VtkLocalFunctionInterface<GridView>
{
using Self = LocalFunctionWrapper;
using Interface = VtkLocalFunctionInterface<GridView>;
using Entity = typename Interface::Entity;
using LocalCoordinate = typename Interface::LocalCoordinate;
template <class F, class D>
using Range = std::decay_t<decltype(std::declval<F>()(std::declval<D>()))>;
template <class F, class D>
using VectorValued = decltype(std::declval<Range<F,D>>()[0u]);
public:
template <class LocalFct, disableCopyMove<Self, LocalFct> = 0>
LocalFunctionWrapper (LocalFct&& localFct)
: localFct_(std::forward<LocalFct>(localFct))
{}
virtual void bind (Entity const& entity) override
{
localFct_.bind(entity);
}
virtual void unbind () override
{
localFct_.unbind();
}
virtual double evaluate (int comp, LocalCoordinate const& xi) const override
{
return evaluateImpl(comp, xi, Std::is_detected<VectorValued,LocalFunction,LocalCoordinate>{});
}
private:
// Evaluate a component of a vector valued data
double evaluateImpl (int comp, LocalCoordinate const& xi, std::true_type) const
{
auto y = localFct_(xi);
return comp < y.size() ? y[comp] : 0.0;
}
// Return the scalar values
double evaluateImpl (int comp, LocalCoordinate const& xi, std::false_type) const
{
assert(comp == 0);
return localFct_(xi);
}
private:
LocalFunction localFct_;
};
}} // end namespace Dune::experimental
#pragma once
#include <memory>
#include <dune/grid/io/file/vtk/function.hh>
#include "vtklocalfunctioninterface.hh"
namespace Dune { namespace experimental
{
/// Type erasure for Legacy VTKFunction
template <class GridView>
class VTKLocalFunctionWrapper final
: public VtkLocalFunctionInterface<GridView>
{
using Interface = VtkLocalFunctionInterface<GridView>;
using Entity = typename Interface::Entity;
using LocalCoordinate = typename Interface::LocalCoordinate;
public:
VTKLocalFunctionWrapper (std::shared_ptr<VTKFunction<GridView> const> const& fct)
: fct_(fct)
{}
virtual void bind (Entity const& entity) override
{
entity_ = &entity;
}
virtual void unbind () override
{
entity_ = nullptr;
}
virtual double evaluate (int comp, LocalCoordinate const& xi) const override
{
return fct_->evaluate(comp, *entity_, xi);
}
private:
std::shared_ptr<VTKFunction<GridView> const> fct_;
Entity const* entity_;
};
}} // end namespace Dune::experimental
...@@ -4,227 +4,11 @@ ...@@ -4,227 +4,11 @@
#include <dune/common/std/type_traits.hh> #include <dune/common/std/type_traits.hh>
#include <dune/functions/common/signature.hh> #include <dune/functions/common/signature.hh>
#include <dune/grid/io/file/vtk/function.hh>
#include "vtklocalfunction.hh"
namespace Dune { namespace experimental namespace Dune { namespace experimental
{ {
/// An abstract base class for LocalFunctions
template <class GridView>
class VtkLocalFunctionInterface
{
public:
using Entity = typename GridView::template Codim<0>::Entity;
using LocalCoordinate = typename Entity::Geometry::LocalCoordinate;
/// Bind the function to the grid entity
virtual void bind (Entity const& entity) = 0;
/// Unbind from the currently bound entity
virtual void unbind () = 0;
/// Evaluate single component comp in the entity at local coordinates xi
virtual double evaluate (int comp, LocalCoordinate const& xi) const = 0;
/// Virtual destructor
virtual ~VtkLocalFunctionInterface () = default;
};
/// Type erasure for dune-functions LocalFunction interface
template <class GridView, class LocalFunction>
class LocalFunctionWrapper
: public VtkLocalFunctionInterface<GridView>
{
using Self = LocalFunctionWrapper;
using Interface = VtkLocalFunctionInterface<GridView>;
using Entity = typename Interface::Entity;
using LocalCoordinate = typename Interface::LocalCoordinate;
template <class F, class D>
using Range = std::decay_t<decltype(std::declval<F>()(std::declval<D>()))>;
template <class F, class D>
using VectorValued = decltype(std::declval<Range<F,D>>()[0u]);
public:
template <class LocalFct, disableCopyMove<Self, LocalFct> = 0>
LocalFunctionWrapper (LocalFct&& localFct)
: localFct_(std::forward<LocalFct>(localFct))
{}
virtual void bind (Entity const& entity) override
{
localFct_.bind(entity);
}
virtual void unbind () override
{
localFct_.unbind();
}
virtual double evaluate (int comp, LocalCoordinate const& xi) const override
{
return evaluateImpl(comp, xi, Std::is_detected<VectorValued,LocalFunction,LocalCoordinate>{});
}
private:
// Evaluate a component of a vector valued data
double evaluateImpl (int comp, LocalCoordinate const& xi, std::true_type) const
{
auto y = localFct_(xi);
return comp < y.size() ? y[comp] : 0.0;
}
// Return the scalar values
double evaluateImpl (int comp, LocalCoordinate const& xi, std::false_type) const
{
assert(comp == 0);
return localFct_(xi);
}
private:
LocalFunction localFct_;
};
/// Type erasure for Legacy VTKFunction
template <class GridView>
class VTKLocalFunctionWrapper
: public VtkLocalFunctionInterface<GridView>
{
using Interface = VtkLocalFunctionInterface<GridView>;
using Entity = typename Interface::Entity;
using LocalCoordinate = typename Interface::LocalCoordinate;
public:
VTKLocalFunctionWrapper (std::shared_ptr<VTKFunction<GridView> const> const& fct)
: fct_(fct)
{}
virtual void bind (Entity const& entity) override
{
entity_ = &entity;
}
virtual void unbind () override
{
entity_ = nullptr;
}
virtual double evaluate (int comp, LocalCoordinate const& xi) const override
{
return fct_->evaluate(comp, *entity_, xi);
}
private:
std::shared_ptr<VTKFunction<GridView> const> fct_;
Entity const* entity_;
};
template <class GridView>
class VtkLocalFunction
{
using Self = VtkLocalFunction;
using Entity = typename GridView::template Codim<0>::Entity;
using LocalCoordinate = typename Entity::Geometry::LocalCoordinate;
template <class LF, class E>
using HasBind = decltype(std::declval<LF>().bind(std::declval<E>()));
public:
// Store wrapper around dune-function LocalFunction
template <class LocalFct, disableCopyMove<Self, LocalFct> = 0,
std::enable_if_t<Std::is_detected<HasBind, LocalFct, Entity>::value,int> = 0>
VtkLocalFunction (LocalFct&& lf)
: localFct_(std::make_unique<LocalFunctionWrapper<GridView, std::decay_t<LocalFct>>>(std::forward<LocalFct>(lf)))
{}
// store wrapper around legacy VTKFunction
VtkLocalFunction (std::shared_ptr<VTKFunction<GridView> const> const& lf)
: localFct_(std::make_unique<VTKLocalFunctionWrapper<GridView>>(lf))
{}
VtkLocalFunction () = default;
/// Bind the function to the grid entity
void bind (Entity const& entity)
{
localFct_->bind(entity);
}
/// Unbind from the currently bound entity
void unbind ()
{
localFct_->unbind();
}
/// Evaluate the `comp` component of the Range value at local coordinate `xi`
double evaluate (int comp, LocalCoordinate const& xi) const
{
return localFct_->evaluate(comp, xi);
}
private:
std::shared_ptr<VtkLocalFunctionInterface<GridView>> localFct_;
};
// ---------------------------------------------------------------------------
/// An abstract base class for GlobalFunctions
template <class GridView>
class VtkFunctionInterface
{
public:
/// Create a local function
virtual VtkLocalFunction<GridView> makeLocalFunction () const = 0;
/// Virtual destructor
virtual ~VtkFunctionInterface () = default;
};
template <class GridView, class GridViewFunction>
class GridViewFunctionWrapper
: public VtkFunctionInterface<GridView>
{
using Self = GridViewFunctionWrapper;
public:
template <class GVFct, disableCopyMove<Self, GVFct> = 0>
GridViewFunctionWrapper (GVFct&& gvFct)
: gvFct_(std::forward<GVFct>(gvFct))
{}
virtual VtkLocalFunction<GridView> makeLocalFunction () const override
{
return VtkLocalFunction<GridView>{localFunction(gvFct_)};
}
private:
GridViewFunction gvFct_;
};
template <class GridView>
class VTKFunctionWrapper
: public VtkFunctionInterface<GridView>
{
public:
VTKFunctionWrapper (std::shared_ptr<VTKFunction<GridView> const> const& fct)
: fct_(fct)
{}
virtual VtkLocalFunction<GridView> makeLocalFunction () const override
{
return VtkLocalFunction<GridView>{fct_};
}
private:
std::shared_ptr<VTKFunction<GridView> const> fct_;
};
template <class GridView> template <class GridView>
class VtkFunction class VtkFunction
{ {
...@@ -232,37 +16,39 @@ namespace Dune { namespace experimental ...@@ -232,37 +16,39 @@ namespace Dune { namespace experimental
using HasLocalFunction = decltype(localFunction(std::declval<F>())); using HasLocalFunction = decltype(localFunction(std::declval<F>()));
template <class F> template <class F>
using Signature = typename std::decay_t<F>::Signature; using Domain = typename std::decay_t<F>::EntitySet::GlobalCoordinate;
template <class F>
using Range = std::decay_t<decltype(std::declval<F>()(std::declval<Domain<F>>()))>;
public: public:
template <class F, /// Constructor VtkFunction from legacy VTKFunction
std::enable_if_t<Std::is_detected<HasLocalFunction,F>::value, int> = 0, VtkFunction (std::shared_ptr<VTKFunction<GridView> const> const& fct)
class Range = typename Functions::SignatureTraits<Signature<F>>::Range> : localFct_(fct)
VtkFunction (F&& f, std::string name, int ncomps = 1, , name_(fct->name())
Vtk::DataTypes type = Vtk::Map::type<Range>) , ncomps_(fct->ncomps())
: fct_(std::make_unique<GridViewFunctionWrapper<GridView,std::decay_t<F>>>(std::forward<F>(f))) , type_(Vtk::FLOAT64)
, name_(std::move(name))
, ncomps_(ncomps > 3 ? 9 : ncomps > 1 ? 3 : 1) // tensor, vector, or scalar
, type_(type)
{} {}
/// Construct VtkFunction from dune-functions GridFunction with Signature
template <class F, template <class F,
std::enable_if_t<Std::is_detected<HasLocalFunction,F>::value, int> = 0, std::enable_if_t<Std::is_detected<HasLocalFunction,F>::value, int> = 0,
std::enable_if_t<not Std::is_detected<Signature,F>::value,int> = 0> std::enable_if_t<Std::is_detected<Range,F>::value,int> = 0>
VtkFunction (F&& f, std::string name, int ncomps = 1, VtkFunction (F&& fct, std::string name, int ncomps = 1, Vtk::DataTypes type = Vtk::Map::type<Range<F>>)
Vtk::DataTypes type = Vtk::FLOAT32) : localFct_(localFunction(std::forward<F>(fct)))
: fct_(std::make_unique<GridViewFunctionWrapper<GridView,std::decay_t<F>>>(std::forward<F>(f)))
, name_(std::move(name)) , name_(std::move(name))
, ncomps_(ncomps > 3 ? 9 : ncomps > 1 ? 3 : 1) // tensor, vector, or scalar , ncomps_(ncomps)
, type_(type) , type_(type)
{} {}
VtkFunction (std::shared_ptr<VTKFunction<GridView> const> const& fct, /// Construct VtkFunction from dune-functions GridFunction without Signature
std::string name, int ncomps = 1, template <class F,
Vtk::DataTypes type = Vtk::FLOAT32) std::enable_if_t<Std::is_detected<HasLocalFunction,F>::value, int> = 0,
: fct_(std::make_unique<VTKFunctionWrapper<GridView>>(fct)) std::enable_if_t<not Std::is_detected<Range,F>::value,int> = 0>
VtkFunction (F const& fct, std::string name, int ncomps = 1, Vtk::DataTypes type = Vtk::FLOAT32)
: localFct_(localFunction(std::forward<F>(fct)))
, name_(std::move(name)) , name_(std::move(name))
, ncomps_(ncomps > 3 ? 9 : ncomps > 1 ? 3 : 1) // tensor, vector, or scalar , ncomps_(ncomps)
, type_(type) , type_(type)
{} {}
...@@ -271,7 +57,7 @@ namespace Dune { namespace experimental ...@@ -271,7 +57,7 @@ namespace Dune { namespace experimental
/// Create a LocalFunction /// Create a LocalFunction
friend VtkLocalFunction<GridView> localFunction (VtkFunction const& self) friend VtkLocalFunction<GridView> localFunction (VtkFunction const& self)
{ {
return self.fct_->makeLocalFunction(); return self.localFct_;
} }
/// Return a name associated with the function /// Return a name associated with the function
...@@ -293,10 +79,10 @@ namespace Dune { namespace experimental ...@@ -293,10 +79,10 @@ namespace Dune { namespace experimental
} }
private: private:
std::shared_ptr<VtkFunctionInterface<GridView>> fct_; VtkLocalFunction<GridView> localFct_;
std::string name_; std::string name_;
int ncomps_ = 1; int ncomps_ = 1;
Vtk::DataTypes type_; Vtk::DataTypes type_ = Vtk::FLOAT32;
}; };
}} // end namespace Dune::experimental }} // end namespace Dune::experimental
#pragma once
#include <memory>
#include <type_traits>
#include <dune/common/std/type_traits.hh>
#include "vtklocalfunctioninterface.hh"
#include "legacyvtkfunction.hh"
#include "defaultvtkfunction.hh"
namespace Dune { namespace experimental
{
template <class GridView>
class VtkLocalFunction
{
using Self = VtkLocalFunction;
using Entity = typename GridView::template Codim<0>::Entity;
using LocalCoordinate = typename Entity::Geometry::LocalCoordinate;
template <class LF, class E>
using HasBind = decltype(std::declval<LF>().bind(std::declval<E>()));
public:
template <class LF, disableCopyMove<Self, LF> = 0,
std::enable_if_t<Std::is_detected<HasBind,LF,Entity>::value, int> = 0>
VtkLocalFunction (LF&& lf)
: localFct_(std::make_shared<LocalFunctionWrapper<GridView,LF>>(std::forward<LF>(lf)))
{}
VtkLocalFunction (std::shared_ptr<VTKFunction<GridView> const> const& lf)
: localFct_(std::make_shared<VTKLocalFunctionWrapper<GridView>>(lf))
{}
VtkLocalFunction () = default;
/// Bind the function to the grid entity
void bind (Entity const& entity)
{
localFct_->bind(entity);
}
/// Unbind from the currently bound entity
void unbind ()
{
localFct_->unbind();
}
/// Evaluate the `comp` component of the Range value at local coordinate `xi`
double evaluate (int comp, LocalCoordinate const& xi) const
{
return localFct_->evaluate(comp, xi);
}
private:
std::shared_ptr<VtkLocalFunctionInterface<GridView>> localFct_;
};
}} // end namespace Dune::experimental
#pragma once
namespace Dune { namespace experimental
{
/// An abstract base class for LocalFunctions
template <class GridView>
class VtkLocalFunctionInterface
{
public:
using Entity = typename GridView::template Codim<0>::Entity;
using LocalCoordinate = typename Entity::Geometry::LocalCoordinate;
/// Bind the function to the grid entity
virtual void bind (Entity const& entity) = 0;
/// Unbind from the currently bound entity
virtual void unbind () = 0;
/// Evaluate single component comp in the entity at local coordinates xi
virtual double evaluate (int comp, LocalCoordinate const& xi) const = 0;
/// Virtual destructor
virtual ~VtkLocalFunctionInterface () = default;
};
}} // end namespace Dune::experimental
...@@ -21,8 +21,7 @@ namespace Dune { namespace experimental ...@@ -21,8 +21,7 @@ namespace Dune { namespace experimental
protected: protected:
static constexpr int dimension = GridView::dimension; static constexpr int dimension = GridView::dimension;
using GlobalFunction = VtkFunction<GridView>; using VtkFunction = Dune::experimental::VtkFunction<GridView>;
using LocalFunction = VtkLocalFunction<GridView>;
using pos_type = typename std::ostream::pos_type; using pos_type = typename std::ostream::pos_type;
enum PositionTypes { enum PositionTypes {
...@@ -47,23 +46,19 @@ namespace Dune { namespace experimental ...@@ -47,23 +46,19 @@ namespace Dune { namespace experimental
Vtk::FormatTypes format, Vtk::FormatTypes format,
Vtk::DataTypes datatype = Vtk::FLOAT32); Vtk::DataTypes datatype = Vtk::FLOAT32);
/// Attach point data to the writer /// Attach point data to the writer, \see VtkFunction for possible arguments
template <class GridViewFunction> template <class Function, class... Args>
VtkWriterInterface& addPointData (GridViewFunction const& gridViewFct, VtkWriterInterface& addPointData (Function const& fct, Args&&... args)
std::string const& name = {},
int ncomps = 1)
{ {
pointData_.emplace_back(gridViewFct, name, ncomps); pointData_.emplace_back(fct, std::forward<Args>(args)...);
return *this; return *this;
} }
/// Attach cell data to the writer /// Attach cell data to the writer, \see VtkFunction for possible arguments
template <class GridViewFunction> template <class Function, class... Args>
VtkWriterInterface& addCellData (GridViewFunction const& gridViewFct, VtkWriterInterface& addCellData (Function const& fct, Args&&... args)
std::string const& name = {},
int ncomps = 1)
{ {
cellData_.emplace_back(gridViewFct, name, ncomps); cellData_.emplace_back(fct, std::forward<Args>(args)...);
return *this; return *this;
} }
...@@ -84,14 +79,14 @@ namespace Dune { namespace experimental ...@@ -84,14 +79,14 @@ namespace Dune { namespace experimental
// attributes "offset" in the vector `offsets`. // attributes "offset" in the vector `offsets`.
void writeData (std::ofstream& out, void writeData (std::ofstream& out,
std::vector<pos_type>& offsets, std::vector<pos_type>& offsets,
GlobalFunction const& fct, VtkFunction const& fct,
PositionTypes type) const; PositionTypes type) const;
// Collect point or cell data (depending on \ref PositionTypes) and pass // Collect point or cell data (depending on \ref PositionTypes) and pass
// the resulting vector to \ref writeAppended. // the resulting vector to \ref writeAppended.
template <class T> template <class T>
std::uint64_t writeDataAppended (std::ofstream& out, std::uint64_t writeDataAppended (std::ofstream& out,
GlobalFunction const& fct, VtkFunction const& fct,
PositionTypes type) const; PositionTypes type) const;
// Write the coordinates of the vertices to the output stream `out`. In case // Write the coordinates of the vertices to the output stream `out`. In case
...@@ -110,7 +105,7 @@ namespace Dune { namespace experimental ...@@ -110,7 +105,7 @@ namespace Dune { namespace experimental
std::uint64_t writeAppended (std::ofstream& out, std::vector<T> const& values) const; std::uint64_t writeAppended (std::ofstream& out, std::vector<T> const& values) const;
/// Return PointData/CellData attributes for the name of the first scalar/vector/tensor DataArray /// Return PointData/CellData attributes for the name of the first scalar/vector/tensor DataArray
std::string getNames (std::vector<GlobalFunction> const& data) const std::string getNames (std::vector<VtkFunction> const& data) const
{ {
auto scalar = std::find_if(data.begin(), data.end(), [](auto const& v) { return v.ncomps() == 1; }); auto scalar = std::find_if(data.begin(), data.end(), [](auto const& v) { return v.ncomps() == 1; });
auto vector = std::find_if(data.begin(), data.end(), [](auto const& v) { return v.ncomps() == 3; }); auto vector = std::find_if(data.begin(), data.end(), [](auto const& v) { return v.ncomps() == 3; });
...@@ -135,8 +130,8 @@ namespace Dune { namespace experimental ...@@ -135,8 +130,8 @@ namespace Dune { namespace experimental
Vtk::DataTypes datatype_; Vtk::DataTypes datatype_;
// attached data // attached data
std::vector<GlobalFunction> pointData_; std::vector<VtkFunction> pointData_;
std::vector<GlobalFunction> cellData_; std::vector<VtkFunction> cellData_;
std::size_t const block_size = 1024*32; std::size_t const block_size = 1024*32;
int compression_level = -1; // in [0,9], -1 ... use default value int compression_level = -1; // in [0,9], -1 ... use default value
......
...@@ -65,7 +65,7 @@ void VtkWriterInterface<GV,DC> ...@@ -65,7 +65,7 @@ void VtkWriterInterface<GV,DC>
template <class GV, class DC> template <class GV, class DC>
void VtkWriterInterface<GV,DC> void VtkWriterInterface<GV,DC>
::writeData (std::ofstream& out, std::vector<pos_type>& offsets, ::writeData (std::ofstream& out, std::vector<pos_type>& offsets,
GlobalFunction const& fct, PositionTypes type) const VtkFunction const& fct, PositionTypes type) const
{ {
out << "<DataArray Name=\"" << fct.name() << "\" type=\"" << to_string(fct.type()) << "\"" out << "<DataArray Name=\"" << fct.name() << "\" type=\"" << to_string(fct.type()) << "\""
<< " NumberOfComponents=\"" << fct.ncomps() << "\" format=\"" << (format_ == Vtk::ASCII ? "ascii\">\n" : "appended\""); << " NumberOfComponents=\"" << fct.ncomps() << "\" format=\"" << (format_ == Vtk::ASCII ? "ascii\">\n" : "appended\"");
...@@ -116,7 +116,7 @@ void VtkWriterInterface<GV,DC> ...@@ -116,7 +116,7 @@ void VtkWriterInterface<GV,DC>
template <class GV, class DC> template <class GV, class DC>
template <class T> template <class T>
std::uint64_t VtkWriterInterface<GV,DC> std::uint64_t VtkWriterInterface<GV,DC>
::writeDataAppended (std::ofstream& out, GlobalFunction const& fct, PositionTypes type) const ::writeDataAppended (std::ofstream& out, VtkFunction const& fct, PositionTypes type) const
{ {
assert(is_a(format_, Vtk::APPENDED) && "Function should by called only in appended mode!\n"); assert(is_a(format_, Vtk::APPENDED) && "Function should by called only in appended mode!\n");
......
...@@ -22,6 +22,10 @@ add_executable("structuredgridwriter" structuredgridwriter.cc) ...@@ -22,6 +22,10 @@ add_executable("structuredgridwriter" structuredgridwriter.cc)
target_link_dune_default_libraries("structuredgridwriter") target_link_dune_default_libraries("structuredgridwriter")
target_link_libraries("structuredgridwriter" dunevtk) target_link_libraries("structuredgridwriter" dunevtk)
add_executable("legacyvtkwriter" legacyvtkwriter.cc)
target_link_dune_default_libraries("legacyvtkwriter")
target_link_libraries("legacyvtkwriter" dunevtk)
if (dune-polygongrid_FOUND) if (dune-polygongrid_FOUND)
add_executable("polygongrid" polygongrid.cc) add_executable("polygongrid" polygongrid.cc)
target_link_dune_default_libraries("polygongrid") target_link_dune_default_libraries("polygongrid")
......
// -*- 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
#include <iostream>
#include <vector>
#include <dune/common/parallel/mpihelper.hh> // An initializer of MPI
#include <dune/common/exceptions.hh> // We use exceptions
#include <dune/common/filledarray.hh>
#include <dune/functions/functionspacebases/defaultglobalbasis.hh>
#include <dune/functions/functionspacebases/lagrangebasis.hh>
#include <dune/functions/functionspacebases/interpolate.hh>
#include <dune/functions/gridfunctions/analyticgridviewfunction.hh>
#include <dune/functions/gridfunctions/discreteglobalbasisfunction.hh>
#include <dune/grid/uggrid.hh>
#include <dune/grid/yaspgrid.hh>
#include <dune/vtk/writers/vtkunstructuredgridwriter.hh>
#include <dune/vtk/legacyvtkfunction.hh>
using namespace Dune;
using namespace Dune::experimental;
using namespace Dune::Functions;
#define GRID_TYPE 1
int main(int argc, char** argv)
{
Dune::MPIHelper::instance(argc, argv);
const int dim = 3;
#if GRID_TYPE == 1
using GridType = YaspGrid<dim>;
FieldVector<double,dim> upperRight; upperRight = 1.0;
auto numElements = filledArray<dim,int>(8);
GridType grid(upperRight,numElements);
#elif GRID_TYPE == 2
using GridType = UGGrid<dim>;
FieldVector<double,dim> lowerLeft; lowerLeft = 0.0;
FieldVector<double,dim> upperRight; upperRight = 1.0;
auto numElements = filledArray<dim,unsigned int>(4);
auto gridPtr = StructuredGridFactory<GridType>::createSimplexGrid(lowerLeft, upperRight, numElements);
auto& grid = *gridPtr;
#endif
using GridView = typename GridType::LeafGridView;
GridView gridView = grid.leafGridView();
using namespace BasisFactory;
auto basis = makeBasis(gridView, lagrange<1>());
std::vector<double> p1function(basis.dimension());
interpolate(basis, p1function, [](auto const& x) {
return 100*x[0] + 10*x[1] + 1*x[2];
});
using P1Function = P1VTKFunction<GridView,std::vector<double>>;
std::shared_ptr<VTKFunction<GridView> const> p1FctWrapped(new P1Function(gridView, p1function, "p1"));
using Writer = VtkUnstructuredGridWriter<GridView>;
Writer vtkWriter(gridView);
vtkWriter.addPointData(p1FctWrapped);
vtkWriter.write("test_ascii_float32.vtu", Vtk::ASCII);
vtkWriter.write("test_binary_float32.vtu", Vtk::BINARY);
vtkWriter.write("test_compressed_float32.vtu", Vtk::COMPRESSED);
vtkWriter.write("test_ascii_float64.vtu", Vtk::ASCII, Vtk::FLOAT64);
vtkWriter.write("test_binary_float64.vtu", Vtk::BINARY, Vtk::FLOAT64);
vtkWriter.write("test_compressed_float64.vtu", Vtk::COMPRESSED, Vtk::FLOAT64);
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment