Skip to content

Commit

Permalink
add tensorProduct quadrature rule and [0,1] to [-1,1] transformation
Browse files Browse the repository at this point in the history
  • Loading branch information
rath3t committed Jan 23, 2024
1 parent 6bb59e7 commit 9e17aaf
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 0 deletions.
1 change: 1 addition & 0 deletions ikarus/utils/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ install(
polyfit.hh
pythonautodiffdefinitions.hh
tensorutils.hh
tensorproductquadrule.hh
traits.hh
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/ikarus/utils
)
Expand Down
35 changes: 35 additions & 0 deletions ikarus/utils/tensorproductquadrule.hh
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// SPDX-FileCopyrightText: 2023 The Ikarus Developers [email protected]
// SPDX-License-Identifier: LGPL-2.1-or-later
#pragma once

#include <dune/geometry/quadraturerules.hh>
namespace Ikarus {
template <class BaseQuadrature, class Quadrature>
auto tensorProductQuadrature(const BaseQuadrature& baseQuad, const Quadrature& onedQuad) {
constexpr int baseQuadDim = BaseQuadrature::d;
auto rule = Dune::QuadratureRule<double, baseQuadDim + 1>();
const unsigned int baseQuadSize = baseQuad.size();
for (unsigned int bqi = 0; bqi < baseQuadSize; ++bqi) {
const typename Dune::QuadraturePoint<double, baseQuadDim>::Vector& basePoint = baseQuad[bqi].position();
const double& baseWeight = baseQuad[bqi].weight();

typename Dune::QuadraturePoint<double, baseQuadDim + 1>::Vector point;
for (unsigned int i = 0; i < baseQuadDim; ++i)
point[i] = basePoint[i];

const unsigned int onedQuadSize = onedQuad.size();
for (unsigned int oqi = 0; oqi < onedQuadSize; ++oqi) {
point[baseQuadDim] = onedQuad[oqi].position()[0];
rule.emplace_back(Dune::QuadraturePoint(point, baseWeight * onedQuad[oqi].weight()));
}
}
return rule;
}

auto transformFromZeroOneToMinusOneToOne(const Dune::QuadraturePoint<double, 1>& gp) {
typename Dune::QuadraturePoint<double, 1>::Vector mappedCoordinate = gp.position();
mappedCoordinate[0] = 2 * mappedCoordinate[0] - 1.0;
double mappedWeight = gp.weight() * 2.0;
return Dune::QuadraturePoint<double, 1>(mappedCoordinate, mappedWeight);

Check warning on line 33 in ikarus/utils/tensorproductquadrule.hh

View check run for this annotation

Codecov / codecov/patch

ikarus/utils/tensorproductquadrule.hh#L29-L33

Added lines #L29 - L33 were not covered by tests
}
} // namespace Ikarus
29 changes: 29 additions & 0 deletions tests/src/testshellthicknessquadrule.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// SPDX-FileCopyrightText: 2023 The Ikarus Developers [email protected]
// SPDX-License-Identifier: LGPL-2.1-or-later

#include <config.h>

#include <dune/common/test/testsuite.hh>
using Dune::TestSuite;
#include <dune/common/float_cmp.hh>

#include <ikarus/utils/init.hh>
#include <ikarus/utils/tensorproductquadrule.hh>

int main(int argc, char** argv) {
Ikarus::init(argc, argv);
TestSuite t;

for (int i = 0; i < 5; ++i) {
const auto& twoDRule = Dune::QuadratureRules<double, 2>::rule(Dune::GeometryTypes::quadrilateral, i);
const auto& oneDRule = Dune::QuadratureRules<double, 1>::rule(Dune::GeometryTypes::line, 1);

const auto rule = Ikarus::tensorProductQuadrature(twoDRule, oneDRule);
double vol = 0;
for (int gpIndex = 0; auto& gp : rule) {
vol += gp.weight();
gpIndex++;
}
t.check(Dune::FloatCmp::eq(vol, 1.0));
}
}

0 comments on commit 9e17aaf

Please sign in to comment.