Chaste Commit::1fd4e48e3990e67db148bc1bc4cf6991a0049d0c
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 c_vector<double, 3> gradN {};
175 switch (basisIndex)
176 {
177 case 0:
178 gradN(0) = -1;
179 gradN(1) = -1;
180 gradN(2) = -1;
181 break;
182 case 1:
183 gradN(0) = 1;
184 gradN(1) = 0;
185 gradN(2) = 0;
186 break;
187 case 2:
188 gradN(0) = 0;
189 gradN(1) = 1;
190 gradN(2) = 0;
191 break;
192 case 3:
193 gradN(0) = 0;
194 gradN(1) = 0;
195 gradN(2) = 1;
196 break;
197 default:
198 ; //not possible to get here because of assertions above
199 }
200 return gradN;
201}
202
215template <>
217 const ChastePoint<2>& rPoint,
218 unsigned basisIndex)
219{
220 assert(basisIndex <= 2);
221 c_vector<double, 2> gradN {};
222 switch (basisIndex)
223 {
224 case 0:
225 gradN(0) = -1;
226 gradN(1) = -1;
227 break;
228 case 1:
229 gradN(0) = 1;
230 gradN(1) = 0;
231 break;
232 case 2:
233 gradN(0) = 0;
234 gradN(1) = 1;
235 break;
236 default:
237 ; //not possible to get here because of assertions above
238 }
239 return gradN;
240}
241
254template <>
256 const ChastePoint<1>& rPoint,
257 unsigned basisIndex)
258{
259 assert(basisIndex <= 1);
260 c_vector<double,1> gradN {};
261 switch (basisIndex)
262 {
263 case 0:
264 gradN(0) = -1;
265 break;
266 case 1:
267 gradN(0) = 1;
268 break;
269 default:
270 ; //not possible to get here because of assertions above
271 }
272 return gradN;
273}
274
275
283template <unsigned ELEMENT_DIM>
285 c_vector<double, ELEMENT_DIM+1>& rReturnValue)
286{
287 assert(ELEMENT_DIM < 4 && ELEMENT_DIM > 0);
288 for (unsigned i=0; i<ELEMENT_DIM+1; i++)
289 {
290 rReturnValue(i) = ComputeBasisFunction(rPoint, i);
291 }
292}
293
303 c_vector<double,1>& rReturnValue)
304{
305 rReturnValue(0) = ComputeBasisFunction(rPoint, 0);
306}
307
316template <unsigned ELEMENT_DIM>
318 c_matrix<double, ELEMENT_DIM, ELEMENT_DIM+1>& rReturnValue)
319{
320 assert(ELEMENT_DIM < 4 && ELEMENT_DIM > 0);
321 for (unsigned j=0; j<ELEMENT_DIM+1; j++)
322 {
323 matrix_column<c_matrix<double, ELEMENT_DIM, ELEMENT_DIM+1> > column(rReturnValue, j);
324 column = ComputeBasisFunctionDerivative(rPoint, j);
325 }
326}
327
342template <unsigned ELEMENT_DIM>
344 const c_matrix<double, ELEMENT_DIM, ELEMENT_DIM>& rInverseJacobian,
345 c_matrix<double, ELEMENT_DIM, ELEMENT_DIM+1>& rReturnValue)
346{
347 assert(ELEMENT_DIM < 4 && ELEMENT_DIM > 0);
348
349 ComputeBasisFunctionDerivatives(rPoint, rReturnValue);
350 rReturnValue = prod(trans(rInverseJacobian), rReturnValue);
351}
352
353// Explicit instantiation
354template class LinearBasisFunction<1>;
355template class LinearBasisFunction<2>;
356template 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)