Skip to content

Commit 594aaea

Browse files
committed
tutorials 14 to 27
1 parent 628f688 commit 594aaea

9 files changed

Lines changed: 37 additions & 30 deletions

src/TopOptEMFocus.jl

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -421,12 +421,14 @@ function gf_p(p0::Vector, grad::Vector; r, β, η, phys_params, fem_params)
421421
grad[:] = dgdp
422422
end
423423
gvalue = gf_p(p0::Vector; r, β, η, phys_params, fem_params)
424-
open("gvalue.txt", "a") do io
424+
open("output_path/gvalue.txt", "a") do io
425425
write(io, "$gvalue \n")
426426
end
427427
gvalue
428428
end
429429

430+
mkpath("output_path")
431+
430432
# Using the following codes, we can check if we can get the derivatives correctly from the adjoint method by comparing it with the finite difference results.
431433
#
432434

@@ -494,7 +496,7 @@ ax.aspect = AxisAspect(1)
494496
ax.title = "Design Shape"
495497
rplot = 110 # Region for plot
496498
limits!(ax, -rplot, rplot, (h1)/2-rplot, (h1)/2+rplot)
497-
save("shape.png", fig)
499+
save("output_path/shape.png", fig)
498500

499501

500502
# ![](../assets/TopOptEMFocus/shape.png)
@@ -512,7 +514,7 @@ Colorbar(fig[1,2], plt)
512514
ax.title = "|E|"
513515
ax.aspect = AxisAspect(1)
514516
limits!(ax, -rplot, rplot, (h1)/2-rplot, (h1)/2+rplot)
515-
save("Field.png", fig)
517+
save("output_path/Field.png", fig)
516518

517519
# ![](../assets/TopOptEMFocus/Field.png)
518520
#

src/geometry_dev.jl

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,8 @@ reffes, cell_types = compress_cell_data(cell_reffes)
225225
new_grid = UnstructuredGrid(new_node_coordinates,cell_to_nodes,reffes,cell_types)
226226

227227
# Save for visualization:
228-
writevtk(new_grid,"half_cylinder_linear")
228+
mkpath("output_path")
229+
writevtk(new_grid,"output_path/half_cylinder_linear")
229230

230231
#
231232
# If we visualize the result, we'll notice that despite applying a curved mapping,
@@ -267,7 +268,7 @@ new_node_coordinates = map(F,new_node_coordinates)
267268

268269
# Create the high-order grid:
269270
new_grid = UnstructuredGrid(new_node_coordinates,new_cell_to_nodes,new_reffes,cell_types)
270-
writevtk(new_grid,"half_cylinder_quadratic")
271+
writevtk(new_grid,"output_path/half_cylinder_quadratic")
271272

272273
# The resulting mesh now accurately represents the curved geometry of the half-cylinder,
273274
# with quadratic elements properly capturing the curvature (despite paraview still showing
@@ -427,7 +428,7 @@ node_to_entity = get_face_entity(labels,0) # For each node, its associated entit
427428

428429
# It is usually more convenient to visualise it in Paraview by exporting to vtk:
429430

430-
writevtk(model,"labels_basic",labels=labels)
431+
writevtk(model,"output_path/labels_basic",labels=labels)
431432

432433
# Another useful way to create a `FaceLabeling` is by providing a coloring for the mesh cells,
433434
# where each color corresponds to a different tag.
@@ -436,21 +437,21 @@ writevtk(model,"labels_basic",labels=labels)
436437
cell_to_tag = [1,1,1,2,2,3,2,2,3]
437438
tag_to_name = ["A","B","C"]
438439
labels_cw = Geometry.face_labeling_from_cell_tags(topo,cell_to_tag,tag_to_name)
439-
writevtk(model,"labels_cellwise",labels=labels_cw)
440+
writevtk(model,"output_path/labels_cellwise",labels=labels_cw)
440441

441442
# We can also create a `FaceLabeling` from a vertex filter. The resulting `FaceLabeling` will have
442443
# only one tag, gathering the d-faces whose vertices ALL fullfill `filter(x) == true`.
443444

444445
vfilter(x) = abs(x[1]- 1.0) < 1.e-5
445446
labels_vf = Geometry.face_labeling_from_vertex_filter(topo, "top", vfilter)
446-
writevtk(model,"labels_filter",labels=labels_vf)
447+
writevtk(model,"output_path/labels_filter",labels=labels_vf)
447448

448449
# `FaceLabeling` objects can also be merged together. The resulting `FaceLabeling` will have
449450
# the union of the tags and entities of the original ones.
450451
# Note that this modifies the first `FaceLabeling` in place.
451452

