Skip to content

Commit 805ab72

Browse files
committed
improved convergencehistory! plotter, export of some low level stuff, some other small improvements
1 parent b64d4a5 commit 805ab72

File tree

5 files changed

+49
-29
lines changed

5 files changed

+49
-29
lines changed

Project.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ DiffResults = "1"
2727
CommonSolve = "0.2"
2828
DocStringExtensions = "0.8,0.9"
2929
ExtendableGrids = "0.9.16"
30-
ExtendableSparse = "1.0.1"
31-
ForwardDiff = "^0.10"
30+
ExtendableSparse = "1.2"
31+
ForwardDiff = "^0.10.35"
3232
GridVisualize = "0.5.2,0.6.1,1"
3333
LinearSolve = "1.37"
3434
SparseDiffTools = "^1.19,2"

examples/Example203_ReactionConvectionDiffusion2D.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,9 +127,9 @@ function main(; verbosity = 0, Plotter = nothing, ν = 1e-5, τ = 1e-2, nlevels
127127
## plot
128128
p = GridVisualizer(; Plotter = Plotter, layout = (1,3), clear = true, resolution = (1500,500))
129129
scalarplot!(p[1,1], xgrid, view(nodevalues(Solution[1]),1,:), levels = 7, title = "u_h")
130-
scalarplot!(p[1,2], xgrid, view(nodevalues(Solution[1], Gradient; abs = true),1,:), levels = 0, colorbarticks = 9, title = "∇u_h (abs + quiver)")
130+
scalarplot!(p[1,2], xgrid, view(nodevalues(Solution[1], Gradient; abs = true),1,:), levels = 7, colorbarticks = 9, title = "∇u_h (abs + quiver)")
131131
vectorplot!(p[1,2], xgrid, evaluate(PointEvaluator(Solution[1], Gradient)), vscale = 0.8, clear = false)
132-
convergencehistory!(p[1,3], NDofs, Results; add_h_powers = [order,order+1], X_to_h = X -> X.^(-1/2), legend = :lb, fontsize = 20, ylabels = ["|| u - u_h ||", "|| u - Iu ||", "|| ∇(u - u_h) ||", "|| ∇(u - Iu) ||"])
132+
convergencehistory!(p[1,3], NDofs, Results; add_h_powers = [order,order+1], X_to_h = X -> X.^(-1/2), legend = :lb, fontsize = 20, ylabels = ["|| u - u_h ||", "|| u - Iu ||", "|| ∇(u - u_h) ||", "|| ∇(u - Iu) ||"], limits = (1e-8,1e-1))
133133

134134
## print convergence history
135135
print_convergencehistory(NDofs, Results; X_to_h = X -> X.^(-1/2), ylabels = ["|| u - u_h ||", "|| u - Iu ||", "|| ∇(u - u_h) ||", "|| ∇(u - Iu) ||"])

examples/Example219_AxisymmetricStokes25D.jl

Lines changed: 37 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ a(u,v) := \int_{\Omega} \left( \nabla u : \nabla v + r^{-2} u_r v_r \right) r dr
4141
b(q,v) := \int_{\Omega} q \left( \mathrm{div}(v) + r^{-1} u_r \right) r dr dz
4242
\end{aligned}
4343
```
44-
where the usual Cartesian differential operators can be used.
44+
where the usual Cartesian differential operators can be used. The factor ``2\pi`` from the
45+
integral over the rotation angle drops out on both sides.
4546
4647
4748
=#
@@ -52,16 +53,6 @@ using GradientRobustMultiPhysics
5253
using ExtendableGrids
5354
using GridVisualize
5455

55-
## data for axisymmetric Hagen-Poiseuille flow
56-
function exact_pressure!(μ)
57-
function closure(result,x)
58-
result[1] = 4*μ*(1-x[1])
59-
end
60-
end
61-
function exact_velocity!(result,x)
62-
result[1] = (1.0-x[2]^2);
63-
result[2] = 0.0;
64-
end
6556

6657
## custom bilinearform a for the axisymmetric Stokes problem
6758
function ASLaplaceOperator(μ)
@@ -108,14 +99,36 @@ function ASPressureOperatorTransposed()
10899
end
109100

110101
## everything is wrapped in a main function
111-
function main(; verbosity = 0, Plotter = nothing, μ = 1)
102+
## problem = 1 is Hagen-Poiseuille
103+
## problem = 2 is stagnation point flow without solid surface
104+
## μ = viscosity
105+
## k = parameter for problem = 2
106+
function main(; problem = 1, k = 1, verbosity = 0, Plotter = nothing, μ = 1)
112107

113108
## set log level
114109
set_verbosity(verbosity)
115110

111+
## boundary/comparison data for axisymmetric Hagen-Poiseuille flow
112+
function exact_pressure!(result, x)
113+
if problem == 1 # Hagen-Poiseuille
114+
result[1] = 4*μ*(1-x[1])
115+
elseif problem == 2 # stagnation point flow without solid surface
116+
result[1] = k
117+
end
118+
end
119+
function exact_velocity!(result, x)
120+
if problem == 1 # Hagen-Poiseuille
121+
result[1] = (1.0-x[2]^2);
122+
result[2] = 0.0;
123+
elseif problem == 2 # stagnation point flow without solid surface
124+
result[1] = -2*k*x[1]
125+
result[2] = k*x[2]
126+
end
127+
end
128+
116129
## negotiate data functions to the package
117130
u = DataFunction(exact_velocity!, [2,2]; name = "u", dependencies = "X", bonus_quadorder = 2)
118-
p = DataFunction(exact_pressure!(μ), [1,2]; name = "p", dependencies = "X", bonus_quadorder = 1)
131+
p = DataFunction(exact_pressure!, [1,2]; name = "p", dependencies = "X", bonus_quadorder = 1)
119132

120133
## grid
121134
xgrid = uniform_refine(grid_unitsquare(Triangle2D), 5);
@@ -132,9 +145,14 @@ function main(; verbosity = 0, Plotter = nothing, μ = 1)
132145
add_operator!(Problem, [2,1], ASPressureOperatorTransposed())
133146

134147
## boundary conditions
135-
add_boundarydata!(Problem, 1, [4], BestapproxDirichletBoundary; data = u)
136-
add_boundarydata!(Problem, 1, [3], HomogeneousDirichletBoundary)
137-
add_boundarydata!(Problem, 1, [1], HomogeneousDirichletBoundary; mask = (0,1))
148+
if problem == 1
149+
add_boundarydata!(Problem, 1, [3,4], InterpolateDirichletBoundary; data = u)
150+
add_boundarydata!(Problem, 1, [1], HomogeneousDirichletBoundary; mask = (0,1))
151+
elseif problem == 2
152+
add_boundarydata!(Problem, 1, [2], InterpolateDirichletBoundary; data = u)
153+
add_boundarydata!(Problem, 1, [4], HomogeneousDirichletBoundary; mask = (1,0))
154+
add_boundarydata!(Problem, 1, [1], HomogeneousDirichletBoundary; mask = (0,1))
155+
end
138156
@show Problem
139157

140158
## generate FESpaces
@@ -152,8 +170,9 @@ function main(; verbosity = 0, Plotter = nothing, μ = 1)
152170

153171
## plot
154172
p = GridVisualizer(; Plotter = Plotter, layout = (1,2), clear = true, resolution = (1000,500))
155-
scalarplot!(p[1,1],xgrid,view(nodevalues(Solution[1]; abs = true),1,:), levels = 9)
156-
scalarplot!(p[1,2],xgrid,view(nodevalues(Solution[2]),1,:), levels = 11, title = "p_h")
173+
scalarplot!(p[1,1],xgrid,view(nodevalues(Solution[1]; abs = true),1,:), levels = 6, xlabel = "z", ylabel = "r")
174+
vectorplot!(p[1,1],xgrid,evaluate(PointEvaluator(Solution[1], Identity)), spacing = 0.1, clear = false)
175+
scalarplot!(p[1,2],xgrid,view(nodevalues(Solution[2]),1,:), levels = 5, xlabel = "z", ylabel = "r", title = "p_h")
157176
end
158177

159178
end

src/GradientRobustMultiPhysics.jl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ export nodevalues_view
9292
export FEVectorBlock, FEVector
9393
export dot, norm, norms
9494
export FEMatrixBlock, FEMatrix, _addnz
95-
export fill!, addblock!, addblock_matmul!, lrmatmul, add!, apply_penalties!
95+
export fill!, addblock!, addblock_matmul!, lrmatmul, mul!, add!, apply_penalties!
9696

9797
export get_reconstruction_matrix
9898

@@ -120,9 +120,10 @@ include("assemblypatterns.jl")
120120
export AssemblyPatternType, AssemblyPreparations
121121
export ItemIntegrator, L2ErrorIntegrator, L2NormIntegrator, L2DifferenceIntegrator
122122
export DiscreteLinearForm
123-
export APT_BilinearForm, APT_SymmetricBilinearForm, APT_LumpedBilinearForm
123+
export AssemblyPattern, APT_BilinearForm, APT_SymmetricBilinearForm, APT_LumpedBilinearForm
124124
export DiscreteBilinearForm, DiscreteSymmetricBilinearForm, DiscreteLumpedBilinearForm
125125
export DiscreteNonlinearForm
126+
export assemble!, full_assemble!
126127
export prepare_assembly!
127128
export assemble!, evaluate!, evaluate
128129
export AssemblyManager, update_assembly!

src/plots.jl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
function convergencehistory!(target, X, Y; add_h_powers = [], X_to_h = X -> X, colors = [:blue, :green, :red, :magenta, :lightblue], title = "convergence history", legend = :best, ylabel = "", ylabels = [], xlabel = "ndofs", clear = true, fontsize = 14)
1+
function convergencehistory!(target, X, Y; add_h_powers = [], X_to_h = X -> X, colors = [:blue, :green, :red, :magenta, :lightblue], title = "convergence history", legend = :best, ylabel = "", ylabels = [], xlabel = "ndofs", markershape = :circle, markevery = 1, clear = true, args...)
22
for j = 1 : size(Y,2)
33
Xk = []
44
Yk = []
@@ -13,15 +13,15 @@ function convergencehistory!(target, X, Y; add_h_powers = [], X_to_h = X -> X, c
1313
else
1414
label = "Data $j"
1515
end
16-
scalarplot!(target, simplexgrid(Xk), Yk; fontsize = fontsize, xlabel = xlabel, ylabel = ylabel, color = length(colors) >= j ? colors[j] : :black, clear = j == 1 ? clear : false, xscale = :log, yscale = :log, markershape = :circle, markevery = 1, label = label, legend = legend, title = title)
16+
scalarplot!(target, simplexgrid(Xk), Yk; xlabel = xlabel, ylabel = ylabel, color = length(colors) >= j ? colors[j] : :black, clear = j == 1 ? clear : false, markershape = markershape, markevery = markevery, xscale = :log, yscale = :log, label = label, legend = legend, title = title, args...)
1717
end
1818
for p in add_h_powers
1919
label = "h^$p"
20-
scalarplot!(target, simplexgrid(X), X_to_h(X).^p; fontsize = fontsize, linestyle = :dot, xlabel = xlabel, ylabel = ylabel, color = :gray, clear = false, markershape = :none, xscale = :log, yscale = :log, label = label, legend = legend, title = title)
20+
scalarplot!(target, simplexgrid(X), X_to_h(X).^p; linestyle = :dot, xlabel = xlabel, ylabel = ylabel, color = :gray, clear = false, markershape = :none, xscale = :log, yscale = :log, label = label, legend = legend, title = title, args...)
2121
end
2222
end
2323

24-
function plot_convergencehistory(X, Y; Plotter = nothing, resolution = (800,600), add_h_powers = [], X_to_h = X -> X, colors = [:blue, :green, :red, :magenta, :lightblue], title = title, legend = :best, ylabel = "", ylabels = [], xlabel = "ndofs", clear = true, fontsize = 14)
24+
function plot_convergencehistory(X, Y; Plotter = nothing, resolution = (800,600), add_h_powers = [], X_to_h = X -> X, colors = [:blue, :green, :red, :magenta, :lightblue], legend = :best, ylabel = "", ylabels = [], xlabel = "ndofs", clear = true, args...)
2525
p=GridVisualizer(; Plotter = Plotter, layout = (1,1), clear = true, resolution = resolution)
26-
plot_convergencehistory!(p[1,1], X, Y; add_h_powers = add_h_powers, X_to_h = X_to_h, colors = colors, title = title, legend = legend, ylabel = ylabel, ylabels = ylabels, xlabel = xlabel, clear = clear, fontsize = fontsize)
26+
plot_convergencehistory!(p[1,1], X, Y; add_h_powers = add_h_powers, X_to_h = X_to_h, colors = colors, legend = legend, ylabel = ylabel, ylabels = ylabels, xlabel = xlabel, clear = clear, args...)
2727
end

0 commit comments

Comments
 (0)