Chaste  Release::3.4
LinearBasisFunction.cpp
1 /*
2 
3 Copyright (c) 2005-2016, 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  ; //not possible to get here because of assertions above
73  }
74  return 0.0; // Avoid compiler warning
75 }
76 
86 template <>
88  const ChastePoint<2>& rPoint,
89  unsigned basisIndex)
90 {
91  assert(basisIndex <= 2);
92 
93  switch (basisIndex)
94  {
95  case 0:
96  return 1.0 - rPoint[0] - rPoint[1];
97  break;
98  case 1:
99  return rPoint[0];
100  break;
101  case 2:
102  return rPoint[1];
103  break;
104  default:
105  ; //not possible to get here because of assertions above
106  }
107  return 0.0; // Avoid compiler warning
108 }
109 
119 template <>
121  const ChastePoint<1>& rPoint,
122  unsigned basisIndex)
123 {
124  assert(basisIndex <= 1);
125 
126  switch (basisIndex)
127  {
128  case 0:
129  return 1.0 - rPoint[0];
130  break;
131  case 1:
132  return rPoint[0];
133  break;
134  default:
135  ; //not possible to get here because of assertions above
136  }
137  return 0.0; // Avoid compiler warning
138 }
139 
149 double LinearBasisFunction<0>::ComputeBasisFunction(const ChastePoint<0>& rPoint, unsigned basisIndex)
150 {
151  assert(basisIndex == 0);
152  return 1.0;
153 }
154 
167 template <>
169  const ChastePoint<3>& rPoint,
170  unsigned basisIndex)
171 {
172  assert(basisIndex <= 3);
173 
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 
215 template <>
217  const ChastePoint<2>& rPoint,
218  unsigned basisIndex)
219 {
220  assert(basisIndex <= 2);
221 
222  c_vector<double, 2> gradN;
223  switch (basisIndex)
224  {
225  case 0:
226  gradN(0) = -1;
227  gradN(1) = -1;
228  break;
229  case 1:
230  gradN(0) = 1;
231  gradN(1) = 0;
232  break;
233  case 2:
234  gradN(0) = 0;
235  gradN(1) = 1;
236  break;
237  default:
238  ; //not possible to get here because of assertions above
239  }
240  return gradN;
241 }
242 
255 template <>
257  const ChastePoint<1>& rPoint,
258  unsigned basisIndex)
259 {
260  assert(basisIndex <= 1);
261 
262  c_vector<double,1> gradN;
263  switch (basisIndex)
264  {
265  case 0:
266  gradN(0) = -1;
267  break;
268  case 1:
269  gradN(0) = 1;
270  break;
271  default:
272  ; //not possible to get here because of assertions above
273  }
274  return gradN;
275 }
276 
277 
285 template <unsigned ELEMENT_DIM>
287  c_vector<double, ELEMENT_DIM+1>& rReturnValue)
288 {
289  assert(ELEMENT_DIM < 4 && ELEMENT_DIM > 0);
290  for (unsigned i=0; i<ELEMENT_DIM+1; i++)
291  {
292  rReturnValue(i) = ComputeBasisFunction(rPoint, i);
293  }
294 }
295 
305  c_vector<double,1>& rReturnValue)
306 {
307  rReturnValue(0) = ComputeBasisFunction(rPoint, 0);
308 }
309 
319 template <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 
346 template <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 
358 // Explicit instantiation
360 
361 template class LinearBasisFunction<1>;
362 template class LinearBasisFunction<2>;
363 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)
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)