|
| 1 | +/****************************************************************************** |
| 2 | +* SOFA, Simulation Open-Framework Architecture * |
| 3 | +* (c) 2006 INRIA, USTL, UJF, CNRS, MGH * |
| 4 | +* * |
| 5 | +* This program is free software; you can redistribute it and/or modify it * |
| 6 | +* under the terms of the GNU Lesser General Public License as published by * |
| 7 | +* the Free Software Foundation; either version 2.1 of the License, or (at * |
| 8 | +* your option) any later version. * |
| 9 | +* * |
| 10 | +* This program is distributed in the hope that it will be useful, but WITHOUT * |
| 11 | +* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * |
| 12 | +* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License * |
| 13 | +* for more details. * |
| 14 | +* * |
| 15 | +* You should have received a copy of the GNU Lesser General Public License * |
| 16 | +* along with this program. If not, see <http://www.gnu.org/licenses/>. * |
| 17 | +******************************************************************************* |
| 18 | +* Authors: The SOFA Team and external contributors (see Authors.txt) * |
| 19 | +* * |
| 20 | +* Contact information: contact@sofa-framework.org * |
| 21 | +******************************************************************************/ |
| 22 | +#pragma once |
| 23 | +#include <sofa/fem/FiniteElement.h> |
| 24 | + |
| 25 | +#if !defined(SOFA_FEM_FINITE_ELEMENT_PRISM_CPP) |
| 26 | +#include <sofa/defaulttype/VecTypes.h> |
| 27 | +#endif |
| 28 | + |
| 29 | +namespace sofa::fem |
| 30 | +{ |
| 31 | + |
| 32 | +template <class DataTypes> |
| 33 | +struct FiniteElement<sofa::geometry::Prism, DataTypes> |
| 34 | +{ |
| 35 | + FINITEELEMENT_HEADER(sofa::geometry::Prism, DataTypes, 3); |
| 36 | + static_assert(spatial_dimensions == 3, "Prisms are only defined in 3D"); |
| 37 | + |
| 38 | + constexpr static std::array<ReferenceCoord, NumberOfNodesInElement> referenceElementNodes {{ |
| 39 | + {0, 0, 0}, |
| 40 | + {1, 0, 0}, |
| 41 | + {0, 1, 0}, |
| 42 | + {0, 0, 1}, |
| 43 | + {1, 0, 1}, |
| 44 | + {0, 1, 1}, |
| 45 | + }}; |
| 46 | + |
| 47 | + static const sofa::type::vector<TopologyElement>& getElementSequence(sofa::core::topology::BaseMeshTopology& topology) |
| 48 | + { |
| 49 | + return topology.getPrisms(); |
| 50 | + } |
| 51 | + |
| 52 | + static constexpr sofa::type::Vec<NumberOfNodesInElement, Real> shapeFunctions(const sofa::type::Vec<TopologicalDimension, Real>& q) |
| 53 | + { |
| 54 | + return { |
| 55 | + q[0] * q[2] - q[0] + q[1] * q[2] - q[1] - q[2] + 1, |
| 56 | + (1 - q[2]) * q[0], |
| 57 | + (1 - q[2]) * q[1], |
| 58 | + (-q[0] - q[1] + 1) * q[2], |
| 59 | + q[0] * q[2], |
| 60 | + q[1] * q[2] |
| 61 | + }; |
| 62 | + } |
| 63 | + |
| 64 | + static constexpr sofa::type::Mat<NumberOfNodesInElement, TopologicalDimension, Real> gradientShapeFunctions(const sofa::type::Vec<TopologicalDimension, Real>& q) |
| 65 | + { |
| 66 | + SOFA_UNUSED(q); |
| 67 | + return { |
| 68 | + {q[2] - 1, q[2] - 1, q[0] + q[1] - 1}, |
| 69 | + {1 - q[2], 0, -q[0]}, |
| 70 | + {0, 1 - q[2], -q[1]}, |
| 71 | + {-q[2], -q[2], -q[0] - q[1] + 1}, |
| 72 | + {q[2], 0, q[0]}, |
| 73 | + {0, q[2], q[1]}, |
| 74 | + }; |
| 75 | + } |
| 76 | + |
| 77 | + static constexpr std::array<QuadraturePointAndWeight, 2> quadraturePoints() |
| 78 | + { |
| 79 | + constexpr auto third = static_cast<Real>(1) / static_cast<Real>(3); |
| 80 | + constexpr auto sqrt_3 = static_cast<Real>(0.57735026919); // 1/sqrt(3) |
| 81 | + constexpr auto one = static_cast<Real>(1); |
| 82 | + constexpr QuadraturePoint q0 {third, third, static_cast<Real>(0.5) * (one - sqrt_3)}; |
| 83 | + constexpr QuadraturePoint q1 {third, third, static_cast<Real>(0.5) * (one + sqrt_3)}; |
| 84 | + |
| 85 | + constexpr std::array<QuadraturePointAndWeight, 2> q { |
| 86 | + std::make_pair(q0, 1./4.), |
| 87 | + std::make_pair(q1, 1./4.), |
| 88 | + }; |
| 89 | + return q; |
| 90 | + } |
| 91 | +}; |
| 92 | + |
| 93 | +#if !defined(SOFA_FEM_FINITE_ELEMENT_PRISM_CPP) |
| 94 | +extern template struct SOFA_FEM_API FiniteElement<sofa::geometry::Prism, sofa::defaulttype::Vec3Types>; |
| 95 | +#endif |
| 96 | + |
| 97 | +} |
0 commit comments