Skip to content

Commit

Permalink
Merge pull request #19 from deltaeecs/dev
Browse files Browse the repository at this point in the history
Remove dependencies on Meshes.jl
  • Loading branch information
deltaeecs authored May 26, 2024
2 parents f5e4564 + 00f21cd commit 4ee751c
Show file tree
Hide file tree
Showing 9 changed files with 66 additions and 123 deletions.
4 changes: 1 addition & 3 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
name = "MoM_Basics"
uuid = "84796d1e-6a74-43fe-971c-cdafebd16eaa"
authors = ["deltaeecs <1225385871@qq.com> and contributors"]
version = "0.1.1"
version = "0.1.2"

[deps]
Dates = "ade2ca70-3891-5945-98fb-dc099432e06a"
FastGaussQuadrature = "442a2c76-b920-505d-bb47-c5924d526838"
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
Meshes = "eacbb407-ea5a-433e-ab97-5258b1ca43fa"
OffsetArrays = "6fe1bfb0-de20-5000-8ca7-80f57d26f881"
Printf = "de0858da-6303-5e67-8744-51eddeeeb8d7"
ProgressMeter = "92933f4c-e287-5a05-a399-4b506db050ca"
Expand All @@ -20,7 +19,6 @@ ThreadsX = "ac1d9e8a-700a-412c-b207-f0111f4b6c0d"