452453
labels = merge!(labels, labels_cw, labels_vf)
453-
writevtk(model,"labels_merged",labels=labels)
454+
writevtk(model,"output_path/labels_merged",labels=labels)
454455

455456
# ### Creating new tags from existing ones
456457
#
@@ -474,7 +475,7 @@ Geometry.add_tag_from_tags_complementary!(labels,"!A",["A"])
474475
# and creates a new tag that contains all the d-faces that are in the first list but not in the second.
475476
Geometry.add_tag_from_tags_setdiff!(labels,"A-B",["A"],["B"]) # set difference
476477

477-
writevtk(model,"labels_setops",labels=labels)
478+
writevtk(model,"output_path/labels_setops",labels=labels)
478479

479480
# ### FaceLabeling queries
480481
#

src/interpolation_fe.jl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,8 +131,9 @@ g̃ₕ.cell_dof_values
131131

132132
# We can visualize the results using Paraview
133133

134-
writevtk(get_triangulation(fₕ), "source", cellfields=["fₕ"=>fₕ])
135-
writevtk(get_triangulation(gₕ), "target", cellfields=["gₕ"=>gₕ])
134+
mkpath("output_path")
135+
writevtk(get_triangulation(fₕ), "output_path/source", cellfields=["fₕ"=>fₕ])
136+
writevtk(get_triangulation(gₕ), "output_path/target", cellfields=["gₕ"=>gₕ])
136137

137138
# which produces the following output
138139

src/lagrange_multipliers.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,4 +124,5 @@ l2_error = sqrt(sum(∫(eh⋅eh)*dΩ))
124124
#
125125
# We can visualize the solution and error by writing them to a VTK file:
126126

127-
writevtk(Ω, "results", cellfields=["uh"=>uh, "error"=>eh])
127+
mkpath("output_path")
128+
writevtk(Ω, "output_path/results", cellfields=["uh"=>uh, "error"=>eh])

src/poisson_amr.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,7 @@ end
164164
nsteps = 5
165165
order = 1
166166
model = LShapedModel(10)
167+
mkpath("output_path")
167168

168169
last_error = Inf
169170
for i in 1:nsteps
@@ -173,7 +174,7 @@ for i in 1:nsteps
173174

