version 0.4.1
simpleassemblers.hh
Go to the documentation of this file.
1// SPDX-FileCopyrightText: 2021-2024 The Ikarus Developers mueller@ibb.uni-stuttgart.de
2// SPDX-License-Identifier: LGPL-3.0-or-later
3
9#pragma once
10
11#include <utility>
12
13#include <Eigen/Core>
14#include <Eigen/Sparse>
15
18
19namespace Ikarus {
27template <typename FEC, typename DV>
28class ScalarFlatAssembler : public ScalarAssembler<ScalarFlatAssembler<FEC, DV>, FEC, DV, double>,
29 public FlatAssemblerBase<FEC, DV>
30{
31protected:
34
35 using Base::Base;
36
37public:
38 using typename Base::Basis;
39 using typename Base::DirichletValuesType;
40 using typename Base::FEContainer;
41 using typename Base::FERequirement;
42 using typename Base::GlobalIndex;
44
45protected:
46 ScalarType& getScalarImpl(const FERequirement& feRequirements, ScalarAffordance affordance);
47
49};
50
51#ifndef DOXYGEN
52template <class T, class DirichletValuesType>
53ScalarFlatAssembler(T&& fes, const DirichletValuesType& dirichletValues) -> ScalarFlatAssembler<T, DirichletValuesType>;
54#endif
55
63template <typename FEC, typename DV>
65 public VectorAssembler<VectorFlatAssembler<FEC, DV>, FEC, DV, Eigen::VectorXd>
66{
67protected:
70
71 using Base::Base;
72
73public:
74 using typename Base::Basis;
75 using typename Base::DirichletValuesType;
76 using typename Base::FEContainer;
77 using typename Base::FERequirement;
78 using typename Base::GlobalIndex;
79
80 using typename Base::ScalarType;
82
83protected:
84 void assembleRawVectorImpl(const FERequirement& feRequirements, VectorAffordance affordance, VectorType& assemblyVec);
85 VectorType& getRawVectorImpl(const FERequirement& feRequirements, VectorAffordance affordance);
86 VectorType& getVectorImpl(const FERequirement& feRequirements, VectorAffordance affordance);
87
88 VectorType& getReducedVectorImpl(const FERequirement& feRequirements, VectorAffordance affordance);
89
93};
94
95#ifndef DOXYGEN
96template <class T, class DirichletValuesType>
97VectorFlatAssembler(T&& fes, const DirichletValuesType& dirichletValues) -> VectorFlatAssembler<T, DirichletValuesType>;
98#endif
99
108template <typename FEC, typename DV>
109class SparseFlatAssembler : public MatrixAssembler<SparseFlatAssembler<FEC, DV>, FEC, DV, Eigen::SparseMatrix<double>>,
110 public VectorFlatAssembler<FEC, DV>
111{
112protected:
115
116 using Base::Base;
117
118public:
119 using typename Base::Basis;
120 using typename Base::DirichletValuesType;
121 using typename Base::FEContainer;
122 using typename Base::FERequirement;
123 using typename Base::GlobalIndex;
124 using typename Base::ScalarType;
125 using typename Base::VectorType;
127
128private:
129 void assembleRawMatrixImpl(const FERequirement& feRequirements, MatrixAffordance affordance, MatrixType& assemblyMat);
130
131protected:
132 MatrixType& getRawMatrixImpl(const FERequirement& feRequirements, MatrixAffordance affordance);
133 MatrixType& getMatrixImpl(const FERequirement& feRequirements, MatrixAffordance affordance);
134 MatrixType& getReducedMatrixImpl(const FERequirement& feRequirements, MatrixAffordance affordance);
135
136private:
139 void createOccupationPattern(MatrixType& assemblyMat);
140
143 void createReducedOccupationPattern(MatrixType& assemblyMat);
144
146 void createLinearDOFsPerElement(MatrixType& assemblyMat);
147
150 void createLinearDOFsPerElementReduced(MatrixType& assemblyMat);
151
153 void preProcessSparseMatrix(MatrixType& assemblyMat);
154
156 void preProcessSparseMatrixReduced(MatrixType& assemblyMat);
157
158 MatrixType spMatRaw_;
159 MatrixType spMat_;
160 MatrixType spMatReduced_;
161 std::vector<std::vector<Eigen::Index>>
162 elementLinearIndices_;
163 std::vector<std::vector<Eigen::Index>>
164 elementLinearReducedIndices_;
165 bool sparsePreProcessorRaw_{}, sparsePreProcessor_{},
166 sparsePreProcessorReduced_{};
167};
168
169#ifndef DOXYGEN
170template <class FEC, class DV>
171SparseFlatAssembler(FEC&& fes, const DV& dirichletValues) -> SparseFlatAssembler<FEC, DV>;
172#endif
173
174template <typename FEC, typename DV>
175auto makeSparseFlatAssembler(FEC&& fes, const DV& dirichletValues) {
176 return std::make_shared<SparseFlatAssembler<FEC, DV>>(std::forward<FEC>(fes), dirichletValues);
177}
178
188template <typename FEC, typename DV>
189class DenseFlatAssembler : public MatrixAssembler<DenseFlatAssembler<FEC, DV>, FEC, DV, Eigen::MatrixXd>,
190 public VectorFlatAssembler<FEC, DV>
191{
192protected:
195
196 using Base::Base;
197
198public:
199 using typename Base::Basis;
200 using typename Base::DirichletValuesType;
201 using typename Base::FEContainer;
202 using typename Base::FERequirement;
203 using typename Base::GlobalIndex;
204 using typename Base::ScalarType;
205 using typename Base::VectorType;
207
208private:
209 void assembleRawMatrixImpl(const FERequirement& feRequirements, MatrixAffordance affordance, MatrixType& assemblyMat);
210
211protected:
212 MatrixType& getRawMatrixImpl(const FERequirement& feRequirements, MatrixAffordance affordance);
213 MatrixType& getMatrixImpl(const FERequirement& feRequirements, MatrixAffordance affordance);
214 MatrixType& getReducedMatrixImpl(const FERequirement& feRequirements, MatrixAffordance affordance);
215
216private:
217 MatrixType matRaw_{};
218 MatrixType mat_{};
219 MatrixType matRed_{};
220};
221
222#ifndef DOXYGEN
223// https://en.cppreference.com/w/cpp/language/class_template_argument_deduction
224template <class FEC, class DV>
225DenseFlatAssembler(FEC&& fes, const DV& dirichletValues) -> DenseFlatAssembler<FEC, DV>;
226#endif
227
228template <typename FEC, typename DV>
229auto makeDenseFlatAssembler(FEC&& fes, const DV& dirichletValues) {
230 return std::make_shared<DenseFlatAssembler<FEC, DV>>(std::forward<FEC>(fes), dirichletValues);
231}
232} // namespace Ikarus
233
234#include "simpleassemblers.inl"
Implementation of assembler functions.
Definition of the LinearElastic class for finite element mechanics computations.
Definition: assemblermanipulatorbuildingblocks.hh:22
MatrixAffordance
A strongly typed enum class representing the matrix affordance.
Definition: ferequirements.hh:63
auto makeSparseFlatAssembler(FEC &&fes, const DV &dirichletValues)
Definition: simpleassemblers.hh:175
auto makeDenseFlatAssembler(FEC &&fes, const DV &dirichletValues)
Definition: simpleassemblers.hh:229
VectorAffordance
A strongly typed enum class representing the vector affordance.
Definition: ferequirements.hh:48
ScalarAffordance
A strongly typed enum class representing the scalar affordance.
Definition: ferequirements.hh:37
def dirichletValues(basis)
Definition: dirichlet_values.py:38
The FlatAssemblerBase takes care of common subtasks done by flat assemblers.
Definition: assembler/interface.hh:30
typename FEContainerRaw::value_type::Requirement FERequirement
Type of the finite element requirement.
Definition: assembler/interface.hh:34
FEC FEContainer
Type of the finite element container (reference or by value).
Definition: assembler/interface.hh:39
typename FEContainerRaw::value_type::GlobalIndex GlobalIndex
Type of the global index.
Definition: assembler/interface.hh:35
DV DirichletValuesType
Type of the Dirichlet values.
Definition: assembler/interface.hh:40
typename DV::Basis Basis
Type of the basis.
Definition: assembler/interface.hh:36
The ScalarAssembler provides an interface for an assembler that assembles scalar quantities.
Definition: assembler/interface.hh:267
ST ScalarType
Definition: assembler/interface.hh:270
The VectorAssembler provides an interface for an assembler that assembles vector quantities.
Definition: assembler/interface.hh:312
VT VectorType
Definition: assembler/interface.hh:315
The MatrixAssembler provides an interface for an assembler that assembles matrix quantities.
Definition: assembler/interface.hh:389
Eigen::SparseMatrix< double > MatrixType
Definition: assembler/interface.hh:392
ScalarFlatAssembler assembles scalar quantities.
Definition: simpleassemblers.hh:30
typename FEContainerRaw::value_type::Requirement FERequirement
Type of the finite element requirement.
Definition: assembler/interface.hh:34
FEC FEContainer
Type of the finite element container (reference or by value).
Definition: assembler/interface.hh:39
ScalarType & getScalarImpl(const FERequirement &feRequirements, ScalarAffordance affordance)
Definition: simpleassemblers.inl:15
ScalarType scal_
Definition: simpleassemblers.hh:48
typename FEContainerRaw::value_type::GlobalIndex GlobalIndex
Type of the global index.
Definition: assembler/interface.hh:35
DV DirichletValuesType
Type of the Dirichlet values.
Definition: assembler/interface.hh:40
FlatAssemblerBase< FEC, DV > Base
Type alias for the base class.
Definition: simpleassemblers.hh:32
typename DV::Basis Basis
Type of the basis.
Definition: assembler/interface.hh:36
VectorFlatAssembler assembles vector quantities using a flat basis Indexing strategy.
Definition: simpleassemblers.hh:66
VectorType vecRed_
Reduced vector quantity.
Definition: simpleassemblers.hh:92
VectorType vec_
Vector quantity.
Definition: simpleassemblers.hh:91
typename FEContainerRaw::value_type::Requirement FERequirement
Type of the finite element requirement.
Definition: assembler/interface.hh:34
ScalarFlatAssembler< FEC, DV > Base
Type alias for the base class.
Definition: simpleassemblers.hh:68
FEC FEContainer
Type of the finite element container (reference or by value).
Definition: assembler/interface.hh:39
void assembleRawVectorImpl(const FERequirement &feRequirements, VectorAffordance affordance, VectorType &assemblyVec)
Definition: simpleassemblers.inl:42
VectorType & getRawVectorImpl(const FERequirement &feRequirements, VectorAffordance affordance)
Definition: simpleassemblers.inl:62
typename FEContainerRaw::value_type::GlobalIndex GlobalIndex
Type of the global index.
Definition: assembler/interface.hh:35
VectorType & getReducedVectorImpl(const FERequirement &feRequirements, VectorAffordance affordance)
Definition: simpleassemblers.inl:79
VectorType & getVectorImpl(const FERequirement &feRequirements, VectorAffordance affordance)
Definition: simpleassemblers.inl:69
DV DirichletValuesType
Type of the Dirichlet values.
Definition: assembler/interface.hh:40
VectorType vecRaw_
Raw vector without changes for dirichlet degrees of freedom.
Definition: simpleassemblers.hh:90
typename DV::Basis Basis
Type of the basis.
Definition: assembler/interface.hh:36
SparseFlatAssembler assembles matrix quantities using a flat basis Indexing strategy....
Definition: simpleassemblers.hh:111
MatrixType & getMatrixImpl(const FERequirement &feRequirements, MatrixAffordance affordance)
Definition: simpleassemblers.inl:134
MatrixType & getReducedMatrixImpl(const FERequirement &feRequirements, MatrixAffordance affordance)
Definition: simpleassemblers.inl:154
MatrixType & getRawMatrixImpl(const FERequirement &feRequirements, MatrixAffordance affordance)
Definition: simpleassemblers.inl:122
DenseFlatAssembler assembles matrix quantities using a flat basis Indexing strategy....
Definition: simpleassemblers.hh:191
MatrixType & getRawMatrixImpl(const FERequirement &feRequirements, MatrixAffordance affordance)
Definition: simpleassemblers.inl:306
MatrixType & getMatrixImpl(const FERequirement &feRequirements, MatrixAffordance affordance)
Definition: simpleassemblers.inl:313
MatrixType & getReducedMatrixImpl(const FERequirement &feRequirements, MatrixAffordance affordance)
Definition: simpleassemblers.inl:329
Defines the interface for flat, scalar, vector and matrix assemblers.