3.2-git
DUNE for Multi-{Phase, Component, Scale, Physics, ...} flow and transport in porous media
spline.hh
Go to the documentation of this file.
1// -*- mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2// vi: set et ts=4 sw=4 sts=4:
3/*****************************************************************************
4 * See the file COPYING for full copying permissions. *
5 * *
6 * This program is free software: you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License as published by *
8 * the Free Software Foundation, either version 3 of the License, or *
9 * (at your option) any later version. *
10 * *
11 * This program is distributed in the hope that it will be useful, *
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14 * GNU General Public License for more details. *
15 * *
16 * You should have received a copy of the GNU General Public License *
17 * along with this program. If not, see <http://www.gnu.org/licenses/>. *
18 *****************************************************************************/
24#ifndef DUMUX_SPLINE_HH
25#define DUMUX_SPLINE_HH
26
27#include "fixedlengthspline_.hh"
29#include "splinecommon_.hh"
30
31namespace Dumux {
32
53template<class Scalar, int numSamples = 2>
54class Spline : public FixedLengthSpline_<Scalar, numSamples>
55{
56public:
63 { };
64
71 template <class ScalarArray>
72 Spline(const ScalarArray &x,
73 const ScalarArray &y)
74 { this->setXYArrays(numSamples, x, y); }
75
81 template <class PointArray>
82 Spline(const PointArray &points)
83 { this->setArrayOfPoints(numSamples, points); }
84
93 template <class ScalarArray>
94 Spline(const ScalarArray &x,
95 const ScalarArray &y,
96 Scalar m0,
97 Scalar m1)
98 { this->setXYArrays(numSamples, x, y, m0, m1); }
99
107 template <class PointArray>
108 Spline(const PointArray &points,
109 Scalar m0,
110 Scalar m1)
111 { this->setArrayOfPoints(numSamples, points, m0, m1); }
112};
113
135template<class Scalar>
136class Spline<Scalar, /*numSamples=*/-1> : public VariableLengthSpline_<Scalar>
137{
138public:
145 { }
146
154 template <class ScalarArrayX, class ScalarArrayY>
155 Spline(int nSamples,
156 const ScalarArrayX &x,
157 const ScalarArrayY &y)
158 { this->setXYArrays(nSamples, x, y); }
159
166 template <class PointArray>
167 Spline(int nSamples,
168 const PointArray &points)
169 { this->setArrayOfPoints(nSamples, points); }
170
177 template <class ScalarContainer>
178 Spline(const ScalarContainer &x,
179 const ScalarContainer &y)
180 { this->setXYContainers(x, y); }
181
187 template <class PointContainer>
188 Spline(const PointContainer &points)
189 { this->setContainerOfPoints(points); }
190
200 template <class ScalarArray>
201 Spline(int nSamples,
202 const ScalarArray &x,
203 const ScalarArray &y,
204 Scalar m0,
205 Scalar m1)
206 { this->setXYArrays(nSamples, x, y, m0, m1); }
207
216 template <class PointArray>
217 Spline(int nSamples,
218 const PointArray &points,
219 Scalar m0,
220 Scalar m1)
221 { this->setArrayOfPoints(nSamples, points, m0, m1); }
222
231 template <class ScalarContainerX, class ScalarContainerY>
232 Spline(const ScalarContainerX &x,
233 const ScalarContainerY &y,
234 Scalar m0,
235 Scalar m1)
236 { this->setXYContainers(x, y, m0, m1); }
237
245 template <class PointContainer>
246 Spline(const PointContainer &points,
247 Scalar m0,
248 Scalar m1)
249 { this->setContainerOfPoints(points, m0, m1); }
250};
251
255template<class Scalar>
256class Spline<Scalar, /*numSamples=*/0>
257// Splines with zero sampling points do not make sense!
258{ private: Spline() { }; };
259
263template<class Scalar>
264class Spline<Scalar, /*numSamples=*/1>
265// Splines with one sampling point do not make sense!
266{ private: Spline() { }; };
267
274template<class Scalar>
275class Spline<Scalar, 2> : public SplineCommon_<Scalar, Spline<Scalar, 2> >
276{
277 friend class SplineCommon_<Scalar, Spline<Scalar, 2> >;
278 using Vector = Dune::FieldVector<Scalar, 2>;
279 using Matrix = Dune::FieldMatrix<Scalar, 2, 2>;
280
281public:
283 {};
284
293 template <class ScalarArrayX, class ScalarArrayY>
294 Spline(const ScalarArrayX &x,
295 const ScalarArrayY &y,
296 Scalar m0, Scalar m1)
297 { setXYArrays(2, x, y, m0, m1); }
298
306 template <class PointArray>
307 Spline(const PointArray &points,
308 Scalar m0,
309 Scalar m1)
310 { this->setArrayOfPoints(2, points, m0, m1); }
311
322 Spline(Scalar x0, Scalar x1,
323 Scalar y0, Scalar y1,
324 Scalar m0, Scalar m1)
325 {
326 set(x0, x1,
327 y0, y1,
328 m0, m1);
329 };
330
334 int numSamples() const
335 { return 2; }
336
348 void set(Scalar x0, Scalar x1,
349 Scalar y0, Scalar y1,
350 Scalar m0, Scalar m1)
351 {
352 Matrix M(numSamples());
353 Vector d;
354 assignXY_(x0, x1, y0, y1);
355 this->makeFullSystem_(M, d, m0, m1);
356
357 // solve for the moments
358 M.solve(m_, d);
359 }
360
371 template <class ScalarContainer>
372 void setXYArrays(int nSamples,
373 const ScalarContainer &x,
374 const ScalarContainer &y,
375 Scalar m0, Scalar m1)
376 {
377 assert(nSamples == 2);
378 set(x[0], x[1], y[0], y[1], m0, m1);
379 }
380
390 template <class ScalarContainerX, class ScalarContainerY>
391 void setXYContainers(const ScalarContainerX &x,
392 const ScalarContainerY &y,
393 Scalar m0, Scalar m1)
394 {
395 assert(x.size() == y.size());
396 assert(x.size() == 2);
397
398 Matrix M(numSamples());
399 Vector d;
400
401 typename ScalarContainerX::const_iterator xIt0 = x.begin();
402 typename ScalarContainerX::const_iterator xIt1 = xIt0;
403 ++xIt1;
404 typename ScalarContainerY::const_iterator yIt0 = y.begin();
405 typename ScalarContainerY::const_iterator yIt1 = yIt0;
406 ++yIt1;
407 set(*xIt0, *xIt1, *yIt0, *yIt1);
408 }
409
419 template <class PointArray>
420 void setArrayOfPoints(int nSamples,
421 const PointArray &points,
422 Scalar m0,
423 Scalar m1)
424 {
425 assert(nSamples == 2);
426
427 set(points[0][0],
428 points[1][0],
429 points[0][1],
430 points[1][1],
431 m0, m1);
432 }
433
442 template <class PointContainer>
443 void setContainerOfPoints(const PointContainer &points,
444 Scalar m0,
445 Scalar m1)
446 {
447 assert(points.size() == 2);
448
449 Matrix M;
450 Vector d;
451 typename PointContainer::const_iterator it0 = points.begin();
452 typename PointContainer::const_iterator it1 = it0;
453 ++it1;
454
455 set((*it0)[0],
456 (*it0)[1],
457 (*it1)[0],
458 (*it1)[1],
459 m0, m1);
460 }
461
470 template <class TupleContainer>
471 void setContainerOfTuples(const TupleContainer &tuples,
472 Scalar m0,
473 Scalar m1)
474 {
475 assert(tuples.size() == 2);
476
477 typename TupleContainer::const_iterator it0 = tuples.begin();
478 typename TupleContainer::const_iterator it1 = it0;
479 ++it1;
480
481 set(std::get<0>(*it0),
482 std::get<1>(*it0),
483 std::get<0>(*it1),
484 std::get<1>(*it1),
485 m0, m1);
486 }
487
488protected:
489 void assignXY_(Scalar x0, Scalar x1,
490 Scalar y0, Scalar y1)
491 {
492 if (x0 > x1) {
493 xPos_[0] = x1;
494 xPos_[1] = x0;
495 yPos_[0] = y1;
496 yPos_[1] = y0;
497 }
498 else {
499 xPos_[0] = x0;
500 xPos_[1] = x1;
501 yPos_[0] = y0;
502 yPos_[1] = y1;
503 }
504 };
505
509 Scalar x_(int i) const
510 { return xPos_[i]; }
511
515 Scalar y_(int i) const
516 { return yPos_[i]; }
517
522 Scalar moment_(int i) const
523 { return m_[i]; }
524
525 Vector xPos_;
526 Vector yPos_;
527 Vector m_;
528};
529
530} // end namespace Dumux
531
532#endif
Implements a spline with a fixed number of sampling points.
The common code for all 3rd order polynomial splines.
Implements a spline with a variable number of sampling points.
Definition: adapt.hh:29
The common code for all 3rd order polynomial splines with more than two sampling points.
Definition: fixedlengthspline_.hh:44
BlockVector m_
Definition: fixedlengthspline_.hh:409
Vector xPos_
Definition: fixedlengthspline_.hh:407
void setContainerOfPoints(const XYContainer &points, Scalar m0, Scalar m1)
Set the sampling points and the boundary slopes of a full spline using a STL-compatible container of ...
Definition: fixedlengthspline_.hh:164
void setXYArrays(int numberSamples, const ScalarArrayX &x, const ScalarArrayY &y, Scalar m0, Scalar m1)
Set the sampling points and the boundary slopes of a full spline using C-style arrays.
Definition: fixedlengthspline_.hh:84
void setArrayOfPoints(int numberSamples, const PointArray &points, Scalar m0, Scalar m1)
Set the sampling points and the boundary slopes of a full spline using a C-style array.
Definition: fixedlengthspline_.hh:135
Vector yPos_
Definition: fixedlengthspline_.hh:408
int numSamples() const
Returns the number of sampling points.
Definition: fixedlengthspline_.hh:61
void setXYContainers(const ScalarContainerX &x, const ScalarContainerY &y, Scalar m0, Scalar m1)
Set the sampling points and the boundary slopes of a full spline using STL-compatible containers.
Definition: fixedlengthspline_.hh:110
A 3rd order polynomial spline.
Definition: spline.hh:55
Spline()
Default constructor for a spline.
Definition: spline.hh:62
Spline(const PointArray &points, Scalar m0, Scalar m1)
Convenience constructor for a full spline.
Definition: spline.hh:108
Spline(const PointArray &points)
Convenience constructor for a full spline.
Definition: spline.hh:82
Spline(const ScalarArray &x, const ScalarArray &y)
Convenience constructor for a full spline.
Definition: spline.hh:72
Spline(const ScalarArray &x, const ScalarArray &y, Scalar m0, Scalar m1)
Convenience constructor for a full spline.
Definition: spline.hh:94
Spline(const ScalarContainer &x, const ScalarContainer &y)
Convenience constructor for a natural spline.
Definition: spline.hh:178
Spline()
Default constructor for a spline.
Definition: spline.hh:144
Spline(int nSamples, const ScalarArray &x, const ScalarArray &y, Scalar m0, Scalar m1)
Convenience constructor for a full spline.
Definition: spline.hh:201
Spline(const PointContainer &points, Scalar m0, Scalar m1)
Convenience constructor for a full spline.
Definition: spline.hh:246
Spline(int nSamples, const PointArray &points)
Convenience constructor for a natural spline.
Definition: spline.hh:167
Spline(const PointContainer &points)
Convenience constructor for a natural spline.
Definition: spline.hh:188
Spline(int nSamples, const PointArray &points, Scalar m0, Scalar m1)
Convenience constructor for a full spline.
Definition: spline.hh:217
Spline(int nSamples, const ScalarArrayX &x, const ScalarArrayY &y)
Convenience constructor for a natural spline.
Definition: spline.hh:155
Spline(const ScalarContainerX &x, const ScalarContainerY &y, Scalar m0, Scalar m1)
Convenience constructor for a full spline.
Definition: spline.hh:232
int numSamples() const
Returns the number of sampling points.
Definition: spline.hh:334
void set(Scalar x0, Scalar x1, Scalar y0, Scalar y1, Scalar m0, Scalar m1)
Set the sampling points and the boundary slopes of the spline.
Definition: spline.hh:348
Scalar y_(int i) const
Returns the y coordinate of the i-th sampling point.
Definition: spline.hh:515
void setContainerOfPoints(const PointContainer &points, Scalar m0, Scalar m1)
Set the sampling points and the boundary slopes from an STL-like container of points.
Definition: spline.hh:443
Vector m_
Definition: spline.hh:527
Spline(Scalar x0, Scalar x1, Scalar y0, Scalar y1, Scalar m0, Scalar m1)
Convenience constructor for a full spline.
Definition: spline.hh:322
Spline(const PointArray &points, Scalar m0, Scalar m1)
Convenience constructor for a full spline.
Definition: spline.hh:307
void setXYContainers(const ScalarContainerX &x, const ScalarContainerY &y, Scalar m0, Scalar m1)
Set the sampling points and the boundary slopes of the spline.
Definition: spline.hh:391
Vector yPos_
Definition: spline.hh:526
void setContainerOfTuples(const TupleContainer &tuples, Scalar m0, Scalar m1)
Set the sampling points and the boundary slopes from an STL-like container of tuples.
Definition: spline.hh:471
Spline(const ScalarArrayX &x, const ScalarArrayY &y, Scalar m0, Scalar m1)
Convenience constructor for a full spline.
Definition: spline.hh:294
void assignXY_(Scalar x0, Scalar x1, Scalar y0, Scalar y1)
Definition: spline.hh:489
Scalar moment_(int i) const
Returns the moment (i.e. second derivative) of the spline at the i-th sampling point.
Definition: spline.hh:522
Spline()
Definition: spline.hh:282
void setXYArrays(int nSamples, const ScalarContainer &x, const ScalarContainer &y, Scalar m0, Scalar m1)
Set the sampling points and the boundary slopes of the spline.
Definition: spline.hh:372
Scalar x_(int i) const
Returns the x coordinate of the i-th sampling point.
Definition: spline.hh:509
void setArrayOfPoints(int nSamples, const PointArray &points, Scalar m0, Scalar m1)
Set the sampling points and the boundary slopes of the spline.
Definition: spline.hh:420
Vector xPos_
Definition: spline.hh:525
The common code for all 3rd order polynomial splines.
Definition: splinecommon_.hh:45
void makeFullSystem_(Matrix &M, Vector &d, Scalar m0, Scalar m1)
Make the linear system of equations Mx = d which results in the moments of the full spline.
Definition: splinecommon_.hh:429
The common code for all 3rd order polynomial splines with where the number of sampling points only kn...
Definition: variablelengthspline_.hh:45