Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
dumux
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
dumux-repositories
dumux
Commits
7a5d7f6c
Commit
7a5d7f6c
authored
5 years ago
by
Ned Coltman
Committed by
Timo Koch
5 years ago
Browse files
Options
Downloads
Patches
Plain Diff
[math][linspace] move linspace to math.hh
parent
2fe262e9
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!1624
Feature/linspace
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
dumux/common/math.hh
+20
-0
20 additions, 0 deletions
dumux/common/math.hh
test/common/spline/test_cubicspline.cc
+4
-12
4 additions, 12 deletions
test/common/spline/test_cubicspline.cc
test/common/spline/test_monotonecubicspline.cc
+4
-12
4 additions, 12 deletions
test/common/spline/test_monotonecubicspline.cc
with
28 additions
and
24 deletions
dumux/common/math.hh
+
20
−
0
View file @
7a5d7f6c
...
...
@@ -562,6 +562,26 @@ struct LinearTable
}
// end namespace InterpolationPolicy
/*!
* \ingroup Common
* \brief Generates linearly spaced vectors
*
* \param begin The first value in the vector
* \param end The last value in the vector
* \param samples The size of the vector
*/
template
<
class
Scalar
>
std
::
vector
<
Scalar
>
linspace
(
const
Scalar
begin
,
const
Scalar
end
,
std
::
size_t
samples
)
{
using
std
::
max
;
samples
=
max
(
std
::
size_t
{
2
},
samples
);
// only makes sense for 2 or more samples
const
Scalar
delta
=
(
end
-
begin
)
/
static_cast
<
Scalar
>
(
samples
-
1
);
std
::
vector
<
Scalar
>
vec
(
samples
);
for
(
std
::
size_t
i
=
0
;
i
<
samples
;
++
i
)
vec
[
i
]
=
begin
+
i
*
delta
;
return
vec
;
}
/*!
* \ingroup Common
...
...
This diff is collapsed.
Click to expand it.
test/common/spline/test_cubicspline.cc
+
4
−
12
View file @
7a5d7f6c
...
...
@@ -29,18 +29,10 @@
#include
<dune/common/exceptions.hh>
#include
<dune/common/parallel/mpihelper.hh>
#include
<dumux/common/math.hh>
#include
<dumux/common/cubicspline.hh>
#include
<dumux/io/gnuplotinterface.hh>
std
::
vector
<
double
>
linspace
(
const
double
begin
,
const
double
end
,
const
double
samples
)
{
const
double
delta
=
(
end
-
begin
)
/
static_cast
<
double
>
(
samples
-
1
);
std
::
vector
<
double
>
vec
(
samples
);
for
(
int
i
=
0
;
i
<
samples
;
++
i
)
vec
[
i
]
=
begin
+
i
*
delta
;
return
vec
;
}
template
<
class
Function
>
std
::
vector
<
double
>
eval
(
const
Function
&
f
,
const
std
::
vector
<
double
>&
x
)
{
...
...
@@ -58,12 +50,12 @@ int main(int argc, char** argv)
const
auto
df
=
[](
double
x
){
return
-
2.0
*
x
/
((
1.0
+
x
*
x
)
*
(
1.0
+
x
*
x
));
};
// create some test samples
const
auto
testPoints
=
linspace
(
-
4.0
,
4.0
,
1000
);
const
auto
testPoints
=
Dumux
::
linspace
(
-
4.0
,
4.0
,
1000
);
const
auto
ref
=
eval
(
f
,
testPoints
);
const
auto
refDeriv
=
eval
(
df
,
testPoints
);
// create the spline sample points
const
auto
samplePoints
=
linspace
(
-
4.0
,
4.0
,
15
);
const
auto
samplePoints
=
Dumux
::
linspace
(
-
4.0
,
4.0
,
15
);
const
auto
y
=
eval
(
f
,
samplePoints
);
// create the spline
...
...
@@ -86,7 +78,7 @@ int main(int argc, char** argv)
DUNE_THROW
(
Dune
::
Exception
,
"Maximum error in spline interpolation too large!"
);
// plot with Gnuplot (plot a bit more so we can see the linear extension)
const
auto
plotPoints
=
linspace
(
-
8.0
,
8.0
,
1000
);
const
auto
plotPoints
=
Dumux
::
linspace
(
-
8.0
,
8.0
,
1000
);
const
auto
refPlot
=
eval
(
f
,
plotPoints
);
const
auto
refDerivPlot
=
eval
(
df
,
plotPoints
);
const
auto
resultPlot
=
eval
([
&
](
const
double
x
)
{
return
spline
.
eval
(
x
);
},
plotPoints
);
...
...
This diff is collapsed.
Click to expand it.
test/common/spline/test_monotonecubicspline.cc
+
4
−
12
View file @
7a5d7f6c
...
...
@@ -29,18 +29,10 @@
#include
<dune/common/exceptions.hh>
#include
<dune/common/parallel/mpihelper.hh>
#include
<dumux/common/math.hh>
#include
<dumux/common/monotonecubicspline.hh>
#include
<dumux/io/gnuplotinterface.hh>
std
::
vector
<
double
>
linspace
(
const
double
begin
,
const
double
end
,
const
double
samples
)
{
const
double
delta
=
(
end
-
begin
)
/
static_cast
<
double
>
(
samples
-
1
);
std
::
vector
<
double
>
vec
(
samples
);
for
(
int
i
=
0
;
i
<
samples
;
++
i
)
vec
[
i
]
=
begin
+
i
*
delta
;
return
vec
;
}
template
<
class
Function
>
std
::
vector
<
double
>
eval
(
const
Function
&
f
,
const
std
::
vector
<
double
>&
x
)
{
...
...
@@ -58,12 +50,12 @@ int main(int argc, char** argv)
const
auto
df
=
[](
double
x
){
return
3
*
x
*
x
;
};
// create some test samples
const
auto
testPoints
=
linspace
(
0.0
,
4.0
,
1000
);
const
auto
testPoints
=
Dumux
::
linspace
(
0.0
,
4.0
,
1000
);
const
auto
ref
=
eval
(
f
,
testPoints
);
const
auto
refDeriv
=
eval
(
df
,
testPoints
);
// create the spline sample points
const
auto
samplePoints
=
linspace
(
0.0
,
5.0
,
10
);
const
auto
samplePoints
=
Dumux
::
linspace
(
0.0
,
5.0
,
10
);
const
auto
y
=
eval
(
f
,
samplePoints
);
// create the spline
...
...
@@ -88,7 +80,7 @@ int main(int argc, char** argv)
DUNE_THROW
(
Dune
::
Exception
,
"Maximum error in spline interpolation too large!"
);
// plot with Gnuplot (plot a bit more so we can see the linear extension)
const
auto
plotPoints
=
linspace
(
-
1.0
,
5.0
,
1000
);
const
auto
plotPoints
=
Dumux
::
linspace
(
-
1.0
,
5.0
,
1000
);
const
auto
refPlot
=
eval
(
f
,
plotPoints
);
const
auto
refDerivPlot
=
eval
(
df
,
plotPoints
);
const
auto
resultPlot
=
eval
([
&
](
const
double
x
)
{
return
spline
.
eval
(
x
);
},
plotPoints
);
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment