Skip to content
Snippets Groups Projects
Commit 4cb92ef2 authored by Tobias Leibner's avatar Tobias Leibner
Browse files

[local.discretefunction] improve performance for fv spaces

parent 132f2feb
No related branches found
No related tags found
No related merge requests found
......@@ -64,12 +64,13 @@ public:
ConstLocalDiscreteFunction(const SpaceType& spc, const ConstDofVectorType& dof_vector)
: BaseType()
, space_(spc.copy())
, space_is_fv_(space_->type() == GDT::SpaceType::finite_volume)
, dof_vector_(dof_vector.localize())
, basis_(space_->basis().localize())
, basis_values_(space_->mapper().max_local_size())
, dynamic_basis_values_(space_->mapper().max_local_size())
, basis_derivatives_(space_->mapper().max_local_size())
, dynamic_basis_derivatives_(space_->mapper().max_local_size())
, basis_values_(space_is_fv_ ? 0 : space_->mapper().max_local_size())
, dynamic_basis_values_(basis_values_.size())
, basis_derivatives_(basis_values_.size())
, dynamic_basis_derivatives_(basis_values_.size())
{}
virtual ~ConstLocalDiscreteFunction() = default;
......@@ -119,7 +120,7 @@ public:
{
DUNE_THROW_IF(!this->is_bound_, Exceptions::not_bound_to_an_element_yet, "");
RangeReturnType result(0);
if (space_->type() == GDT::SpaceType::finite_volume) {
if (space_is_fv_) {
for (size_t ii = 0; ii < r; ++ii)
result[ii] = dof_vector_[ii];
} else {
......@@ -135,7 +136,7 @@ public:
{
DUNE_THROW_IF(!this->is_bound_, Exceptions::not_bound_to_an_element_yet, "");
DerivativeRangeReturnType result(0);
if (space_->type() == GDT::SpaceType::finite_volume) {
if (space_is_fv_) {
return result;
} else {
basis_->jacobians(point_in_reference_element, basis_derivatives_, param);
......@@ -150,7 +151,7 @@ public:
const XT::Common::Parameter& /*param*/ = {}) const override final
{
DUNE_THROW_IF(!this->is_bound_, Exceptions::not_bound_to_an_element_yet, "");
DUNE_THROW_IF(space_->type() != GDT::SpaceType::finite_volume,
DUNE_THROW_IF(space_is_fv_,
Exceptions::discrete_function_error,
"arbitrary derivatives are not supported by the local finite elements!\n\n"
<< "alpha = " << alpha << "\n"
......@@ -182,11 +183,11 @@ public:
{
DUNE_THROW_IF(!this->is_bound_, Exceptions::not_bound_to_an_element_yet, "");
RangeSelector::ensure_size(result);
result *= 0;
if (space_->type() == GDT::SpaceType::finite_volume) {
if (space_is_fv_) {
for (size_t ii = 0; ii < r; ++ii)
result[ii] = dof_vector_[ii];
} else {
result *= 0;
basis_->evaluate(point_in_reference_element, dynamic_basis_values_, param);
for (size_t ii = 0; ii < basis_->size(); ++ii)
result.axpy(dof_vector_[ii], dynamic_basis_values_[ii]);
......@@ -200,7 +201,7 @@ public:
DUNE_THROW_IF(!this->is_bound_, Exceptions::not_bound_to_an_element_yet, "");
DerivativeRangeSelector::ensure_size(result);
result *= 0;
if (space_->type() == GDT::SpaceType::finite_volume) {
if (space_is_fv_) {
return;
} else {
basis_->jacobians(point_in_reference_element, dynamic_basis_derivatives_, param);
......@@ -215,7 +216,7 @@ public:
const XT::Common::Parameter& /*param*/ = {}) const override final
{
DUNE_THROW_IF(!this->is_bound_, Exceptions::not_bound_to_an_element_yet, "");
DUNE_THROW_IF(space_->type() != GDT::SpaceType::finite_volume,
DUNE_THROW_IF(space_is_fv_,
Exceptions::discrete_function_error,
"arbitrary derivatives are not supported by the local finite elements!\n\n"
<< "alpha = " << alpha << "\n"
......@@ -248,7 +249,7 @@ public:
{
DUNE_THROW_IF(!this->is_bound_, Exceptions::not_bound_to_an_element_yet, "");
this->assert_correct_dims(row, col, "evaluate");
if (space_->type() == GDT::SpaceType::finite_volume) {
if (space_is_fv_) {
return dof_vector_[row];
} else {
R result(0);
......@@ -266,7 +267,7 @@ public:
{
DUNE_THROW_IF(!this->is_bound_, Exceptions::not_bound_to_an_element_yet, "");
this->assert_correct_dims(row, col, "jacobian");
if (space_->type() == GDT::SpaceType::finite_volume) {
if (space_is_fv_) {
return 0;
} else {
SingleDerivativeRangeReturnType result(0);
......@@ -281,6 +282,7 @@ public:
private:
std::unique_ptr<const SpaceType> space_;
const bool space_is_fv_;
ConstLocalDofVectorType dof_vector_;
std::unique_ptr<LocalBasisType> basis_;
mutable std::vector<RangeType> basis_values_;
......
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