// -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- // vi: set et ts=4 sw=2 sts=2: // SPDX-FileCopyrightInfo: Copyright © DUNE Project contributors, see file LICENSE.md in module root // SPDX-License-Identifier: LicenseRef-GPL-2.0-only-with-DUNE-exception #include #include #include #include #include #include #include #include #include #include #define DUNE_DISABLE_DEPRECATION_WARNING_PQ22D #include #undef DUNE_DISABLE_DEPRECATION_WARNING_PQ22D /** \file \brief Test the dynamically polymorphic shape function interface This file mainly tests whether the polymorphic interface can be properly instantiated, compiled and run without crashed. It does _not_ test whether the shape function sets behave correctly. */ using namespace Dune; template void syntax_check( const T& ) {} // A test function to test the local interpolation template struct TestFunction { using DomainType = D; using RangeType = R; RangeType operator()(const DomainType& in) const { // May not be flexible enough to compile for all range types RangeType out; out = 1; return out; } }; template void testLocalBasis(const LocalBasisVirtualInterface* localBasis) { // call each method once to test that it's there syntax_check( localBasis->order() ); [[maybe_unused]] unsigned int size = localBasis->size(); // evaluate the local basis at (0,...,0) typename T::DomainType in(0); std::vector out; localBasis->evaluateFunction(in, out); assert(out.size() == size); std::vector jacobianOut; localBasis->evaluateJacobian(in, jacobianOut); assert(jacobianOut.size() == localBasis->size()); } void testLocalCoefficients(const LocalCoefficientsVirtualInterface* localCoefficients) { if (!localCoefficients) DUNE_THROW(Dune::Exception, "Received an invalid pointer to LocalCoefficientsVirtualInterface"); if (localCoefficients->size() < 1) DUNE_THROW(Dune::Exception, "LocalCoefficients does not provide any coefficients!"); for (std::size_t i=0; isize(); i++) { // Test the localKey method // We just test whether the interface is there. Correctness is tested elsewhere syntax_check( localCoefficients->localKey(i).subEntity() ); syntax_check( localCoefficients->localKey(i).codim() ); syntax_check( localCoefficients->localKey(i).index() ); } } template void testLocalInterpolation(const LocalInterpolationVirtualInterface* localInterpolation) { // Test interpolation of a function object derived from VirtualFunction TestFunction testFunction; std::vector coefficients; ////////////////////////////////////////////////////////////////////////////// // Feed the function to the 'interpolate' method in form of a callable. ////////////////////////////////////////////////////////////////////////////// localInterpolation->interpolate(testFunction, coefficients); } // Test all methods of a local finite element given as a pointer to the abstract base class template void testLocalFiniteElement(const LocalFiniteElementVirtualInterface* localFiniteElement) { // Test method type() std::cout << "Testing local finite element for a " << localFiniteElement->type() << "." << std::endl; typedef LocalFiniteElementVirtualInterface FEType; // Test the local basis const typename FEType::Traits::LocalBasisType& basis = localFiniteElement->localBasis(); testLocalBasis(&basis); // Test the local coefficients const typename FEType::Traits::LocalCoefficientsType& coeffs = localFiniteElement->localCoefficients(); testLocalCoefficients(&coeffs); // Test the interpolation const typename FEType::Traits::LocalInterpolationType& interp = localFiniteElement->localInterpolation(); testLocalInterpolation(&interp); // Test cloning const LocalFiniteElementVirtualInterface* other = localFiniteElement->clone(); // Make sure new object has the same type if (typeid(other).hash_code() != typeid(localFiniteElement).hash_code()) DUNE_THROW(Dune::Exception, "'clone' method returns object of wrong type"); // But it shouldn't be the same object if (other==localFiniteElement) DUNE_THROW(Dune::Exception, "'clone' method returned the object it was called for!"); delete other; } int main (int argc, char *argv[]) { typedef Dune::LagrangeSimplexLocalFiniteElement::Traits::LocalBasisType::Traits LBTraits; const Dune::P0LocalFiniteElement p0FE(Dune::GeometryTypes::cube(2)); const Dune::LocalFiniteElementVirtualImp > p0VFE(p0FE); testLocalFiniteElement(&p0VFE); DUNE_NO_DEPRECATED_BEGIN const Dune::PQ22DLocalFiniteElement pq2FE(Dune::GeometryTypes::cube(2)); const Dune::PQ22DLocalFiniteElement pq2FE2(pq2FE); const Dune::LocalFiniteElementVirtualImp > pq2VFE(pq2FE); testLocalFiniteElement(&pq2VFE); DUNE_NO_DEPRECATED_END const Dune::LocalFiniteElementVirtualImp> p1VFE; testLocalFiniteElement(&p1VFE); const Dune::LocalFiniteElementVirtualImp>> p1VVFE; testLocalFiniteElement(&p1VVFE); typedef Dune::MonomialLocalFiniteElement Monom7; const Monom7 monom7FE(Dune::GeometryTypes::cube(2)); const Dune::LocalFiniteElementVirtualImp monom7VFE(monom7FE); const Dune::LocalFiniteElementVirtualImp< Dune::LocalFiniteElementVirtualImp > monom7VVFE(monom7VFE); testLocalFiniteElement(&monom7VVFE); return 0; }