Skip to content
Snippets Groups Projects
Commit 782050c9 authored by Dr. Felix Tobias Schindler's avatar Dr. Felix Tobias Schindler
Browse files

[discretefunction.bochner] some updates

* update ListVectorArray usage
* add preliminary visualization
parent 866409df
No related branches found
No related tags found
No related merge requests found
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
#include <dune/xt/grid/search.hh> #include <dune/xt/grid/search.hh>
#include <dune/gdt/exceptions.hh> #include <dune/gdt/exceptions.hh>
#include <dune/gdt/discretefunction/default.hh>
#include <dune/gdt/spaces/bochner.hh> #include <dune/gdt/spaces/bochner.hh>
namespace Dune { namespace Dune {
...@@ -23,31 +24,37 @@ namespace GDT { ...@@ -23,31 +24,37 @@ namespace GDT {
/** /**
* \todo Turn this into a parametric LocalizableFunction. * \todo Turn this into a parametric LocalizableFunction.
* \todo add ConstDiscreteBochnerFunction
*/ */
template <class V, class GV, size_t r = 1, size_t rC = 1, class R = double> template <class V, class GV, size_t r = 1, size_t rC = 1, class R = double>
class DiscreteBochnerFunction class DiscreteBochnerFunction
{ {
public: public:
DiscreteBochnerFunction(const BochnerSpace<GV, r, rC, R>& bochner_space, XT::LA::ListVectorArray<V>& dof_vectors) DiscreteBochnerFunction(const BochnerSpace<GV, r, rC, R>& bochner_space,
XT::LA::ListVectorArray<V>& dof_vectors,
const std::string nm = "")
: bochner_space_(bochner_space) : bochner_space_(bochner_space)
, dof_vectors_(dof_vectors) , dof_vectors_(dof_vectors)
, name_(nm.empty() ? "DiscreteBochnerFunction" : nm)
{ {
DUNE_THROW_IF(this->dof_vectors().length() != bochner_space_.temporal_space().mapper().size(), DUNE_THROW_IF(this->dof_vectors().length() != bochner_space_.temporal_space().mapper().size(),
Exceptions::space_error, Exceptions::space_error,
"\n this->dof_vectors().length() = " << this->dof_vectors().length() << "\n " "\n this->dof_vectors().length() = " << this->dof_vectors().length() << "\n "
<< bochner_space_.temporal_space().mapper().size()); << bochner_space_.temporal_space().mapper().size());
for (const auto& vec : this->dof_vectors()) for (const auto& vec : this->dof_vectors())
DUNE_THROW_IF(vec.size() != bochner_space_.spatial_space().mapper().size(), DUNE_THROW_IF(vec.vector().size() != bochner_space_.spatial_space().mapper().size(),
Exceptions::space_error, Exceptions::space_error,
"\n vec.size() = " << vec.size() << "\n " << bochner_space_.spatial_space().mapper().size()); "\n vec.vector().size() = " << vec.vector().size() << "\n "
<< bochner_space_.spatial_space().mapper().size());
} // DiscreteBochnerFunction(...) } // DiscreteBochnerFunction(...)
DiscreteBochnerFunction(const BochnerSpace<GV, r, rC, R>& bochner_space) DiscreteBochnerFunction(const BochnerSpace<GV, r, rC, R>& bochner_space, const std::string nm = "")
: bochner_space_(bochner_space) : bochner_space_(bochner_space)
, dof_vectors_(new XT::LA::ListVectorArray<V>(bochner_space_.spatial_space().mapper().size(), , dof_vectors_(new XT::LA::ListVectorArray<V>(bochner_space_.spatial_space().mapper().size(),
bochner_space_.temporal_space().mapper().size())) bochner_space_.temporal_space().mapper().size()))
, name_(nm.empty() ? "DiscreteBochnerFunction" : nm)
{ {
} // DiscreteBochnerFunction(...) }
const BochnerSpace<GV, r, rC, R>& space() const const BochnerSpace<GV, r, rC, R>& space() const
{ {
...@@ -64,6 +71,11 @@ public: ...@@ -64,6 +71,11 @@ public:
return dof_vectors_.access(); return dof_vectors_.access();
} }
std::string name() const
{
return name_;
}
V evaluate(const double& time) const V evaluate(const double& time) const
{ {
const auto search_result = XT::Grid::make_entity_in_level_search(bochner_space_.temporal_space().grid_view())( const auto search_result = XT::Grid::make_entity_in_level_search(bochner_space_.temporal_space().grid_view())(
...@@ -78,13 +90,25 @@ public: ...@@ -78,13 +90,25 @@ public:
V result(bochner_space_.spatial_space().mapper().size(), 0.); V result(bochner_space_.spatial_space().mapper().size(), 0.);
const auto global_dof_indices = bochner_space_.temporal_space().mapper().global_indices(time_interval); const auto global_dof_indices = bochner_space_.temporal_space().mapper().global_indices(time_interval);
for (size_t ii = 0; ii < temporal_basis->size(); ++ii) for (size_t ii = 0; ii < temporal_basis->size(); ++ii)
result.axpy(temporal_basis_values[ii], this->dof_vectors()[global_dof_indices[ii]]); result.axpy(temporal_basis_values[ii], this->dof_vectors()[global_dof_indices[ii]].vector());
return result; return result;
} // ... evaluate(...) } // ... evaluate(...)
void visualize(const std::string filename_prefix, const VTK::OutputType vtk_output_type = VTK::appendedraw) const
{
DUNE_THROW_IF(
filename_prefix.empty(), XT::Common::Exceptions::wrong_input_given, "filename_prefix must not be empty!");
for (const auto& annotated_vector : dof_vectors_.access()) {
const double time = annotated_vector.note().get("_t").at(0);
auto df = make_const_discrete_function(bochner_space_.spatial_space(), annotated_vector.vector(), name_);
df.visualize(filename_prefix + "_" + XT::Common::to_string(time), vtk_output_type);
}
} // ... visualize(...)
private: private:
const BochnerSpace<GV, r, rC, R>& bochner_space_; const BochnerSpace<GV, r, rC, R>& bochner_space_;
XT::Common::StorageProvider<XT::LA::ListVectorArray<V>> dof_vectors_; XT::Common::StorageProvider<XT::LA::ListVectorArray<V>> dof_vectors_;
const std::string name_;
}; // class DiscreteBochnerFunction }; // class DiscreteBochnerFunction
......
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