Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
SemiSmoothNewton.jl
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
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
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
Stephan Hilb
SemiSmoothNewton.jl
Commits
754a746b
Commit
754a746b
authored
3 years ago
by
Stephan Hilb
Browse files
Options
Downloads
Patches
Plain Diff
implement l2 norm and introduce stopping criteria
parent
d6b041f8
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/function.jl
+26
-1
26 additions, 1 deletion
src/function.jl
src/run.jl
+13
-5
13 additions, 5 deletions
src/run.jl
with
39 additions
and
6 deletions
src/function.jl
+
26
−
1
View file @
754a746b
using
Statistics
:
mean
using
Statistics
:
mean
using
StaticArrays
:
SA
,
SArray
,
MVector
,
MMatrix
using
StaticArrays
:
SA
,
SArray
,
MVector
,
MMatrix
export
FeSpace
,
Mapper
,
FeFunction
,
P1
,
DP0
,
DP1
export
FeSpace
,
Mapper
,
FeFunction
,
P1
,
DP0
,
DP1
export
interpolate!
,
sample
,
bind!
,
evaluate
,
nabla
export
interpolate!
,
sample
,
bind!
,
evaluate
,
integrate
,
nabla
# Finite Elements
# Finite Elements
struct
P1
end
struct
P1
end
...
@@ -182,7 +182,32 @@ function project!(dst::FeFunction, ::DP0, expr; params...)
...
@@ -182,7 +182,32 @@ function project!(dst::FeFunction, ::DP0, expr; params...)
gdofs
=
space
.
dofmap
[
:
,
1
,
cell
]
gdofs
=
space
.
dofmap
[
:
,
1
,
cell
]
dst
.
data
[
gdofs
]
.=
myvec
(
expr
(
centroid
;
opvalues
...
))
.*
intel
dst
.
data
[
gdofs
]
.=
myvec
(
expr
(
centroid
;
opvalues
...
))
.*
intel
end
end
end
function
integrate
(
mesh
::
Mesh
,
expr
;
params
...
)
opparams
=
NamedTuple
(
params
)
qw
,
qx
=
quadrature
()
# only for type inference
opvalues
=
map
(
f
->
evaluate
(
f
,
SA
[
0.
,
0.
]),
opparams
)
val
=
zero
(
expr
(
SA
[
0.
,
0.
];
opvalues
...
))
for
cell
in
cells
(
mesh
)
foreach
(
f
->
bind!
(
f
,
cell
),
opparams
)
delmap
=
jacobian
(
elmap
(
mesh
,
cell
),
SA
[
0.
,
0.
])
intel
=
abs
(
det
(
delmap
))
# quadrature points
for
k
in
axes
(
qx
,
2
)
xhat
=
qx
[
:
,
k
]
x
=
elmap
(
mesh
,
cell
)(
xhat
)
opvalues
=
map
(
f
->
evaluate
(
f
,
x
),
opparams
)
val
+=
qw
[
k
]
*
expr
(
x
;
opvalues
...
)
*
intel
end
end
return
val
end
end
function
bind!
(
f
::
FeFunction
,
cell
)
function
bind!
(
f
::
FeFunction
,
cell
)
...
...
This diff is collapsed.
Click to expand it.
src/run.jl
+
13
−
5
View file @
754a746b
...
@@ -323,6 +323,8 @@ function test_refine(mesh = nothing)
...
@@ -323,6 +323,8 @@ function test_refine(mesh = nothing)
return
ctx
return
ctx
end
end
norm_l2
(
f
)
=
sqrt
(
integrate
(
f
.
space
.
mesh
,
(
x
;
f
)
->
dot
(
f
,
f
);
f
))
function
denoise
(
img
;
name
,
params
...
)
function
denoise
(
img
;
name
,
params
...
)
m
=
1
m
=
1
mesh
=
init_grid
(
img
;
type
=:
vertex
)
mesh
=
init_grid
(
img
;
type
=:
vertex
)
...
@@ -334,7 +336,7 @@ function denoise(img; name, params...)
...
@@ -334,7 +336,7 @@ function denoise(img; name, params...)
interpolate!
(
ctx
.
g
,
x
->
interpolate_bilinear
(
img
,
x
))
interpolate!
(
ctx
.
g
,
x
->
interpolate_bilinear
(
img
,
x
))
m
=
(
size
(
img
)
.-
1
)
./
2
.+
1
m
=
(
size
(
img
)
.-
1
)
./
2
.+
1
interpolate!
(
ctx
.
g
,
x
->
norm
(
x
.-
m
)
<
norm
(
m
)
/
3
)
interpolate!
(
ctx
.
g
,
x
->
norm
(
x
.-
m
)
<
norm
(
m
.-
1
)
/
3
)
save_denoise
(
ctx
,
i
)
=
save_denoise
(
ctx
,
i
)
=
save
(
ctx
,
"
$
(ctx.name)_
$
(lpad(i, 5, '0')).vtu"
,
save
(
ctx
,
"
$
(ctx.name)_
$
(lpad(i, 5, '0')).vtu"
,
...
@@ -345,20 +347,24 @@ function denoise(img; name, params...)
...
@@ -345,20 +347,24 @@ function denoise(img; name, params...)
k
=
0
k
=
0
while
true
while
true
for
i
in
1
:
10
while
true
k
+=
1
k
+=
1
step!
(
ctx
)
step!
(
ctx
)
estimate!
(
ctx
)
estimate!
(
ctx
)
pvd
[
k
]
=
save_denoise
(
ctx
,
k
)
pvd
[
k
]
=
save_denoise
(
ctx
,
k
)
println
()
println
()
println
(
"ndofs:
$
(ndofs(ctx.u.space)), est:
$
(norm_l2(ctx.est)))"
)
norm_step
=
sqrt
(
norm_l2
(
ctx
.
du
)
^
2
+
norm_l2
(
ctx
.
dp1
)
^
2
+
norm_l2
(
ctx
.
dp2
))
norm_step
<=
1e-3
&&
break
end
end
marked_cells
=
mark
(
ctx
;
theta
=
0.
7
)
marked_cells
=
mark
(
ctx
;
theta
=
0.
5
)
#println(marked_cells)
#println(marked_cells)
println
(
"refining ..."
)
println
(
"refining ..."
)
ctx
=
refine
(
ctx
,
marked_cells
)
ctx
=
refine
(
ctx
,
marked_cells
)
test_mesh
(
ctx
.
mesh
)
test_mesh
(
ctx
.
mesh
)
interpolate!
(
ctx
.
g
,
x
->
norm
(
x
.-
m
)
<
norm
(
m
)
/
3
)
interpolate!
(
ctx
.
g
,
x
->
norm
(
x
.-
m
)
<
norm
(
m
.-
1
)
/
3
)
k
>=
5
0
&&
break
k
>=
20
0
&&
break
end
end
vtk_save
(
pvd
)
vtk_save
(
pvd
)
return
ctx
return
ctx
...
@@ -384,6 +390,8 @@ function inpaint(img, imgmask; name, params...)
...
@@ -384,6 +390,8 @@ function inpaint(img, imgmask; name, params...)
interpolate!
(
mask
,
x
->
imgmask
[
round
.
(
Int
,
x
)
...
])
interpolate!
(
mask
,
x
->
imgmask
[
round
.
(
Int
,
x
)
...
])
#interpolate!(mask, x -> abs(x[2] - 0.5) > 0.1)
#interpolate!(mask, x -> abs(x[2] - 0.5) > 0.1)
interpolate!
(
ctx
.
g
,
x
->
imgmask
[
round
.
(
Int
,
x
)
...
]
?
img
[
round
.
(
Int
,
x
)
...
]
:
0.
)
interpolate!
(
ctx
.
g
,
x
->
imgmask
[
round
.
(
Int
,
x
)
...
]
?
img
[
round
.
(
Int
,
x
)
...
]
:
0.
)
m
=
(
size
(
img
)
.-
1
)
./
2
.+
1
interpolate!
(
ctx
.
g
,
x
->
norm
(
x
.-
m
)
<
norm
(
m
)
/
3
)
save_inpaint
(
i
)
=
save_inpaint
(
i
)
=
save
(
ctx
,
"
$
(ctx.name)_
$
(lpad(i, 5, '0')).vtu"
,
save
(
ctx
,
"
$
(ctx.name)_
$
(lpad(i, 5, '0')).vtu"
,
...
...
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