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
9ef68af4
Commit
9ef68af4
authored
5 months ago
by
Timo Koch
Browse files
Options
Downloads
Patches
Plain Diff
[common] Add option for five-point stencil numeric difference
parent
c4f04b7b
No related branches found
Branches containing commit
No related tags found
1 merge request
!3866
[common] Add option for five-point stencil numeric difference
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
dumux/common/numericdifferentiation.hh
+17
-1
17 additions, 1 deletion
dumux/common/numericdifferentiation.hh
with
17 additions
and
1 deletion
dumux/common/numericdifferentiation.hh
+
17
−
1
View file @
9ef68af4
...
@@ -61,7 +61,7 @@ public:
...
@@ -61,7 +61,7 @@ public:
* \param fx0 The result of the function evaluated at x0
* \param fx0 The result of the function evaluated at x0
* \param eps The numeric epsilon used in the differentiation
* \param eps The numeric epsilon used in the differentiation
* \param numericDifferenceMethod The numeric difference method
* \param numericDifferenceMethod The numeric difference method
* (1: forward differences (default), 0: central differences, -1: backward differences)
* (1: forward differences (default), 0: central differences, -1: backward differences
, 5: five-point stencil method
)
*/
*/
template
<
class
Function
,
class
Scalar
,
class
FunctionEvalType
>
template
<
class
Function
,
class
Scalar
,
class
FunctionEvalType
>
static
void
partialDerivative
(
const
Function
&
function
,
Scalar
x0
,
static
void
partialDerivative
(
const
Function
&
function
,
Scalar
x0
,
...
@@ -70,7 +70,23 @@ public:
...
@@ -70,7 +70,23 @@ public:
const
Scalar
eps
,
const
Scalar
eps
,
const
int
numericDifferenceMethod
=
1
)
const
int
numericDifferenceMethod
=
1
)
{
{
// Five-point stencil numeric difference,
// Abramowitz & Stegun, Table 25.2.
// The error is proportional to eps^4.
if
(
numericDifferenceMethod
==
5
)
{
derivative
=
function
(
x0
+
eps
);
derivative
-=
function
(
x0
-
eps
);
derivative
*=
8.0
;
derivative
+=
function
(
x0
-
2
*
eps
);
derivative
-=
function
(
x0
+
2
*
eps
);
derivative
/=
12
*
eps
;
return
;
}
// Forward, central, or backward differences
Scalar
delta
=
0.0
;
Scalar
delta
=
0.0
;
// we are using forward or central differences, i.e. we need to calculate f(x + \epsilon)
// we are using forward or central differences, i.e. we need to calculate f(x + \epsilon)
if
(
numericDifferenceMethod
>=
0
)
if
(
numericDifferenceMethod
>=
0
)
{
{
...
...
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