Chaste  Release::2017.1
LinearBasisFunction.cpp
1 /*
2 
3 Copyright (c) 2005-2017, University of Oxford.
4 All rights reserved.
5 
6 University of Oxford means the Chancellor, Masters and Scholars of the
7 University of Oxford, having an administrative office at Wellington
8 Square, Oxford OX1 2JD, UK.
9 
10 This file is part of Chaste.
11 
12 Redistribution and use in source and binary forms, with or without
13 modification, 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 
23 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
24 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
27 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
28 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
29 GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30 HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
32 OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 
34 */
35 
36 #include "UblasCustomFunctions.hpp"
37 #include "LinearBasisFunction.hpp"
38 #include "ChastePoint.hpp"
39 #include <cassert>
40 
50 template <>
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 
87 template <>
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 
120 template <>
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 
150 double LinearBasisFunction<0>::ComputeBasisFunction(const ChastePoint<0>& rPoint, unsigned basisIndex)
151 {
152  assert(basisIndex == 0);
153  return 1.0;
154 }
155 
168 template <>
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 
216 template <>
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 
256 template <>
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 
286 template <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 
320 template <unsigned ELEMENT_DIM>
322  c_matrix<double, ELEMENT_DIM, ELEMENT_DIM+1>& rReturnValue)
323 {
324  assert(ELEMENT_DIM < 4 && ELEMENT_DIM > 0);
325 
326  for (unsigned j=0; j<ELEMENT_DIM+1; j++)
327  {
328  matrix_column<c_matrix<double, ELEMENT_DIM, ELEMENT_DIM+1> > column(rReturnValue, j);
329  column = ComputeBasisFunctionDerivative(rPoint, j);
330  }
331 }
332 
347 template <unsigned ELEMENT_DIM>
349  const c_matrix<double, ELEMENT_DIM, ELEMENT_DIM>& rInverseJacobian,
350  c_matrix<double, ELEMENT_DIM, ELEMENT_DIM+1>& rReturnValue)
351 {
352  assert(ELEMENT_DIM < 4 && ELEMENT_DIM > 0);
353 
354  ComputeBasisFunctionDerivatives(rPoint, rReturnValue);
355  rReturnValue = prod(trans(rInverseJacobian), rReturnValue);
356 }
357 
358 // Explicit instantiation
359 template class LinearBasisFunction<1>;
360 template class LinearBasisFunction<2>;
361 template class LinearBasisFunction<3>;
static c_vector< double, ELEMENT_DIM > ComputeBasisFunctionDerivative(const ChastePoint< ELEMENT_DIM > &rPoint, unsigned basisIndex)
static void ComputeBasisFunctionDerivatives(const ChastePoint< ELEMENT_DIM > &rPoint, c_matrix< double, ELEMENT_DIM, ELEMENT_DIM+1 > &rReturnValue)
#define NEVER_REACHED
Definition: Exception.hpp:206
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 double ComputeBasisFunction(const ChastePoint< ELEMENT_DIM > &rPoint, unsigned basisIndex)
static void ComputeBasisFunctions(const ChastePoint< ELEMENT_DIM > &rPoint, c_vector< double, ELEMENT_DIM+1 > &rReturnValue)