Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
dune-gfe
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
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
Sander, Oliver
dune-gfe
Commits
a4698348
Commit
a4698348
authored
14 years ago
by
Oliver Sander
Committed by
sander@FU-BERLIN.DE
14 years ago
Browse files
Options
Downloads
Patches
Plain Diff
various fixes and improvements
[[Imported from SVN: r7041]]
parent
d8018f23
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
test/unitvectortest.cc
+53
-38
53 additions, 38 deletions
test/unitvectortest.cc
with
53 additions
and
38 deletions
test/unitvectortest.cc
+
53
−
38
View file @
a4698348
...
...
@@ -6,24 +6,9 @@
#include
<typeinfo>
#ifdef __GNUC__
#include
<cxxabi.h>
#endif
using
Dune
::
FieldVector
;
using
std
::
complex
;
template
<
class
T
>
std
::
string
className
(
T
&
t
)
{
#ifdef __GNUC__
int
status
;
return
abi
::
__cxa_demangle
(
typeid
(
t
).
name
(),
0
,
0
,
&
status
);
#else
return
typeid
(
t
).
name
();
#endif
};
/** \file
\brief Unit tests for the UnitVector class
...
...
@@ -56,24 +41,25 @@ double energy(const FieldVector<double,dim>& a, const FieldVector<double,dim>& b
The formula for the Riemannian Hessian has been taken from Absil, Mahony, Sepulchre:
'Optimization algorithms on matrix manifolds', page 107
*/
template
<
class
TargetSpace
,
int
d
im
>
FieldMatrix
<
double
,
dim
,
d
im
>
getSecondDerivativeOfSecondArgumentFD
(
const
TargetSpace
&
a
,
const
TargetSpace
&
b
)
template
<
class
TargetSpace
,
int
worldD
im
>
FieldMatrix
<
double
,
worldDim
,
worldD
im
>
getSecondDerivativeOfSecondArgumentFD
(
const
TargetSpace
&
a
,
const
TargetSpace
&
b
)
{
// finite-difference approximation
FieldMatrix
<
double
,
dim
,
dim
>
d2d2_fd
(
0
);
const
size_t
spaceDim
=
TargetSpace
::
dim
;
// finite-difference approximation
FieldMatrix
<
double
,
spaceDim
,
spaceDim
>
d2d2_fd
(
0
);
FieldMatrix
<
double
,
dim
,
d
im
>
B
=
b
.
orthonormalFrame
();
FieldMatrix
<
double
,
spaceDim
,
worldD
im
>
B
=
b
.
orthonormalFrame
();
for
(
size_t
i
=
0
;
i
<
spaceDim
;
i
++
)
{
for
(
size_t
j
=
0
;
j
<
spaceDim
;
j
++
)
{
FieldVector
<
double
,
d
im
>
epsXi
=
B
[
i
];
epsXi
*=
eps
;
FieldVector
<
double
,
d
im
>
epsEta
=
B
[
j
];
epsEta
*=
eps
;
FieldVector
<
double
,
worldD
im
>
epsXi
=
B
[
i
];
epsXi
*=
eps
;
FieldVector
<
double
,
worldD
im
>
epsEta
=
B
[
j
];
epsEta
*=
eps
;
FieldVector
<
double
,
d
im
>
minusEpsXi
=
epsXi
;
minusEpsXi
*=
-
1
;
FieldVector
<
double
,
d
im
>
minusEpsEta
=
epsEta
;
minusEpsEta
*=
-
1
;
FieldVector
<
double
,
worldD
im
>
minusEpsXi
=
epsXi
;
minusEpsXi
*=
-
1
;
FieldVector
<
double
,
worldD
im
>
minusEpsEta
=
epsEta
;
minusEpsEta
*=
-
1
;
double
forwardValue
=
energy
(
a
,
TargetSpace
::
exp
(
b
,
epsXi
+
epsEta
))
-
energy
(
a
,
TargetSpace
::
exp
(
b
,
epsXi
))
-
energy
(
a
,
TargetSpace
::
exp
(
b
,
epsEta
));
double
centerValue
=
energy
(
a
,
b
)
-
energy
(
a
,
b
)
-
energy
(
a
,
b
);
...
...
@@ -84,17 +70,17 @@ FieldMatrix<double,dim,dim> getSecondDerivativeOfSecondArgumentFD(const TargetSp
}
}
B
.
invert
();
FieldMatrix
<
double
,
dim
,
d
im
>
BT
;
for
(
int
i
=
0
;
i
<
d
im
;
i
++
)
for
(
int
j
=
0
;
j
<
d
im
;
j
++
)
//
B.invert();
FieldMatrix
<
double
,
worldDim
,
spaceD
im
>
BT
;
for
(
int
i
=
0
;
i
<
worldD
im
;
i
++
)
for
(
int
j
=
0
;
j
<
spaceD
im
;
j
++
)
BT
[
i
][
j
]
=
B
[
j
][
i
];
FieldMatrix
<
double
,
dim
,
d
im
>
ret1
;
FieldMatrix
<
double
,
spaceDim
,
worldD
im
>
ret1
;
FMatrixHelp
::
multMatrix
(
d2d2_fd
,
B
,
ret1
);
FieldMatrix
<
double
,
dim
,
d
im
>
ret2
;
FieldMatrix
<
double
,
worldDim
,
worldD
im
>
ret2
;
FMatrixHelp
::
multMatrix
(
BT
,
ret1
,
ret2
);
return
ret2
;
}
...
...
@@ -256,17 +242,46 @@ void testDerivativesOfSquaredDistance(const TargetSpace& a, const TargetSpace& b
}
void
testUnitVector2d
()
{
int
nTestPoints
=
1
;
double
testPoints
[
1
][
2
][
2
]
=
{{{
1
,
0
},
{
0
,
1
}}};
// Set up elements of S^1
for
(
int
i
=
0
;
i
<
nTestPoints
;
i
++
)
{
Dune
::
array
<
double
,
2
>
w0
=
{
testPoints
[
i
][
0
][
0
],
testPoints
[
i
][
0
][
1
]};
UnitVector
<
2
>
uv0
(
w0
);
Dune
::
array
<
double
,
2
>
w1
=
{
testPoints
[
i
][
1
][
0
],
testPoints
[
i
][
1
][
1
]};
UnitVector
<
2
>
uv1
(
w1
);
testDerivativesOfSquaredDistance
<
UnitVector
<
2
>
,
2
>
(
uv0
,
uv1
);
}
}
void
testUnitVector3d
()
{
int
nTestPoints
=
1
;
double
testPoints
[
1
][
2
][
3
]
=
{{{
1
,
0
,
0
},
{
0
,
1
,
0
}}};
// Set up elements of S^1
for
(
int
i
=
0
;
i
<
nTestPoints
;
i
++
)
{
Dune
::
array
<
double
,
3
>
w0
=
{
testPoints
[
i
][
0
][
0
],
testPoints
[
i
][
0
][
1
],
testPoints
[
i
][
0
][
2
]};
UnitVector
<
3
>
uv0
(
w0
);
Dune
::
array
<
double
,
3
>
w1
=
{
testPoints
[
i
][
1
][
0
],
testPoints
[
i
][
1
][
1
],
testPoints
[
i
][
1
][
2
]};
UnitVector
<
3
>
uv1
(
w1
);
testDerivativesOfSquaredDistance
<
UnitVector
<
3
>
,
3
>
(
uv0
,
uv1
);
}
}
int
main
()
{
#if 1
// Set up elements of S^1
Dune
::
array
<
double
,
2
>
w0
=
{{
1
,
0
}};
UnitVector
<
2
>
uv0
(
w0
);
Dune
::
array
<
double
,
2
>
w1
=
{{
0
,
1
}};
UnitVector
<
2
>
uv1
(
w1
);
testDerivativesOfSquaredDistance
<
UnitVector
<
2
>
,
2
>
(
uv0
,
uv1
);
#endif
testUnitVector2d
();
testUnitVector3d
();
// Set up elements of R^1
Dune
::
FieldVector
<
double
,
2
>
rtw0
;
rtw0
[
0
]
=
0
;
rtw0
[
1
]
=
1
;
...
...
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