Skip to content

Commit

Permalink
New tutorial (#57)
Browse files Browse the repository at this point in the history
* add new tutorial with syemmtry lines

* add proper figure links

* fix weird spacing

* add missing keyword to docstring

* add new helper function to rename inner or outer boundary curves

* rewrite and simplify the symmetric mesh tutorial

* adjust boundary names in tutorital to make it easier to follow

* update text in final script at the end of the tutorial

* add test for new renaming helper function

* fix typo

* Update symmetric_mesh.md

Make some corrections and editorial cahnges.

* remove colon to render tip box in docs

* add line breaks for readibility of the markdown source

* update remove_mesh command to remove control, plot and stats files

* add new helper function renameCruve to the API docs

* adjust wording to be less awkward

* update tutorial with new boundary names and other review comments

* Edits on renameCurve

Make changes to indicate that renameCurve! will change the name of all curves that have a given name.

* Update symmetric_mesh.md

Fix a typo and modify one sentence.

* add sleep commands to idle tests for a brief time to avoid file access issues on Windows

* remove sleep commands, did not fix anything

* see if only the control file removal causes Windows issue

* add an additional close statement to see if Windows works

* move close statement to the proper place

* remove unnecessary close statments. Try to force file removal

* try again with the sleep command

---------

Co-authored-by: DavidAKopriva <[email protected]>
Co-authored-by: David Kopriva <[email protected]>
  • Loading branch information
3 people authored Jun 25, 2024
1 parent 03ba68a commit ee72a13
Show file tree
Hide file tree
Showing 11 changed files with 475 additions and 21 deletions.
1 change: 1 addition & 0 deletions docs/make.jl
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ makedocs(
joinpath("tutorials", "curved_outer_boundary.md"),
joinpath("tutorials", "spline_curves.md"),
joinpath("tutorials", "create_edit_curves.md"),
joinpath("tutorials", "symmetric_mesh.md"),
],
"Advanced topics & developers" => [
"Development" => "development.md",
Expand Down
5 changes: 5 additions & 0 deletions docs/src/interactive-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -437,6 +437,11 @@ and checked by
```
getCurveName(crv::Dict{String,Any})
```
Alternatively, all curves on an outer or inner boundary with the same name
can have that name changed all at once everywhere in the project with the function
```
renameCurve!(proj::Project, oldName::String, newName::String)
```

Otherwise there are special functions to change the parameters of curves
```
Expand Down
6 changes: 3 additions & 3 deletions docs/src/tutorials/create_edit_curves.md
Original file line number Diff line number Diff line change
Expand Up @@ -279,9 +279,9 @@ Note, this step is not required, but it helps avoid confusion when editing sever
remove_mesh!(sandbox_project)
updatePlot!(sandbox_project, MODEL+GRID)
```
Additionally, the `remove_mesh!` command deletes the mesh information from the `sandbox_project`
and `sandbox.mesh` from the `out` folder. However, the `sandbox.control` and `sandbox.tec` files
are still present in `out` directory.
The `remove_mesh!` command deletes the mesh information from the `sandbox_project`
as well as the mesh file `sandbox.mesh`, control file `sandbox.control`, plot file `sandbox.tec`,
and mesh statistics file `sandbox.txt` from the `out` folder.

## Edit an inner boundary chain

Expand Down
17 changes: 16 additions & 1 deletion docs/src/tutorials/introduction.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,4 +80,19 @@ Demonstrates how to:
* Construct and add parametric spline curves.
* Construct and add a curve from parametric equations.
* Construct and add straight line segments.
* Construct and add circular arc segments.
* Construct and add circular arc segments.

## [Symmetric mesh](@ref)

This tutorial constructs a mesh given a closed chain of outer boundary curves
that is then reflected over a straight line or several co-linear lines indicated by the user.
The result is a mesh that is symmetric with respect to the prescribed straight line.

### Synopsis

Demonstrates how to:
* Indicate a symmetry boundary line.
* Construct an outer boundary with several connected curves.
* Add the background grid when an outer boundary curve is present.
* Rename boundaries in an existing interactive mesh project.
* Visualize an interactive mesh project.
363 changes: 363 additions & 0 deletions docs/src/tutorials/symmetric_mesh.md

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions src/HOHQMesh.jl
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ export addCurveToOuterBoundary!,
getInnerBoundaryCurve

# Functions from `Project.jl`
export newProject, openProject, saveProject
export newProject, openProject, saveProject, renameCurve!

# Functions from `RefinementRegionsAPI.jl`
export newRefinementCenter,
Expand Down Expand Up @@ -154,7 +154,7 @@ export MODEL, GRID, MESH, EMPTY, REFINEMENTS, ALL
generate_mesh(control_file;
output_directory="out",
mesh_filename=nothing, plot_filename=nothing, stats_filename=nothing,
verbose=false)
verbose=false, subdivision_maximum=8)
Generate a mesh based on the `control_file` with the HOHQMesh mesh generator and store resulting
files in `output_directory`.
Expand Down
16 changes: 13 additions & 3 deletions src/Mesh/Meshing.jl
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,21 @@ end
"""
remove_mesh!(proj::Project)
Remove the mesh file from `proj.projectDirectory` and delete the mesh from the plot
Remove the mesh file, control file, plot file, and stats file from `proj.projectDirectory`
and delete the mesh from the plot.
"""
function remove_mesh!(proj::Project)
meshFile = getMeshFileName(proj)
rm(meshFile)
# Remove all the output files associated with the current `proj`
fileName = getMeshFileName(proj)
rm(fileName)
# Get the control file name of the current project
fileName = joinpath(proj.projectDirectory,proj.name) * ".control"
rm(fileName)
fileName = getPlotFileName(proj)
rm(fileName)
fileName = getStatsFileName(proj)
rm(fileName)
# Delete the mesh nodes from internal storage used by the plotting routines
proj.xMesh = Float64[]
proj.yMesh = Float64[]
postNotificationWithName(proj,"MESH_WAS_DELETED_NOTIFICATION",(nothing,))
Expand Down
16 changes: 8 additions & 8 deletions src/Project/ModelAPI.jl
Original file line number Diff line number Diff line change
Expand Up @@ -224,12 +224,12 @@ function insertInnerBoundaryCurveAtIndex!(proj::Project, crv::Dict{String,Any},
insert!(lst,indx,crv)

if i > length(proj.innerBoundaryPoints) # New inner boundary chain
a = []
push!(a,curvePoints(crv,defaultPlotPts))
push!(proj.innerBoundaryPoints,a)
a = []
push!(a,curvePoints(crv,defaultPlotPts))
push!(proj.innerBoundaryPoints,a)
else
innerBoundaryPoints = proj.innerBoundaryPoints[i]
insert!(innerBoundaryPoints,indx,curvePoints(crv,defaultPlotPts))
innerBoundaryPoints = proj.innerBoundaryPoints[i]
insert!(innerBoundaryPoints,indx,curvePoints(crv,defaultPlotPts))
end
insert!(proj.innerBoundaryNames[i],indx,crv["name"])

Expand All @@ -247,7 +247,7 @@ function removeInnerBoundaryCurveAtIndex!(proj::Project, indx::Int, chainName::S
i, chain = getInnerBoundaryChainWithName(proj,chainName)
lst = chain["LIST"]
if indx > 0
crv = lst[indx]
crv = lst[indx]
deleteat!(lst, indx)
if isempty(lst) # Boundary chain contained a single curve
# Complete removal. Requires a different function to be posted
Expand Down Expand Up @@ -363,7 +363,7 @@ end


"""
getInnerBoundaryWithName(proj::Project, name::String)
getInnerBoundaryChainWithName(proj::Project, name::String)
Get the inner boundary CHAIN with the given name. If one does not exist, it
is created.
Expand Down Expand Up @@ -395,7 +395,7 @@ end
"""
function getInnerBoundaryCurve(proj::Project, curveName::String, boundaryName::String)
i, chain = getInnerBoundaryChainWithName(proj, boundaryName)
lst = chain["LIST"]
lst = chain["LIST"]
for crv in lst
if crv["name"] == curveName
return crv
Expand Down
52 changes: 48 additions & 4 deletions src/Project/Project.jl
Original file line number Diff line number Diff line change
Expand Up @@ -281,17 +281,61 @@ function projectGrid(proj::Project)
end


"""
renameCurve!(proj::Project, oldName::String, newName::String)
Any curve(s) on the outer boundary or in the inner boundary chain(s)
with `oldName` are renamed with `newName`.
"""
function renameCurve!(proj::Project, oldName::String, newName::String)
#
# Check if the curve is in the outer boundary
#
for (i, s) in enumerate(proj.outerBndryNames)
if s == oldName
# Rename in global list used in the legend of `proj.plt`
proj.outerBndryNames[i] = newName
# Rename in the appropriate `crv` used when the mesh file is created
crv = getOuterBoundaryCurveWithName(proj, oldName)
setCurveName!(crv, newName)
end
end
#
# Otherwise, find the curve to rename among the inner boundary curve chain(s)
#
chains = getAllInnerBoundaries(proj)
for (chain_idx, chain) in enumerate(chains)
crvList = chain["LIST"]
for (crv_idx, crv) in enumerate(crvList)
if crv["name"] == oldName
# Rename in global list used in the legend of `proj.plt`
proj.innerBoundaryNames[chain_idx][crv_idx] = newName
# Rename in the appropriate `crv` used when the mesh file is created
setCurveName!(crv, newName)
end
end
end

if !isnothing(proj.plt)
options = proj.plotOptions
updatePlot!(proj, options)
end

return nothing
end


#
# NOTIFICATION ACTIONS
#
function curveDidChange(proj::Project,crv::Dict{String,Any})
function curveDidChange(proj::Project, crv::Dict{String,Any})
curveName = getCurveName(crv)
#
# Find the curve location: See if the curve is in the outer boundary
#
for (i,s) in enumerate(proj.outerBndryNames)
if s == curveName
proj.outerBndryPoints[i] = curvePoints(crv,defaultPlotPts)
proj.outerBndryPoints[i] = curvePoints(crv, defaultPlotPts)
if !isnothing(proj.plt)
options = proj.plotOptions
updatePlot!(proj, options)
Expand All @@ -302,12 +346,12 @@ function curveDidChange(proj::Project,crv::Dict{String,Any})
#
# Otherwise, see if it is an inner boundary
#
crvNumber, bndryNumber = innerBoundaryIndices(proj,curveName)
crvNumber, bndryNumber = innerBoundaryIndices(proj, curveName)
if crvNumber == 0 || bndryNumber == 0
return nothing
end
innerBoundaryPoints = proj.innerBoundaryPoints[bndryNumber]
innerBoundaryPoints[crvNumber] = curvePoints(crv,defaultPlotPts)
innerBoundaryPoints[crvNumber] = curvePoints(crv, defaultPlotPts)
proj.backgroundGridShouldUpdate = true

if !isnothing(proj.plt)
Expand Down
10 changes: 10 additions & 0 deletions test/test_project_with_viz.jl
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,13 @@ using CairoMakie
outer_line2 = newEndPointsLineCurve("outerline2", [-5.0, 3.0, 0.0], [0.0, -7.0, 0.0])
add!(p_scratch, outer_line2)

# Initial test the boundary name is correct
@test getCurveName(getOuterBoundaryCurveWithName(p_scratch, "outerline2")) == "outerline2"

# Rename one of the outer boundary names and test that it was successful
renameCurve!(p_scratch, "outerline2", "LINE2")
@test getCurveName(getOuterBoundaryCurveWithName(p_scratch, "LINE2")) == "LINE2"

# Check the computed background grid against expected values
x_grid_control = [-8.0, -7.0, -6.0, -5.0, -4.0, -3.0, -2.0, -1.0, 0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0]
y_grid_control = [-8.0, -7.0, -6.0, -5.0, -4.0, -3.0, -2.0, -1.0, 0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0]
Expand All @@ -52,6 +59,9 @@ using CairoMakie
inner_top_arc = newCircularArcCurve("innerTopArc", [0.0, 5.0, 0.0], 1.0, 180.0, 0.0, "degrees")
add!(p_scratch, inner_top_arc, "inner1")

# Rename one of the inner boundary names
renameCurve!(p_scratch, "innerBottomArc", "BottomArc")

# Add in a refinement center and adjust its width manually
cent = newRefinementCenter("center1", "smooth", [0.0, -1.0, 0.0], 0.25, 1.0)
add!(p_scratch, cent)
Expand Down
6 changes: 6 additions & 0 deletions test/test_visualization.jl
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ using CairoMakie
# Create the mesh which contains a plotting update for ISM
@test_nowarn generate_mesh(p_visu, verbose=true)

# Add a delay to ensure that the Windows system has released the file handles
sleep(2.0) # arbitrarily pick 2 seconds

# Destroy the mesh and reset the background grid
@test_nowarn remove_mesh!(p_visu)

Expand Down Expand Up @@ -92,6 +95,9 @@ using CairoMakie
# Create the mesh which contains a plotting update for ISM-V2
@test_nowarn generate_mesh(p_visu)

# Add a delay to ensure that the Windows system has released the file handles
sleep(2.0) # arbitrarily pick 2 seconds

# Destroy the mesh and reset the background grid
@test_nowarn remove_mesh!(p_visu)

Expand Down

0 comments on commit ee72a13

Please sign in to comment.