Skip to content

Commit

Permalink
Merge branch 'cherry-pick-0901f441' into 'releases/2.9'
Browse files Browse the repository at this point in the history
Merge branch 'feature/raviart-thomas-pyramid-and-prism' into 'releases/2.9''

See merge request core/dune-localfunctions!232
  • Loading branch information
Robert K committed Oct 14, 2022
2 parents ea4c647 + a76a3eb commit f610b1b
Show file tree
Hide file tree
Showing 14 changed files with 747 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ SPDX-License-Identifier: LicenseRef-GPL-2.0-only-with-DUNE-exception

# Master (will become release 2.9)

* The implementation of the Raviart-Thomas element now also includes 0th order shape functions on prisms and pyramids.

## Deprecations and removals

- Deprecated many of the Lagrange headers, use
Expand Down
2 changes: 2 additions & 0 deletions dune/localfunctions/raviartthomas.hh
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,7 @@
#include <dune/localfunctions/raviartthomas/raviartthomas3cube2d.hh>
#include <dune/localfunctions/raviartthomas/raviartthomas0cube3d.hh>
#include <dune/localfunctions/raviartthomas/raviartthomas1cube3d.hh>
#include <dune/localfunctions/raviartthomas/raviartthomas0pyramid.hh>
#include <dune/localfunctions/raviartthomas/raviartthomas0prism.hh>

#endif // #ifndef DUNE_RAVIARTTHOMASFINITEELEMENT_HH
4 changes: 4 additions & 0 deletions dune/localfunctions/raviartthomas/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ add_subdirectory(raviartthomas2cube2d)
add_subdirectory(raviartthomas3cube2d)
add_subdirectory(raviartthomas4cube2d)
add_subdirectory(raviartthomassimplex)
add_subdirectory(raviartthomas0pyramid)
add_subdirectory(raviartthomas0prism)

