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

App interface #4

Open
wants to merge 18 commits into
base: master
Choose a base branch
from
16 changes: 7 additions & 9 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
name = "AirfoilGmsh"
uuid = "e68ec710-8e48-43c5-af1a-c38c4248fd7b"
authors = ["Carlo Brunelli"]
version = "0.1.2"
version = "0.1.3"

[deps]
CSV = "336ed68f-0bac-5ca0-87d4-7b16caf5d00b"
Chain = "8be319e6-bccf-4806-a6f7-6fae938471bc"
CubicSplines = "9c784101-8907-5a6d-9be6-98f00873c89b"
DataFrames = "a93c6f00-e57d-5684-b7b6-d8193f3e46c0"
Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4"
DocumenterTools = "35a29f4d-8980-5a13-9543-d66fff28ecb8"
Downloads = "f43a241f-c20a-4ad4-852c-f6b1247861c6"
FileIO = "5789e2e9-d7fb-5bc7-8068-2c6fae9b9549"
Gridap = "56d4f2e9-7ea1-5844-9cf6-b9c51ca7ce8e"
GridapGmsh = "3025c34a-b394-11e9-2a55-3fee550c04c8"
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
Optim = "429524aa-4258-5aef-a3af-852621145aeb"
Optimization = "7f7a1694-90dd-40f0-9382-eb1efda571ba"
OptimizationBBO = "3e6eede4-6085-4f62-9a71-46d9bc1eb92b"
Expand All @@ -29,16 +29,14 @@ Documenter = "0.27.24"
DocumenterTools = "0.1.16"
Downloads = "1.6.0"
FileIO = "1.16.0"
Gridap = "0.17.17"
GridapGmsh = "0.6.1"
Plots = "1.38.16"
Revise = "3.5.1"
XLSX = "0.8.4, 0.9"
julia = "1.8.2"
Optim = "1.7.6"
Optimization = "3.15.2"
OptimizationBBO = "0.1.4"
Parameters = "0.12.3"
Plots = "1.38.16"
Revise = "3.5.1"
XLSX = "0.8.4, 0.9"
julia = "1.8.2"

[extras]
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
Expand Down
23 changes: 20 additions & 3 deletions src/AirfoilGmsh.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,25 @@ using Plots
using Optim
using Optimization, OptimizationBBO
using Parameters
using CubicSplines
using LinearAlgebra

export DomainDivision
export DomainMeshDivisions
export DomainInfo
export BoundaryLayer
export ElementShape
export QUAD
export TRI
export HEX
export TETRA
include("DefaultValues.jl")


export from_url_to_csv
include("ReadWeb.jl")


export AirfoilPoints
export AirfoilParams
export get_airfoil_features
Expand All @@ -23,8 +38,6 @@ export get_airfoil_name
include("AirfoilUtils.jl")


export start_writing
include("WriteFileUtils.jl")

export addAirfoilPoints
export addShearPoint
Expand All @@ -43,9 +56,13 @@ export RecombineSurfaces
export addPhysicalGroup
include("GmshUtils.jl")

export refinement_parameters


include("BLanalysis.jl")

export start_writing
include("WriteFileUtils.jl")

export map_entities
include("MapLines.jl")