174175
Ω = Triangulation(model)
175176
writevtk(
176-
Ω,"model_$(i-1)",append=false,
177+
Ω,"output_path/model_$(i-1)",append=false,
177178
cellfields = [
178179
"uh" => uh, # Computed solution
179180
"η" => CellField(η,Ω), # Error indicators

src/poisson_distributed.jl

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,12 @@ function main_ex1(rank_partition,distribute)
3333
l(v) = ( v*f )dΩ
3434
op = AffineFEOperator(a,l,U,V)
3535
uh = solve(op)
36-
writevtk(Ω,"results_ex1",cellfields=["uh"=>uh,"grad_uh"=>(uh)])
36+
writevtk(Ω,"output_path/results_ex1",cellfields=["uh"=>uh,"grad_uh"=>(uh)])
3737
end
3838

3939
# Once the `main_ex1` function has been defined, we have to trigger its execution on the different parts. To this end, one calls the `with_mpi` function of [`PartitionedArrays.jl`](https://github.com/fverdugo/PartitionedArrays.jl) right at the beginning of the program.
4040

41+
mkpath("output_path")
4142
rank_partition = (2,2)
4243
with_mpi() do distribute
4344
main_ex1(rank_partition,distribute)
@@ -73,7 +74,7 @@ function main_ex2(rank_partition,distribute)
7374
op = AffineFEOperator(a,l,U,V)
7475
solver = PETScLinearSolver()
7576
uh = solve(solver,op)
76-
writevtk(Ω,"results_ex2",cellfields=["uh"=>uh,"grad_uh"=>(uh)])
77+
writevtk(Ω,"output_path/results_ex2",cellfields=["uh"=>uh,"grad_uh"=>(uh)])
7778
end
7879
end
7980

@@ -112,7 +113,7 @@ function main_ex3(nparts,distribute)
112113
op = AffineFEOperator(a,l,U,V)
113114
solver = PETScLinearSolver()
114115
uh = solve(solver,op)
115-
writevtk(Ω,"results_ex3",cellfields=["uh"=>uh,"grad_uh"=>(uh)])
116+
writevtk(Ω,"output_path/results_ex3",cellfields=["uh"=>uh,"grad_uh"=>(uh)])
116117
end
117118
end
118119

@@ -144,7 +145,7 @@ function main_ex4(nparts,distribute)
144145
op = AffineFEOperator(a,l,U,V)
145146
solver = PETScLinearSolver()
146147
uh = solve(solver,op)
147-
writevtk(Ω,"results_ex4",cellfields=["uh"=>uh,"grad_uh"=>(uh)])
148+
writevtk(Ω,"output_path/results_ex4",cellfields=["uh"=>uh,"grad_uh"=>(uh)])
148149
end
149150
end
150151

src/poisson_hdg.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,8 @@ dΩ = Measure(Ω,degree)
154154
eh = uh - u
155155
l2_uh = sqrt(sum((eheh)*dΩ))
156156

157-
writevtk(Ω,"results",cellfields=["uh"=>uh,"qh"=>qh,"eh"=>eh])
157+
mkpath("output_path")
158+
writevtk(Ω,"output_path/results",cellfields=["uh"=>uh,"qh"=>qh,"eh"=>eh])
158159

159160
# ## Going Further
160161
#

src/poisson_unfitted.jl

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,9 @@ cutgeo = cut(bgmodel,geo3)
104104
# To illustrate this concept, we can plot both the background and active triangulations to compare them.
105105

106106
Ω_bg = Triangulation(bgmodel)
107-
writevtk(Ω_bg,"bg_trian")
108-
writevtk(Ω_act,"act_trian")
107+
mkpath("output_path")
108+
writevtk(Ω_bg,"output_path/bg_trian")
109+
writevtk(Ω_act,"output_path/act_trian")
109110

110111
# In the picture below of the background grid, white cells are _inactive_, whereas gray cells are _active_.
111112
#
@@ -116,7 +117,7 @@ writevtk(Ω_act,"act_trian")
116117
# An `EmbeddedDiscretization` instance (here, `cutgeo`) also generates subtriangulations on each cut cells to represent the portion of the cell which is inside the domain of analysis. We use these subtriangulations to generate the so called _physical_ triangulations. Physical triangulations are nothing other than a body-fitted mesh of our domain $\Omega$, but _we only use them to integrate the weak form_ of the problem in $\Omega$, we won't define FE spaces and assign DoFs on top of them. In [GridapEmbedded](https://github.com/gridap/GridapEmbedded.jl) we build physical triangulations using the `PHYSICAL` keyword.
117118

118119
Ω = Triangulation(cutgeo,PHYSICAL)
119-
writevtk(Ω,"phys_trian")
120+
writevtk(Ω,"output_path/phys_trian")
120121

121122
# Once again, we can combine plots of the physical and active triangulations to illustrate these concepts. In the first plot, we show the physical triangulation within the background one.
122123
#
@@ -172,7 +173,7 @@ aggregates = aggregate(strategy,cutgeo)
172173

173174
colors = color_aggregates(aggregates,bgmodel)
174175
Ω_bg = Triangulation(bgmodel)
175-
writevtk(Ω_bg,"aggs_on_bg_trian",celldata=["aggregate"=>aggregates,"color"=>colors])
176+
writevtk(Ω_bg,"output_path/aggs_on_bg_trian",celldata=["aggregate"=>aggregates,"color"=>colors])
176177

177178
# Finally, we use the aggregates to constrain the exterior DoFs of `Vstd` in terms of the interior ones. This leads to the AgFEM space.
178179

@@ -250,7 +251,7 @@ using Test
250251
@test el2/ul2 < 1.e-8
251252
@test eh1/uh1 < 1.e-7
252253

253-
writevtk(Ω,"results.vtu",cellfields=["uh"=>uh])
254+
writevtk(Ω,"output_path/results.vtu",cellfields=["uh"=>uh])
254255

255256
# ![fig10](../assets/unfitted_poisson/fig_results.png)
256257

src/transient_nonlinear.jl

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -126,14 +126,12 @@ uh = solve(solver, op_sl, t0, tF, uh0)
126126

127127
# Here again, we export the solution at each time step as follows
128128

129-
if !isdir("tmp_nl")
130-
mkdir("tmp_nl")
131-
end
129+
mkpath("output_path/results")
132130

133-
createpvd("results_nl") do pvd
134-
pvd[0] = createvtk(Ω, "tmp_nl/results_0" * ".vtu", cellfields=["u" => uh0])
131+
createpvd("output_path/results_nl") do pvd
132+
pvd[0] = createvtk(Ω, "output_path/results/results_0" * ".vtu", cellfields=["u" => uh0])
135133
for (tn, uhn) in uh
136-
pvd[tn] = createvtk(Ω, "tmp_nl/results_$tn" * ".vtu", cellfields=["u" => uhn])
134+
pvd[tn] = createvtk(Ω, "output_path/results/results_$tn" * ".vtu", cellfields=["u" => uhn])
137135
end
138136
end
139137

0 commit comments

Comments
 (0)