ug4
lagrange1d.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2010-2015: G-CSC, Goethe University Frankfurt
3  * Author: Andreas Vogel
4  *
5  * This file is part of UG4.
6  *
7  * UG4 is free software: you can redistribute it and/or modify it under the
8  * terms of the GNU Lesser General Public License version 3 (as published by the
9  * Free Software Foundation) with the following additional attribution
10  * requirements (according to LGPL/GPL v3 §7):
11  *
12  * (1) The following notice must be displayed in the Appropriate Legal Notices
13  * of covered and combined works: "Based on UG4 (www.ug4.org/license)".
14  *
15  * (2) The following notice must be displayed at a prominent place in the
16  * terminal output of covered works: "Based on UG4 (www.ug4.org/license)".
17  *
18  * (3) The following bibliography is recommended for citation and must be
19  * preserved in all covered files:
20  * "Reiter, S., Vogel, A., Heppner, I., Rupp, M., and Wittum, G. A massively
21  * parallel geometric multigrid solver on hierarchically distributed grids.
22  * Computing and visualization in science 16, 4 (2013), 151-164"
23  * "Vogel, A., Reiter, S., Rupp, M., Nägel, A., and Wittum, G. UG4 -- a novel
24  * flexible software system for simulating pde based models on high performance
25  * computers. Computing and visualization in science 16, 4 (2013), 165-179"
26  *
27  * This program is distributed in the hope that it will be useful,
28  * but WITHOUT ANY WARRANTY; without even the implied warranty of
29  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
30  * GNU Lesser General Public License for more details.
31  */
32 
33 #ifndef __H__UG__LIB_DISC__LOCAL_SHAPE_FUNCTION_SET__COMMON__LAGRANGE1D__
34 #define __H__UG__LIB_DISC__LOCAL_SHAPE_FUNCTION_SET__COMMON__LAGRANGE1D__
35 
36 #include "./polynomial1d.h"
37 #include "common/math/ugmath.h"
38 #include <vector>
39 
40 namespace ug{
41 
46  : public Polynomial1D
47 {
48  public:
54  Lagrange1D(const size_t i, const std::vector<number>& vPos)
55  {
56  // compute coefficients
57  compute_coeffs(i, vPos);
58 
59  // remember positions
60  m_vPos = vPos;
61  }
62 
64  number position(const size_t i) const
65  {
66  UG_ASSERT(i < m_vPos.size(), "Invalid index");
67  return m_vPos[i];
68  }
69 
70  protected:
72  void compute_coeffs(const size_t i, const std::vector<number>& vPos)
73  {
74  // start coefficients
75  std::vector<number> vStart(1, 1.0);
76 
77  // start polynomial
78  this->set_coefficients(vStart);
79 
80  // help polynomial used for each factor
81  std::vector<number> vFactor(2,1.0);
82 
83  // scaling of polynom
84  number scale = 1.0;
85 
86  // fill coefficients
87  for(size_t j = 0; j < vPos.size(); ++j)
88  {
89  if(j == i) continue;
90 
91  // set first coefficent to minus position
92  vFactor[0] = -vPos[j];
93  // create polynom for (-vPos, 1)
94  Polynomial1D tmpPol(vFactor);
95  // multiply
96  (*this) *= tmpPol;
97  // multiply scale
98  scale *= 1./(vPos[i]-vPos[j]);
99  }
100 
101  // multiply by scale
102  (*this) *= scale;
103  }
104 
105  private:
106  std::vector<number> m_vPos;
107 };
108 
113  : public Polynomial1D
114 {
115  public:
120  EquidistantLagrange1D(const size_t i, const size_t degree)
121  {
122  UG_ASSERT(i <= degree, "Only #degree shape functions.");
124  }
125 
127  static number position(const size_t i, const size_t degree)
128  {
129  UG_ASSERT(i <= degree, "Invalid index");
130  return (number)i/(number)degree;
131  }
132 
133  protected:
135  void compute_coeffs(const int i, const int p)
136  {
137  // start coefficients
138  std::vector<number> vStart(1, 1.0);
139 
140  // start polynomial
141  this->set_coefficients(vStart);
142 
143  // help polynomial used for each factor
144  std::vector<number> vFactor(2, p);
145 
146  // scaling of polynom
147  number scale = 1.0;
148 
149  // fill coefficients
150  for(int j = 0; j <= p; ++j)
151  {
152  if(j == i) continue;
153 
154  // set first coefficent to minus position
155  vFactor[0] = -j;
156  // create polynom for (-j, p)
157  Polynomial1D tmpPol(vFactor);
158  // multiply
159  (*this) *= tmpPol;
160  // multiply scale
161  scale *= 1./(i-j);
162  }
163 
164  // multiply by scale
165  (*this) *= scale;
166  }
167 };
168 
176  : public Polynomial1D
177 {
178  public:
183  TruncatedEquidistantLagrange1D(const size_t i, const size_t degree)
184  {
185  UG_ASSERT(i <= degree, "Only #degree shape functions.");
186 
188  }
189 
191  static number position(const size_t i, const size_t degree)
192  {
193  UG_ASSERT(i <= degree, "Invalid index");
194  return (number)i/(number)degree;
195  }
196 
197  protected:
199  void compute_coeffs(const int i, const int p)
200  {
201  // start coefficients
202  std::vector<number> vStart(1, 1.0);
203 
204  // start polynomial
205  this->set_coefficients(vStart);
206 
207  // help polynomial used for each factor
208  std::vector<number> vFactor(2, p);
209 
210  // scaling of polynom
211  number scale = 1.0;
212 
213  // fill coefficients
214  for(int j = 0; j < i; ++j)
215  {
216  // set first coefficent to minus position
217  vFactor[0] = -j;
218  // create polynom for (-j, p)
219  Polynomial1D tmpPol(vFactor);
220  // multiply
221  (*this) *= tmpPol;
222  // multiply scale
223  scale *= 1./(i-j);
224  }
225 
226  // multiply by scale
227  (*this) *= scale;
228  }
229 };
230 
240  : public Polynomial1D
241 {
242  public:
248  BoundedEquidistantLagrange1D(const size_t i, const size_t degree,
249  const size_t bound)
250  {
251  UG_ASSERT(i <= bound, "Only #bound shape functions.");
252  UG_ASSERT(bound <= degree, "Only #bound shape functions.");
253 
254  // init coefficients
255  compute_coeffs(i, degree, bound);
256  }
257 
259  static number position(const size_t i, const size_t degree)
260  {
261  UG_ASSERT(i <= degree, "Invalid index");
262  return (number)i/(number)degree;
263  }
264 
265  protected:
267  void compute_coeffs(const int i, const int p, const int b)
268  {
269  // start coefficients
270  std::vector<number> vStart(1, 1.0);
271 
272  // start polynomial
273  this->set_coefficients(vStart);
274 
275  // help polynomial used for each factor
276  std::vector<number> vFactor(2, p);
277 
278  // scaling of polynom
279  number scale = 1.0;
280 
281  // fill coefficients
282  for(int j = 0; j <= b; ++j)
283  {
284  if(j == i) continue;
285 
286  // set first coefficent to minus position
287  vFactor[0] = -j;
288  // create polynom for (-j, p)
289  Polynomial1D tmpPol(vFactor);
290  // multiply
291  (*this) *= tmpPol;
292  // multiply scale
293  scale *= 1./(i-j);
294  }
295 
296  // multiply by scale
297  (*this) *= scale;
298  }
299 };
300 
301 
302 } // end namespace ug
303 
304 #endif /* __H__UG__LIB_DISC__LOCAL_SHAPE_FUNCTION_SET__COMMON__LAGRANGE1D__ */
parameterString p
Definition: lagrange1d.h:241
static number position(const size_t i, const size_t degree)
returns the position of the i'th interpolation point
Definition: lagrange1d.h:259
void compute_coeffs(const int i, const int p, const int b)
computes the coefficients for passed interpolation points
Definition: lagrange1d.h:267
BoundedEquidistantLagrange1D(const size_t i, const size_t degree, const size_t bound)
Definition: lagrange1d.h:248
Definition: lagrange1d.h:114
static number position(const size_t i, const size_t degree)
returns the position of the i'th interpolation point
Definition: lagrange1d.h:127
EquidistantLagrange1D(const size_t i, const size_t degree)
Definition: lagrange1d.h:120
void compute_coeffs(const int i, const int p)
computes the coefficients for passed interpolation points
Definition: lagrange1d.h:135
Definition: lagrange1d.h:47
Lagrange1D(const size_t i, const std::vector< number > &vPos)
Definition: lagrange1d.h:54
number position(const size_t i) const
returns the position of the i'th interpolation point
Definition: lagrange1d.h:64
std::vector< number > m_vPos
Definition: lagrange1d.h:106
void compute_coeffs(const size_t i, const std::vector< number > &vPos)
computes the coefficients for passed interpolation points
Definition: lagrange1d.h:72
Definition: polynomial1d.h:51
size_t degree() const
Definition: polynomial1d.h:72
void set_coefficients(const std::vector< number > &a)
Definition: polynomial1d.h:143
Definition: lagrange1d.h:177
void compute_coeffs(const int i, const int p)
computes the coefficients for passed interpolation points
Definition: lagrange1d.h:199
static number position(const size_t i, const size_t degree)
returns the position of the i'th interpolation point
Definition: lagrange1d.h:191
TruncatedEquidistantLagrange1D(const size_t i, const size_t degree)
Definition: lagrange1d.h:183
#define UG_ASSERT(expr, msg)
Definition: assert.h:70
double number
Definition: types.h:124
the ug namespace