Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
dumux-repositories
dumux
Commits
71684091
Commit
71684091
authored
Oct 01, 2020
by
Timo Koch
Browse files
[math][linspace] Include option to make a range not including the endpoint
parent
8c667f5c
Changes
1
Hide whitespace changes
Inline
Side-by-side
dumux/common/math.hh
View file @
71684091
...
...
@@ -573,13 +573,17 @@ struct LinearTable
* \param begin The first value in the vector
* \param end The last value in the vector
* \param samples The size of the vector
* \param endPoint if the range is including the interval's end point or not
*/
template
<
class
Scalar
>
std
::
vector
<
Scalar
>
linspace
(
const
Scalar
begin
,
const
Scalar
end
,
std
::
size_t
samples
)
std
::
vector
<
Scalar
>
linspace
(
const
Scalar
begin
,
const
Scalar
end
,
std
::
size_t
samples
,
bool
endPoint
=
true
)
{
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
);
const
Scalar
divisor
=
endPoint
?
samples
-
1
:
samples
;
const
Scalar
delta
=
(
end
-
begin
)
/
divisor
;
std
::
vector
<
Scalar
>
vec
(
samples
);
for
(
std
::
size_t
i
=
0
;
i
<
samples
;
++
i
)
vec
[
i
]
=
begin
+
i
*
delta
;
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment