Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
dune-tnnmg
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
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
agnumpde
dune-tnnmg
Commits
a946cf04
Commit
a946cf04
authored
4 years ago
by
Lasse Hinrichsen
Browse files
Options
Downloads
Patches
Plain Diff
clean up
parent
c2bd24db
No related branches found
No related tags found
1 merge request
!25
WIP: Semilinear functional
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
dune/tnnmg/functionals/semilinearfunctional.hh
+0
-8
0 additions, 8 deletions
dune/tnnmg/functionals/semilinearfunctional.hh
dune/tnnmg/functionals/semilinearfunctionallinearization.hh
+25
-39
25 additions, 39 deletions
dune/tnnmg/functionals/semilinearfunctionallinearization.hh
with
25 additions
and
47 deletions
dune/tnnmg/functionals/semilinearfunctional.hh
+
0
−
8
View file @
a946cf04
...
@@ -237,14 +237,6 @@ public:
...
@@ -237,14 +237,6 @@ public:
return
Semilinearfunctional
(
f
.
weights_
,
new_origin
,
f
.
phi_
);
return
Semilinearfunctional
(
f
.
weights_
,
new_origin
,
f
.
phi_
);
}
}
friend
auto
derivative
(
const
Semilinearfunctional
&
f
)
{
// TODO: is this too much to ask for?
// auto phi_prime = derivative(f.phi_);
DUNE_THROW
(
Dune
::
NotImplemented
,
"Derivative not yet implemented"
);
return
42
;
}
friend
auto
directionalRestriction
(
const
Semilinearfunctional
&
f
,
friend
auto
directionalRestriction
(
const
Semilinearfunctional
&
f
,
const
Vector
&
origin
,
const
Vector
&
origin
,
const
Vector
&
direction
)
const
Vector
&
direction
)
...
...
This diff is collapsed.
Click to expand it.
dune/tnnmg/functionals/semilinearfunctionallinearization.hh
+
25
−
39
View file @
a946cf04
...
@@ -2,6 +2,7 @@
...
@@ -2,6 +2,7 @@
#include
<dune/common/hybridutilities.hh>
#include
<dune/common/hybridutilities.hh>
#include
<dune/common/typetraits.hh>
#include
<dune/common/typetraits.hh>
#include
<dune/matrix-vector/algorithm.hh>
#include
<dune/matrix-vector/algorithm.hh>
#include
<dune/tnnmg/functionals/semilinearfunctional.hh>
#include
<type_traits>
#include
<type_traits>
namespace
Dune
::
TNNMG
{
namespace
Dune
::
TNNMG
{
...
@@ -12,24 +13,6 @@ actually could be applied in other contexts, too. Some are even part of open MR
...
@@ -12,24 +13,6 @@ actually could be applied in other contexts, too. Some are even part of open MR
that gathered dust by now.
that gathered dust by now.
*/
*/
/** \brief For two vectors of equal size (and blocking), apply a scalar function
* componentswise such that u_i = f(v_i).
*/
template
<
typename
F
,
typename
V
>
void
applyComponentwise
(
F
&&
f
,
V
&
u
,
const
V
&
v
)
{
namespace
H
=
Dune
::
Hybrid
;
H
::
ifElse
(
Dune
::
IsNumber
<
std
::
decay_t
<
V
>>
(),
[
&
](
auto
&&
id
)
{
u
=
f
(
id
(
v
));
},
[
&
](
auto
id
)
{
H
::
forEach
(
H
::
integralRange
(
H
::
size
(
id
(
v
))),
[
&
](
auto
i
)
{
applyComponentwise
(
f
,
H
::
elementAt
(
u
,
i
),
H
::
elementAt
(
v
,
i
));
});
});
}
/** Multiply the i-th component of u by the i-th component of v, i.e.
/** Multiply the i-th component of u by the i-th component of v, i.e.
* u_i <- u_i*v_i
* u_i <- u_i*v_i
*/
*/
...
@@ -38,14 +21,13 @@ void
...
@@ -38,14 +21,13 @@ void
multiplyComponentwise
(
V
&
u
,
const
V
&
v
)
multiplyComponentwise
(
V
&
u
,
const
V
&
v
)
{
{
namespace
H
=
Dune
::
Hybrid
;
namespace
H
=
Dune
::
Hybrid
;
H
::
ifElse
(
if
constexpr
(
Dune
::
IsNumber
<
std
::
decay_t
<
V
>>
())
{
Dune
::
IsNumber
<
std
::
decay_t
<
V
>>
(),
u
*=
v
;
[
&
](
auto
&&
id
)
{
u
*=
id
(
v
);
},
}
else
{
[
&
](
auto
id
)
{
H
::
forEach
(
H
::
integralRange
(
H
::
size
(
v
)),
[
&
](
auto
i
)
{
H
::
forEach
(
H
::
integralRange
(
H
::
size
(
id
(
v
))),
[
&
](
auto
i
)
{
multiplyComponentwise
(
H
::
elementAt
(
u
,
i
),
H
::
elementAt
(
v
,
i
));
multiplyComponentwise
(
H
::
elementAt
(
u
,
i
),
H
::
elementAt
(
v
,
i
));
});
});
});
}
}
}
template
<
class
M
,
class
V
>
template
<
class
M
,
class
V
>
...
@@ -53,15 +35,15 @@ void
...
@@ -53,15 +35,15 @@ void
writeDiagonal
(
M
&
m
,
V
&&
v
)
writeDiagonal
(
M
&
m
,
V
&&
v
)
{
{
namespace
H
=
Dune
::
Hybrid
;
namespace
H
=
Dune
::
Hybrid
;
H
::
ifElse
(
if
constexpr
(
Dune
::
IsNumber
<
std
::
decay_t
<
V
>>
())
{
Dune
::
IsNumber
<
std
::
decay_t
<
V
>>
(),
m
=
v
;
[
&
](
auto
&&
id
)
{
m
=
id
(
v
);
},
}
else
{
[
&
](
auto
&&
id
)
{
H
::
forEach
(
H
::
integralRange
(
H
::
size
(
v
)),
[
&
](
auto
i
)
{
H
::
forEach
(
H
::
integralRange
(
H
::
size
(
id
(
v
))),
[
&
](
auto
i
)
{
writeDiagonal
(
H
::
elementAt
(
H
::
elementAt
(
m
,
i
),
i
),
H
::
elementAt
(
v
,
i
));
writeDiagonal
(
H
::
elementAt
(
H
::
elementAt
(
m
,
i
),
i
),
H
::
elementAt
(
v
,
i
));
});
});
});
}
}
}
template
<
class
NV
,
class
NBV
,
class
F
>
template
<
class
NV
,
class
NBV
,
class
F
>
void
void
determineTruncation
(
const
NV
&
x
,
NBV
&&
truncationFlags
,
const
F
&
function
)
determineTruncation
(
const
NV
&
x
,
NBV
&&
truncationFlags
,
const
F
&
function
)
...
@@ -72,7 +54,8 @@ determineTruncation(const NV& x, NBV&& truncationFlags, const F& function)
...
@@ -72,7 +54,8 @@ determineTruncation(const NV& x, NBV&& truncationFlags, const F& function)
}
else
{
}
else
{
assert
(
x
.
size
()
==
truncationFlags
.
size
());
assert
(
x
.
size
()
==
truncationFlags
.
size
());
H
::
forEach
(
H
::
integralRange
(
H
::
size
(
x
)),
[
&
](
auto
&&
i
)
{
H
::
forEach
(
H
::
integralRange
(
H
::
size
(
x
)),
[
&
](
auto
&&
i
)
{
determineTruncation
(
x
[
i
],
truncationFlags
[
i
],
function
);
// todo element_at
determineTruncation
(
H
::
elementAt
(
x
,
i
),
H
::
elementAt
(
truncationFlags
,
i
),
function
);
});
});
}
}
}
}
...
@@ -86,8 +69,9 @@ truncateVector(NV& x, const NBV& truncationFlags)
...
@@ -86,8 +69,9 @@ truncateVector(NV& x, const NBV& truncationFlags)
if
(
truncationFlags
)
if
(
truncationFlags
)
x
=
0
;
x
=
0
;
}
else
{
}
else
{
H
::
forEach
(
H
::
integralRange
(
H
::
size
(
x
)),
H
::
forEach
(
H
::
integralRange
(
H
::
size
(
x
)),
[
&
](
auto
&&
i
)
{
[
&
](
auto
&&
i
)
{
truncateVector
(
x
[
i
],
truncationFlags
[
i
]);
});
truncateVector
(
H
::
elementAt
(
x
,
i
),
H
::
elementAt
(
truncationFlags
,
i
));
});
}
}
}
}
...
@@ -104,9 +88,11 @@ truncateMatrix(NM& A,
...
@@ -104,9 +88,11 @@ truncateMatrix(NM& A,
A
=
0
;
A
=
0
;
}
else
{
}
else
{
H
::
forEach
(
H
::
integralRange
(
H
::
size
(
rowTruncationFlags
)),
[
&
](
auto
&&
i
)
{
H
::
forEach
(
H
::
integralRange
(
H
::
size
(
rowTruncationFlags
)),
[
&
](
auto
&&
i
)
{
auto
&&
Ai
=
A
[
i
]
;
auto
&&
Ai
=
H
::
elementAt
(
A
,
i
)
;
sparseRangeFor
(
Ai
,
[
&
](
auto
&&
Aij
,
auto
&&
j
)
{
sparseRangeFor
(
Ai
,
[
&
](
auto
&&
Aij
,
auto
&&
j
)
{
truncateMatrix
(
Aij
,
rowTruncationFlags
[
i
],
colTruncationFlags
[
j
]);
truncateMatrix
(
Aij
,
H
::
elementAt
(
rowTruncationFlags
,
i
),
H
::
elementAt
(
colTruncationFlags
,
i
));
});
});
});
});
}
}
...
@@ -158,14 +144,14 @@ public:
...
@@ -158,14 +144,14 @@ public:
// Assuming that the supplied function does not explode if it is evaluated
// Assuming that the supplied function does not explode if it is evaluated
// in a point where it's actually not defined.
// in a point where it's actually not defined.
Helper
::
applyComponentwise
(
derivative
(
f_
.
phi
()),
ngrad_
,
x
);
Impl
::
applyComponentwise
(
derivative
(
f_
.
phi
()),
ngrad_
,
x
);
Helper
::
multiplyComponentwise
(
ngrad_
,
f_
.
weights
());
Helper
::
multiplyComponentwise
(
ngrad_
,
f_
.
weights
());
ngrad_
*=
-
1
;
ngrad_
*=
-
1
;
mat_
=
0
;
mat_
=
0
;
// compute diagonal entries
// compute diagonal entries
auto
diag
=
x
;
auto
diag
=
x
;
Helper
::
applyComponentwise
(
derivative
(
derivative
(
f_
.
phi
())),
diag
,
x
);
Impl
::
applyComponentwise
(
derivative
(
derivative
(
f_
.
phi
())),
diag
,
x
);
Helper
::
multiplyComponentwise
(
diag
,
f_
.
weights
());
Helper
::
multiplyComponentwise
(
diag
,
f_
.
weights
());
// now, write them into the diagonal of the Hessian
// now, write them into the diagonal of the Hessian
Helper
::
writeDiagonal
(
mat_
,
diag
);
Helper
::
writeDiagonal
(
mat_
,
diag
);
...
...
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