diff --git a/docs/make.jl b/docs/make.jl index facf11a8..92614fbb 100644 --- a/docs/make.jl +++ b/docs/make.jl @@ -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", diff --git a/docs/src/interactive-api.md b/docs/src/interactive-api.md index 3c74ceb3..e131203b 100644 --- a/docs/src/interactive-api.md +++ b/docs/src/interactive-api.md @@ -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 ``` diff --git a/docs/src/tutorials/create_edit_curves.md b/docs/src/tutorials/create_edit_curves.md index 04f6ced6..75e6eb34 100644 --- a/docs/src/tutorials/create_edit_curves.md +++ b/docs/src/tutorials/create_edit_curves.md @@ -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 diff --git a/docs/src/tutorials/introduction.md b/docs/src/tutorials/introduction.md index 47afe661..389f50ea 100644 --- a/docs/src/tutorials/introduction.md +++ b/docs/src/tutorials/introduction.md @@ -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. \ No newline at end of file +* 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. \ No newline at end of file diff --git a/docs/src/tutorials/symmetric_mesh.md b/docs/src/tutorials/symmetric_mesh.md new file mode 100644 index 00000000..e1d84171 --- /dev/null +++ b/docs/src/tutorials/symmetric_mesh.md @@ -0,0 +1,363 @@ +# Symmetric mesh + +The purpose of this tutorial is to demonstrate how to create an unstructured mesh +that is symmetric with respect to a straight line outer boundary as prescribed by the user. +At the end of this tutorial one can find the script necessary to generate the meshes +described herein. + +### Synopsis + +This tutorial 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. + +## Initialization + +From a Julia REPL we load the HOHQMesh package as well as +[GLMakie](https://github.com/JuliaPlots/GLMakie.jl/), a backend of +[Makie.jl](https://github.com/JuliaPlots/Makie.jl/), to visualize the +curves, mesh, etc. from the interactive tool. +```julia +julia> using GLMakie, HOHQMesh +``` +Now we are ready to interactively generate unstructured quadrilateral meshes! + +We create a new project with the name `"symmetric_mesh"` and +assign `"out"` to be the folder where any output files from the mesh generation process +will be saved. By default, the output files created by HOHQMesh will carry the same name +as the project. For example, the resulting HOHQMesh control file from this tutorial +will be named `symmetric_mesh.control`. +If the folder `out` does not exist, it will be created automatically in +the current working directory. +```julia +symmetric_mesh = newProject("symmetric_mesh", "out") +``` + +## Adjusting project parameters + +When a new project is created it is filled with several default +`RunParameters` such as the polynomial order used to represent curved boundaries +or the mesh file format. These `RunParameters` can be queried and adjusted with +appropriate getter/setter pairs, see [Controlling the mesh generation](@ref) +for more details. + +For the `symmetric_mesh` project we query the current values for the polynomial +order and the mesh output format +```julia +julia> getPolynomialOrder(symmetric_mesh) +5 + +julia> getMeshFileFormat(symmetric_mesh) +"ISM-V2" +``` + +We change the default polynomial order in the `symmetric_mesh` to be $6$ with a corresponding +setter function +```julia +setPolynomialOrder!(symmetric_mesh, 6) +``` + +## Add a background grid + +HOHQMesh requires a background grid for the mesh generation process. This background grid sets +the base resolution of the desired mesh. HOHQMesh will automatically subdivide from this background +grid near sharp features of any curved boundaries. + +For a domain bounded by an outer boundary curve, this background grid is set by indicating the desired +element size in the $x$ and $y$ directions. To start, we set the background grid for `symmetric_mesh` +to have elements with side length $0.25$ in each direction +```julia +addBackgroundGrid!(spline_project, [0.25, 0.25, 0.0]) +``` + +## Add the outer boundary + +With the background grid size set, we next build the outer boundary for the present mesh project. +This outer boundary is composed of nine straight line segments and a half circle arc. +The curves will afterwards be added to the mesh project `symmetric_mesh` +in counter-clockwise order as required by HOHQMesh. +```julia +line1 = newEndPointsLineCurve(":symmetry", [-0.05, 2.0, 0.0], + [-0.05, 0.0, 0.0]) + +line2 = newEndPointsLineCurve("bottom", [-0.05, 0.0, 0.0], + [1.0, 0.0, 0.0]) + +line3 = newEndPointsLineCurve("right", [1.0, 0.0, 0.0], + [1.0, 0.5, 0.0]) + +half_circle = newCircularArcCurve("circle", # curve name + [1.0, 0.75, 0.0], # circle center + 0.25, # circle radius + 270.0, # start angle + 90.0, # end angle + "degrees") # angle units + +line4 = newEndPointsLineCurve("right", [1.0, 1.0, 0.0], + [1.0, 1.5, 0.0]) + +line5 = newEndPointsLineCurve("bump", [1.0, 1.5, 0.0], + [0.75, 1.5, 0.0]) + +line6 = newEndPointsLineCurve("bump", [0.75, 1.5, 0.0], + [0.75, 1.75, 0.0]) + +line7 = newEndPointsLineCurve("bump", [0.75, 1.75, 0.0], + [1.0, 1.75, 0.0]) + +line8 = newEndPointsLineCurve("right", [1.0, 1.75, 0.0], + [1.0, 2.0, 0.0]) + +line9 = newEndPointsLineCurve("top", [1.0, 2.0, 0.0], + [-0.05, 2.0, 0.0]) +``` +The given boundary names will also be the element boundary names written to the mesh file. +The only exception is the first boundary curve that is given +the name `":symmetry"`. +This outer boundary curve name is a special keyword +in HOHQMesh that says it is a straight line across which +a reflection will occur. +Two worthwhile notes are + 1. the leading colon on this boundary name keyword is present to avoid conflicts with any other use of the *symmetry* name. + 2. if the curve designated as `":symmetry"` is not a straight line, then an error is thrown by HOHQMesh and the mesh will not be reflected. + +!!! tip "Name of the symmetry boundary" + The name of the reflection boundary line is not + case-sensitive, thus`":symmetry"` or `":Symmetry"` or `":SYMMETRY"` + are all valid and will be recognized as the keyword for symmetry. + +Now that all the outer boundary curves are defined we add them to the `symmetric_mesh` +project in counter-clockwise order +```julia +addCurveToOuterBoundary!(symmetric_mesh, line1) +addCurveToOuterBoundary!(symmetric_mesh, line2) +addCurveToOuterBoundary!(symmetric_mesh, half_circle) +addCurveToOuterBoundary!(symmetric_mesh, line3) +addCurveToOuterBoundary!(symmetric_mesh, line4) +addCurveToOuterBoundary!(symmetric_mesh, line5) +addCurveToOuterBoundary!(symmetric_mesh, line6) +addCurveToOuterBoundary!(symmetric_mesh, line7) +addCurveToOuterBoundary!(symmetric_mesh, line8) +addCurveToOuterBoundary!(symmetric_mesh, line9) +``` + +We visualize the outer boundary curve chain and background grid with the following +```julia +plotProject!(symmetric_mesh, MODEL+GRID) +``` +Here, we take the sum of the keywords `MODEL` and `GRID` in order to simultaneously visualize +the outer boundary and background grid. The resulting plot is given below. The chain of outer boundary +curves is called `"Outer"` and its constituent curve segments are labeled accordingly with the names +prescribed in the curve construction above. + +![before_generation](https://github.com/trixi-framework/HOHQMesh.jl/assets/25242486/2755fb08-9796-4e79-9d2d-055ef476dd4b) + +## Generate the mesh + +We next generate the mesh from the information contained in `symmetric_mesh`. +This will output the following files to the `out` folder: + +* `symmetric_mesh.control`: A HOHQMesh control file for the current project. +* `symmetric_mesh.tec`: A TecPlot formatted file to visualize the mesh with other software, e.g., [ParaView](https://www.paraview.org/). +* `symmetric_mesh.mesh`: A mesh file with format `ISM-V2` (the default format). + +To do this we execute the command +```julia +generate_mesh(symmetric_mesh) + + ******************* + 2D Mesh Statistics: + ******************* + Total time = 4.0154999999999996E-002 + Number of nodes = 343 + Number of Edges = 626 + Number of Elements = 284 + Number of Subdivisions = 2 + + Mesh Quality: + Measure Minimum Maximum Average Acceptable Low Acceptable High Reference + Signed Area 0.00227157 0.06552808 0.01366911 0.00000000 999.99900000 1.00000000 + Aspect Ratio 1.00389317 2.07480912 1.22443835 1.00000000 999.99900000 1.00000000 + Condition 1.00048947 1.93007666 1.12853177 1.00000000 4.00000000 1.00000000 + Edge Ratio 1.00607156 3.56541719 1.44892631 1.00000000 4.00000000 1.00000000 + Jacobian 0.00158627 0.06202757 0.01120120 0.00000000 999.99900000 1.00000000 + Minimum Angle 48.35050023 89.33703938 75.39251039 40.00000000 90.00000000 90.00000000 + Maximum Angle 90.94150752 129.91539960 106.20679399 90.00000000 135.00000000 90.00000000 + Area Sign 1.00000000 1.00000000 1.00000000 1.00000000 1.00000000 1.00000000 +``` +Note that the call to `generate_mesh` prints mesh quality statistics to the screen +and updates the visualization. +The background grid is *removed* from the visualization when the mesh is generated. + +!!! note "Mesh visualization" + Currently, only the "skeleton" of the mesh is visualized. Thus, the high-order curved boundary information + is not seen in the plot but this information **is present** in the mesh file generated. + +![first_reflect_mesh](https://github.com/trixi-framework/HOHQMesh.jl/assets/25242486/c271d208-6779-4e47-9045-a8cd21c5896d) + +!!! tip "Boundary names in the mesh file" + The boundary names of the original outer curves will be those defined by the user + in their construction above. The boundary labeled `":symmetry"` is now internal and + is marked appropriately as such. The reflected boundary names are appended + with `_R` (for reflected) in the mesh file. For instance, the reflected version + of the boundary `bottom` has the name `bottom_R` or the boundary named `circle` has the + reflected boundary counterpart named `circle_R`. These can be changed as desired by editing the mesh file. + +## Changing the reflection line + +It is also possible to create a symmetry boundary composed of multiple co-linear segments. + +To change the line along which the mesh is reflected, we remove the current mesh +that was just generated and re-plot the model curves +and background grid. +```julia +remove_mesh!(symmetric_mesh) +updatePlot!(symmetric_mesh, MODEL+GRID) +``` +The `remove_mesh!` command deletes the mesh information from +the interactive mesh project `symmetric_mesh` as well as the mesh file `symmetric_mesh.mesh`, +control file `symmetric_mesh.control`, plot file `symmetric_mesh.tec`, +and mesh statistics file `symmetric_mesh.txt` from the `out` folder. + +To illustrate the reflection about multiple boundary curves (which must be co-linear!), +we first rename the current symmetry boundary curve `O.1` to have the name `"left"`. +Next, we rename all the co-linear boundary curves `O.3`, `O.5`, and `O.9` to have the name `":symmetry"`. +Both are done with the function `renameCurve!` +```julia +renameCurve!(symmetric_mesh, ":symmetry", # existing curve name + "left") # new curve name +renameCurve!(symmetric_mesh, "right", ":symmetry") +``` +After the boundary names are adjusted the plot updates automatically to give the figure below. + +![before_generation2](https://github.com/trixi-framework/HOHQMesh.jl/assets/25242486/0118a02f-0343-4280-8a63-eba5a59d69e3) + +We then generate the new mesh from the information contained in `symmetric_mesh`. +Again, a check ensures that the curves designated as `":symmetry"` are co-linear. +An error is thrown if this is not the case and the mesh will not be reflected. +This saves the control, tec, and mesh files into the `out` folder and yields +```julia +generate_mesh(symmetric_mesh) + + ******************* + 2D Mesh Statistics: + ******************* + Total time = 3.7763000000000019E-002 + Number of nodes = 337 + Number of Edges = 622 + Number of Elements = 284 + Number of Subdivisions = 2 + + Mesh Quality: + Measure Minimum Maximum Average Acceptable Low Acceptable High Reference + Signed Area 0.00227157 0.06552808 0.01366911 0.00000000 999.99900000 1.00000000 + Aspect Ratio 1.00389317 2.07480912 1.22443835 1.00000000 999.99900000 1.00000000 + Condition 1.00048947 1.93007666 1.12853177 1.00000000 4.00000000 1.00000000 + Edge Ratio 1.00607156 3.56541719 1.44892631 1.00000000 4.00000000 1.00000000 + Jacobian 0.00158627 0.06202757 0.01120120 0.00000000 999.99900000 1.00000000 + Minimum Angle 48.35050023 89.33703938 75.39251039 40.00000000 90.00000000 90.00000000 + Maximum Angle 90.94150752 129.91539960 106.20679399 90.00000000 135.00000000 90.00000000 + Area Sign 1.00000000 1.00000000 1.00000000 1.00000000 1.00000000 1.00000000 +``` +The updated visualization is given below. Note, the flexibility to define multiple +co-linear symmetric boundaries creates a symmetric mesh with closed internal boundaries. +In this example, a circle and a rectangle. + +![first_reflect_mesh2](https://github.com/trixi-framework/HOHQMesh.jl/assets/25242486/7e5baf73-9c48-45be-84e4-90eb331103a5) + +## Summary + +In this tutorial we demonstrated 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. + +For completeness, we include two scripts with all the commands to generate the meshes displayed +for a reflection about the left boundary line `O.1` as well as a reflection about +the right boundary composed of the three co-linear segments `O.3`, `O.5`, and `O.9`. +Note, we **do not** include the plotting in these scripts. +```julia +# Interactive mesh with reflection on the left over a single symmetry boundary +# as well as a reflection on the right over multiple co-linear symmetry boundaries. +# +# Keywords: outer boundary, reflection, symmetric mesh +using HOHQMesh + +# new project +symmetric_mesh = newProject("symmetric_mesh", "out") + +# reset the polynomial degree of the mesh +setPolynomialOrder!(symmetric_mesh, 6) + +# A background grid is required for the mesh generation +addBackgroundGrid!(symmetric_mesh, [0.25, 0.25, 0.0]) + +# Create all the outer boundary curves and add them to the mesh project. +# Note: (1) Curve names are those that will be present in the mesh file +# (2) Boundary named ":symmetry" is where reflection occurs + +line1 = newEndPointsLineCurve(":symmetry", [-0.05, 2.0, 0.0], + [-0.05, 0.0, 0.0]) + +line2 = newEndPointsLineCurve("bottom", [-0.05, 0.0, 0.0], + [1.0, 0.0, 0.0]) + +line3 = newEndPointsLineCurve("right", [1.0, 0.0, 0.0], + [1.0, 0.5, 0.0]) + +half_circle = newCircularArcCurve("circle", # curve name + [1.0, 0.75, 0.0], # circle center + 0.25, # circle radius + 270.0, # start angle + 90.0, # end angle + "degrees") # angle units + +line4 = newEndPointsLineCurve("right", [1.0, 1.0, 0.0], + [1.0, 1.5, 0.0]) + +line5 = newEndPointsLineCurve("bump", [1.0, 1.5, 0.0], + [0.75, 1.5, 0.0]) + +line6 = newEndPointsLineCurve("bump", [0.75, 1.5, 0.0], + [0.75, 1.75, 0.0]) + +line7 = newEndPointsLineCurve("bump", [0.75, 1.75, 0.0], + [1.0, 1.75, 0.0]) + +line8 = newEndPointsLineCurve("right", [1.0, 1.75, 0.0], + [1.0, 2.0, 0.0]) + +line9 = newEndPointsLineCurve("top", [1.0, 2.0, 0.0], + [-0.05, 2.0, 0.0]) + +addCurveToOuterBoundary!(symmetric_mesh, line1) +addCurveToOuterBoundary!(symmetric_mesh, line2) +addCurveToOuterBoundary!(symmetric_mesh, half_circle) +addCurveToOuterBoundary!(symmetric_mesh, line3) +addCurveToOuterBoundary!(symmetric_mesh, line4) +addCurveToOuterBoundary!(symmetric_mesh, line5) +addCurveToOuterBoundary!(symmetric_mesh, line6) +addCurveToOuterBoundary!(symmetric_mesh, line7) +addCurveToOuterBoundary!(symmetric_mesh, line8) +addCurveToOuterBoundary!(symmetric_mesh, line9) + +# Generate the mesh. Saves the mesh file to the directory "out". +generate_mesh(symmetric_mesh) + +# Delete the existing mesh before modifying boundary names. +remove_mesh!(symmetric_mesh) + +# Rename the outer boundaries appropriately to set the symmetry boundary +# on the right composed of multiple co-linear segments. +renameCurve!(symmetric_mesh, ":symmetry", # existing curve name + "left") # new curve name +renameCurve!(symmetric_mesh, "right", ":symmetry") + +# Generate the mesh. Saves the mesh file to the directory "out". +generate_mesh(symmetric_mesh) +``` \ No newline at end of file diff --git a/src/HOHQMesh.jl b/src/HOHQMesh.jl index 99c1daa6..7003804e 100644 --- a/src/HOHQMesh.jl +++ b/src/HOHQMesh.jl @@ -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, @@ -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`. diff --git a/src/Mesh/Meshing.jl b/src/Mesh/Meshing.jl index 8aaceef7..fa101405 100644 --- a/src/Mesh/Meshing.jl +++ b/src/Mesh/Meshing.jl @@ -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,)) diff --git a/src/Project/ModelAPI.jl b/src/Project/ModelAPI.jl index bfa5ebc6..c8dac82c 100644 --- a/src/Project/ModelAPI.jl +++ b/src/Project/ModelAPI.jl @@ -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"]) @@ -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 @@ -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. @@ -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 diff --git a/src/Project/Project.jl b/src/Project/Project.jl index dc42e445..69beb797 100644 --- a/src/Project/Project.jl +++ b/src/Project/Project.jl @@ -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) @@ -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) diff --git a/test/test_project_with_viz.jl b/test/test_project_with_viz.jl index 6b77cf52..8b6282ba 100644 --- a/test/test_project_with_viz.jl +++ b/test/test_project_with_viz.jl @@ -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] @@ -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) diff --git a/test/test_visualization.jl b/test/test_visualization.jl index 0ad0d594..b3156b29 100644 --- a/test/test_visualization.jl +++ b/test/test_visualization.jl @@ -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) @@ -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)