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
99a07e46
Commit
99a07e46
authored
13 years ago
by
Elias Pipping
Committed by
Elias Pipping
13 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Move nonlinearity-related code to the nonlinearity class
parent
f5f7bb37
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/mynonlinearity.hh
+15
-3
15 additions, 3 deletions
src/mynonlinearity.hh
src/samplefunctional.hh
+20
-15
20 additions, 15 deletions
src/samplefunctional.hh
with
35 additions
and
18 deletions
src/mynonlinearity.hh
+
15
−
3
View file @
99a07e46
...
@@ -22,10 +22,12 @@ class MyNonlinearity {
...
@@ -22,10 +22,12 @@ class MyNonlinearity {
typedef
SmallVector
VectorType
;
typedef
SmallVector
VectorType
;
typedef
SmallMatrix
MatrixType
;
typedef
SmallMatrix
MatrixType
;
double
operator
()(
VectorType
const
x
)
const
{
return
func_
(
x
.
two_norm
());
}
// directional subdifferential: at u on the line u + t*v
// directional subdifferential: at u on the line u + t*v
// u and v are assumed to be non-zero
// u and v are assumed to be non-zero
void
directionalSubDiff
(
VectorType
const
u
,
VectorType
const
v
,
void
directionalSubDiff
(
VectorType
const
u
,
VectorType
const
v
,
Interval
<
double
>
&
D
)
const
{
Interval
<
double
>
&
D
)
const
{
if
(
u
==
SmallVector
(
0.0
))
{
if
(
u
==
SmallVector
(
0.0
))
{
D
[
0
]
=
D
[
1
]
=
func_
.
rightDifferential
(
0
);
D
[
0
]
=
D
[
1
]
=
func_
.
rightDifferential
(
0
);
return
;
return
;
...
@@ -42,8 +44,18 @@ class MyNonlinearity {
...
@@ -42,8 +44,18 @@ class MyNonlinearity {
}
}
}
}
void
directionalDomain
(
const
VectorType
&
,
const
VectorType
&
,
void
upperGradient
(
const
SmallVector
x
,
SmallVector
&
ret
)
const
{
Interval
<
double
>&
dom
)
const
{
ret
=
x
;
ret
*=
func_
.
rightDifferential
(
x
.
two_norm
())
/
x
.
two_norm
();
}
void
lowerGradient
(
const
SmallVector
x
,
SmallVector
&
ret
)
const
{
ret
=
x
;
ret
*=
func_
.
leftDifferential
(
x
.
two_norm
())
/
x
.
two_norm
();
}
void
directionalDomain
(
const
VectorType
&
,
const
VectorType
&
,
Interval
<
double
>
&
dom
)
const
{
dom
[
0
]
=
std
::
numeric_limits
<
double
>::
min
();
dom
[
0
]
=
std
::
numeric_limits
<
double
>::
min
();
dom
[
1
]
=
std
::
numeric_limits
<
double
>::
max
();
dom
[
1
]
=
std
::
numeric_limits
<
double
>::
max
();
}
}
...
...
This diff is collapsed.
Click to expand it.
src/samplefunctional.hh
+
20
−
15
View file @
99a07e46
...
@@ -21,25 +21,28 @@ class SampleFunctional {
...
@@ -21,25 +21,28 @@ class SampleFunctional {
typedef
Dune
::
FieldMatrix
<
double
,
dimension
,
dimension
>
SmallMatrix
;
typedef
Dune
::
FieldMatrix
<
double
,
dimension
,
dimension
>
SmallMatrix
;
typedef
Function
FunctionType
;
typedef
Function
FunctionType
;
SampleFunctional
(
SmallMatrix
_A
,
SmallVector
_b
)
:
A
(
_A
),
b
(
_b
),
func_
()
{}
typedef
MyNonlinearity
<
dimension
,
Function
>
NonlinearityType
;
SampleFunctional
(
SmallMatrix
_A
,
SmallVector
_b
)
:
A
(
_A
),
b
(
_b
)
{}
double
operator
()(
const
SmallVector
v
)
const
{
double
operator
()(
const
SmallVector
v
)
const
{
SmallVector
y
;
SmallVector
y
;
A
.
mv
(
v
,
y
);
// y = Av
A
.
mv
(
v
,
y
);
// y = Av
y
/=
2
;
// y = 1/2 Av
y
/=
2
;
// y = 1/2 Av
y
-=
b
;
// y = 1/2 Av - b
y
-=
b
;
// y = 1/2 Av - b
return
y
*
v
+
func_
(
v
.
two_norm
()
);
// <1/2 Av - b,v> + H(|v|)
return
y
*
v
+
phi_
(
v
);
// <1/2 Av - b,v> + H(|v|)
}
}
void
descentDirection
(
const
SmallVector
x
,
SmallVector
&
ret
)
const
{
void
descentDirection
(
const
SmallVector
x
,
SmallVector
&
ret
)
const
{
if
(
x
==
SmallVector
(
0.0
))
{
if
(
x
==
SmallVector
(
0.0
))
{
// If there is a direction of descent, this is it
SmallVector
const
d
=
smoothGradient
(
x
);
SmallVector
const
d
=
smoothGradient
(
x
);
// Decline of the smooth part in the negative gradient direction
Interval
<
double
>
D
;
double
smoothDecline
=
-
(
d
*
d
);
phi_
.
directionalSubDiff
(
x
,
d
,
D
);
double
nonlinearDecline
=
double
const
nonlinearDecline
=
D
[
1
];
func_
.
rightDifferential
(
0.0
)
*
d
.
two_norm
();
// TODO: is this correct?
double
const
smoothDecline
=
-
(
d
*
d
);
double
combinedDecline
=
smoothDecline
+
nonlinearDecline
;
double
const
combinedDecline
=
smoothDecline
+
nonlinearDecline
;
if
(
combinedDecline
<
0
)
{
if
(
combinedDecline
<
0
)
{
ret
=
d
;
ret
=
d
;
...
@@ -82,7 +85,7 @@ class SampleFunctional {
...
@@ -82,7 +85,7 @@ class SampleFunctional {
SmallVector
b
;
SmallVector
b
;
private
:
private
:
Function
func
_
;
NonlinearityType
phi
_
;
// Gradient of the smooth part
// Gradient of the smooth part
SmallVector
smoothGradient
(
const
SmallVector
x
)
const
{
SmallVector
smoothGradient
(
const
SmallVector
x
)
const
{
...
@@ -93,14 +96,16 @@ class SampleFunctional {
...
@@ -93,14 +96,16 @@ class SampleFunctional {
}
}
SmallVector
upperGradient
(
const
SmallVector
x
)
const
{
SmallVector
upperGradient
(
const
SmallVector
x
)
const
{
SmallVector
y
=
smoothGradient
(
x
);
SmallVector
y
;
y
.
axpy
(
func_
.
rightDifferential
(
x
.
two_norm
())
/
x
.
two_norm
(),
x
);
phi_
.
upperGradient
(
x
,
y
);
y
+=
smoothGradient
(
x
);
return
y
;
return
y
;
}
}
SmallVector
lowerGradient
(
const
SmallVector
x
)
const
{
SmallVector
lowerGradient
(
const
SmallVector
x
)
const
{
SmallVector
y
=
smoothGradient
(
x
);
SmallVector
y
;
y
.
axpy
(
func_
.
leftDifferential
(
x
.
two_norm
())
/
x
.
two_norm
(),
x
);
phi_
.
lowerGradient
(
x
,
y
);
y
+=
smoothGradient
(
x
);
return
y
;
return
y
;
}
}
...
...
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