Commit 3d8ea458 authored by Andreas Nüßing's avatar Andreas Nüßing

[DipoleStatistics] add infrastructure

We add infrastructure to determine different statistics about a dipole. In
a first step, this is only the conductivity of the element the dipole is
in. A first implementation is provided for fitted meshes. This includes
tetrahedral, standard hexahedral and geometry adapted hexahedral meshes.
The configurartion for creating an object of this statistic is a subset
of the one for creating a MEEGDriver.
parent b2151a89
#ifndef DUNEURO_DIPOLE_STATISTICS_HH
#define DUNEURO_DIPOLE_STATISTICS_HH
#include <duneuro/common/dipole.hh>
#include <duneuro/common/fitted_driver_data.hh>
#include <duneuro/common/flags.hh>
#include <duneuro/common/volume_conductor_storage.hh>
namespace duneuro
{
template <int dim>
struct DipoleStatisticsInterface {
using Coordinate = Dune::FieldVector<double, dim>;
using DipoleType = Dipole<double, dim>;
using TensorType = Dune::FieldMatrix<double, dim, dim>;
virtual ~DipoleStatisticsInterface()
{
}
virtual TensorType conductivity(const DipoleType& x) const = 0;
};
template <int dim, ElementType elementType, bool geometryAdaption = false>
class FittedDipoleStatistics : public DipoleStatisticsInterface<dim>
{
public:
using BaseT = DipoleStatisticsInterface<dim>;
using Coordinate = typename BaseT::Coordinate;
using DipoleType = typename BaseT::DipoleType;
using TensorType = typename BaseT::TensorType;
using VCStorage = VolumeConductorStorage<dim, elementType, geometryAdaption>;
using VC = typename VCStorage::Type;
using ElementSearch = KDTreeElementSearch<typename VC::GridView>;
FittedDipoleStatistics(const FittedDriverData<dim>& data, const Dune::ParameterTree& config,
DataTree dataTree = DataTree())
: config_(config)
, volumeConductorStorage_(data, config.sub("volume_conductor"),
dataTree.sub("volume_conductor"))
, elementSearch_(std::make_shared<ElementSearch>(volumeConductorStorage_.get()->gridView()))
{
}
virtual TensorType conductivity(const DipoleType& x) const override
{
return volumeConductorStorage_.get()->tensor(elementSearch_->findEntity(x.position()));
}
private:
Dune::ParameterTree config_;
VCStorage volumeConductorStorage_;
std::shared_ptr<ElementSearch> elementSearch_;
};
}
#endif // DUNEURO_DIPOLE_STATISTICS_HH
#ifndef DUNEURO_DIPOLE_STATISTICS_FACTORY_HH
#define DUNEURO_DIPOLE_STATISTICS_FACTORY_HH
#include <duneuro/common/dipole_statistics.hh>
namespace duneuro
{
template <int dim>
struct DipoleStatisticsFactory {
static std::unique_ptr<DipoleStatisticsInterface<dim>>
make_dipole_statistics(const Dune::ParameterTree& config, const FittedDriverData<dim>& data,
DataTree dataTree = DataTree());
};
template <>
std::unique_ptr<DipoleStatisticsInterface<2>> DipoleStatisticsFactory<2>::make_dipole_statistics(
const Dune::ParameterTree& config, const FittedDriverData<2>& data, DataTree dataTree)
{
const int dim = 2;
auto type = config.get<std::string>("type");
if (type == "fitted") {
auto elementType = config.get<std::string>("element_type");
if (elementType == "tetrahedron") {
return Dune::Std::make_unique<FittedDipoleStatistics<dim, ElementType::tetrahedron>>(
data, config, dataTree);
} else if (elementType == "hexahedron") {
if (config.get("geometry_adapted", false)) {
return Dune::Std::make_unique<FittedDipoleStatistics<dim, ElementType::hexahedron, true>>(
data, config, dataTree);
} else {
return Dune::Std::make_unique<FittedDipoleStatistics<dim, ElementType::hexahedron,
false>>(data, config, dataTree);
}
} else {
DUNE_THROW(Dune::Exception, "element type \"" << elementType << "\" not supported");
}
} else {
DUNE_THROW(Dune::Exception, "type \"" << type << "\" not supported");
}
}
template <>
std::unique_ptr<DipoleStatisticsInterface<3>> DipoleStatisticsFactory<3>::make_dipole_statistics(
const Dune::ParameterTree& config, const FittedDriverData<3>& data, DataTree dataTree)
{
const int dim = 3;
auto type = config.get<std::string>("type");
if (type == "fitted") {
auto elementType = config.get<std::string>("element_type");
if (elementType == "tetrahedron") {
return Dune::Std::make_unique<FittedDipoleStatistics<dim, ElementType::tetrahedron>>(
data, config, dataTree);
} else if (elementType == "hexahedron") {
if (config.get("geometry_adapted", false)) {
return Dune::Std::make_unique<FittedDipoleStatistics<dim, ElementType::hexahedron, true>>(
data, config, dataTree);
} else {
return Dune::Std::make_unique<FittedDipoleStatistics<dim, ElementType::hexahedron,
false>>(data, config, dataTree);
}
} else {
DUNE_THROW(Dune::Exception, "element type \"" << elementType << "\" not supported");
}
} else {
DUNE_THROW(Dune::Exception, "type \"" << type << "\" not supported");
}
}
}
#endif // DUNEURO_DIPOLE_STATISTICS_FACTORY_HH
Markdown is supported
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