[compat]
FastGaussQuadrature = "1.0 - 1.2"
Meshes = "0.28 - 0.60"
OffsetArrays = "1.10 - 1.30"
ProgressMeter = "1.7 - 1.20"
Reexport = "1.2 - 1.3"
Expand Down
35 changes: 22 additions & 13 deletions src/BasicVSCellType/Hexahedras.jl
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,22 @@ function setHexaCoor!( hexasInfo::Vector{HexahedraInfo{IT, FT, CT}},
return nothing
end

"""
volume(vertices::Vararg{T, 8}) where {T}
计算八个点`vertices`组成的六面体体积。
"""
function volume(vertices::Vararg{T, 8}) where {T}
v = 0.0
# 分解为 5 个四面体累加体积
v += volume(vertices[1], vertices[2], vertices[3], vertices[6])
v += volume(vertices[1], vertices[3], vertices[4], vertices[8])
v += volume(vertices[1], vertices[5], vertices[6], vertices[8])
v += volume(vertices[1], vertices[3], vertices[6], vertices[8])
v += volume(vertices[3], vertices[6], vertices[7], vertices[8])
return v
end


"""
setHexaParam!(hexasInfo::Vector{HexahedraInfo{IT, FT, CT}}) where {IT<:Integer, FT<:AbstractFloat, CT<:Complex}
Expand All @@ -126,29 +142,25 @@ function setHexaParam!(hexasInfo::Vector{HexahedraInfo{IT, FT, CT}}) where {IT<:
@inbounds begin
# 第 i 六面体
hexaInfo = hexasInfo[i]
# 六面体的网格
hexa = Hexahedron(Meshes.Point3.(eachcol(hexaInfo.vertices))...)
# 体积
hexaInfo.volume = measure(hexa)
hexaInfo.volume = volume(eachcol(hexaInfo.vertices)...)
# 六个四边形面
quads = boundaryRBF(hexa)
quads = boundaryRBF(eachcol(hexaInfo.vertices)...)
# 对四个面循环计算面的外法向量,注意第 facei 个面为 第 facei 个 vertice 对面的四个点构成的四边形
for facei in 1:6
# 第 facei 个四边形
quadi = quads[facei]
# 四个点的视图
faceVertViews = quadi.vertices

# 计算面法向量(未定向\未归一化)
@views facen̂ = hexaInfo.facesn̂[:, facei]
@views facen̂ .= cross(faceVertViews[2] - faceVertViews[1], faceVertViews[2] - faceVertViews[3])
# 未归一化面法向量的模即为四边形面积两倍
faceArea = area(quadi)
@views facen̂ .= cross(quadi[2] - quadi[1], quadi[2] - quadi[3])
# 计算面积
faceArea = area(quadi...)
# 归一化面法向量
facen̂ ./= norm(facen̂)

# 定向,第 facei 个 vertice 点到其余四个点中的一个的向量与外法向量的点乘结果应该大于0
@views ((faceVertViews[1].coords .- hexaInfo.center) facen̂ < 0) && begin facen̂ .*= -1 end
@views ((quadi[1] .- hexaInfo.center) facen̂ < 0) && begin facen̂ .*= -1 end

# 写入结果
hexaInfo.facesArea[facei] = faceArea
Expand All @@ -167,9 +179,6 @@ end # function
根据六面体网格信息 `hexameshData` 和体基函数类型 `VolumeBFType` 生成网格信息向量 `hexasInfo` 和基函数信息向量 `bfsInfo` 。
"""
function getHexasInfo(hexameshData::HexahedraMesh{IT, FT}, VolumeBFType::Symbol) where{IT, FT}

# # 先生成 SimpleMesh
# hexaSimpleMesh = MeshFileReader.fromNodesConns2SimpleMesh(hexameshData.node, hexameshData.hexahedras)
# 分配四边形信息类型数组
hexasInfo = [HexahedraInfo{IT, FT, Complex{FT}}() for _ in 1:hexameshData.hexnum ]
# 写入六面体的八个点的id和点坐标、几何中心数据
Expand Down
11 changes: 11 additions & 0 deletions src/BasicVSCellType/Quadrangle.jl
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,17 @@ function Quads4Hexa{IT, FT}() where {IT <: Integer, FT<:AbstractFloat}
return Quads4Hexa{IT, FT}(isbd, δκ, vertices, edgel, edgev̂, edgen̂)
end

"""
area(vertices::Vararg{T, 3}) where {T}
计算四个点`vertices`组成的四边形面积。
"""
function area(vertices::Vararg{T, 4}) where {T}
a = area(vertices[1], vertices[2], vertices[3])
a += area(vertices[1], vertices[3], vertices[4])
return a
end

"""
(q::Quads4Hexa)(u::FT, v::FT) where {FT}
Expand Down
16 changes: 16 additions & 0 deletions src/BasicVSCellType/Tetrahedras.jl
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,22 @@ function setTetraCoor!( tetrasInfo::Vector{TetrahedraInfo{IT, FT, CT}},

return nothing
end

"""
volume(vertices::Vararg{T, 4}) where {T}
计算四个点`vertices`组成的四面体体积。
"""
function volume(vertices::Vararg{T, 4}) where {T}
# 计算四面体的某个点(第一个)指向第其他个点的三个向量
vert12 = vertices[2] .- vertices[1]
vert13 = vertices[3] .- vertices[1]
vert14 = vertices[4] .- vertices[1]
# 四面体体积
v = cross(vert12, vert13) vert14 / 6
return v
end

"""
setTetraParam!(tetrasInfo::Vector{TetrahedraInfo{IT, FT, CT}}) where {IT<:Integer, FT<:AbstractFloat, CT<:Complex}
Expand Down
13 changes: 13 additions & 0 deletions src/BasicVSCellType/Triangles.jl
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,19 @@ function setTricoor!( trianglesInfo::Vector{TriangleInfo{IT, FT}},
return nothing
end

"""
area(vertices::Vararg{T, 3}) where {T}
计算三个点`vertices`组成的三角形面积。
"""
function area(vertices::Vararg{T, 3}) where {T}
# edgev̂指向三角形的的指向向量(未单位化)
edge12 = vertices[2] - vertices[1]
edge13 = vertices[3] - vertices[1]
a = norm(cross(edge12, edge13))/2
return a
end

"""
setTriParam!(triangleInfo::TriangleInfo)
Expand Down
6 changes: 3 additions & 3 deletions src/BasisFunctions/RBF.jl
Original file line number Diff line number Diff line change
Expand Up @@ -34,18 +34,18 @@ end
RBF() = RBF{IntDtype, Precision.FT}()

@doc raw"""
boundaryRBF(h::Hexahedron)
boundaryRBF(h::vertices::Vararg{T, 8}) where {T}
重载面的提取顺序以匹配屋顶基函数 (RBF) 在六面体中的面按
```math
u=1, u=0, v = 1, v = 0, w = 1, w = 0
```
的顺序排列。
"""
function boundaryRBF(h::Hexahedron)
function boundaryRBF(vertices::Vararg{T, 8}) where {T}
indices = [ (2,3,7,6),(1,4,8,5),(4,3,7,8),
(1,2,6,5),(5,6,7,8),(1,2,3,4)]
SimpleMesh([h.vertices...], connect.(indices))
map(quadIdx -> map(i -> vertices[i], quadIdx), indices)
end


Expand Down
2 changes: 0 additions & 2 deletions src/MeshAndBFs.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
# 根据网格中三角形\四面体的数量,建立RWG、PWC、SWG、RBF基函数
# 网格文件处理函数
# include("MeshFileReader.jl")
# using .MeshFileReader
include("MeshProcess/MeshProcess.jl")
include("BasicVSCellType/CellTypes.jl")
include("BasisFunctions/BFs.jl")
Expand Down
101 changes: 0 additions & 101 deletions src/MeshProcess/MeshFileReader.jl

This file was deleted.

1 change: 0 additions & 1 deletion src/MoM_Basics.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ using StaticArrays, OffsetArrays, SparseArrays
using LinearAlgebra, FastGaussQuadrature, Statistics
using .Threads, ThreadsX
using Rotations
using Meshes

export Vec3D, SVec3D, MVec3D, random_rhat,
∠Info, θϕInfo, r̂func, θhatfunc, ϕhatfunc, r̂θϕInfo,
Expand Down

0 comments on commit 4ee751c

Please sign in to comment.