version 0.4.1
nonlinopfactory.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
16
17namespace Ikarus {
18
20{
21 template <typename Assembler, typename... Affordances>
22 static auto op(Assembler&& as, typename traits::remove_pointer_t<std::remove_cvref_t<Assembler>>::FERequirement& req,
23 AffordanceCollection<Affordances...> affordances, DBCOption dbcOption) {
24 auto assemblerPtr = [as]() {
25 if constexpr (std::is_pointer_v<std::remove_cvref_t<Assembler>> or
27 return as;
28 else
29 return std::make_shared<std::remove_cvref_t<Assembler>>(std::forward<Assembler>(as));
30 }();
31
32 using FERequirement = typename traits::remove_pointer_t<std::remove_cvref_t<Assembler>>::FERequirement;
33 [[maybe_unused]] auto KFunction = [dbcOption, assembler = assemblerPtr, affordances](
34 typename FERequirement::SolutionVectorType& globalSol,
35 typename FERequirement::ParameterType& parameter) -> auto& {
36 FERequirement req;
37 req.insertGlobalSolution(globalSol).insertParameter(parameter);
38
39 return assembler->matrix(req, affordances.matrixAffordance(), dbcOption);
40 };
41
42 [[maybe_unused]] auto residualFunction = [dbcOption, assembler = assemblerPtr, affordances](
43 typename FERequirement::SolutionVectorType& globalSol,
44 typename FERequirement::ParameterType& parameter) -> auto& {
45 FERequirement req;
46 req.insertGlobalSolution(globalSol).insertParameter(parameter);
47 return assembler->vector(req, affordances.vectorAffordance(), dbcOption);
48 };
49
50 assert(req.populated() && " Before you calls this method you have to pass populated fe requirements");
51 if constexpr (affordances.hasScalarAffordance) {
52 [[maybe_unused]] auto energyFunction = [assembler = assemblerPtr, affordances](
53 typename FERequirement::SolutionVectorType& globalSol,
54 typename FERequirement::ParameterType& parameter) -> auto& {
55 FERequirement req;
56 req.insertGlobalSolution(globalSol).insertParameter(parameter);
57
58 return assembler->scalar(req, affordances.scalarAffordance());
59 };
60 return NonLinearOperator(functions(std::move(energyFunction), std::move(residualFunction), std::move(KFunction)),
61 parameter(req.globalSolution(), req.parameter()));
62 } else
63 return NonLinearOperator(functions(std::move(residualFunction), std::move(KFunction)),
64 parameter(req.globalSolution(), req.parameter()));
65 }
66
67 template <typename Assembler>
68 static auto op(Assembler&& as, DBCOption dbcOption) {
69 auto ex = []() {
70 DUNE_THROW(Dune::InvalidStateException,
71 "Assembler has to be bound to a fe requirement and an affordance collection before you can call "
72 "this method");
73 };
74 if constexpr (std::is_pointer_v<std::remove_cvref_t<Assembler>> or
76 if (as->boundToRequirement() and as->boundToAffordanceCollection()) {
77 return op(std::forward<Assembler>(as), as->requirement(), as->affordanceCollection(), dbcOption);
78 } else {
79 ex();
80 }
81 } else {
82 if (as->boundToRequirement() and as->boundToAffordanceCollection()) {
83 return op(std::forward<Assembler>(as), as.requirement(), as.affordanceCollection(), dbcOption);
84 } else {
85 ex();
86 }
87 }
88 __builtin_unreachable();
89 }
90
91 template <typename Assembler>
92 static auto op(Assembler&& as) {
93 auto ex = []() {
94 DUNE_THROW(Dune::InvalidStateException,
95 "Assembler has to be bound to a fe requirement to an affordance collection and to an "
96 "DBCOption before you can call "
97 "this method");
98 };
99 if constexpr (std::is_pointer_v<std::remove_cvref_t<Assembler>> or
101 if (not as->bound())
102 ex();
103 return op(std::forward<Assembler>(as), as->requirement(), as->affordanceCollection(), as->dBCOption());
104 } else {
105 if (not as.bound())
106 ex();
107 return op(std::forward<Assembler>(as), as.requirement(), as.affordanceCollection(), as.dBCOption());
108 }
109 }
110
111 template <typename Assembler, typename... Affordances>
112 static auto op(Assembler&& as, AffordanceCollection<Affordances...> affordances,
113 DBCOption dbcOption = DBCOption::Full) {
114 auto ex = []() {
115 DUNE_THROW(Dune::InvalidStateException,
116 "Assembler has to be bound to a fe requirement before you can call "
117 "this method");
118 };
119
120 if constexpr (std::is_pointer_v<std::remove_cvref_t<Assembler>> or
122 if (not as->boundToRequirement())
123 ex();
124 return op(std::forward<Assembler>(as), as->requirement(), affordances, dbcOption);
125 } else {
126 if (not as.boundToRequirement())
127 ex();
128 return op(std::forward<Assembler>(as), as.requirement(), affordances, dbcOption);
129 }
130 }
131
132 template <typename Assembler>
133 static auto op(Assembler&& as, typename traits::remove_pointer_t<std::remove_cvref_t<Assembler>>::FERequirement& req,
134 DBCOption dbcOption) {
135 auto ex = []() {
136 DUNE_THROW(Dune::InvalidStateException,
137 "Assembler has to be bound to an affordance collection before you can call "
138 "this method");
139 };
140
141 if constexpr (std::is_pointer_v<std::remove_cvref_t<Assembler>> or
143 if (not as->boundToAffordanceCollection())
144 ex();
145 return op(std::forward<Assembler>(as), as->requirement(), as->affordanceCollection(), dbcOption);
146 } else {
147 if (not as.boundToAffordanceCollection())
148 ex();
149 return op(std::forward<Assembler>(as), as.requirement(), as.affordanceCollection(), dbcOption);
150 }
151 }
152};
153
154} // namespace Ikarus
Provides a NonLinearOperator class for handling nonlinear operators.
Definition of the LinearElastic class for finite element mechanics computations.
Definition: assemblermanipulatorbuildingblocks.hh:22
DBCOption
Definition: dirichletbcenforcement.hh:7
auto functions(Args &&... args)
Creates a Functions object.
Definition: nonlinearoperator.hh:127
NonLinearOperator(const Impl::Functions< DerivativeArgs &&... > &a, const Impl::Parameter< ParameterArgs... > &b) -> NonLinearOperator< Impl::Functions< DerivativeArgs... >, Impl::Parameter< ParameterArgs... > >
auto parameter(Args &&... args)
Creates a Parameter object.
Definition: nonlinearoperator.hh:115
typename remove_pointer< T >::type remove_pointer_t
Definition: traits.hh:156
Struct representing a collection of affordances.
Definition: ferequirements.hh:105
auto vectorAffordance() const
Definition: ferequirements.hh:157
static constexpr bool hasScalarAffordance
Definition: ferequirements.hh:112
auto scalarAffordance() const
Definition: ferequirements.hh:152
auto matrixAffordance() const
Definition: ferequirements.hh:162
Definition: nonlinopfactory.hh:20
static auto op(Assembler &&as)
Definition: nonlinopfactory.hh:92
static auto op(Assembler &&as, DBCOption dbcOption)
Definition: nonlinopfactory.hh:68
static auto op(Assembler &&as, typename traits::remove_pointer_t< std::remove_cvref_t< Assembler > >::FERequirement &req, DBCOption dbcOption)
Definition: nonlinopfactory.hh:133
static auto op(Assembler &&as, typename traits::remove_pointer_t< std::remove_cvref_t< Assembler > >::FERequirement &req, AffordanceCollection< Affordances... > affordances, DBCOption dbcOption)
Definition: nonlinopfactory.hh:22
static auto op(Assembler &&as, AffordanceCollection< Affordances... > affordances, DBCOption dbcOption=DBCOption::Full)
Definition: nonlinopfactory.hh:112
Type trait to check if a type is a isSharedPtr.
Definition: traits.hh:134