Chaste Commit::f2ff7ee04e70ac9d06c57344df8d017dbb12b97b
LinearBasisFunction.cpp
1/*
2
3Copyright (c) 2005-2024, University of Oxford.
4All rights reserved.
5
6University of Oxford means the Chancellor, Masters and Scholars of the
7University of Oxford, having an administrative office at Wellington
8Square, Oxford OX1 2JD, UK.
9
10This file is part of Chaste.
11
12Redistribution and use in source and binary forms, with or without
13modification, are permitted provided that the following conditions are met:
14 * Redistributions of source code must retain the above copyright notice,
15 this list of conditions and the following disclaimer.
16 * Redistributions in binary form must reproduce the above copyright notice,
17 this list of conditions and the following disclaimer in the documentation
18 and/or other materials provided with the distribution.
19 * Neither the name of the University of Oxford nor the names of its
20 contributors may be used to endorse or promote products derived from this
21 software without specific prior written permission.
22
23THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
24AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
27LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
28CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
29GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
32OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33
34*/
35
37#include "LinearBasisFunction.hpp"
38#include "ChastePoint.hpp"
39#include <cassert>
40
50template <>
52 const ChastePoint<3>& rPoint,
53 unsigned basisIndex)
54{
55 assert(basisIndex <= 3);
56
57 switch (basisIndex)
58 {
59 case 0:
60 return 1.0 - rPoint[0] - rPoint[1] - rPoint[2];
61 break;
62 case 1:
63 return rPoint[0];
64 break;
65 case 2:
66 return rPoint[1];
67 break;
68 case 3:
69 return rPoint[2];
70 break;
71 default:
72 NEVER_REACHED; //not possible to get here because of assertions above
73 }
74
75 return 0.0; // LCOV_EXCL_LINE // Avoid compiler warning
76}
77
87template <>
89 const ChastePoint<2>& rPoint,
90 unsigned basisIndex)
91{
92 assert(basisIndex <= 2);
93
94 switch (basisIndex)
95 {
96 case 0:
97 return 1.0 - rPoint[0] - rPoint[1];
98 break;
99 case 1:
100 return rPoint[0];
101 break;
102 case 2:
103 return rPoint[1];
104 break;
105 default:
106 NEVER_REACHED; //not possible to get here because of assertions above
107 }
108 return 0.0; // LCOV_EXCL_LINE // Avoid compiler warning
109}
110
120template <>
122 const ChastePoint<1>& rPoint,
123 unsigned basisIndex)
124{
125 assert(basisIndex <= 1);
126
127 switch (basisIndex)
128 {
129 case 0:
130 return 1.0 - rPoint[0];
131 break;
132 case 1:
133 return rPoint[0];
134 break;
135 default:
136 NEVER_REACHED; //not possible to get here because of assertions above
137 }
138 return 0.0; // LCOV_EXCL_LINE // Avoid compiler warning
139}
140
150double LinearBasisFunction<0>::ComputeBasisFunction(const ChastePoint<0>& rPoint, unsigned basisIndex)
151{
152 assert(basisIndex == 0);
153 return 1.0;
154}
155
168template <>
170 const ChastePoint<3>& rPoint,
171 unsigned basisIndex)
172{
173 assert(basisIndex <= 3);
174
175 c_vector<double, 3> gradN;
176 switch (basisIndex)
177 {
178 case 0:
179 gradN(0) = -1;
180 gradN(1) = -1;
181 gradN(2) = -1;
182 break;
183 case 1:
184 gradN(0) = 1;
185 gradN(1) = 0;
186 gradN(2) = 0;
187 break;
188 case 2:
189 gradN(0) = 0;
190 gradN(1) = 1;
191 gradN(2) = 0;
192 break;
193 case 3:
194 gradN(0) = 0;
195 gradN(1) = 0;
196 gradN(2) = 1;
197 break;
198 default:
199 ; //not possible to get here because of assertions above
200 }
201 return gradN;
202}
203
216template <>
218 const ChastePoint<2>& rPoint,
219 unsigned basisIndex)
220{
221 assert(basisIndex <= 2);
222
223 c_vector<double, 2> gradN;
224 switch (basisIndex)
225 {
226 case 0:
227 gradN(0) = -1;
228 gradN(1) = -1;
229 break;
230 case 1:
231 gradN(0) = 1;
232 gradN(1) = 0;
233 break;
234 case 2:
235 gradN(0) = 0;
236 gradN(1) = 1;
237 break;
238 default:
239 ; //not possible to get here because of assertions above
240 }
241 return gradN;
242}
243
256template <>
258 const ChastePoint<1>& rPoint,
259 unsigned basisIndex)
260{
261 assert(basisIndex <= 1);
262
263 c_vector<double,1> gradN;
264 switch (basisIndex)
265 {
266 case 0:
267 gradN(0) = -1;
268 break;
269 case 1:
270 gradN(0) = 1;
271 break;
272 default:
273 ; //not possible to get here because of assertions above
274 }
275 return gradN;
276}
277
278
286template <unsigned ELEMENT_DIM>
288 c_vector<double, ELEMENT_DIM+1>& rReturnValue)
289{
290 assert(ELEMENT_DIM < 4 && ELEMENT_DIM > 0);
291 for (unsigned i=0; i<ELEMENT_DIM+1; i++)
292 {
293 rReturnValue(i) = ComputeBasisFunction(rPoint, i);
294 }
295}
296
306 c_vector<double,1>& rReturnValue)
307{
308 rReturnValue(0) = ComputeBasisFunction(rPoint, 0);
309}
310
319template <unsigned ELEMENT_DIM>
321 c_matrix<double, ELEMENT_DIM, ELEMENT_DIM+1>& rReturnValue)
322{
323 assert(ELEMENT_DIM < 4 && ELEMENT_DIM > 0);
324
325 for (unsigned j=0; j<ELEMENT_DIM+1; j++)
326 {
327 matrix_column<c_matrix<double, ELEMENT_DIM, ELEMENT_DIM+1> > column(rReturnValue, j);
328 column = ComputeBasisFunctionDerivative(rPoint, j);
329 }
330}
331
346template <unsigned ELEMENT_DIM>
348 const c_matrix<double, ELEMENT_DIM, ELEMENT_DIM>& rInverseJacobian,
349 c_matrix<double, ELEMENT_DIM, ELEMENT_DIM+1>& rReturnValue)
350{
351 assert(ELEMENT_DIM < 4 && ELEMENT_DIM > 0);
352
353 ComputeBasisFunctionDerivatives(rPoint, rReturnValue);
354 rReturnValue = prod(trans(rInverseJacobian), rReturnValue);
355}
356
357// Explicit instantiation
358template class LinearBasisFunction<1>;
359template class LinearBasisFunction<2>;
360template class LinearBasisFunction<3>;
#define NEVER_REACHED
static c_vector< double, ELEMENT_DIM > ComputeBasisFunctionDerivative(const ChastePoint< ELEMENT_DIM > &rPoint, unsigned basisIndex)
static void ComputeBasisFunctions(const ChastePoint< ELEMENT_DIM > &rPoint, c_vector< double, ELEMENT_DIM+1 > &rReturnValue)
static void ComputeTransformedBasisFunctionDerivatives(const ChastePoint< ELEMENT_DIM > &rPoint, const c_matrix< double, ELEMENT_DIM, ELEMENT_DIM > &rInverseJacobian, c_matrix< double, ELEMENT_DIM, ELEMENT_DIM+1 > &rReturnValue)
static void ComputeBasisFunctionDerivatives(const ChastePoint< ELEMENT_DIM > &rPoint, c_matrix< double, ELEMENT_DIM, ELEMENT_DIM+1 > &rReturnValue)
static double ComputeBasisFunction(const ChastePoint< ELEMENT_DIM > &rPoint, unsigned basisIndex)