Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
dune-tectonic
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
Deploy
Releases
Container registry
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor 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
podlesny
dune-tectonic
Commits
7b4790fd
Commit
7b4790fd
authored
13 years ago
by
Elias Pipping
Committed by
Elias Pipping
13 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Add identity function
parent
9ee6858e
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/nicefunction.hh
+9
-0
9 additions, 0 deletions
src/nicefunction.hh
src/test-gradient-method.cc
+37
-0
37 additions, 0 deletions
src/test-gradient-method.cc
with
46 additions
and
0 deletions
src/nicefunction.hh
+
9
−
0
View file @
7b4790fd
...
@@ -12,6 +12,15 @@ class NiceFunction : public VirtualFunction<double, double> {
...
@@ -12,6 +12,15 @@ class NiceFunction : public VirtualFunction<double, double> {
virtual
double
rightDifferential
(
const
double
s
)
const
=
0
;
virtual
double
rightDifferential
(
const
double
s
)
const
=
0
;
};
};
class
Identity
:
public
NiceFunction
{
public:
void
virtual
evaluate
(
const
double
&
x
,
double
&
y
)
const
{
y
=
x
;
}
double
virtual
leftDifferential
(
const
double
s
)
const
{
return
1
;
}
double
virtual
rightDifferential
(
const
double
s
)
const
{
return
1
;
}
};
class
SampleFunction
:
public
NiceFunction
{
class
SampleFunction
:
public
NiceFunction
{
public:
public:
void
virtual
evaluate
(
const
double
&
x
,
double
&
y
)
const
{
void
virtual
evaluate
(
const
double
&
x
,
double
&
y
)
const
{
...
...
This diff is collapsed.
Click to expand it.
src/test-gradient-method.cc
+
37
−
0
View file @
7b4790fd
...
@@ -28,6 +28,41 @@ double functionTester(Dune::SampleFunctional<dim> J,
...
@@ -28,6 +28,41 @@ double functionTester(Dune::SampleFunctional<dim> J,
return
final
;
return
final
;
}
}
void
testIdentity
()
{
int
const
dim
=
2
;
typedef
Dune
::
SampleFunctional
<
dim
>
Functional
;
Functional
::
SmallMatrix
A
;
A
[
0
][
0
]
=
3
;
A
[
0
][
1
]
=
1.5
;
A
[
1
][
0
]
=
1.5
;
A
[
1
][
1
]
=
4
;
Functional
::
SmallVector
b
;
b
[
0
]
=
1
;
b
[
1
]
=
2
;
Dune
::
Identity
f
;
Functional
J
(
A
,
b
,
Dune
::
MyNonlinearity
<
dim
>
(
f
));
Functional
::
SmallVector
start
=
b
;
start
*=
17
;
double
const
ret1
=
functionTester
(
J
,
start
,
6
);
// Something random
start
[
0
]
=
279
;
start
[
1
]
=
-
96
;
double
const
ret2
=
functionTester
(
J
,
start
,
10
);
assert
(
std
::
abs
(
ret1
-
ret2
)
<
1e-5
);
start
[
0
]
=
0
;
start
[
1
]
=
0
;
double
const
ret3
=
functionTester
(
J
,
start
,
3
);
assert
(
std
::
abs
(
ret1
-
ret3
)
<
1e-5
);
}
void
testSampleFunction
()
{
void
testSampleFunction
()
{
int
const
dim
=
2
;
int
const
dim
=
2
;
typedef
Dune
::
SampleFunctional
<
dim
>
Functional
;
typedef
Dune
::
SampleFunctional
<
dim
>
Functional
;
...
@@ -331,6 +366,8 @@ void testSampleFunction2() {
...
@@ -331,6 +366,8 @@ void testSampleFunction2() {
int
main
()
{
int
main
()
{
try
{
try
{
testIdentity
();
std
::
cout
<<
std
::
endl
<<
std
::
endl
<<
std
::
endl
;
testSampleFunction
();
testSampleFunction
();
std
::
cout
<<
std
::
endl
<<
std
::
endl
<<
std
::
endl
;
std
::
cout
<<
std
::
endl
<<
std
::
endl
<<
std
::
endl
;
testSampleFunctionNonsmooth
();
testSampleFunctionNonsmooth
();
...
...
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