install(FILES
raviartthomas02d.hh
Expand All @@ -27,4 +29,6 @@ install(FILES
raviartthomascube.hh
raviartthomaslfecache.hh
raviartthomassimplex.hh
raviartthomas0pyramid.hh
raviartthomas0prism.hh
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/dune/localfunctions/raviartthomas)
82 changes: 82 additions & 0 deletions dune/localfunctions/raviartthomas/raviartthomas0prism.hh
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
// -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
// vi: set et ts=4 sw=2 sts=2:
// SPDX-FileCopyrightInfo: Copyright (C) DUNE Project contributors, see file LICENSE.md in module root
// SPDX-License-Identifier: LicenseRef-GPL-2.0-only-with-DUNE-exception
#ifndef DUNE_LOCALFUNCTIONS_RAVIARTTHOMAS0_PRISM_HH
#define DUNE_LOCALFUNCTIONS_RAVIARTTHOMAS0_PRISM_HH

#include <dune/geometry/type.hh>

#include "../common/localfiniteelementtraits.hh"
#include "raviartthomas0prism/raviartthomas0prismlocalbasis.hh"
#include "raviartthomas0prism/raviartthomas0prismlocalcoefficients.hh"
#include "raviartthomas0prism/raviartthomas0prismlocalinterpolation.hh"

namespace Dune
{
/**
* \brief First order Raviart-Thomas shape functions on prisms.
*
* \ingroup RaviartThomas
*
* \tparam D Type to represent the field in the domain.
* \tparam R Type to represent the field in the range.
*/
template<class D, class R>
class RT0PrismLocalFiniteElement
{

public:
typedef LocalFiniteElementTraits<
RT0PrismLocalBasis<D,R>,
RT0PrismLocalCoefficients,
RT0PrismLocalInterpolation<RT0PrismLocalBasis<D,R> > > Traits;


//! \brief Standard constructor
RT0PrismLocalFiniteElement ()
{}

/**
* \brief Make set number s, where 0 <= s < 32
*
* \param s Face orientation indicator
*/
RT0PrismLocalFiniteElement (int s) :
basis(s),
interpolation(s)
{}

const typename Traits::LocalBasisType& localBasis () const
{
return basis;
}

const typename Traits::LocalCoefficientsType& localCoefficients () const
{
return coefficients;
}

const typename Traits::LocalInterpolationType& localInterpolation () const
{
return interpolation;
}

/** \brief Number of shape functions in this finite element */
unsigned int size () const
{
return basis.size();
}

static constexpr GeometryType type ()
{
return GeometryTypes::prism;
}

private:
RT0PrismLocalBasis<D,R> basis;
RT0PrismLocalCoefficients coefficients;
RT0PrismLocalInterpolation<RT0PrismLocalBasis<D,R> > interpolation;
};
}
#endif // DUNE_LOCALFUNCTIONS_RAVIARTTHOMAS0_PRISM_HH
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# SPDX-FileCopyrightText: Copyright (C) DUNE Project contributors, see file LICENSE.md in module root
# SPDX-License-Identifier: LicenseRef-GPL-2.0-only-with-DUNE-exception

install(FILES
raviartthomas0prismlocalbasis.hh
raviartthomas0prismlocalcoefficients.hh
raviartthomas0prismlocalinterpolation.hh
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/dune/localfunctions/raviartthomas/raviartthomas0prism)
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
// -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
// vi: set et ts=4 sw=2 sts=2:
// SPDX-FileCopyrightInfo: Copyright (C) DUNE Project contributors, see file LICENSE.md in module root
// SPDX-License-Identifier: LicenseRef-GPL-2.0-only-with-DUNE-exception
#ifndef DUNE_LOCALFUNCTIONS_RAVIARTTHOMAS0_PRISM_LOCALBASIS_HH
#define DUNE_LOCALFUNCTIONS_RAVIARTTHOMAS0_PRISM_LOCALBASIS_HH

#include <numeric>
#include <vector>

#include <dune/common/fmatrix.hh>

#include "../../common/localbasis.hh"

namespace Dune
{
/**
* \ingroup LocalBasisImplementation
* \brief First order Raviart-Thomas shape functions on the reference prism.
*
* \tparam D Type to represent the field in the domain.
* \tparam R Type to represent the field in the range.
*
* \nosubgrouping
*/
template<class D, class R>
class RT0PrismLocalBasis
{

public:
typedef LocalBasisTraits<D,3,Dune::FieldVector<D,3>,R,3,Dune::FieldVector<R,3>,
Dune::FieldMatrix<R,3,3> > Traits;

/**
* \brief Make set number s, where 0 <= s < 32
*
* \param s Edge orientation indicator
*/
RT0PrismLocalBasis (std::bitset<5> s = 0)
{
for (size_t i=0; i<size(); i++)
sign[i] = s[i] ? -1.0 : 1.0;
}

//! \brief number of shape functions
unsigned int size () const
{
return 5;
}

/**
* \brief Evaluate all shape functions
*
* \param in Position
* \param out return value
*/
inline void evaluateFunction (const typename Traits::DomainType& in,
std::vector<typename Traits::RangeType>& out) const
{
out.resize(5);

out[0] = { in[0], -1.0 + in[1], 0.0};

out[1] = { -1.0 + in[0], in[1], 0.0};

out[2] = { in[0], in[1], 0.0};

out[3] = { 0.0, 0.0, -2.0 + 2.0*in[2]};

out[4] = { 0.0, 0.0, 2.0*in[2]};

for (std::size_t i=0; i<out.size(); i++)
out[i] *= sign[i];

}

/**
* \brief Evaluate Jacobian of all shape functions
*
* \param in Position
* \param out return value
*/
inline void evaluateJacobian (const typename Traits::DomainType& in,
std::vector<typename Traits::JacobianType>& out) const
{
out.resize(5);

for(int i=0; i<size(); i++)
for(int j=0; j<3; j++)
out[i][j] = {0.0, 0.0, 0.0};

out[0][0][0] = sign[0];
out[0][1][1] = sign[0];

out[1][0][0] = sign[1];
out[1][1][1] = sign[1];

out[2][0][0] = sign[2];
out[2][1][1] = sign[2];

out[3][2][2] = sign[3]*(2.0);

out[4][2][2] = sign[4]*(2.0);
}

//! \brief Evaluate partial derivatives of all shape functions
void partial (const std::array<unsigned int, 3>& order,
const typename Traits::DomainType& in, // position
std::vector<typename Traits::RangeType>& out) const // return value
{
auto totalOrder = std::accumulate(order.begin(), order.end(), 0);
if (totalOrder == 0) {
evaluateFunction(in, out);
} else {
DUNE_THROW(NotImplemented, "Desired derivative order is not implemented");
}
}

//! \brief Polynomial order of the shape functions
unsigned int order () const
{
return 1;
}

private:
std::array<R,5> sign;
};
}
#endif // DUNE_LOCALFUNCTIONS_RAVIARTTHOMAS0_PRISM_LOCALBASIS_HH
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
// -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
// vi: set et ts=4 sw=2 sts=2:
// SPDX-FileCopyrightInfo: Copyright (C) DUNE Project contributors, see file LICENSE.md in module root
// SPDX-License-Identifier: LicenseRef-GPL-2.0-only-with-DUNE-exception
#ifndef DUNE_LOCALFUNCTIONS_RAVIARTTHOMAS0_PRISM_LOCALCOEFFICIENTS_HH
#define DUNE_LOCALFUNCTIONS_RAVIARTTHOMAS0_PRISM_LOCALCOEFFICIENTS_HH

#include <cstddef>
#include <vector>

#include "../../common/localkey.hh"

namespace Dune
{

/**
* \ingroup LocalLayoutImplementation
* \brief Layout map for Raviart-Thomas-1 elements on prisms.
*
* \nosubgrouping
* \implements Dune::LocalCoefficientsVirtualImp
*/
class RT0PrismLocalCoefficients
{

public:
//! \brief Standard constructor
RT0PrismLocalCoefficients () : li(size())
{
for(int i=0; i< size(); i++)
li[i] = LocalKey(i,1,0);
}

//! \brief number of coefficients
std::size_t size () const
{
return 5;
}

//! \brief get i'th index
const LocalKey& localKey (std::size_t i) const
{
return li[i];
}

private:
std::vector<LocalKey> li;
};
}
#endif // DUNE_LOCALFUNCTIONS_RAVIARTTHOMAS0_PRISM_LOCALCOEFFICIENTS_HH
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
// -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
// vi: set et ts=4 sw=2 sts=2:
// SPDX-FileCopyrightInfo: Copyright (C) DUNE Project contributors, see file LICENSE.md in module root
// SPDX-License-Identifier: LicenseRef-GPL-2.0-only-with-DUNE-exception
#ifndef DUNE_LOCALFUNCTIONS_RAVIARTTHOMAS0_PRISM_LOCALINTERPOLATION_HH
#define DUNE_LOCALFUNCTIONS_RAVIARTTHOMAS0_PRISM_LOCALINTERPOLATION_HH

#include <vector>

#include <dune/localfunctions/common/localinterpolation.hh>

namespace Dune
{
/**
* \ingroup LocalInterpolationImplementation
* \brief First order Raviart-Thomas shape functions on the reference prism.
*
* \tparam LB corresponding LocalBasis giving traits
*
* \nosubgrouping
*/
template<class LB>
class RT0PrismLocalInterpolation
{

public:

/**
* \brief Make set number s, where 0 <= s < 32
*
* \param s Face orientation indicator
*/
RT0PrismLocalInterpolation (std::bitset<5> s = 0)
{
typedef typename LB::Traits::RangeFieldType Scalar;

for (size_t i=0; i<5; i++)
sign[i] = (s[i]) ? -1.0 : 1.0;

Scalar r = 1/std::sqrt(2);

n[0] = { 0.0, -1.0, 0.0};
n[1] = {-1.0, 0.0, 0.0};
n[2] = { r, r, 0.0};
n[3] = { 0.0, 0.0, -1.0};
n[4] = { 0.0, 0.0, 1.0};

c[0] = 1.0;
c[1] = 1.0;
c[2] = std::sqrt(2);
c[3] = 1/2.0;
c[4] = 1/2.0;

m[0] = { 0.5, 0.0, 0.5};
m[1] = { 0.0, 0.5, 0.5};
m[2] = { 0.5, 0.5, 0.5};
m[3] = { 1/3.0, 1/3.0, 0.0};
m[4] = { 1/3.0, 1/3.0, 1.0};
}

/**
* \brief Interpolate a given function with shape functions
*
* \tparam F Function type for function which should be interpolated
* \tparam C Coefficient type
* \param ff function which should be interpolated
* \param out return value, vector of coefficients
*/
template<class F, class C>
void interpolate (const F& ff, std::vector<C>& out) const
{
auto&& f = Impl::makeFunctionWithCallOperator<typename LB::Traits::DomainType>(ff);

out.resize(5);
for(int i=0; i<5; i++)
out[i] = f(m[i]).dot(n[i]) * c[i] * sign[i];
}

private:
// Facet orientations
std::array<typename LB::Traits::RangeFieldType, 5> sign;
// Facet area
std::array<typename LB::Traits::RangeFieldType, 5> c;

// Facet normals
std::array<typename LB::Traits::DomainType, 5> n;
// Facet midpoints
std::array<typename LB::Traits::DomainType, 5> m;
};
}
#endif // DUNE_LOCALFUNCTIONS_RAVIARTTHOMAS0_PRISM_LOCALINTERPOLATION_HH
Loading

0 comments on commit f610b1b

Please sign in to comment.