Expand Down
12 changes: 10 additions & 2 deletions src/AirfoilUtils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,8 @@ function get_airfoil_features(filename::String, c::Float64, trailing_edge_points
airfoil_points_list = CSV.File(filename, header=true) |> Tables.matrix
formatting_airfoil_points!(airfoil_points_list,c)

trailing_edge_points = findTE(trailing_edge_points, c, airfoil_points_list)
trailing_edge_points,airfoil_points_list = findTE(trailing_edge_points, c, airfoil_points_list)

sharp_end, sharp_idx = detect_end(trailing_edge_points)

leading_edge_points = findLE(leading_edge_points, c, airfoil_points_list)
Expand Down Expand Up @@ -131,19 +132,26 @@ function verify_trailing_edge(airfoil_points_list::Matrix{Float64}, c::Float64)
return airfoil_points_list
end



"""
findTE(trailing_edge_points, c::Float64, airfoil_points_list::Matrix{Float64})

Automatically detects the trailing edge points indexes
"""
function findTE(trailing_edge_points, c::Float64, airfoil_points_list::Matrix{Float64})
atol = 1e-6
if norm(airfoil_points_list[1,:] - airfoil_points_list[end,:])<c .* 0.5e-2
airfoil_points_list = airfoil_points_list[1:end-1,:]
end

while isempty(trailing_edge_points)
trailing_edge_points = findall(x -> isapprox(x, c; atol=atol), airfoil_points_list[:, 1])
atol = atol * 2
end
sort!(trailing_edge_points)
trailing_edge_points

return trailing_edge_points,airfoil_points_list
end

"""
Expand Down
26 changes: 13 additions & 13 deletions src/BLanalysis.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

"""
yt(yh::Float64, G::Float64, N::Int)

Expand Down Expand Up @@ -91,17 +90,18 @@ function boundary_layer_characteristics(Re::Real, H::Real, h0::Real, chord::Floa
end


function refinement_parameters(Reynolds::Real, h0::Real, chord::Real)
if Reynolds < 0 && h0 < 0 #If no reynolds or height specified
return 0.35, 100, 1.12, h0
else
H = 0.35 * chord
if h0 < 0
h0 = chord * sqrt(74) * Reynolds^(-13 / 14)
println("Extimated h0 = $h0 m")
end
H_levels, N_levels, G, h0 = boundary_layer_characteristics(Reynolds, H, h0, chord)
function BoundaryLayer(Reynolds::Int64,ds::DomainInfo )
@unpack chord = ds
h0 = chord * sqrt(74) * Reynolds^(-13 / 14)
BoundaryLayer(h0, ds)
end

return H_levels, N_levels, G, h0
end
function BoundaryLayer(h0::Float64, ds::DomainInfo)
@unpack chord, H_offset = ds
H_levels, N_levels, G, h0 = boundary_layer_characteristics(Reynolds, H_offset, h0, chord)
BoundaryLayer(H_levels=H_levels, N_levels=N_levels, G=G, Reynolds=Reynolds, h0=h0)
end

function BoundaryLayer(H_levels::Float64,N_levels::Int64,G::Float64)
BoundaryLayer(H_levels=H_levels, N_levels=N_levels, G=G)
end
110 changes: 71 additions & 39 deletions src/CreateGeoFile.jl
Original file line number Diff line number Diff line change
@@ -1,31 +1,40 @@
"""
create_geofile(filename::String; Reynolds = -1, h0 = -1, leading_edge_points = Int64[], trailing_edge_points = Int64[], chord=1.0, dimension=2, elements = :QUAD, open_geo = true)
create_geofile(filename::String, domain_mesh_divisions::DomainMeshDivisions, domain_info::DomainInfo, boundary_layer::BoundaryLayer)


It is the main function of the package. From a csv file containing the airfoil points it creates a .geo file.
The .geo file can be created using the function [`from_url_to_csv`](@ref).
The user can specify just the file name.
```julia
create_geofile("naca0012.csv")
```
It is also possibile to provide extra arguments such as the Reynolds number and/or the first layer height for a better extimation of the boundary-cell properties.
It is possible to overwrite the extimation of the trailing edge and leading edge made by the code providing the relative points numbers.
It is possible to provide just the string of the filename.csv where the points are stored.
It is also possible to customize the Mesh Division, Domain Size and provide information on the boundary layer.
See the default parameters in the "DefaultValues.jl" file.


The mesh can be created in 2D or 3D. In 3D case by default are created periodic boundary conditions in the `z` direction.

It is possible to create a mesh with the following options:


| Type of element | Dimension | Symbol |
| Type of element | Dimension | struct |
| ---------------|-----------|-----------|
| Quadrilateral | 2D | :QUAD |
| Hexaedral | 3D | :HEX |
| Triangular | 2D | :TRI |
| Thetraedreal | 3D | :TETRA |
| Quadrilateral | 2D | QUAD() |
| Hexaedral | 3D | HEX() |
| Triangular | 2D | TRI() |
| Thetraedreal | 3D | TETRA() |

"""
function create_geofile(filename::String; Reynolds = -1, h0 = -1, leading_edge_points = Int64[], trailing_edge_points = Int64[], chord=1.0, dimension=2, elements = :QUAD, open_geo = false)

refinement_params = refinement_parameters(Reynolds, h0, chord)
function create_geofile(filename::String, domain_mesh_divisions::DomainMeshDivisions, domain_info::DomainInfo, boundary_layer::BoundaryLayer)


leading_edge_points = Int64[]
trailing_edge_points = Int64[]

@unpack chord,dimension = domain_info

if elements == :QUAD || elements == :HEX
if domain_info.elements == QUAD() || domain_info.elements == HEX()
recombine = true
else
recombine = false
Expand All @@ -38,30 +47,30 @@ Loops = Vector[]
PhysicalGroups = DataFrame(number=Int64[], name=String[], entities=Vector[], type=String[])


Airfoil = AirfoilParams(filename, chord, trailing_edge_points, leading_edge_points)
Airfoil = AirfoilParams( filename, chord, trailing_edge_points, leading_edge_points)

io = start_writing(Airfoil, dimension, chord, refinement_params)
io, geo_filename = start_writing(Airfoil, domain_info, domain_mesh_divisions, boundary_layer)

addAirfoilPoints(Airfoil, Points, io)
Airfoil.points.leading_edge
Airfoil.points.trailing_edge[Airfoil.sharp_idx]

N_edge = 5
N_edge = domain_mesh_divisions.Edge.numdiv
# Create airfoil lines
spline_airfoil_top = addSpline(Airfoil.points.trailing_edge[1] : Airfoil.points.leading_edge[1], Lines, io)[end][1]
spline_airfoil_le = addSpline(Airfoil.points.leading_edge[1] : Airfoil.points.leading_edge[2], Lines, io)[end][1]
spline_airfoil_top = addSpline(collect(Airfoil.points.trailing_edge[1] : Airfoil.points.leading_edge[1]), Lines, io;all=true)[end][1]

spline_airfoil_le = addSpline(collect(Airfoil.points.leading_edge[1] : Airfoil.points.leading_edge[2]), Lines, io; all=true)[end][1]

if ! is_sharp(Airfoil)
spline_airfoil_te = addLine(Airfoil.points.trailing_edge[1], Airfoil.points.trailing_edge[2], Lines, io)[end][1]
spline_airfoil_bottom = addSpline(Airfoil.points.leading_edge[2] : Airfoil.points.trailing_edge[Airfoil.sharp_idx] , Lines, io)[end][1]
spline_airfoil_bottom = addSpline(collect(Airfoil.points.leading_edge[2] : Airfoil.points.trailing_edge[Airfoil.sharp_idx] ), Lines, io; all=true)[end][1]
else
b_points = [Airfoil.points.leading_edge[2]: Airfoil.points.num, Airfoil.points.trailing_edge[Airfoil.sharp_idx]]

spline_airfoil_bottom = addSpline(b_points, Lines, io)[end][1]
end



#External Domain points
point1 = addPoint(0, "C", 0, Points, io; tag ="external")[end][1]
point2 = addPoint(0, "-C", 0, Points, io; tag ="external")[end][1]
Expand Down Expand Up @@ -154,7 +163,7 @@ point7 = addPoint("L", "-L* " * string(x_tmp) * "*Sin(AoA) + " * string(y_tmp) *
l33r = addLine(point3, point3r, Lines, io)[end][1]
l44r = addLine(point4, point4r, Lines, io)[end][1]


loop1 = LoopfromPoints([point1, point1r, point2r, point2], Lines)
loop1r = LoopfromPoints([point1r, Airfoil.points.leading_edge[1], Airfoil.points.leading_edge[2], point2r], Lines)

Expand All @@ -164,7 +173,8 @@ point7 = addPoint("L", "-L* " * string(x_tmp) * "*Sin(AoA) + " * string(y_tmp) *
loop3 = LoopfromPoints([point2, point4, point4r, point2r], Lines)
loop3r = LoopfromPoints([point2r, point4r, Airfoil.points.trailing_edge[Airfoil.sharp_idx], Airfoil.points.leading_edge[2]], Lines)

LinefromPoints(point8r, point6, Lines)

LinefromPoints(Airfoil.points.trailing_edge[Airfoil.sharp_idx], Airfoil.points.leading_edge[2], Lines)

loop4 = LoopfromPoints([point3, point5, point7r, point3r], Lines)
loop4r = LoopfromPoints([point3r, point7r, point7, Airfoil.points.trailing_edge[1]], Lines)
Expand Down Expand Up @@ -257,14 +267,18 @@ point7 = addPoint("L", "-L* " * string(x_tmp) * "*Sin(AoA) + " * string(y_tmp) *



airfoil_lines = [LinefromPoints(point1, point3, Lines),
airfoil_lines_top = [LinefromPoints(point1, point3, Lines),
LinefromPoints(point1r, point3r, Lines),
LinefromPoints(Airfoil.points.trailing_edge[1], Airfoil.points.leading_edge[1], Lines),
LinefromPoints(Airfoil.points.trailing_edge[1], Airfoil.points.leading_edge[1], Lines)]

airfoil_lines_bottom = [
LinefromPoints(Airfoil.points.trailing_edge[Airfoil.sharp_idx], Airfoil.points.leading_edge[2], Lines),
LinefromPoints(point2, point4, Lines),
LinefromPoints(point2r, point4r, Lines)]
TransfiniteCurve(airfoil_lines, "N_airfoil", 1.0, io)


TransfiniteCurve(airfoil_lines_top, "N_airfoil_top", 1.0, io)
TransfiniteCurve(airfoil_lines_bottom, "N_airfoil_bottom", 1.0, io)

if is_sharp(Airfoil)
shear_lines = [LinefromPoints(point3, point5, Lines),
LinefromPoints(point3r, point7r, Lines),
Expand Down Expand Up @@ -361,20 +375,38 @@ point7 = addPoint("L", "-L* " * string(x_tmp) * "*Sin(AoA) + " * string(y_tmp) *
map_entities(Airfoil, PhysicalGroups, io)

end





close(io)

## Open GMSH for visualization of the .geo file and changing the parameters
if open_geo
open_gmsh(Airfoil, dimension)
end

close(io)


return io,geo_filename

end

return io

### DEFAULT
function create_geofile(filename::String )
domain_mesh_divisions=DomainMeshDivisions()
domain_info=DomainInfo()
boundary_layer=BoundaryLayer()
return create_geofile(filename, domain_mesh_divisions, domain_info, boundary_layer)
end

function create_geofile(filename::String, domain_mesh_divisions::DomainMeshDivisions)
domain_info=DomainInfo()
boundary_layer=BoundaryLayer()
return create_geofile(filename, domain_mesh_divisions, domain_info, boundary_layer)
end

function create_geofile(filename::String, domain_info::DomainInfo)
domain_mesh_divisions=DomainMeshDivisions()
boundary_layer=BoundaryLayer()
return create_geofile(filename, domain_mesh_divisions, domain_info, boundary_layer)
end


function create_geofile(filename::String, boundary_layer::BoundaryLayer)
domain_mesh_divisions=DomainMeshDivisions()
domain_info=DomainInfo()
return create_geofile(filename, domain_mesh_divisions, domain_info, boundary_layer)
end
Loading
Loading