From 958694632842285c2c7b316415d0ab95b89a75bb Mon Sep 17 00:00:00 2001 From: Tarun Kumar Mitruka Vinod Kumar Mitruka Date: Fri, 26 Jan 2024 14:49:07 +0100 Subject: [PATCH] merge FETraits and TraitsFromFE (#249) --- .../02_examples/incompressibleRubberBlock.md | 2 +- docs/website/02_examples/kirchhoffPlate.md | 2 +- docs/website/02_examples/vonMisesTruss.md | 2 +- ikarus/finiteelements/febases/autodifffe.hh | 12 ++--- ikarus/finiteelements/febases/powerbasisfe.hh | 12 ++--- ikarus/finiteelements/febases/scalarfe.hh | 17 +++--- ikarus/finiteelements/fetraits.hh | 50 +++++++++++++---- .../mechanics/kirchhoffloveshell.hh | 12 ++--- .../finiteelements/mechanics/linearelastic.hh | 13 ++--- .../mechanics/nonlinearelastic.hh | 13 ++--- ikarus/finiteelements/physicshelper.hh | 54 ------------------- tests/src/checkfebyautodiff.hh | 1 + 12 files changed, 84 insertions(+), 106 deletions(-) diff --git a/docs/website/02_examples/incompressibleRubberBlock.md b/docs/website/02_examples/incompressibleRubberBlock.md index f971ad3e1..a801a10ea 100644 --- a/docs/website/02_examples/incompressibleRubberBlock.md +++ b/docs/website/02_examples/incompressibleRubberBlock.md @@ -15,7 +15,7 @@ The `struct` named `Solid` is created which is not inherited from any class. It ```cpp Solid(const Basis &basis, const typename LocalView::Element &element, double emod, double nu) - : localView_{basis.flat().localView()}, emod_{emod}, nu_{nu} { + : localView_{basis.localView()}, emod_{emod}, nu_{nu} { localView_.bind(element); mu_ = emod_ / (2 * (1 + nu_)); lambdaMat = convertLameConstants({.emodul = emod_, .nu = nu_}).toLamesFirstParameter(); diff --git a/docs/website/02_examples/kirchhoffPlate.md b/docs/website/02_examples/kirchhoffPlate.md index 6a5ace40d..75269839c 100644 --- a/docs/website/02_examples/kirchhoffPlate.md +++ b/docs/website/02_examples/kirchhoffPlate.md @@ -16,7 +16,7 @@ It is constructed as shown below: ```cpp KirchhoffPlate(const Basis &basis, const typename LocalView::Element &element, double p_Emodul, double p_nu, double p_thickness) - : BaseDisp(basis.flat(), element), + : BaseDisp(basis, element), Emodul{p_Emodul}, nu{p_nu}, thickness{p_thickness} { diff --git a/docs/website/02_examples/vonMisesTruss.md b/docs/website/02_examples/vonMisesTruss.md index ebf29108d..e474cbff0 100644 --- a/docs/website/02_examples/vonMisesTruss.md +++ b/docs/website/02_examples/vonMisesTruss.md @@ -13,7 +13,7 @@ It is constructed as shown below: ```cpp Truss(const Basis &basis, const typename LocalView::Element &element, double p_EA) - : BaseDisp(basis.flat(), element), EA{p_EA} { + : BaseDisp(basis, element), EA{p_EA} { this->localView().bind(element); } ``` diff --git a/ikarus/finiteelements/febases/autodifffe.hh b/ikarus/finiteelements/febases/autodifffe.hh index 456c65880..6018974b3 100644 --- a/ikarus/finiteelements/febases/autodifffe.hh +++ b/ikarus/finiteelements/febases/autodifffe.hh @@ -12,7 +12,7 @@ #include #include -#include +#include #include namespace Ikarus { @@ -31,11 +31,11 @@ template , bool class AutoDiffFE : public RealFE_ { public: - using RealFE = RealFE_; ///< Type of the base finite element. - using Basis = typename RealFE::Basis; ///< Type of the basis. - using Traits = TraitsFromFE; ///< Type traits for local view. - using LocalView = typename Traits::LocalView; ///< Type of the local view. - using Element = typename Traits::Element; ///< Type of the element. + using RealFE = RealFE_; ///< Type of the base finite element. + using Basis = typename RealFE::Basis; ///< Type of the basis. + using Traits = FETraits; ///< Type traits for local view. + using LocalView = typename Traits::LocalView; ///< Type of the local view. + using Element = typename Traits::Element; ///< Type of the element. using FERequirementType = typename Traits::FERequirementType; ///< Type of the Finite Element Requirements. /** diff --git a/ikarus/finiteelements/febases/powerbasisfe.hh b/ikarus/finiteelements/febases/powerbasisfe.hh index 6b5c89a27..f674ce931 100644 --- a/ikarus/finiteelements/febases/powerbasisfe.hh +++ b/ikarus/finiteelements/febases/powerbasisfe.hh @@ -23,11 +23,11 @@ template class PowerBasisFE { public: - using RootBasis = Basis; ///< Type of the root basis. - using LocalView = typename Basis::LocalView; ///< Type of the local view. - using GlobalIndex = typename LocalView::MultiIndex; ///< Type of the global index. - using GridElement = typename LocalView::Element; ///< Type of the grid element. - using Traits = FETraits; ///< Type of the traits. + using Traits = FETraits; ///< Type of the traits. + using RootBasis = typename Traits::FlatBasis; ///< Type of the root basis. + using LocalView = typename Traits::LocalView; ///< Type of the local view. + using GlobalIndex = typename Traits::GlobalIndex; ///< Type of the global index. + using GridElement = typename Traits::Element; ///< Type of the grid element. /** * @brief Constructor for the PowerBasisFE class. @@ -36,7 +36,7 @@ public: * @param element The local element. */ explicit PowerBasisFE(const Basis& p_basis, const typename LocalView::Element& element) - : localView_{p_basis.localView()} { + : localView_{p_basis.flat().localView()} { static_assert(Ikarus::Concepts::PowerBasis, "You didn't pass a localview of a power basis to this method"); static_assert(RootBasis::PreBasis::Node::degree() != 1, "The basis has only one children. Maybe use scalarFE.hh."); diff --git a/ikarus/finiteelements/febases/scalarfe.hh b/ikarus/finiteelements/febases/scalarfe.hh index ed924a3f6..1e0c1cb27 100644 --- a/ikarus/finiteelements/febases/scalarfe.hh +++ b/ikarus/finiteelements/febases/scalarfe.hh @@ -21,12 +21,13 @@ template class ScalarFieldFE { public: - using Basis = Basis_; ///< Type of the root basis. - using LocalView = typename Basis::LocalView; ///< Type of the local view. - using GlobalIndex = typename LocalView::MultiIndex; ///< Type of the global index. - using GridElement = typename LocalView::Element; ///< Type of the grid element. - using Traits = FETraits; ///< Type of the traits. - static constexpr int worlddim = Traits::worlddim; ///< Dimension of the world space. + using Traits = FETraits; ///< Type of the traits. + using Basis = typename Traits::Basis; ///< Type of the basis. + using RootBasis = typename Traits::FlatBasis; ///< Type of the root basis. + using LocalView = typename Traits::LocalView; ///< Type of the local view. + using GlobalIndex = typename Traits::GlobalIndex; ///< Type of the global index. + using GridElement = typename Traits::Element; ///< Type of the grid element. + static constexpr int worlddim = Traits::worlddim; ///< Dimension of the world space. /** * @brief Constructor for the ScalarFieldFE class. * @@ -34,8 +35,8 @@ public: * @param element The local element. */ explicit ScalarFieldFE(const Basis& basis, const typename LocalView::Element& element) - : localView_{basis.localView()} { - static_assert(Basis::PreBasis::Node::CHILDREN == 0, "This is no scalar basis!"); + : localView_{basis.flat().localView()} { + static_assert(RootBasis::PreBasis::Node::CHILDREN == 0, "This is no scalar basis!"); localView_.bind(element); } diff --git a/ikarus/finiteelements/fetraits.hh b/ikarus/finiteelements/fetraits.hh index 745eee8b4..dd16dff5e 100644 --- a/ikarus/finiteelements/fetraits.hh +++ b/ikarus/finiteelements/fetraits.hh @@ -8,30 +8,59 @@ #pragma once +#include #include namespace Ikarus { /** - * \brief Template structure defining traits for a given grid element entity type. + * \brief Traits for handling finite elements. * - * \tparam GridElement Type of the grid element entity. + * \tparam Basis_ The basis type for the finite element. + * \tparam FERequirements_ The requirements for the finite element. * \tparam useRef Boolean indicating whether to use Eigen::Ref for VectorType and MatrixType. */ -template +template , bool useRef = false> struct FETraits { + /** \brief Type of the basis of the finite element */ + using Basis = Basis_; + + /** \brief Type of the requirements for the finite element */ + using FERequirementType = FERequirements_; + + /** \brief Type of the result requirements */ + using ResultRequirementsType = ResultRequirements; + + /** \brief Type of the flat basis */ + using FlatBasis = typename Basis::FlatBasis; + + /** \brief Type of the local view */ + using LocalView = typename FlatBasis::LocalView; + + /** \brief Type of the grid view */ + using GridView = typename FlatBasis::GridView; + + /** \brief Type of the grid element */ + using Element = typename LocalView::Element; + + /** \brief Type of the element geometry */ + using Geometry = typename Element::Geometry; + + /** \brief Type of the global index */ + using GlobalIndex = typename LocalView::MultiIndex; + /** \brief Type used for coordinates */ using ctype = double; /** \brief Dimension of the world space */ - static constexpr int worlddim = GridElement::Geometry::coorddimension; + static constexpr int worlddim = Geometry::coorddimension; /** \brief Dimension of the geometry */ - static constexpr int mydim = GridElement::mydimension; + static constexpr int mydim = Element::mydimension; /** \brief Dimension of the grid */ - static constexpr int dimension = GridElement::dimension; + static constexpr int dimension = Element::dimension; /** \brief Type of the coordinate */ using GlobalCoordinates = Eigen::Matrix; @@ -40,13 +69,12 @@ struct FETraits using ParameterSpaceType = Eigen::Matrix; /** \brief Type of the internal forces */ - using VectorType = std::conditional_t, Eigen::VectorXd>; - - /** \brief Type of the internal forces */ - using ScalarType = ctype; + template + using VectorType = std::conditional_t>, Eigen::VectorX&>; /** \brief Type of the stiffness matrix */ - using MatrixType = std::conditional_t, Eigen::MatrixXd>; + template + using MatrixType = std::conditional_t>, Eigen::MatrixX&>; }; } // namespace Ikarus diff --git a/ikarus/finiteelements/mechanics/kirchhoffloveshell.hh b/ikarus/finiteelements/mechanics/kirchhoffloveshell.hh index 47b5727c4..a1ff98f50 100644 --- a/ikarus/finiteelements/mechanics/kirchhoffloveshell.hh +++ b/ikarus/finiteelements/mechanics/kirchhoffloveshell.hh @@ -36,14 +36,14 @@ namespace Ikarus { * @tparam useEigenRef A boolean indicating whether to use Eigen references for efficiency. */ template , bool useEigenRef = false> -class KirchhoffLoveShell : public PowerBasisFE, +class KirchhoffLoveShell : public PowerBasisFE, public Volume, - TraitsFromFE>, + FETraits>, public Traction, - TraitsFromFE> + FETraits> { public: - using Traits = TraitsFromFE; + using Traits = FETraits; using Basis = typename Traits::Basis; using FlatBasis = typename Traits::FlatBasis; using FERequirementType = typename Traits::FERequirementType; @@ -52,7 +52,7 @@ public: using GridView = typename Traits::GridView; using Element = typename Traits::Element; using ResultRequirementsType = typename Traits::ResultRequirementsType; - using BasePowerFE = PowerBasisFE; // Handles globalIndices function + using BasePowerFE = PowerBasisFE; // Handles globalIndices function using VolumeType = Volume, Traits>; using TractionType = Traction, Traits>; using LocalBasisType = decltype(std::declval().tree().child(0).finiteElement().localBasis()); @@ -106,7 +106,7 @@ public: double thickness, VolumeLoad p_volumeLoad = {}, const BoundaryPatch* p_neumannBoundary = nullptr, NeumannBoundaryLoad p_neumannBoundaryLoad = {}) - : BasePowerFE(globalBasis.flat(), element), + : BasePowerFE(globalBasis, element), VolumeType(p_volumeLoad), TractionType(p_neumannBoundary, p_neumannBoundaryLoad), emod_{emod}, diff --git a/ikarus/finiteelements/mechanics/linearelastic.hh b/ikarus/finiteelements/mechanics/linearelastic.hh index 8311fbfb0..ef891192a 100644 --- a/ikarus/finiteelements/mechanics/linearelastic.hh +++ b/ikarus/finiteelements/mechanics/linearelastic.hh @@ -24,6 +24,7 @@ #include #include #include + #include #include #include #include @@ -42,14 +43,14 @@ namespace Ikarus { * @tparam useEigenRef A boolean flag indicating whether to use Eigen references. */ template , bool useEigenRef = false> -class LinearElastic : public PowerBasisFE, +class LinearElastic : public PowerBasisFE, public Volume, - TraitsFromFE>, + FETraits>, public Traction, - TraitsFromFE> + FETraits> { public: - using Traits = TraitsFromFE; + using Traits = FETraits; using Basis = typename Traits::Basis; using FlatBasis = typename Traits::FlatBasis; using FERequirementType = typename Traits::FERequirementType; @@ -58,7 +59,7 @@ public: using GridView = typename Traits::GridView; using Element = typename Traits::Element; using ResultRequirementsType = typename Traits::ResultRequirementsType; - using BaseDisp = PowerBasisFE; // Handles globalIndices function + using BaseDisp = PowerBasisFE; // Handles globalIndices function using VolumeType = Volume, Traits>; using TractionType = Traction, Traits>; static constexpr int myDim = Traits::mydim; @@ -81,7 +82,7 @@ public: LinearElastic(const Basis& globalBasis, const typename LocalView::Element& element, double emod, double nu, VolumeLoad p_volumeLoad = {}, const BoundaryPatch* p_neumannBoundary = nullptr, NeumannBoundaryLoad p_neumannBoundaryLoad = {}) - : BaseDisp(globalBasis.flat(), element), + : BaseDisp(globalBasis, element), VolumeType(p_volumeLoad), TractionType(p_neumannBoundary, p_neumannBoundaryLoad), emod_{emod}, diff --git a/ikarus/finiteelements/mechanics/nonlinearelastic.hh b/ikarus/finiteelements/mechanics/nonlinearelastic.hh index c13e7e659..a928c2a1a 100644 --- a/ikarus/finiteelements/mechanics/nonlinearelastic.hh +++ b/ikarus/finiteelements/mechanics/nonlinearelastic.hh @@ -21,6 +21,7 @@ #include #include #include + #include #include #include #include @@ -41,14 +42,14 @@ namespace Ikarus { * @tparam useEigenRef A boolean flag indicating whether to use Eigen references. */ template , bool useEigenRef = false> -class NonLinearElastic : public PowerBasisFE, +class NonLinearElastic : public PowerBasisFE, public Volume, - TraitsFromFE>, + FETraits>, public Traction, - TraitsFromFE> + FETraits> { public: - using Traits = TraitsFromFE; + using Traits = FETraits; using Basis = typename Traits::Basis; using FlatBasis = typename Traits::FlatBasis; using FERequirementType = typename Traits::FERequirementType; @@ -57,7 +58,7 @@ public: using GridView = typename Traits::GridView; using Element = typename Traits::Element; using ResultRequirementsType = typename Traits::ResultRequirementsType; - using BasePowerFE = PowerBasisFE; // Handles globalIndices function + using BasePowerFE = PowerBasisFE; // Handles globalIndices function using Material = Material_; using VolumeType = Volume, Traits>; using TractionType = Traction, Traits>; @@ -82,7 +83,7 @@ public: NonLinearElastic(const Basis& globalBasis, const typename LocalView::Element& element, const Material& p_mat, VolumeLoad p_volumeLoad = {}, const BoundaryPatch* p_neumannBoundary = nullptr, NeumannBoundaryLoad p_neumannBoundaryLoad = {}) - : BasePowerFE(globalBasis.flat(), element), + : BasePowerFE(globalBasis, element), VolumeType(p_volumeLoad), TractionType(p_neumannBoundary, p_neumannBoundaryLoad), mat{p_mat} { diff --git a/ikarus/finiteelements/physicshelper.hh b/ikarus/finiteelements/physicshelper.hh index 4d9e834e1..ecf3b3b38 100644 --- a/ikarus/finiteelements/physicshelper.hh +++ b/ikarus/finiteelements/physicshelper.hh @@ -11,8 +11,6 @@ #include #include - -#include namespace Ikarus { /** @@ -57,58 +55,6 @@ namespace Ikarus { return C; } -/** - * \brief Traits for handling finite elements. - * - * \tparam Basis_ The basis type for the finite element. - * \tparam FERequirements_ The requirements for the finite element. - * \tparam useRef Boolean indicating whether to use Eigen::Ref for VectorType and MatrixType. - */ -template -struct TraitsFromFE -{ - /** \brief Type of the basis of the finite element */ - using Basis = Basis_; - - /** \brief Type of the requirements for the finite element */ - using FERequirementType = FERequirements_; - - /** \brief Type of the result requirements */ - using ResultRequirementsType = ResultRequirements; - - /** \brief Type of the flat basis */ - using FlatBasis = typename Basis::FlatBasis; - - /** \brief Type of the local view */ - using LocalView = typename FlatBasis::LocalView; - - /** \brief Type of the grid view */ - using GridView = typename FlatBasis::GridView; - - /** \brief Type of the grid element */ - using Element = typename LocalView::Element; - - /** \brief Type of the element geometry */ - using Geometry = typename Element::Geometry; - - /** \brief Dimension of the world space */ - static constexpr int worlddim = Element::Geometry::coorddimension; - - /** \brief Dimension of the geometry */ - static constexpr int mydim = Element::mydimension; - - /** \brief Dimension of the grid */ - static constexpr int dimension = Element::dimension; - - /** \brief Type of the internal forces */ - template - using VectorType = std::conditional_t>, Eigen::VectorX&>; - - /** \brief Type of the stiffness matrix */ - template - using MatrixType = std::conditional_t>, Eigen::MatrixX&>; -}; - ///< Structure representing Young's modulus and Poisson's ratio. \brief see ///< https://en.wikipedia.org/wiki/Lam%C3%A9_parameters struct YoungsModulusAndPoissonsRatio diff --git a/tests/src/checkfebyautodiff.hh b/tests/src/checkfebyautodiff.hh index 7e618992a..11d4a0cb7 100644 --- a/tests/src/checkfebyautodiff.hh +++ b/tests/src/checkfebyautodiff.hh @@ -2,6 +2,7 @@ // SPDX-License-Identifier: LGPL-3.0-or-later #pragma once +#include #include #include