Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
O
ogs
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
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
Özgür Ozan Sen
ogs
Commits
fb23e5ce
Commit
fb23e5ce
authored
4 years ago
by
Dmitri Naumov
Committed by
Tom Fischer
4 years ago
Browse files
Options
Downloads
Patches
Plain Diff
[T/MPL] Random derivative testing of exp property.
parent
d6c18ce9
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
Tests/MaterialLib/TestMPLExponential.cpp
+68
-0
68 additions, 0 deletions
Tests/MaterialLib/TestMPLExponential.cpp
with
68 additions
and
0 deletions
Tests/MaterialLib/TestMPLExponential.cpp
+
68
−
0
View file @
fb23e5ce
...
@@ -10,12 +10,80 @@
...
@@ -10,12 +10,80 @@
*/
*/
#include
<gtest/gtest.h>
#include
<gtest/gtest.h>
#include
<autocheck/autocheck.hpp>
#include
<cmath>
#include
<cmath>
#include
"MaterialLib/MPL/Properties/Exponential.h"
#include
"MaterialLib/MPL/Properties/Exponential.h"
#include
"Tests/AutoCheckTools.h"
namespace
ac
=
autocheck
;
namespace
MPL
=
MaterialPropertyLib
;
namespace
MPL
=
MaterialPropertyLib
;
struct
MaterialPropertyLibExponentialProperty
:
public
::
testing
::
Test
{
void
SetUp
()
override
{
double
const
y_ref
=
1.
;
double
const
T_ref
=
1.
;
double
const
factor
=
2.
;
p
=
std
::
make_unique
<
MPL
::
Exponential
>
(
"exponential"
,
y_ref
,
MPL
::
ExponentData
{
MPL
::
Variable
::
temperature
,
T_ref
,
factor
});
}
std
::
unique_ptr
<
MPL
::
Property
>
p
;
ac
::
gtest_reporter
gtest_reporter
;
};
// First order derivative approximated with second order central differences.
template
<
typename
F
>
double
dydx_C2
(
double
const
x
,
F
&&
f
,
double
const
h
)
{
return
(
f
(
x
+
h
)
-
f
(
x
-
h
))
/
(
2
*
h
);
}
// Second order derivative approximated with second order central differences.
template
<
typename
F
>
double
d2ydx2_C2
(
double
const
x
,
F
&&
f
,
double
const
h
)
{
return
(
f
(
x
+
h
)
-
2
*
f
(
x
)
+
f
(
x
-
h
))
/
(
h
*
h
);
}
TEST_F
(
MaterialPropertyLibExponentialProperty
,
TestNumericalDerivatives
)
{
double
const
eps
=
1e-5
;
ParameterLib
::
SpatialPosition
const
pos
;
double
const
time
=
std
::
numeric_limits
<
double
>::
quiet_NaN
();
double
const
dt
=
std
::
numeric_limits
<
double
>::
quiet_NaN
();
auto
y
=
[
&
](
double
const
T
)
{
MPL
::
VariableArray
variable_array
;
variable_array
[
static_cast
<
int
>
(
MPL
::
Variable
::
temperature
)]
=
T
;
return
p
->
template
value
<
double
>(
variable_array
,
pos
,
time
,
dt
);
};
auto
f
=
[
&
](
double
const
T
){
MPL
::
VariableArray
variable_array
;
variable_array
[
static_cast
<
int
>
(
MPL
::
Variable
::
temperature
)]
=
T
;
double
const
v
=
p
->
template
value
<
double
>(
variable_array
,
pos
,
time
,
dt
);
double
const
dv
=
p
->
template
dValue
<
double
>(
variable_array
,
MPL
::
Variable
::
temperature
,
pos
,
time
,
dt
);
double
const
dv2
=
p
->
template
d2Value
<
double
>(
variable_array
,
MPL
::
Variable
::
temperature
,
MPL
::
Variable
::
temperature
,
pos
,
time
,
dt
);
double
const
Dv
=
dydx_C2
(
T
,
y
,
eps
);
double
const
Dv2
=
d2ydx2_C2
(
T
,
y
,
eps
);
return
(
std
::
abs
(
dv
-
Dv
)
<=
1e-9
*
v
)
&&
(
std
::
abs
(
dv2
-
Dv2
)
<=
eps
*
v
);
};
// Limit values to avoid +-inf.
auto
gen
=
ac
::
IntervalGenerator
(
-
100.
,
100.
);
ac
::
check
<
double
>
(
f
,
10000
,
ac
::
make_arbitrary
(
gen
),
gtest_reporter
);
}
TEST
(
MaterialPropertyLib
,
Exponential
)
TEST
(
MaterialPropertyLib
,
Exponential
)
{
{
double
const
y_ref
=
1e-3
;
double
const
y_ref
=
1e-3
;
...
...
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