Skip to content

Commit b04c6ac

Browse files
committed
Add tests. Make getNumberOfComponents and allocateWorkspace free functions. Update EvaluatorConcept
1 parent 73e5e37 commit b04c6ac

32 files changed

Lines changed: 381 additions & 100 deletions

include/MGIS/Function/Algorithms.ixx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -255,14 +255,14 @@ namespace mgis::function {
255255
if (!areEquivalent(getSpace(f), getSpace(e))) {
256256
return ctx.registerErrorMessage("unmatched spaces");
257257
}
258-
if (f.getNumberOfComponents() != e.getNumberOfComponents()) {
258+
if (getNumberOfComponents(f) != getNumberOfComponents(e)) {
259259
return ctx.registerErrorMessage("unmatched number of components");
260260
}
261261
//
262262
if (!e.check(ctx)) {
263263
return false;
264264
}
265-
e.allocateWorkspace();
265+
allocateWorkspace(e);
266266
if constexpr ((internals::same_decay_type<function_result_type, real>)&& //
267267
(internals::same_decay_type<evaluator_result_type, real>)) {
268268
internals::assign_scalar_impl(f, e);
@@ -280,14 +280,14 @@ namespace mgis::function {
280280
requires(LinearElementSpaceConcept<std::decay_t<
281281
decltype(getSpace(std::declval<EvaluatorType>()))>>) {
282282
using Space = std::decay_t<decltype(getSpace(e))>;
283-
if (e.getNumberOfComponents() != 1) {
283+
if (getNumberOfComponents(e) != 1) {
284284
return ctx.registerErrorMessage("non scalar evaluator");
285285
}
286286
//
287287
if (!e.check(ctx)) {
288288
return false;
289289
}
290-
e.allocateWorkspace();
290+
allocateWorkspace(e);
291291
const auto& space = getSpace(e);
292292
const auto ne = getSpaceSize(space);
293293
auto r = initial_value;

include/MGIS/Function/BinaryOperation.hxx

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,11 @@ namespace mgis::function {
7272
constexpr BinaryOperationModifier(const CallableType&,
7373
const FirstEvaluatorType&,
7474
const SecondEvaluatorType&);
75+
//
76+
using internals::BinaryOperationModifierBase<
77+
CallableType,
78+
FirstEvaluatorType,
79+
SecondEvaluatorType>::getNumberOfComponents;
7580
//! \brief apply the modifier
7681
constexpr auto apply(const evaluator_result<FirstEvaluatorType>&,
7782
const evaluator_result<SecondEvaluatorType>&) const;
@@ -80,6 +85,15 @@ namespace mgis::function {
8085
CallableType modifier;
8186
};
8287

88+
//! \return the number of components
89+
template <typename CallableType,
90+
EvaluatorConcept FirstEvaluatorType,
91+
EvaluatorConcept SecondEvaluatorType>
92+
constexpr mgis::size_type getNumberOfComponents(
93+
const BinaryOperationModifier<CallableType,
94+
FirstEvaluatorType,
95+
SecondEvaluatorType>&);
96+
8397
template <typename CallableType,
8498
EvaluatorConcept FirstEvaluatorType,
8599
EvaluatorConcept SecondEvaluatorType>
@@ -110,11 +124,25 @@ namespace mgis::function {
110124
BinaryOperationModifier2,
111125
FirstEvaluatorType,
112126
SecondEvaluatorType>::BinaryOperationEvaluatorBase;
127+
//
128+
using internals::BinaryOperationModifierBase<
129+
CallableType,
130+
FirstEvaluatorType,
131+
SecondEvaluatorType>::getNumberOfComponents;
113132
//! \brief apply the modifier
114133
constexpr auto apply(const evaluator_result<FirstEvaluatorType>&,
115134
const evaluator_result<SecondEvaluatorType>&) const;
116135
};
117136

137+
//! \return the number of components
138+
template <typename CallableType,
139+
EvaluatorConcept FirstEvaluatorType,
140+
EvaluatorConcept SecondEvaluatorType>
141+
constexpr mgis::size_type getNumberOfComponents(
142+
const BinaryOperationModifier2<CallableType,
143+
FirstEvaluatorType,
144+
SecondEvaluatorType>&);
145+
118146
namespace internals {
119147

120148
template <typename CallableType, EvaluatorConcept SecondEvaluatorType>

include/MGIS/Function/BinaryOperation.ixx

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,26 @@ namespace mgis::function {
5656
return c(v1, v2);
5757
} // end of apply
5858

59+
template <typename CallableType,
60+
EvaluatorConcept FirstEvaluatorType,
61+
EvaluatorConcept SecondEvaluatorType>
62+
constexpr mgis::size_type getNumberOfComponents(
63+
const BinaryOperationModifier<CallableType,
64+
FirstEvaluatorType,
65+
SecondEvaluatorType>& e) {
66+
return e.getNumberOfComponents();
67+
} // end of getNumberOfComponents
68+
69+
template <typename CallableType,
70+
EvaluatorConcept FirstEvaluatorType,
71+
EvaluatorConcept SecondEvaluatorType>
72+
constexpr mgis::size_type getNumberOfComponents(
73+
const BinaryOperationModifier2<CallableType,
74+
FirstEvaluatorType,
75+
SecondEvaluatorType>& e) {
76+
return e.getNumberOfComponents();
77+
} // end of getNumberOfComponents
78+
5979
namespace internals {
6080

6181
template <typename CallableType, EvaluatorConcept SecondEvaluatorType>

include/MGIS/Function/BinaryOperationEvaluatorBase.hxx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,14 @@ namespace mgis::function {
120120
const BinaryOperationEvaluatorBase<Child,
121121
FirstEvaluatorType,
122122
SecondEvaluatorType>&);
123+
//! \brief allocate internal workspace
124+
template <typename Child,
125+
EvaluatorConcept FirstEvaluatorType,
126+
EvaluatorConcept SecondEvaluatorType>
127+
constexpr void allocateWorkspace(
128+
BinaryOperationEvaluatorBase<Child,
129+
FirstEvaluatorType,
130+
SecondEvaluatorType>&);
123131

124132
} // end of namespace mgis::function
125133

include/MGIS/Function/BinaryOperationEvaluatorBase.ixx

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,8 @@ namespace mgis::function {
7676
Child,
7777
FirstEvaluatorType,
7878
SecondEvaluatorType>::allocateWorkspace() {
79-
this->first_evaluator.allocateWorkspace();
80-
this->second_evaluator.allocateWorkspace();
79+
internals::disambiguateAllocateWorkspace(this->first_evaluator);
80+
internals::disambiguateAllocateWorkspace(this->second_evaluator);
8181
} // end of allocatWorkspace
8282

8383
template <typename Child,
@@ -169,6 +169,16 @@ namespace mgis::function {
169169
return e.getSpace();
170170
} // end of getSpace
171171

172+
template <typename Child,
173+
EvaluatorConcept FirstEvaluatorType,
174+
EvaluatorConcept SecondEvaluatorType>
175+
constexpr void allocateWorkspace(
176+
BinaryOperationEvaluatorBase<Child,
177+
FirstEvaluatorType,
178+
SecondEvaluatorType>& e){
179+
return e.allocateWorkspace();
180+
} // end of allocateWorkspace
181+
172182
} // end of namespace mgis::function
173183

174184
#endif /* LIB_MGIS_FUNCTION_BINARYOPERATIONEVALUATORBASE_IXX */

include/MGIS/Function/EvaluatorConcept.hxx

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,9 @@ namespace mgis::function {
150150
std::is_copy_constructible_v<EvaluatorType> && SpaceConcept<
151151
std::decay_t<decltype(getSpace(std::declval<EvaluatorType>()))>> &&
152152
requires(EvaluatorType& e) {
153-
e.allocateWorkspace();
153+
allocateWorkspace(e);
154+
} && requires(const EvaluatorType& e) {
155+
{ getNumberOfComponents(e) } -> std::same_as<mgis::size_type>;
154156
} &&((internals::EvaluatorResultQuery<EvaluatorType>::b1) ||
155157
(internals::EvaluatorResultQuery<EvaluatorType>::b2) ||
156158
(internals::EvaluatorResultQuery<EvaluatorType>::b3) ||
@@ -226,6 +228,18 @@ namespace mgis::function {
226228
*/
227229
template <EvaluatorConcept EvaluatorType>
228230
constexpr decltype(auto) disambiguateGetSpace(const EvaluatorType&);
231+
/*!
232+
* This helper function allows to disambiguate the call to
233+
* the allocateWorkspace function
234+
*/
235+
template <EvaluatorConcept EvaluatorType>
236+
constexpr void disambiguateAllocateWorkspace(const EvaluatorType&);
237+
/*!
238+
* This helper function allows to disambiguate the call to
239+
* the getNumberOfComponents function
240+
*/
241+
template <EvaluatorConcept EvaluatorType>
242+
constexpr mgis::size_type disambiguateGetNumberOfComponents(EvaluatorType&);
229243

230244
/*!
231245
* \brief number of components of a type when known at compile-time,

include/MGIS/Function/EvaluatorConcept.ixx

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,17 @@ namespace mgis::function::internals {
1515
return getSpace(e);
1616
}
1717

18+
template <EvaluatorConcept EvaluatorType>
19+
constexpr void disambiguateAllocateWorkspace(EvaluatorType& e) {
20+
allocateWorkspace(e);
21+
} // end of disambiguateAllocateWorkspace
22+
23+
template <EvaluatorConcept EvaluatorType>
24+
constexpr mgis::size_type disambiguateGetNumberOfComponents(
25+
const EvaluatorType& e) {
26+
return getNumberOfComponents(e);
27+
} // end of disambiguateGetNumberOfComponents
28+
1829
} // end of namespace mgis::function::internals
1930

2031
#endif /* LIB_MGIS_FUNCTION_EVALUATORCONCEPT_IXX */

include/MGIS/Function/EvaluatorModifierBase.hxx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,10 @@ namespace mgis::function {
7777
template <typename Child, EvaluatorConcept EvaluatorType>
7878
constexpr decltype(auto) getSpace(
7979
const EvaluatorModifierBase<Child, EvaluatorType>&);
80+
//! \brief allocate internal workspace
81+
template <typename Child, EvaluatorConcept EvaluatorType>
82+
constexpr void allocateWorkspace(
83+
EvaluatorModifierBase<Child, EvaluatorType>&);
8084

8185
} // namespace mgis::function
8286

include/MGIS/Function/EvaluatorModifierBase.ixx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ namespace mgis::function {
3232
template <typename Child, EvaluatorConcept EvaluatorType>
3333
constexpr void
3434
EvaluatorModifierBase<Child, EvaluatorType>::allocateWorkspace() {
35-
this->evaluator.allocateWorkspace();
35+
internals::disambiguateAllocateWorkspace(this->evaluator);
3636
} // end of allocatWorkspace
3737

3838
template <typename Child, EvaluatorConcept EvaluatorType>
@@ -81,6 +81,12 @@ namespace mgis::function {
8181
return e.getSpace();
8282
}
8383

84+
template <typename Child, EvaluatorConcept EvaluatorType>
85+
constexpr void allocateWorkspace(
86+
EvaluatorModifierBase<Child, EvaluatorType>& e){
87+
return e.allocateWorkspace();
88+
} // end of allocateWorkspace
89+
8490
} // end of namespace mgis::function
8591

8692
#endif /* LIB_MGIS_FUNCTION_EVALUATORMODIFIERBASE_IXX */

include/MGIS/Function/FixedSizeModifier.hxx

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ namespace mgis::function {
3333
* \param[in] e: evaluator
3434
*/
3535
static constexpr bool checkPreconditions(AbstractErrorHandler&,
36-
const EvaluatorType&) noexcept;
36+
const EvaluatorType&);
3737
/*!
3838
* \brief constructor
3939
* \param[in] values: function
@@ -48,13 +48,13 @@ namespace mgis::function {
4848
constexpr FixedSizeModifier(const PreconditionsCheck<doPreconditionsCheck>&,
4949
const EvaluatorType&);
5050
//! \brief perform consistency checks
51-
constexpr bool check(AbstractErrorHandler&) const noexcept;
51+
constexpr bool check(AbstractErrorHandler&) const;
5252
//! \brief allocate internal workspace
5353
constexpr void allocateWorkspace();
5454
//! \brief return the underlying space
5555
decltype(auto) getSpace() const;
5656
//! \return the number of components
57-
constexpr size_type getNumberOfComponents() const noexcept;
57+
constexpr size_type getNumberOfComponents() const;
5858
/*!
5959
* \brief call operator
6060
* \param[in] i: integration point index
@@ -107,6 +107,14 @@ namespace mgis::function {
107107
template <EvaluatorConcept EvaluatorType, size_type N>
108108
decltype(auto) getSpace(const FixedSizeModifier<EvaluatorType, N>&);
109109

110+
//! \brief allocate internal workspace
111+
template <EvaluatorConcept EvaluatorType, size_type N>
112+
constexpr void allocateWorkspace(FixedSizeModifier<EvaluatorType, N>&);
113+
//! \return the number of components
114+
template <EvaluatorConcept EvaluatorType, size_type N>
115+
constexpr size_type getNumberOfComponents(
116+
const FixedSizeModifier<EvaluatorType, N>&);
117+
110118
} // end of namespace mgis::function
111119

112120
#include "MGIS/Function/FixedSizeModifier.ixx"

0 commit comments

Comments
 (0)