14#include <dune/functions/backends/istlvectorbackend.hh>
17#include <Eigen/Sparse>
33template <
typename FEC,
typename DV>
40 using GlobalIndex =
typename FEContainerRaw::value_type::GlobalIndex;
41 using Basis =
typename DV::Basis;
57 constraintsBelow_.reserve(dirichletValues_->size());
59 for (
auto iv : std::ranges::iota_view{
decltype(dirichletValues_->size())(0), dirichletValues_->size()}) {
60 constraintsBelow_.emplace_back(counter);
61 if (dirichletValues_->isConstrained(iv))
64 fixedDofs_ = dirichletValues_->fixedDOFsize();
71 size_t reducedSize() {
return dirichletValues_->size() - fixedDofs_; }
77 size_t size() {
return dirichletValues_->size(); }
86 Eigen::VectorXd
createFullVector(Eigen::Ref<const Eigen::VectorXd> reducedVector);
108 [[nodiscard]]
bool isConstrained(
size_t i)
const {
return dirichletValues_->isConstrained(i); }
117 return dirichletValues_->basis().gridView().size(GridView::dimension) * 8;
130 req_ = std::make_optional<FERequirement>(req);
132 dBCOption_ = std::make_optional<DBCOption>(dbcOption);
156 void bind(
DBCOption dbcOption) { dBCOption_ = std::make_optional<DBCOption>(dbcOption); }
168 DUNE_THROW(Dune::InvalidStateException,
"The assembler is not bound to a requirement, affordance or dBCOption.");
178 return req_.has_value();
188 return affordances_.has_value();
198 return dBCOption_.has_value();
206 if (req_.has_value())
209 DUNE_THROW(Dune::InvalidStateException,
"The requirement can only be obtained after binding");
217 if (affordances_.has_value())
218 return affordances_.value();
220 DUNE_THROW(Dune::InvalidStateException,
"The affordance can only be obtained after binding");
228 if (dBCOption_.has_value())
229 return dBCOption_.value();
231 DUNE_THROW(Dune::InvalidStateException,
"The dBCOption can only be obtained after binding");
237 std::optional<FERequirement> req_;
238 std::optional<AffordanceCollectionType> affordances_;
239 std::vector<size_t> constraintsBelow_{};
241 std::optional<DBCOption> dBCOption_;
245template <
class T,
class DirichletValuesType>
246FlatAssemblerBase(T&& fes,
const DirichletValuesType&
dirichletValues) -> FlatAssemblerBase<T, DirichletValuesType>;
256template <
typename FEC,
typename DV>
286 return getScalarImpl(feRequirements, affordance);
306 scal_ += calculateScalar(fe, feRequirements, affordance);
315template <
class T,
class DirichletValuesType>
316ScalarAssembler(T&& fes,
const DirichletValuesType&
dirichletValues) -> ScalarAssembler<T, DirichletValuesType>;
326template <
typename FEC,
typename DV>
365 return getRawVectorImpl(feRequirements, affordance);
367 return getReducedVectorImpl(feRequirements, affordance);
369 return getVectorImpl(feRequirements, affordance);
371 __builtin_unreachable();
400 Eigen::VectorXd& assemblyVec);
406 Eigen::VectorXd vecRaw_{};
407 Eigen::VectorXd vec_{};
408 Eigen::VectorXd vecRed_{};
412template <
class T,
class DirichletValuesType>
413VectorFlatAssembler(T&& fes,
const DirichletValuesType&
dirichletValues) -> VectorFlatAssembler<T, DirichletValuesType>;
424template <
typename FEC,
typename DV>
462 return getRawMatrixImpl(feRequirements, affordance);
464 return getReducedMatrixImpl(feRequirements, affordance);
466 return getMatrixImpl(feRequirements, affordance);
468 __builtin_unreachable();
495 Eigen::SparseMatrix<double>& assemblyMat);
502 void createOccupationPattern(Eigen::SparseMatrix<double>& assemblyMat);
506 void createReducedOccupationPattern(Eigen::SparseMatrix<double>& assemblyMat);
509 void createLinearDOFsPerElement(Eigen::SparseMatrix<double>& assemblyMat);
513 void createLinearDOFsPerElementReduced(Eigen::SparseMatrix<double>& assemblyMat);
516 void preProcessSparseMatrix(Eigen::SparseMatrix<double>& assemblyMat);
519 void preProcessSparseMatrixReduced(Eigen::SparseMatrix<double>& assemblyMat);
521 Eigen::SparseMatrix<double> spMatRaw_;
522 Eigen::SparseMatrix<double> spMat_;
523 Eigen::SparseMatrix<double> spMatReduced_;
524 std::vector<std::vector<Eigen::Index>>
525 elementLinearIndices_;
526 std::vector<std::vector<Eigen::Index>>
527 elementLinearReducedIndices_;
528 bool sparsePreProcessorRaw_{}, sparsePreProcessor_{},
529 sparsePreProcessorReduced_{};
533template <
class FEC,
class DV>
534SparseFlatAssembler(FEC&& fes,
const DV&
dirichletValues) -> SparseFlatAssembler<FEC, DV>;
537template <
typename FEC,
typename DV>
539 return std::make_shared<SparseFlatAssembler<FEC, DV>>(std::forward<FEC>(fes),
dirichletValues);
551template <
typename FEC,
typename DV>
588 return getRawMatrixImpl(feRequirements, affordance);
590 return getReducedMatrixImpl(feRequirements, affordance);
592 return getMatrixImpl(feRequirements, affordance);
594 __builtin_unreachable();
620 Eigen::MatrixXd& assemblyMat);
625 Eigen::MatrixXd matRaw_{};
626 Eigen::MatrixXd mat_{};
627 Eigen::MatrixXd matRed_{};
632template <
class FEC,
class DV>
633DenseFlatAssembler(FEC&& fes,
const DV&
dirichletValues) -> DenseFlatAssembler<FEC, DV>;
636template <
typename FEC,
typename DV>
638 return std::make_shared<DenseFlatAssembler<FEC, DV>>(std::forward<FEC>(fes),
dirichletValues);
Implementation of assembler functions.
Definition of the LinearElastic class for finite element mechanics computations.
Definition: dirichletbcenforcement.hh:6
auto vectorAffordance(MatrixAffordance affordanceM)
Definition: ferequirements.hh:176
MatrixAffordance
A strongly typed enum class representing the matrix affordance.
Definition: ferequirements.hh:63
auto makeSparseFlatAssembler(FEC &&fes, const DV &dirichletValues)
Definition: simpleassemblers.hh:538
auto scalarAffordance(MatrixAffordance affordanceM)
Definition: ferequirements.hh:185
DBCOption
Definition: dirichletbcenforcement.hh:7
auto makeDenseFlatAssembler(FEC &&fes, const DV &dirichletValues)
Definition: simpleassemblers.hh:637
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:7
The FlatAssemblerBase takes care of common subtasks done by flat assemblers.
Definition: simpleassemblers.hh:35
void bind(AffordanceCollectionType affordanceCollection)
Binds the assembler to an affordance collection.
Definition: simpleassemblers.hh:147
std::remove_cvref_t< FEC > FEContainerRaw
Type of the raw finite element container.
Definition: simpleassemblers.hh:37
FlatAssemblerBase(FEContainer &&fes, const DirichletValuesType &dirichletValues)
Constructor for FlatAssemblerBase.
Definition: simpleassemblers.hh:54
void bind(const FERequirement &req, AffordanceCollectionType affordanceCollection, DBCOption dbcOption=DBCOption::Full)
Binds the assembler to a set of finite element requirement and affordance.
Definition: simpleassemblers.hh:128
typename FEContainerRaw::value_type::Requirement FERequirement
Type of the finite element requirement.
Definition: simpleassemblers.hh:39
void bind(DBCOption dbcOption)
Binds the assembler to an affordance collection.
Definition: simpleassemblers.hh:156
void bind(const FERequirement &req)
Binds the assembler to a finite element requirement.
Definition: simpleassemblers.hh:140
bool boundToAffordanceCollection() const
Returns true if the assembler is bound to an affordance collection.
Definition: simpleassemblers.hh:187
FEC FEContainer
Type of the finite element container.
Definition: simpleassemblers.hh:43
Eigen::VectorXd createFullVector(Eigen::Ref< const Eigen::VectorXd > reducedVector)
Creates the full-sized vector of size Dof and inserts the values of a reduced vector at the "free" de...
Definition: simpleassemblers.inl:15
FERequirement & requirement()
Returns the requirement.
Definition: simpleassemblers.hh:205
bool boundToRequirement() const
Returns true if the assembler is bound to a finite element requirement.
Definition: simpleassemblers.hh:177
bool boundToDBCOption() const
Returns true if the assembler is bound to an affordance collection.
Definition: simpleassemblers.hh:197
DBCOption dBCOption() const
Returns the dirichlet boundary condition enforcement option.
Definition: simpleassemblers.hh:227
bool isConstrained(size_t i) const
Returns true if a given degree of freedom is fixed by a Dirichlet boundary condition.
Definition: simpleassemblers.hh:108
size_t reducedSize()
Returns the size of the free degrees of freedom, which are not fixed by a Dirichlet boundary conditio...
Definition: simpleassemblers.hh:71
typename FEContainerRaw::value_type::GlobalIndex GlobalIndex
Type of the global index.
Definition: simpleassemblers.hh:40
size_t constraintsBelow(size_t i) const
Returns the number of constraints below a given degrees of freedom index.
Definition: simpleassemblers.hh:100
auto & finiteElements() const
Returns the container of finite elements.
Definition: simpleassemblers.hh:92
DV DirichletValuesType
Type of the Dirichlet values.
Definition: simpleassemblers.hh:46
typename Basis::GridView GridView
Type of the grid view.
Definition: simpleassemblers.hh:42
std::conditional_t< std::is_reference_v< FEContainer >, const FEContainer, FEContainer > FEContainerType
Type of the finite element container (reference or by value).
Definition: simpleassemblers.hh:45
bool bound() const
Returns true if the assembler is bound to a finite element requirement and affordance.
Definition: simpleassemblers.hh:164
size_t estimateOfConnectivity() const
Coarse estimate of node connectivity, i.e., this relates to the bandwidth of a sparse matrix....
Definition: simpleassemblers.hh:116
AffordanceCollectionType affordanceCollection() const
Returns the affordance.
Definition: simpleassemblers.hh:216
size_t size()
Returns the size of nodes, i.e., the number of degrees of freedom.
Definition: simpleassemblers.hh:77
typename DV::Basis Basis
Type of the basis.
Definition: simpleassemblers.hh:41
ScalarAssembler assembles scalar quantities.
Definition: simpleassemblers.hh:258
const double & scalar(const FERequirement &feRequirements, ScalarAffordance affordance)
Calculates the scalar quantity requested by feRequirements and affordance.
Definition: simpleassemblers.hh:285
const double & scalar()
Calculates the scalar quantity requested by the bound feRequirements and returns a reference.
Definition: simpleassemblers.hh:294
typename FEContainerRaw::value_type::Requirement FERequirement
Type of the finite element requirement.
Definition: simpleassemblers.hh:39
FEC FEContainer
Type of the finite element container.
Definition: simpleassemblers.hh:43
typename FEContainerRaw::value_type::GlobalIndex GlobalIndex
Type of the global index.
Definition: simpleassemblers.hh:40
DV DirichletValuesType
Type of the Dirichlet values.
Definition: simpleassemblers.hh:46
ScalarAssembler(FEContainer &&fes, const DirichletValuesType &dirichletValues)
Constructor for ScalarAssembler.
Definition: simpleassemblers.hh:275
typename DV::Basis Basis
Type of the basis.
Definition: simpleassemblers.hh:41
VectorFlatAssembler assembles vector quantities using a flat basis Indexing strategy.
Definition: simpleassemblers.hh:328
const Eigen::VectorXd & vector()
Calculates the vectorial quantity requested by the bound feRequirements, the affordance and the dBCOp...
Definition: simpleassemblers.hh:396
typename FEContainerRaw::value_type::Requirement FERequirement
Type of the finite element requirement.
Definition: simpleassemblers.hh:39
FEC FEContainer
Type of the finite element container.
Definition: simpleassemblers.hh:43
const Eigen::VectorXd & vector(const FERequirement &feRequirements, VectorAffordance affordance, DBCOption dbcOption=DBCOption::Full)
Calculates the vectorial quantity requested by the feRequirements and the affordance....
Definition: simpleassemblers.hh:362
typename FEContainerRaw::value_type::GlobalIndex GlobalIndex
Type of the global index.
Definition: simpleassemblers.hh:40
DV DirichletValuesType
Type of the Dirichlet values.
Definition: simpleassemblers.hh:46
const Eigen::VectorXd & vector(DBCOption dbcOption)
Calculates the vectorial quantity requested by the bound feRequirements and the affordance....
Definition: simpleassemblers.hh:384
VectorFlatAssembler(FEContainer &&fes, const DirichletValuesType &dirichletValues)
Constructor for VectorFlatAssembler.
Definition: simpleassemblers.hh:346
typename DV::Basis Basis
Type of the basis.
Definition: simpleassemblers.hh:41
SparseFlatAssembler assembles matrix quantities using a flat basis Indexing strategy....
Definition: simpleassemblers.hh:426
typename FEContainerRaw::value_type::Requirement FERequirement
Type of the finite element requirement.
Definition: simpleassemblers.hh:39
const Eigen::SparseMatrix< double > & matrix(const FERequirement &feRequirements, MatrixAffordance affordance, DBCOption dbcOption=DBCOption::Full)
Calculates the matrix quantity requested by feRequirements and the affordance. For DBCOption::Full a ...
Definition: simpleassemblers.hh:459
const Eigen::SparseMatrix< double > & matrix(DBCOption dbcOption)
Calculates the matrix quantity requested by the bound feRequirements and the affordance.
Definition: simpleassemblers.hh:479
const Eigen::SparseMatrix< double > & matrix()
Calculates the matrix quantity requested by the bound feRequirements, the affordance and the dBCOptio...
Definition: simpleassemblers.hh:491
SparseFlatAssembler(FEContainer &&fes, const DirichletValuesType &dirichletValues)
Constructor for SparseFlatAssembler.
Definition: simpleassemblers.hh:443
DenseFlatAssembler assembles matrix quantities using a flat basis Indexing strategy....
Definition: simpleassemblers.hh:553
typename FEContainerRaw::value_type::Requirement FERequirement
Type of the finite element requirement.
Definition: simpleassemblers.hh:39
const Eigen::MatrixXd & matrix(DBCOption dbcOption)
Calculates the matrix quantity requested by the bound feRequirements and the affordance....
Definition: simpleassemblers.hh:606
const Eigen::MatrixXd & matrix(const FERequirement &feRequirements, MatrixAffordance affordance, DBCOption dbcOption=DBCOption::Full)
Calculates the matrix quantity requested by feRequirements and the affordance. For DBCOption::Full a ...
Definition: simpleassemblers.hh:585
const Eigen::MatrixXd & matrix()
Definition: simpleassemblers.hh:616
DenseFlatAssembler(FEContainer &&fes, const DirichletValuesType &dirichletValues)
< Type of the global index.
Definition: simpleassemblers.hh:570
Struct representing a collection of affordances.
Definition: ferequirements.hh:105
Definition of DirichletValues class for handling Dirichlet boundary conditions.