Skip to content

Commit 5a00148

Browse files
committed
change viz to have easier semantics in 2D if wanted
1 parent 6fdd0c9 commit 5a00148

File tree

1 file changed

+42
-72
lines changed

1 file changed

+42
-72
lines changed

src/2DModel/viz.jl

Lines changed: 42 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,8 @@ Named tuple containing:
2222
- `y`: Y-coordinates of the generated 3D points.
2323
- `z`: Z-coordinates of the generated 3D points.
2424
- `A`: Cross-sectional areas at each point.
25-
- `w`: Flow velocities at each point.
26-
- `P`: Pressure values at each point.
27-
28-
### Notes
29-
- The function first extracts unique spatial positions from the mesh.
30-
- The blood flow variables (`A`, `Q`, `E`, `A0`) are obtained from the solution array.
31-
- Pressure is computed using the `pressure` function.
32-
- A cylindrical coordinate transformation is applied to represent the vessel cross-section.
33-
- If `vtk` is `true`, the function writes the data to VTK format using `vtk_grid`.
25+
- `wtheta`: Flow angular velocity at each point.
26+
- `ws`: Flow axial velocity at each point.
3427
"""
3528
function get3DData(eq::BloodFlowEquations2D,curve::F1,er::F2,semi,sol,time_index ::Int = 1;vtk ::Bool=false,out ::T="./datas") where {T<:AbstractString,F1<:Function,F2<:Function}
3629
thetaval = semi.cache.elements.node_coordinates[1,:,:,:]
@@ -58,11 +51,11 @@ function get3DData(eq::BloodFlowEquations2D,curve::F1,er::F2,semi,sol,time_index
5851
thvali = thetaval[i]
5952
svali = sval[i]
6053
Avali = aval[i] + A0val[i]
54+
Rvali = sqrt(2*Avali)
55+
wthetavali = Typ(4/3*(Qthval[i]/Rvali)/Avali)
6156
wthetavali =Qthval[i]/Avali
6257
wsvali = Qsval[i]/Avali
6358
Pvali = Pval[i]
64-
Rvali = sqrt(2*Avali)
65-
# for thetaj in theta
6659
xi,yi,zi = M(thvali,svali,Rvali)
6760
x[c] = xi
6861
y[c] = yi
@@ -72,7 +65,6 @@ function get3DData(eq::BloodFlowEquations2D,curve::F1,er::F2,semi,sol,time_index
7265
ws[c] = wsvali
7366
P[c] = Pvali
7467
c+=1
75-
# end
7668
end
7769
if vtk
7870
npoints = length(x)
@@ -113,69 +105,47 @@ Named tuple containing:
113105
- `y`: Y-coordinates of the generated 3D points.
114106
- `z`: Z-coordinates of the generated 3D points.
115107
- `A`: Cross-sectional areas at each point.
116-
- `w`: Flow velocities at each point.
117-
- `P`: Pressure values at each point.
108+
- `wtheta`: Flow angular velocity at each point.
109+
- `ws`: Flow axial velocity at each point.
118110
119-
### Notes
120-
- The function first extracts unique spatial positions from the mesh.
121-
- The blood flow variables (`A`, `Q`, `E`, `A0`) are obtained from the solution array.
122-
- Pressure is computed using the `pressure` function.
123-
- A cylindrical coordinate transformation is applied to represent the vessel cross-section.
124-
- If `vtk` is `true`, the function writes the data to VTK format using `vtk_grid`.
125111
"""
126112
function get3DData(eq::BloodFlowEquations2D,curve::F1,tanj::F2,nor::F3,semi,sol,time_index ::Int = 1;vtk ::Bool=false,out ::T="./datas") where {T<:AbstractString,F1<:Function,F2<:Function,F3<:Function}
127-
thetaval = semi.cache.elements.node_coordinates[1,:,:,:]
128-
sval = semi.cache.elements.node_coordinates[2,:,:,:]
129-
# Get unique values
130-
soltime = sol[time_index]
131-
aval =@view(soltime[1:5:end])
132-
Qthval =@view(soltime[2:5:end])
133-
Qsval =@view(soltime[3:5:end])
134-
Eval =@view(soltime[4:5:end])
135-
A0val = @view(soltime[5:5:end])
136-
Pval = map((a,Qth,Qs,E,A0)->BloodFlowTrixi.pressure(SA[a,Qth,Qs,E,A0],eq),aval,Qthval,Qsval,Eval,A0val)
137113
(v,w) = SA[v[2]*w[3]-v[3]*w[2],v[3]*w[1]-v[1]*w[3],v[1]*w[2]-v[2]*w[1]]
138114
er(theta,s) = cos(theta).*nor(s) .+ sin(theta).*∧(tanj(s),nor(s))
139-
M(theta,s,R) = curve(s) .+ R.*er(theta,s)
140-
Typ = eltype(sval)
141-
s = length(thetaval)
142-
x = zeros(Typ,s)
143-
y = zeros(Typ,s)
144-
z = zeros(Typ,s)
145-
A = zeros(Typ,s)
146-
wtheta = zeros(Typ,s)
147-
ws = zeros(Typ,s)
148-
P = zeros(Typ,s)
149-
c=1
150-
for i in eachindex(thetaval,sval,aval,Qthval,Qsval,A0val,Pval)
151-
thvali = thetaval[i]
152-
svali = sval[i]
153-
Avali = aval[i] + A0val[i]
154-
Rvali = sqrt(2*Avali)
155-
wthetavali = Typ(4/3*(Qthval[i]/Rvali)/Avali) # wθ = (4 / 3 * QRθ / R) / A
156-
wsvali = Qsval[i]/Avali
157-
Pvali = Pval[i]
158-
# for thetaj in theta
159-
xi,yi,zi = M(thvali,svali,Rvali)
160-
x[c] = xi
161-
y[c] = yi
162-
z[c] = zi
163-
A[c] = Avali
164-
wtheta[c] = wthetavali
165-
ws[c] = wsvali
166-
P[c] = Pvali
167-
c+=1
168-
# end
169-
end
170-
if vtk
171-
npoints = length(x)
172-
cells = [MeshCell(VTKCellTypes.VTK_VERTEX, (i, )) for i = 1:npoints]
173-
vtk_grid(joinpath(out,"./points$time_index"), x, y, z, cells) do vtk
174-
vtk["Area", VTKPointData()] = A
175-
vtk["Angular_Speed", VTKPointData()] = wtheta
176-
vtk["Axial", VTKPointData()] = ws
177-
vtk["Pressure", VTKPointData()] = P
178-
end
179-
end
180-
return (;x=x,y=y,z=z,A=A,wtheta=wtheta,ws=ws)
115+
return get3DData(eq,curve,er,semi,sol,time_index;vtk=vtk,out=out)
116+
end
117+
118+
@doc raw"""
119+
get3DData(eq::BloodFlowEquations2D,semi,sol,time_index ::Int = 1;vtk ::Bool=false,out ::T="./datas") where {T<:AbstractString,F1<:Function,F2<:Function,F3<:Function}
120+
121+
Generates 3D spatial data from a 2D blood flow model for visualization. This will use a straight vessel.
122+
This function extracts unique node coordinates, computes relevant flow parameters,
123+
and generates a 3D representation of the arterial domain using cylindrical coordinates.
124+
Optionally, it can export the data in VTK format.
125+
126+
### Parameters
127+
- `eq::BloodFlowEquations1D`: Instance of `BloodFlowEquations1D` representing the blood flow model.
128+
- `semi`: Semi-discretization structure containing mesh and numerical information.
129+
- `sol`: Solution array containing the numerical state variables.
130+
- `time_index::Int=1`: Time step index for extracting the solution (default: 1).
131+
- `vtk::Bool=false`: Whether to export data to VTK format (default: `false`).
132+
- `out::T="./datas"`: Output directory for VTK files (default: `"./datas"`).
133+
134+
### Returns
135+
Named tuple containing:
136+
- `x`: X-coordinates of the generated 3D points.
137+
- `y`: Y-coordinates of the generated 3D points.
138+
- `z`: Z-coordinates of the generated 3D points.
139+
- `A`: Cross-sectional areas at each point.
140+
- `wtheta`: Flow angular velocity at each point.
141+
- `ws`: Flow axial velocity at each point.
142+
143+
"""
144+
function get3DData(eq::BloodFlowEquations2D,semi,sol,time_index ::Int = 1;vtk ::Bool=false,out ::T="./datas") where {T<:AbstractString,F1<:Function,F2<:Function,F3<:Function}
145+
curve(s) = [s,0.0,0.0]
146+
tanj(s) = [1.0,0.0,0.0]
147+
nor(s) = [0.0,1.0,0.0]
148+
(v,w) = SA[v[2]*w[3]-v[3]*w[2],v[3]*w[1]-v[1]*w[3],v[1]*w[2]-v[2]*w[1]]
149+
er(theta,s) = cos(theta).*nor(s) .+ sin(theta).*∧(tanj(s),nor(s))
150+
return get3DData(eq,curve,er,semi,sol,time_index;vtk=vtk,out=out)
181151
end

0 commit comments

Comments
 (0)