Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update the wrapper function #12

Merged
merged 11 commits into from
Nov 5, 2021
78 changes: 78 additions & 0 deletions examples/IceCreamCone_Abaqus.control
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
%
% -----------------------------------------------------------------------------
% Control file for a circular outer boundary and ice cream cone inner boundary.
% -----------------------------------------------------------------------------
%
% -------------
% Control Block
% -------------
%
\begin{CONTROL_INPUT}
\begin{RUN_PARAMETERS}
mesh file name = Benchmarks/MeshFiles/Tests/abaqus_ice_cream_cone.inp
plot file name = Benchmarks/PlotFiles/Tests/abaqus_ice_cream_cone.tec
stats file name = Benchmarks/StatsFiles/Tests/abaqus_ice_cream_cone.txt
test file name = Benchmarks/BenchmarkData/abaqus_ice_cream_cone.txt
mesh file format = ABAQUS
polynomial order = 4
plot file format = skeleton
\end{RUN_PARAMETERS}

\begin{MESH_PARAMETERS}
element type = quad
\end{MESH_PARAMETERS}

\begin{BACKGROUND_GRID}
background grid size = [1.0, 1.0, 0.0]
\end{BACKGROUND_GRID}

\begin{SPRING_SMOOTHER}
smoothing = ON
smoothing type = LinearAndCrossBarSpring
number of iterations = 25
\end{SPRING_SMOOTHER}

\end{CONTROL_INPUT}

\begin{MODEL}

\begin{OUTER_BOUNDARY}
\begin{PARAMETRIC_EQUATION_CURVE}
name = OuterCircle
xEqn = x(t) = 8.0*sin(2.0*pi*t)
yEqn = y(t) = 8.0*cos(2.0*pi*t)
zEqn = z(t) = 0.0
\end{PARAMETRIC_EQUATION_CURVE}

\end{OUTER_BOUNDARY}

\begin{INNER_BOUNDARIES}

\begin{CHAIN}
name = IceCreamCone
\begin{END_POINTS_LINE}
name = LeftSlant
xStart = [-2.0, 1.0, 0.0]
xEnd = [ 0.0, -3.0, 0.0]
\end{END_POINTS_LINE}

\begin{END_POINTS_LINE}
name = RightSlant
xStart = [ 0.0, -3.0, 0.0]
xEnd = [ 2.0, 1.0, 0.0]
\end{END_POINTS_LINE}

\begin{CIRCULAR_ARC}
name = IceCream
units = degrees
center = [ 0.0, 1.0, 0.0]
radius = 2.0
start angle = 0.0
end angle = 180.0
\end{CIRCULAR_ARC}
\end{CHAIN}

\end{INNER_BOUNDARIES}

\end{MODEL}
\end{FILE}
31 changes: 29 additions & 2 deletions src/HOHQMesh.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ export generate_mesh
"""
generate_mesh(control_file;
output_directory="out",
mesh_filename=nothing, plot_filename=nothing, stats_filename=nothing)
mesh_filename=nothing, plot_filename=nothing, stats_filename=nothing,
verbose=false)

Generate a mesh based on the `control_file` with the HOHQMesh mesh generator and store resulting
files in `output_directory`.
Expand All @@ -33,7 +34,14 @@ function generate_mesh(control_file;
# Determine output filenames
filebase = splitext(basename(control_file))[1]
if isnothing(mesh_filename)
mesh_filename = filebase * ".mesh"
mesh_file_format = extract_mesh_file_format(control_file)
if mesh_file_format == "ISM" || mesh_file_format == "ISM-V2" || mesh_file_format == "ISM-v2"
mesh_filename = filebase * ".mesh"
elseif mesh_file_format == "ABAQUS"
mesh_filename = filebase * ".inp"
else
error("Unknown mesh file format: ", mesh_file_format, " (must be one of ISM, ISM-V2, or ABAQUS)")
end
end
if isnothing(plot_filename)
plot_filename = filebase * ".tec"
Expand Down Expand Up @@ -81,6 +89,25 @@ function generate_mesh(control_file;
end


"""
extract_mesh_file_format(control_file)

Return a string with the desired output format of the HOHQMesh generated mesh file.
This information is given within the `RUN_PARAMETERS` of the `CONTROL_INPUT` block
of the control file.
See the [`HOHQMesh` documentation](https://trixi-framework.github.io/HOHQMesh/) for details.
"""
function extract_mesh_file_format(control_file)
# Find the file line that gives the mesh file format
file_lines = readlines(open(control_file))
line_index = findfirst(contains("mesh file format"), file_lines)
# Extract the mesh file format keyword
file_format = split(file_lines[line_index])[5]

return file_format
end


"""
examples_dir()

Expand Down
1 change: 1 addition & 0 deletions test/Project.toml
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
[deps]
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
AbaqusReader = "bc6b9049-e460-56d6-94b4-a597b2c0390d"
26 changes: 26 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
using HOHQMesh
using Test
using AbaqusReader

# Start with a clean environment: remove HOHQMesh output directory if it exists
outdir = "out"
isdir(outdir) && rm(outdir, recursive=true)

@testset "HOHQMesh.jl" begin

Expand All @@ -17,4 +22,25 @@ using Test
@test generate_mesh(control_file, verbose=true) isa String
end

@testset "generate_mesh() with ABAQUS output" begin
control_file = joinpath(HOHQMesh.examples_dir(), "IceCreamCone_Abaqus.control")
generate_mesh(control_file)
parse_mesh = abaqus_read_mesh(joinpath(outdir, "IceCreamCone_Abaqus.inp"))
# set some reference values for comparison. These are the corner IDs for element 114
reference_ids = [140, 141, 154, 153]
@test parse_mesh["elements"][114] == reference_ids
end

@testset "generate_mesh() with invalid format" begin
# Create temporary control file option that is invalid
mktemp() do path, io
write(io, "mesh file format = ABBAKISS")
flush(io)
@test_throws ErrorException generate_mesh(path)
end
end

end # testset "HOHQMesh.jl"

# Clean up afterwards: delete HOHQMesh output directory
@test_nowarn rm(outdir, recursive=true)