2
2
// SPDX-License-Identifier: LGPL-3.0-or-later
3
3
#include < config.h>
4
4
5
- #include " testhelpers.hh"
6
-
7
5
#include < vector>
8
6
9
7
#include < dune/common/float_cmp.hh>
@@ -44,22 +42,23 @@ static auto dirichletBCTest() {
44
42
using namespace Dune ::Functions::BasisFactory;
45
43
auto basis = Ikarus::makeBasis (gridView, power<2 >(lagrange<1 >()));
46
44
47
- auto basisP = std::make_shared<const decltype (basis)>(basis);
45
+ auto basisP = std::make_shared<const decltype (basis)>(basis);
46
+ auto flatBasis = basisP->flat ();
48
47
49
- Ikarus::DirichletValues dirichletValues1 (basisP-> flat () );
48
+ Ikarus::DirichletValues dirichletValues1 (flatBasis );
50
49
dirichletValues1.fixDOFs ([](auto & basis_, auto & dirichFlags) {
51
50
Dune::Functions::forEachBoundaryDOF (basis_, [&](auto && indexGlobal) { dirichFlags[indexGlobal] = true ; });
52
51
});
53
52
54
- Ikarus::DirichletValues dirichletValues2 (basisP-> flat () );
53
+ Ikarus::DirichletValues dirichletValues2 (flatBasis );
55
54
dirichletValues2.fixBoundaryDOFs ([](auto & dirichFlags, auto && indexGlobal) { dirichFlags[indexGlobal] = true ; });
56
55
57
- for (std::size_t i = 0 ; i < basisP-> flat () .size (); ++i)
56
+ for (std::size_t i = 0 ; i < flatBasis .size (); ++i)
58
57
t.check (dirichletValues1.isConstrained (i) == dirichletValues2.isConstrained (i))
59
58
<< " Different dirichlet value creations didn't provide the same result. Index: i=" << i;
60
59
61
60
auto testSubSpaceBasis = [&](auto && tree1, auto && tree2) {
62
- Ikarus::DirichletValues dirichletValues_SSB (basisP-> flat () );
61
+ Ikarus::DirichletValues dirichletValues_SSB (flatBasis );
63
62
dirichletValues_SSB.fixBoundaryDOFs ([](auto & dirichFlags, auto && indexGlobal) { dirichFlags[indexGlobal] = true ; },
64
63
tree1);
65
64
@@ -94,10 +93,10 @@ static auto dirichletBCTest() {
94
93
if (intersection.geometry ().center ()[0 ] > 4 - 1e-8 )
95
94
dirichletFlags[localView.index (localIndex)] = true ;
96
95
};
97
- Ikarus::DirichletValues dirichletValues5 (basisP-> flat () );
96
+ Ikarus::DirichletValues dirichletValues5 (flatBasis );
98
97
dirichletValues5.fixBoundaryDOFs (fixLambda);
99
98
100
- Ikarus::DirichletValues dirichletValues_SSB2 (basisP-> flat () );
99
+ Ikarus::DirichletValues dirichletValues_SSB2 (flatBasis );
101
100
dirichletValues_SSB2.fixBoundaryDOFs (fixLambda, treePath0);
102
101
103
102
t.check (dirichletValues5.fixedDOFsize () == dirichletValues_SSB2.fixedDOFsize () * 2 )
@@ -113,15 +112,13 @@ static auto dirichletBCTest() {
113
112
<< dirichletValues_SSB2.fixedDOFsize () << " , where as the full basis has " << dirichletValues5.fixedDOFsize ()
114
113
<< " fixed DOFs" ;
115
114
116
- for (std::size_t i = 0 ; i < basisP-> flat () .size (); ++i)
115
+ for (std::size_t i = 0 ; i < flatBasis .size (); ++i)
117
116
t.check (dirichletValues_SSB2.isConstrained (i) == dirichletValues5.isConstrained (i))
118
117
<< " Different dirichlet value creations with subspace basis didn't provide the same result as with full basis. "
119
118
" Index: i="
120
119
<< i;
121
120
122
- auto sum = [](const auto & container_) {
123
- return std::accumulate (container_.begin (), container_.end (), 0 , std::plus ());
124
- };
121
+ auto sum = [](const auto & container_) { return std::accumulate (container_.begin (), container_.end (), 0 ); };
125
122
auto manual_sum = [](const auto & dv) {
126
123
int sum = 0 ;
127
124
for (auto i : Dune::range (dv.size ()))
@@ -130,6 +127,18 @@ static auto dirichletBCTest() {
130
127
return sum;
131
128
};
132
129
130
+ // Fix non-boundaryDOFs
131
+ // Ikarus::DirichletValues dirichletValues6(flatBasis);
132
+ // dirichletValues6.fixDOFs([](const auto& basis, auto& dirichletFlags) {
133
+ // Dune::Functions::forEachBoundaryDOF(basis, [&](auto&& localIndex, auto&& localView, auto&& intersection) {
134
+ // dirichletFlags[localView.index(localIndex)] = true;
135
+ // });
136
+ // });
137
+
138
+ // t.check(dirichletValues6.fixedDOFsize() == flatBasis.size())
139
+ // << "All Dofs should be fixed but only " << dirichletValues6.fixedDOFsize() << "out of " << flatBasis.size()
140
+ // << "are fixed";
141
+
133
142
// Test container
134
143
auto & container = dirichletValues2.container ();
135
144
static_assert (std::is_reference_v<decltype (container)>, " container should be a reference" );
@@ -143,17 +152,21 @@ static auto dirichletBCTest() {
143
152
t.check (sumManual == sumPre)
144
153
<< " Summing over container should yield the same amount of fixed DOFs then checking manually" ;
145
154
146
- dirichletValues2.unfixIthDOF ( {1 });
155
+ dirichletValues2.setSingleDOF ( decltype (flatBasis)::MultiIndex {1 }, false );
147
156
t.check (sum (container) == sumPre - 1 ) << " The sum of fixed DOFs should be one less then after unfixing one" ;
148
157
149
158
t.check (manual_sum (dirichletValues2) == sumPre - 1 )
150
159
<< " Summing over container should yield the same amount of fixed DOFs then checking manually" ;
151
160
161
+ dirichletValues2.setSingleDOF (2 , false );
162
+ t.check (sum (container) == sumPre - 2 ) << " The sum of fixed DOFs should be two less then after unfixing two" ;
163
+
152
164
// Reset
153
165
dirichletValues2.reset ();
154
166
t.check (sum (container) == 0 ) << " After resetting container should have only false entries" ;
155
- t.check (manual_sum (dirichletValues2) == 0 ) << " After resetting all DOFs should be false" ;
167
+ t.check (manual_sum (dirichletValues2) == 0 ) << " After resetting, all DOFs should be false" ;
156
168
169
+ // Inhomogenious Boundary Conditions
157
170
auto inhomogeneousDisplacement = []<typename T>(const auto & globalCoord, const T& lambda) {
158
171
Eigen::Vector<T, 2 > localInhomogeneous;
159
172
if (globalCoord[0 ] > 4 - 1e-8 ) {
@@ -251,7 +264,7 @@ static auto dirichletBCTest() {
251
264
(std::abs (nodalPos[i][1 ]) < tol) or (std::abs (nodalPos[i][1 ] - Ly) < tol))
252
265
for (auto fixedDirection = 0 ; fixedDirection < 2 ; ++fixedDirection) {
253
266
auto fixIndex = localView.index (localView.tree ().child (fixedDirection).localIndex (i));
254
- dirichletValues4.fixIthDOF (fixIndex);
267
+ dirichletValues4.setSingleDOF (fixIndex, true );
255
268
}
256
269
}
257
270
0 commit comments