3.2-git
DUNE for Multi-{Phase, Component, Scale, Physics, ...} flow and transport in porous media
variablelengthspline_.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_VARIABLE_LENGTH_SPLINE_HH
25#define DUMUX_VARIABLE_LENGTH_SPLINE_HH
26
27#include <dune/common/fvector.hh>
28#include <dune/common/fmatrix.hh>
29#include <dune/istl/bvector.hh>
30#include <dune/istl/btdmatrix.hh>
31
32#include "splinecommon_.hh"
33
34namespace Dumux {
35
41template<class ScalarT>
43 : public SplineCommon_<ScalarT,
44 VariableLengthSpline_<ScalarT> >
45{
46 friend class SplineCommon_<ScalarT, VariableLengthSpline_<ScalarT> >;
47
48 using Scalar = ScalarT;
49 using Vector = Dune::BlockVector<Dune::FieldVector<Scalar, 1> >;
50 using BTDMatrix = Dune::BTDMatrix<Dune::FieldMatrix<Scalar, 1, 1> >;
51
52public:
56 int numSamples() const
57 { return xPos_.size(); }
58
59
63 // Full splines //
67
79 template <class ScalarArrayX, class ScalarArrayY>
80 void setXYArrays(int nSamples,
81 const ScalarArrayX &x,
82 const ScalarArrayY &y,
83 Scalar m0, Scalar m1)
84 {
85 assert(nSamples > 1);
86
87 setNumSamples_(nSamples);
88 for (int i = 0; i < nSamples; ++i) {
89 xPos_[i] = x[i];
90 yPos_[i] = y[i];
91 }
92 makeFullSpline_(m0, m1);
93 }
94
106 template <class ScalarContainerX, class ScalarContainerY>
107 void setXYContainers(const ScalarContainerX &x,
108 const ScalarContainerY &y,
109 Scalar m0, Scalar m1)
110 {
111 assert(x.size() == y.size());
112 assert(x.size() > 1);
113
114 setNumSamples_(x.size());
115 std::copy(x.begin(), x.end(), xPos_.begin());
116 std::copy(y.begin(), y.end(), yPos_.begin());
117 makeFullSpline_(m0, m1);
118 }
119
132 template <class PointArray>
133 void setArrayOfPoints(int nSamples,
134 const PointArray &points,
135 Scalar m0,
136 Scalar m1)
137 {
138 // a spline with no or just one sampling points? what an
139 // incredible bad idea!
140 assert(nSamples > 1);
141
142 setNumSamples_(nSamples);
143 for (int i = 0; i < nSamples; ++i) {
144 xPos_[i] = points[i][0];
145 yPos_[i] = points[i][1];
146 }
147 makeFullSpline_(m0, m1);
148 }
149
162 template <class XYContainer>
163 void setContainerOfPoints(const XYContainer &points,
164 Scalar m0,
165 Scalar m1)
166 {
167 // a spline with no or just one sampling points? what an
168 // incredible bad idea!
169 assert(points.size() > 1);
170
171 setNumSamples_(points.size());
172 typename XYContainer::const_iterator it = points.begin();
173 typename XYContainer::const_iterator endIt = points.end();
174 for (int i = 0; it != endIt; ++i, ++it) {
175 xPos_[i] = (*it)[0];
176 yPos_[i] = (*it)[1];
177 }
178
179 // make a full spline
180 makeFullSpline_(m0, m1);
181 }
182
198 template <class XYContainer>
199 void setContainerOfTuples(const XYContainer &points,
200 Scalar m0,
201 Scalar m1)
202 {
203 // resize internal arrays
204 setNumSamples_(points.size());
205 typename XYContainer::const_iterator it = points.begin();
206 typename XYContainer::const_iterator endIt = points.end();
207 for (int i = 0; it != endIt; ++i, ++it) {
208 xPos_[i] = std::get<0>(*it);
209 yPos_[i] = std::get<1>(*it);
210 }
211
212 // make a full spline
213 makeFullSpline_(m0, m1);
214 }
215
219 // Natural splines //
223
233 template <class ScalarArrayX, class ScalarArrayY>
234 void setXYArrays(int nSamples,
235 const ScalarArrayX &x,
236 const ScalarArrayY &y)
237 {
238 assert(nSamples > 1);
239
240 setNumSamples_(nSamples);
241 for (int i = 0; i < nSamples; ++i) {
242 xPos_[i] = x[i];
243 yPos_[i] = y[i];
244 }
245
247 }
248
260 template <class ScalarContainerX, class ScalarContainerY>
261 void setXYContainers(const ScalarContainerX &x,
262 const ScalarContainerY &y)
263 {
264 assert(x.size() == y.size());
265 assert(x.size() > 1);
266
267 setNumSamples_(x.size());
268 std::copy(x.begin(), x.end(), xPos_.begin());
269 std::copy(y.begin(), y.end(), yPos_.begin());
271 }
272
285 template <class PointArray>
286 void setArrayOfPoints(int nSamples,
287 const PointArray &points)
288 {
289 // a spline with no or just one sampling points? what an
290 // incredible bad idea!
291 assert(nSamples > 1);
292
293 setNumSamples_(nSamples);
294 for (int i = 0; i < nSamples; ++i) {
295 xPos_[i] = points[i][0];
296 yPos_[i] = points[i][1];
297 }
299 }
300
312 template <class XYContainer>
313 void setContainerOfPoints(const XYContainer &points)
314 {
315 // a spline with no or just one sampling points? what an
316 // incredible bad idea!
317 assert(points.size() > 1);
318
319 setNumSamples_(points.size());
320 typename XYContainer::const_iterator it = points.begin();
321 typename XYContainer::const_iterator endIt = points.end();
322 for (int i = 0; it != endIt; ++ i, ++it) {
323 xPos_[i] = (*it)[0];
324 yPos_[i] = (*it)[1];
325 }
326
327 // make a natural spline
329 }
330
345 template <class XYContainer>
346 void setContainerOfTuples(const XYContainer &points)
347 {
348 // resize internal arrays
349 setNumSamples_(points.size());
350 typename XYContainer::const_iterator it = points.begin();
351 typename XYContainer::const_iterator endIt = points.end();
352 for (int i = 0; it != endIt; ++i, ++it) {
353 xPos_[i] = std::get<0>(*it);
354 yPos_[i] = std::get<1>(*it);
355 }
356
357 // make a natural spline
359 }
360
361protected:
365 void setNumSamples_(int nSamples)
366 {
367 xPos_.resize(nSamples);
368 yPos_.resize(nSamples);
369 m_.resize(nSamples);
370 }
371
377 void makeFullSpline_(Scalar m0, Scalar m1)
378 {
379 BTDMatrix M(numSamples());
380 Vector d(numSamples());
381
382 // create linear system of equations
383 this->makeFullSystem_(M, d, m0, m1);
384
385 // solve for the moments
386 M.solve(m_, d);
387 }
388
395 {
396 BTDMatrix M(numSamples());
397 Vector d(numSamples());
398
399 // create linear system of equations
400 this->makeNaturalSystem_(M, d);
401
402 // solve for the moments
403 M.solve(m_, d);
404 }
405
409 Scalar x_(int i) const
410 { return xPos_[i]; }
411
415 Scalar y_(int i) const
416 { return yPos_[i]; }
417
422 Scalar moment_(int i) const
423 { return m_[i]; }
424
425 Vector xPos_;
426 Vector yPos_;
427 Vector m_;
428};
429
430} // end namespace Dumux
431
432#endif
The common code for all 3rd order polynomial splines.
Definition: adapt.hh:29
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
void makeNaturalSystem_(Matrix &M, Vector &d)
Make the linear system of equations Mx = d which results in the moments of the natural spline....
Definition: splinecommon_.hh:454
The common code for all 3rd order polynomial splines with where the number of sampling points only kn...
Definition: variablelengthspline_.hh:45
Scalar y_(int i) const
Returns the y coordinate of the i-th sampling point.
Definition: variablelengthspline_.hh:415
void setContainerOfPoints(const XYContainer &points)
Set the sampling points of a natural spline using a STL-compatible container of array-like objects.
Definition: variablelengthspline_.hh:313
int numSamples() const
Returns the number of sampling points.
Definition: variablelengthspline_.hh:56
void setArrayOfPoints(int nSamples, 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: variablelengthspline_.hh:133
Scalar x_(int i) const
Returns the x coordinate of the i-th sampling point.
Definition: variablelengthspline_.hh:409
Vector yPos_
Definition: variablelengthspline_.hh:426
void setContainerOfTuples(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: variablelengthspline_.hh:199
void makeFullSpline_(Scalar m0, Scalar m1)
Create a natural spline from the already set sampling points.
Definition: variablelengthspline_.hh:377
void makeNaturalSpline_()
Create a natural spline from the already set sampling points.
Definition: variablelengthspline_.hh:394
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: variablelengthspline_.hh:163
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: variablelengthspline_.hh:107
void setXYContainers(const ScalarContainerX &x, const ScalarContainerY &y)
Set the sampling points of a natural spline using STL-compatible containers.
Definition: variablelengthspline_.hh:261
void setContainerOfTuples(const XYContainer &points)
Set the sampling points of a natural spline using a STL-compatible container of tuple-like objects.
Definition: variablelengthspline_.hh:346
void setXYArrays(int nSamples, 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: variablelengthspline_.hh:80
void setNumSamples_(int nSamples)
Resizes the internal vectors to store the sample points.
Definition: variablelengthspline_.hh:365
Vector xPos_
Definition: variablelengthspline_.hh:425
void setXYArrays(int nSamples, const ScalarArrayX &x, const ScalarArrayY &y)
Set the sampling points natural spline using C-style arrays.
Definition: variablelengthspline_.hh:234
void setArrayOfPoints(int nSamples, const PointArray &points)
Set the sampling points of a natural spline using a C-style array.
Definition: variablelengthspline_.hh:286
Vector m_
Definition: variablelengthspline_.hh:427
Scalar moment_(int i) const
Returns the moment (i.e. second derivative) of the spline at the i-th sampling point.
Definition: variablelengthspline_.hh:422