Upload
hans-mhelvin-cabrera
View
46
Download
0
Embed Size (px)
Citation preview
24-718 Computational Fluid Dynamics MAY 11, 2012 Final Report / Page 1 of 25
Hans Mhelvin D. Cabrera
e-mail: [email protected]
Biomedical Engineering Department
Carnegie Mellon University
Pittsburgh, PA 15213
Blood Flow in the Aorta
at an Anastomosis with
Left Ventricular Assist
Device Outflow: My Two-
Dimensional Navier-Stokes
Solver vs. Published Results
Left ventricular assist devices (LVADs) are an option available for
people with heart muscle that can no longer support proper blood
circulation. The LVAD takes blood from the heart and injects it into an
anastomosis to the aorta. The hemodynamic environment created may
lead to serious medical complications, such as stagnant flow that can
lead to clot formation, which puts the patient at risk of subsequent
thromboembolism and stroke. Computational fluid dynamics (CFD) has
proved to be a valuable tool to assess the possible flow conditions that
would be created given a particular configuration of the LVAD outflow
graft to the aorta. I have developed a two-dimensional Navier-Stokes
solver based on the finite differencing with the Chorin projection
method to investigate blood flow at the anastomosis site, varying the
angle of entry for the LVAD cannula. Results have been demonstrated
to be qualitatively comparable with other LVAD anastomosis studies as
well as other CFD research perform on blood vessels.
Keywords: blood flow, aorta, anastomosis, left ventricular assist device,
Navier-Stokes, computational fluid dynamics
1 Introduction
For a patient with advanced heart failure, a left ventricular assist device (LVAD) can provide mechanical circulatory
support to augment or completely substitute for the pumping function of the weakened heart. The LVAD draws the
blood from the base of the left ventricle through an outflow cannula, and then delivers it into the aorta via a surgical
connection referred to as an anastomosis (See Fig. 1).
24-718 Computational Fluid Dynamics MAY 11, 2012 Final Report / Page 2 of 25
Fig. 1 Schematic of a LVAD anastomosis [Yang et al, 2009]
Although the LVAD anastomosis is effective in restoring sufficient blood flow for the body, it can also introduce
unnatural hemodynamic conditions in the aorta that then result in significant clinical dangers. Stagnant flow has
been associated with the formation of clots, which can obstruct the flow of blood and deprive downstream tissues of
oxygen [Folie et al, 1989]. Surgeons dealing with ventricular assist devices are concerned about the possibility of
those clots detaching from the blood vessel and travelling to smaller diameter arteries, such as those in the brain
(leading to stroke) or in the heart (leading to a heart attack) [Gross et al, 1999]. This relocation, known as
thromboembolism, becomes more likely in the presence of high wall shear stress [Folie et al, 1989]. On the
contrary, low shear stresses have been linked to atherosclerosis [Ku et al, 1985].
Computational fluid dynamics (CFD) simulations have been performed for a variety of flow scenarios in the
cardiovascular system to predict characteristics such as velocity, shear stress, and pressure. A subset of these studies
focuses on branched flow in blood vessels, where the branch can be another blood vessel, or a graft made of one or
more artificial materials [Perktold et al, 2002]. The largest of the arteries, the aorta, has been investigated with CFD
methods both in isolation [Liu et al, 2009] and in cases where there is a foreign source contributing flow to its
lumen, such as a cannula used in cardiopulmonary bypass [Pekkan et al, 2008]. Of the latter type of study, it is
possible to identify research that looks specifically at the hemodynamics around the site of anastomosis with an
LVAD outflow.
A common topic of these particular studies is to look at the effects of changing the position of the LVAD graft as it
is anastomosed onto the aorta. Kar et al performed a two-dimensional CFD study of aortic flow when comparing
LVAD outflow anastomosis to the descending aorta versus the ascending aorta, identifying regions of stagnant flow
[Kar et al, 2005]. May-Newman et al was interested in how flow in the aorta would be affected by changing the
angle of entry for the LVAD outflow graft [May-Newman et al, 2004]. These two works constitute the inspiration
and foundation for my individual study. Using a two-dimensional Navier-Stokes solver that I developed, I obtained
velocity, pressure, and shear stress results that were qualitatively compared to published results from groups
researching the same or similar problems.
24-718 Computational Fluid Dynamics MAY 11, 2012 Final Report / Page 3 of 25
2 My Two-Dimensional Navier-Stokes Solver
The 2D section of the aorta around the site of anastomosis with the LVAD graft is idealized as a rectangular domain
with rigid walls for both the LVAD cannula and the aorta. To facilitate comparison with published results, the
dimensions selected matched those in the work done by May-Newman et al, in which they used a rectangle that is 30
mm tall and 25 cm long, with a gap that is approximately 15 mm wide at the top wall, centered close to 10 cm from
the left end. The opening is where blood flow comes in from the anastomosed LVAD cannula. Furthermore, this
blood flow comes at a variable angle of entry θ, with the following values considered for this study: 30°, 45°, 60°,
and 90° [May-Newman et al, 2004]. Lastly, the rigid wall simplification ignores the compliance of the aorta, and
can result in higher shear stress results than are present in actuality, but it is a reasonable assumption for studies like
this which are qualitative and serve as a foundation for subsequent research.
The fluid of interest for this CFD study is blood, which is modeled as Newtonian, since in large arteries, shear rates
are sufficiently low such that viscosity can be deemed constant [Fung, 2005]. For simplicity, the fluid is also
considered isothermal and incompressible. A further simplification is made by assuming that blood flow is laminar,
and therefore, a Reynolds number of 1000 was used. As in the study performed by May-Newman et al, constant
velocities were prescribed at both inlets: 0.0589 m/s for the inflow directly from the heart, and 0.7368 m/s from the
LVAD pump. The former represents 2.5 l/min of blood flow from the aortic valve, while the latter represents 5
l/min from the LVAD outflow cannula, for a total of 7.5 l/min, a value that is in the upper part of the range of
normal cardiac outputs [Shahcheraghi et al, 2002; May-Newman et al, 2004]. This was chosen because it was
important to study the best-case scenario where the LVAD is providing a relatively high volumetric rate along with
some contribution from the heart; if there are any issues with the hemodynamics of this scenario, then it is very
likely that a change in design or surgical procedure is required. For clarity, it must be pointed out that the LVAD
outflow serves as an inflow to the fluid problem, since we are considering the aorta as the flow domain. Finally, the
no-slip condition was applied to all the walls of the tubes, also matching the conditions from the study by May-
Newman et al [May-Newman et al, 2004]. A summary diagram of the boundary conditions that were imposed in the
model is shown in Fig. 2.
Fig. 2 Summary of boundary conditions
2.1 Solution Procedure: Chorin Projection Method The objective of the study is to obtain values for velocities u
and v in the x- and y-directions, respectively, pressure p, and shear stress τyx across the flow domain. Towards this
end, the 2D, isothermal, incompressible Navier-Stokes equations are set up as follows (See Fig. 3):
(
)
( )
( )
( )
(
)
( )
( )
( )
( )
24-718 Computational Fluid Dynamics MAY 11, 2012 Final Report / Page 4 of 25
Fig. 3 The Navier-Stokes equations to be addressed by the solver. In order, the conservation of x-momentum,
conservation of y-momentum, and the continuity equations are listed.
My CFD solver is based on a finite difference scheme using the Chorin projection method, which marches in time
[Chorin, 1968]. In each iteration, the algorithm does the following: predicts the velocities un and v
n at the current
time step n, uses this velocity field to solve for the pressure pn+1
at the progressive time step n+1, and then uses this
pressure field as a correction to solve for the velocities un+1
and vn+1
at the progressive time step n+1. To avoid
oscillation of the pressure solution, a staggered grid is used, where the pressure is defined at the center of the cell,
the x-velocity u is defined at the midpoint of the eastern border of the cell, and the y-velocity v is defined at the
midpoint of the northern border of the cell. The numbering of the cells is selected to begin at 1, to facilitate
implementation of the solver into software, wherein matrix indices must begin at 1, not 0. Discretization of the
partial derivatives is based on formulae from Hirt et al, using a discretization mixture parameter of 0.9 to avoid
stability issues [Hirt et al, 1975]. The pressure is obtained by solving a Poisson (elliptical) equation using the Gauss-
Seidel with successive over-relaxation method that iterates with a relaxation factor of 1.7 and has a convergence
criterion where either the residuals are less than a tolerance of 0.001 or a maximum number of 100 iterations is
reached. A time step stabilization scheme is employed with a safety factor of 0.5, until the end time of 0.2 seconds
is reached. There were no body force terms included for either the x or y direction. The resultant velocities for a
regular grid were calculated using bilinear interpolation. My MATLAB script for the solver may be found in the
appendix.
2.2 Grid Convergence Study No qualitative difference in the velocity and shear stress results was detected when
doubling the number of grid points (from 43x13 to 86x26) in both the x and y directions (See Fig. 4). There was
however, a noticeable qualitative difference in pressure magnitude results between the coarse and fine meshes, with
the latter displaying a large hotspot with relatively high magnitude. The pressure for a given single cell of the coarse
mesh does not properly capture the pressures in its corresponding four cells in the fine mesh. Based on this finding,
it has been decided that only the pressure results from the finer mesh will be used for comparison with the published
results.
(a) coarse mesh results (b) fine mesh results
Fig. 4 Comparison of velocity vector, velocity magnitude, pressure magnitude and shear stress results
between a coarse mesh and a finer mesh.
3 Shear Stress Calculation
The shear stress in the direction of the length of the aorta on the face normal to its wall was calculated using
Stokes’ constitutive relations that rely on the assumption that the blood can be modeled as a Newtonian fluid, where
24-718 Computational Fluid Dynamics MAY 11, 2012 Final Report / Page 5 of 25
a constant dynamic viscosity μ of 0.003 kg/(m sec) was used (See Fig. 5). The derivatives in the calculation were
discretized using a second-order central difference.
(
)
Fig. 5 Stokes constitutive relation for shear stress used in this study
4 Simulation Parameters
The model was implemented in the MATLAB® programming environment. A simulation of 0.2 seconds using the
fine mesh lasted 2 h 45 min using an HP Pavilion dv7 Notebook PC with Intel® Core™ i5-2410M CPU @ 2.30
GHz with 6.00 GB RAM.
5 Results and Discussion
5.1 My Velocity Results vs. Published Results My velocity results (vector and magnitude plots) for all four
simulated angles of entry were qualitatively comparable with the study on LVAD insertion angle performed by
May-Newman et al [May-Newman et al, 2004]. In their 3D study, flow recirculation was most prominent at 90°,
decreasing as the angle of entry decreased. This trend was captured in my 2D study, where it was demonstrated that
the region of recirculating flow (shown as a light blue tail pointing to the left, back to the heart) kept getting larger
as one increased the angle of entry from 30° to 90° (See Figs. 6 and 7).
It must be noted that the results that they presented are for a prescribed velocity of 0 m/s directly from the heart and
0.7368 m/s from the LVAD. In contrast, I used a prescribed velocity of 0.0589 m/s directly from the heart (with the
same prescribed velocity that they used for the LVAD). Nevertheless, this difference between the two studies does
not compromise attempts at qualitative comparison, since it is evident from the velocity magnitude images at all four
angle studies that my prescribed velocity directly from the heart (marked in dark blue at the left wall) made a
negligible contribution to the overall velocity field anyway; the LVAD velocity is the dominant factor for
consideration.
24-718 Computational Fluid Dynamics MAY 11, 2012 Final Report / Page 6 of 25
Fig. 6 Comparison of published velocity vector field from May-Newman et al (top rows) with my velocity
vector arrow (middle rows) and magnitude (bottom rows) plots, across the four different angles of entry.
Fig. 7 A refinement of the mesh (doubling the nodes in both the x and y direction) for the velocity results at a
90° LVAD graft angle of entry for enhanced visualization.
5.2 My Shear Stress Results vs. Published Results Fig. 8 shows that my results for shear stress are qualitatively
comparable with the shear stress results from a study on coronary artery bypass graft (CABG) anastomosis
[Sankaranarayanan et al, 2005]. In their study, instead of an LVAD graft anastomosed onto the aorta, a bypass graft
is anastomosed to a coronary artery. They compared an in-plane surgical configuration with an out-of-plane
configuration, which is similar to the comparison made in our study between a 45° and 90° angle of entry. The
shear stress results for both studies are comparable because they both demonstrate an increase in maximum shear
stress when the graft inlet direction is more perpendicular to the main flow domain (i.e., the coronary artery in their
study and the aorta in our study).
One way that the two studies differ is in the relative size of the branch compared to the main stream. In our study,
the LVAD branch is a smaller diameter than the aortic flow domain, whereas in their study, the bypass branch is a
larger diameter than the coronary arterial flow domain. This meant that the outlet of their branch was partially
pinched, resulting in an elliptical shear stress region, whereas our branch outlet is more circular.
24-718 Computational Fluid Dynamics MAY 11, 2012 Final Report / Page 7 of 25
Another difference between the two studies is that in their study, the overall high shear stress distribution region
shrunk when they used the out-of-plane configuration. This was why the group ended up recommending the out-of-
plane configuration to surgeons, despite the higher maximum shear stress associated with it. Unlike theirs, our study
did not reveal a significant difference in shear stress region size when going from 45° to 90°. It is postulated that
their 3D CFD simulation is able to capture phenomena related to the concave geometry of the vessel wall that our
2D study is not.
Fig. 8 Comparison between the shear stress results of 45° LVAD entry (top left) with the in-plane CABG
anastomosis (bottom left) and between the 90° LVAD entry (top right) with the out-of-plane CABG
anastomosis (bottom right).
4.3 My Pressure Results vs. Published Results Fig. 9 demonstrates that my pressure results are qualitatively
comparable to pressure results from a study performed by Marsden et al on their new design of a Y-shaped Fontan
graft [Marsden et al, 2009]. For comparison with the Fontan graft, we look at one of the branches from a bifurcation
of the inferior vena cava before it connects to the pulmonary artery. The blood (travelling upwards) from the
inferior vena cava branch to the horizontal pulmonary artery represents a branched flow scenario similar to an
LVAD graft anastomosed at a 45° angle to the aorta, which was investigated in our CFD study (see velocity
distribution in top of figure). In the case of the inferior vena cavae anastomosed to the pulmonary artery, the
pressure distribution has a hot-spot concentrated around the wall directly opposite the side of flow entry. This result
is analogous to what was observed in the case of the LVAD graft anastomosed to the aorta; the hot-spot was also
focused at the wall across from the hole to where the LVAD was connected. In both cases, the maximum pressure
magnitude is due to incoming flow that makes contact with the opposing wall.
24-718 Computational Fluid Dynamics MAY 11, 2012 Final Report / Page 8 of 25
Fig. 9 (Top half): Comparison between the velocity magnitude plots of the inferior cavae anastomosed to the
pulmonary artery versus the LVAD anastomosed to the aorta at an angle of 45°. (Bottom half): Comparison
between the pressure magnitude plots of the inferior cavae anastomosed to the pulmonary artery versus the
LVAD anastomosed to the aorta at an angle of 45°. To properly make comparisons, consider that the two
visualizations are mirror images across the horizontal and vertical axes. Arrows have been placed to
facilitate comparison: the white arrow represents a horizontal inlet, the red arrow represents a branched,
angled inlet, and the blue arrow represents an outlet.
24-718 Computational Fluid Dynamics MAY 11, 2012 Final Report / Page 9 of 25
5 Conclusion
My velocity results for varying the angle of entry for the LVAD outflow graft as it inserts into the aorta have been
demonstrated to be qualitatively comparable to a similar study performed by May-Newman et al. Likewise, my
pressure results have been shown to be comparable to a study by Marsden et al performed on a Fontan graft, where
the anastomosis is between the inferior vena cava and the pulmonary artery. Finally, reasonable comparisons were
drawn between my shear stress results and those presented in a study by Sankaranarayanan et al on the anastomosis
involved in a coronary artery bypass graft. My 2D Navier-Stokes solver holds the promise of being useful not only
for further studies of the LVAD anastomosis with the aorta, but of potentially a variety of branched vessel
applications, similar to those used in comparison in this study [Bara et al, 2008; El Zahab et al, 2010; Dur et al,
2011; Ku et al, 2002, Lei et al, 2010; Hofer et al, 1996].
References
1. Bara, Christoph L, and Janko F Verhey. “Simulation of the Fluid Dynamics in Artificial Aortic Roots:
Comparison of Two Different Types of Prostheses.” Journal of Artificial Organs: The Official Journal of
the Japanese Society for Artificial Organs 11, no. 3 (2008): 123–129.
2. Chorin, A. “Numerical Solution of the Navier-Stokes Equations.” Mathematics of Computation 22 (1968):
745–762.
3. Dur, Onur, Sinan Coskun, Kasim Coskun, David Frakes, Levent Kara, and Kerem Pekkan. “Computer-
Aided Patient-Specific Coronary Artery Graft Design Improvements Using CFD Coupled Shape
Optimizer.” Cardiovascular Engineering and Technology 2, no. 1 (2011): 35–47.
4. El Zahab, Zaher, Eduardo Divo, and Alain Kassab. “Minimisation of the Wall Shear Stress Gradients in
Bypass Grafts Anastomoses Using Meshless CFD and Genetic Algorithms Optimisation.” Computer
Methods in Biomechanics and Biomedical Engineering 13, no. 1 (February 2010): 35–47.
5. Folie, B J, and L V McIntire. “Mathematical Analysis of Mural Thrombogenesis. Concentration Profiles of
Platelet-activating Agents and Effects of Viscous Shear Flow.” Biophysical Journal 56, no. 6 (December
1989): 1121–1141.
6. Fung, Y. C. Biomechanics. 2nd ed. Springer, 1996.
7. Gross, D R. “Concerning Thromboembolism Associated with Left Ventricular Assist Devices.”
Cardiovascular Research 42, no. 1 (April 1999): 45–47.
8. Hirt, C. W., B. D. Nichols, and N. C. Romero. “SOLA: A Numerical Solution Algorithm for Transient
Fluid Flows.” NASA STI/Recon Technical Report N 75 (January 1975): 32418.
9. Hofer, M, G Rappitsch, K Perktold, W Trubel, and H Schima. “Numerical Study of Wall Mechanics and
Fluid Dynamics in End-to-side Anastomoses and Correlation to Intimal Hyperplasia.” Journal of
Biomechanics 29, no. 10 (October 1996): 1297–1308.
10. Kar, Biswajit, Reynolds M. Delgado, O. H. Frazier, Igor D. Gregoric, Matthew T. Harting, Yasmin Wadia,
Timothy J. Myers, Robert D. Moser, and Jonathan Freund. “The Effect of LVAD Aortic Outflow-Graft
Placement on Hemodynamics and Flow.” Texas Heart Institute Journal 32, no. 3 (2005): 294–298.
11. Ku, D. N., D. P. Giddens, C. K. Zarins, and S. Glagov. “Pulsatile Flow and Atherosclerosis in the Human
Carotid Bifurcation. Positive Correlation Between Plaque Location and Low Oscillating Shear Stress.”
Arteriosclerosis, Thrombosis, and Vascular Biology 5, no. 3 (May 1, 1985): 293–302.
12. Ku, Joy P, Mary T Draney, Frank R Arko, W Anthony Lee, Frandics P Chan, Norbert J Pelc, Christopher K
Zarins, and Charles A Taylor. “In Vivo Validation of Numerical Prediction of Blood Flow in Arterial
Bypass Grafts.” Annals of Biomedical Engineering 30, no. 6 (June 2002): 743–752.
24-718 Computational Fluid Dynamics MAY 11, 2012 Final Report / Page 10 of 25
13. Lei, M, D P Giddens, S A Jones, F Loth, and H Bassiouny. “Pulsatile Flow in an End-to-side Vascular
Graft Model: Comparison of Computations with Experimental Data.” Journal of Biomechanical
Engineering 123, no. 1 (February 2001): 80–87.
14. Liu, Xiao, Fang Pu, Yubo Fan, Xiaoyan Deng, Deyu Li, and Shuyu Li. “A Numerical Study on the Flow of
Blood and the Transport of LDL in the Human Aorta: The Physiological Significance of the Helical Flow
in the Aortic Arch.” American Journal of Physiology - Heart and Circulatory Physiology 297, no. 1 (July
1, 2009): H163–H170.
15. Marsden, Alison L., Adam J. Bernstein, V. Mohan Reddy, Shawn C. Shadden, Ryan L. Spilker, Frandics P.
Chan, Charles A. Taylor, and Jeffrey A. Feinstein. “Evaluation of a Novel Y-shaped Extracardiac Fontan
Baffle Using Computational Fluid Dynamics.” The Journal of Thoracic and Cardiovascular Surgery 137,
no. 2 (February 2009): 394–403.e2.
16. May-Newman, K D, B K Hillen, C S Sironda, and W Dembitsky. “Effect of LVAD Outflow Conduit
Insertion Angle on Flow Through the Native Aorta.” Journal of Medical Engineering & Technology 28, no.
3 (June 2004): 105–109.
17. Pekkan, Kerem, Onur Dur, Kartik Sundareswaran, Kirk Kanter, Mark Fogel, Ajit Yoganathan, and Akif
Undar. “Neonatal Aortic Arch Hemodynamics and Perfusion During Cardiopulmonary Bypass.” Journal of
Biomechanical Engineering 130, no. 6 (December 2008): 061012.
18. Perktold, Karl, Armin Leuprecht, Martin Prosi, Thomas Berk, Martin Czerny, Wolfgang Trubel, and
Heinrich Schima. “Fluid Dynamics, Wall Mechanics, and Oxygen Transfer in Peripheral Bypass
Anastomoses.” Annals of Biomedical Engineering 30, no. 4 (April 2002): 447–460.
19. Sankaranarayanan, M., D.N. Ghista, Chua Leok Poh, Liu Li, and Tan Yong Seng. “Influence of Aorto-Left
Coronary Bypass Graft Geometry on Wall Shear Stress Distribution.” In Engineering in Medicine and
Biology Society, 2005. IEEE-EMBS 2005. 27th Annual International Conference of The, 615 –618, 2005.
20. Shahcheraghi, N., H. A. Dwyer, A. Y. Cheer, A. I. Barakat, and T. Rutaganira. “Unsteady and Three-
Dimensional Simulation of Blood Flow in the Human Aortic Arch.” Journal of Biomechanical Engineering
124, no. 4 (2002): 378–387.
21. Yang, Ning, Steven Deutsch, Eric G Paterson, and Keefe B Manning. “Numerical Study of Blood Flow at
the End-to-side Anastomosis of a Left Ventricular Assist Device for Adult Patients.” Journal of
Biomechanical Engineering 131, no. 11 (November 2009): 111005.
Appendix
Matlab Script for My 2-D N-S Solver
%+24-718 CFD Final Project %Blood flow in Aorta at Anastomosis with LVAD Outflow %My 2-D N-S Solver %Overall plan: To march in (n+1) time steps %Code-friendly numbering used (i.e. i starts at 1, j starts at 1)
%Clear everything clear all close all clc
%Read Parameters t_end = 0.2; %in seconds i_max = 43; j_max = 13;
24-718 Computational Fluid Dynamics MAY 11, 2012 Final Report / Page 11 of 25
Xlength = 0.25; %x-length of domain (not counting boundary strip), in meters Ylength = 0.03; %y-length of domain (not counting boundary strip), in meters delta_x = Xlength/(i_max-1); %in meters delta_y = Ylength/(j_max-1); %in meters delta_t = 0.02; %for 1st time step, in seconds v_aorta = 0.0589; %aortic velocity, in meters/second v_LVAD = 0.7368; %LVAD pump velocity, in meters/second LVAD_angle = 90*pi/180; %lvad outflow graft angle of entry, in radians tau = 0.5; %safety factor for modifying time step (use after 1st time step) u_lid = 1; %normalized velocity of lid (for lid driven cavity problems) TOL = 0.001; %SOR tolerance eps = TOL; %same as TOL omega = 1.7; %SOR relaxation lambda = 0.9; %discretization mixture parameter in Hirt et al. 1975 iter_max = 100; %SOR max iterations, if TOL is not reached g_x = 0; %body force in x g_y = 0; %body force in y Re = 1000; %Reynolds # n_offset = 1; %need this because matrix indices start at 1, not 0
%Set t (time value) = 0, n (time index) = 0 t = 0; n = 0 + n_offset;
%Assign initial values to u,v,p UI = 0; %initial value for u VI = 0; %initial value for v PI = 0; %initial value for p
%Initialize u matrix (n = 0) u = zeros(i_max,j_max+1,1); for i = 1:i_max for j = 1:j_max+1 u(i,j,0+n_offset) = UI; end end
%Initialize v matrix (n = 0) v = zeros(i_max+1,j_max,1); for i = 1:i_max+1 for j = 1:j_max v(i,j,0+n_offset) = VI; end end
%Initialize p matrix (n = 0) p = zeros(i_max+1,j_max+1,1); for i = 1:i_max+1 for j = 1:j_max+1 p(i,j,0+n_offset) = PI; end end
%Define domain: solid (obstacle) = 0 vs. fluid = 1 % domain = zeros(i_max+1,j_max+1);
24-718 Computational Fluid Dynamics MAY 11, 2012 Final Report / Page 12 of 25
% for i = 2:i_max % for j = 2:j_max % if i == j % if i == 2 % domain(i,j) = 1; % elseif i == 3 % domain(i,j) = 1; % domain(i,j-1) = 1; % else % domain(i,j) = 1; % domain(i,j-1) = 1; % domain(i,j-2) = 1; % end % end % end % end
%Algorithm to calculate u,v at n+1 while t < t_end
%Step 1: Compute F(n), G(n) %according to (3.36-3.37) and (3.42, at the boundaries) %from the velocities at u(n), v(n)
% Set Boundary Conditions for u,v
%Set boundary values for u and v, assuming walls are stationary
%>>vertical walls for j = 2:j_max
%inflow on left wall u(1,j,n) = v_aorta; v(1,j,n) = 0;
%outflow on right wall u(i_max,j,n) = u(i_max-1,j,n); v(i_max+1,j,n) = v(i_max,j,n);
end
%>>horizontal walls for i = 2:i_max
hole_left_edge = floor((13/33)*i_max); hole_right_edge = floor((15/33)*i_max); %inflow hole and no slip on top wall if i >= 2 && i < hole_left_edge %no-slip u(i,j_max+1,n) = -u(i,j_max,n); v(i,j_max,n) = 0; elseif i >=hole_left_edge && i < hole_right_edge %inflow hole u(i,j_max+1,n) = v_LVAD*cos(LVAD_angle); v(i,j_max,n) = -v_LVAD*sin(LVAD_angle);
24-718 Computational Fluid Dynamics MAY 11, 2012 Final Report / Page 13 of 25
elseif i >=15 && i <= i_max %no-slip u(i,j_max+1,n) = -u(i,j_max,n); v(i,j_max,n) = 0; end
%no-slip on bottom wall u(i,1,n) = -u(i,2,n); %"averaged" v(i,1,n) = 0;
end
%define specific domain conditions
% Compute F,G
F = zeros(i_max,j_max+1); G = zeros(i_max+1,j_max);
%F & G boundary values
for j = 2:j_max F(1,j) = u(1,j,n); F(i_max,j) = u(i_max,j,n); end
for i = 2:i_max G(i,1) = v(i,1,n); G(i,j_max) = v(i,j_max,n); end % % [u,v,F,G] = BoundaryCellValues2(i,j,u,v,F,G,domain,i_max,j_max);
%Compute F(n)
d2u_dx2 = zeros(i_max,j_max+1); d2u_dy2 = zeros(i_max,j_max+1); du2_dx = zeros(i_max,j_max+1); duv_dy = zeros(i_max,j_max+1);
for i = 2:i_max-1 for j = 2:j_max
d2u_dx2(i,j) = (... u(i+1,j,n) ... - 2*u(i,j,n) ... + u(i-1,j,n) ... )... /(delta_x^2);
d2u_dy2(i,j) = (... u(i,j+1,n) ... - 2*u(i,j,n) ... + u(i,j-1,n)...
24-718 Computational Fluid Dynamics MAY 11, 2012 Final Report / Page 14 of 25
)... /(delta_y^2);
du2_dx(i,j) = (1/delta_x)*(... (((u(i,j,n) + u(i+1,j,n))/2)^2) ... - (((u(i-1,j,n) + u(i,j,n))/2)^2) ... ) ... + (lambda/delta_x)*(... ((abs(u(i,j,n) + u(i+1,j,n)))/2)... *((u(i,j,n) - u(i+1,j,n))/2) ... - ((abs(u(i-1,j,n) + u(i,j,n)))/2)... *((u(i-1,j,n) - u(i,j,n))/2) ... );
duv_dy(i,j) = (1/delta_y)*(... ((v(i,j,n) + v(i+1,j,n))/2)... *(((u(i,j,n) + u(i,j+1,n))/2)) ... - (((v(i,j-1,n) + v(i+1,j-1,n))/2))... *((u(i,j-1,n) + u(i,j,n))/2) ... ) ... + (lambda/delta_y)*(... ((abs(v(i,j,n) + v(i+1,j,n)))/2)... *((u(i,j,n) - u(i,j+1,n))/2) ... - ((abs(v(i,j-1,n) + v(i+1,j-1,n)))/2)... *((u(i,j-1,n) - u(i,j,n))/2) ... );
F(i,j) = u(i,j,n) ... + delta_t*(... (1/Re)*(d2u_dx2(i,j) + d2u_dy2(i,j)) ... - (du2_dx(i,j)) ... - (duv_dy(i,j)) ... + g_x ... ); end end
%Compute G(n)
d2v_dx2 = zeros(i_max+1,j_max); d2v_dy2 = zeros(i_max+1,j_max); duv_dx = zeros(i_max+1,j_max); dv2_dy = zeros(i_max+1,j_max);
for i = 2:i_max for j = 2:j_max-1
d2v_dx2(i,j) = (... v(i+1,j,n) ... - 2*v(i,j,n) ... + v(i-1,j,n)... )... /(delta_x^2);
24-718 Computational Fluid Dynamics MAY 11, 2012 Final Report / Page 15 of 25
d2v_dy2(i,j) = (... v(i,j+1,n) ... - 2*v(i,j,n) ... + v(i,j-1,n)... )... /(delta_y^2);
duv_dx(i,j) = (1/delta_x)*(... ((u(i,j,n) + u(i,j+1,n))/2)... *(((v(i,j,n) + v(i+1,j,n))/2)) ... - (((u(i-1,j,n) + u(i-1,j+1,n))/2))... *((v(i-1,j,n) + v(i,j,n))/2) ... ) ... + (lambda/delta_x)*(... ((abs(u(i,j,n) + u(i,j+1,n)))/2)... *((v(i,j,n) - v(i+1,j,n))/2) ... - ((abs(u(i-1,j,n) + u(i-1,j+1,n)))/2)... *((v(i-1,j,n) - v(i,j,n))/2) ... );
dv2_dy(i,j) = (1/delta_y)*(... (((v(i,j,n) + v(i,j+1,n))/2)^2) ... - (((v(i,j-1,n) + v(i,j,n))/2)^2) ... ) ... + (lambda/delta_y)*(... ((abs(v(i,j,n) + v(i,j+1,n)))/2)... *((v(i,j,n) - v(i,j+1,n))/2) ... - ((abs(v(i,j-1,n) + v(i,j,n)))/2)... *((v(i,j-1,n) - v(i,j,n))/2) ... );
G(i,j) = v(i,j,n) ... + delta_t*(... (1/Re)*(d2v_dx2(i,j) + d2v_dy2(i,j)) ... - (duv_dx(i,j)) ... - (dv2_dy(i,j)) ... + g_y ... ); end end
%Step 2: Solve the Poisson ("pressure") equation (3.32) %for the pressure p(n+1). This is an elliptic equation.
%>>Used my own Gauss-Seidel SOR (edited solver from HW 5, Problem 1)
%Poisson Step 1: Mesh set up N = iter_max; %max # of iterations, it_max TOL = eps; %tolerance
%Initialize [A],{g},{w},[u]
num_int_pts = (i_max-1)*(j_max-1); %number of internal points
24-718 Computational Fluid Dynamics MAY 11, 2012 Final Report / Page 16 of 25
A = zeros(num_int_pts,num_int_pts); g = zeros(num_int_pts,1); w = zeros(num_int_pts,1); p(:,:,n+1) = zeros(i_max+1,j_max+1);
%Incorporate BCs
%Pressure Field BC's for j = 2:j_max p(1,j,n+1) = p(2,j,n+1); %left wall p(i_max+1,j,n+1) = p(i_max,j,n+1); %right wall end
for i = 2:i_max p(i,1,n+1) = p(i,2,n); %bottom wall p(i,j_max+1,n+1) = p(i,j_max,n+1); %top wall end
% %Poisson Step 2: For i = 1,...,(n-1) -> x(i) = a+i*delta_x % x = zeros(1,n-1); % for i = 1:n-1 % x(i) = a+i*delta_x; %x values for internal nodes % end % % %Solver Step 3: For j = 1,...,(m-1) -> y(i) = c+i*delta_y % y = zeros(1,m-1); % for j = 1:m-1 % y(j) = c+j*delta_y; %y values for internal nodes % end
%Poisson Step 4: For i = 1,...,(n-1), For j = 1,...,(m-1), w(i,j) = 0; %(Commented out because w(i,j) is already initialized as w(l) in InitMod) % w = zeros(n-1,m-1); % for i = 1:n-1 % for j = 1:m-1 % w(i,j) = 0; % end % end
%Poisson Step 5: Set q = (delta_x/delta_y)^2 & mu = 2*(1+q) (from Diff.
Eq. (4B))
q = (delta_x/delta_y)^2; mu = 2*(q+1);
%Poisson Step 6: Assemble [A] & {g} (using #5)
%Build [A] and {g} using LHS of difference equation (4B) %LHS = mu*w(i,j)-(w(i+1,j)+w(i-1,j))-q*(w(i,j+1)+w(i,j-1))
for j = j_max-1:-1:1
for i = 1:i_max-1
24-718 Computational Fluid Dynamics MAY 11, 2012 Final Report / Page 17 of 25
point_num = (i) +(j_max-1-(j)) *(i_max-1); %Point number
%initialize LHS, a 4x5 matrix describing the 5 w terms on the %the left hand side of the difference equation (4B) LHS = zeros(4,5);
%Row 1: The coefficient of each of the 5 w terms on the LHS % of the difference equation (4B), from left to right LHS(1,1) = mu; LHS(1,2) = -1; LHS(1,3) = -1; LHS(1,4) = -q; LHS(1,5) = -q;
%Row 2: The i index of each of the 5 w terms on the LHS % of the difference equation (4B), from left to right LHS(2,1) = i; LHS(2,2) = i+1; LHS(2,3) = i-1; LHS(2,4) = i; LHS(2,5) = i;
%Row 3: The j index of each of the 5 w terms on the LHS % of the difference equation (4B), from left to right LHS(3,1) = j; LHS(3,2) = j; LHS(3,3) = j; LHS(3,4) = j+1; LHS(3,5) = j-1;
%Row 4: The l index of each of the 5 w terms on the LHS % of the difference equation (4B), from left to right LHS(4,1) = (i) +(j_max-1-(j)) *(i_max-1); LHS(4,2) = (i+1)+(j_max-1-(j)) *(i_max-1); LHS(4,3) = (i-1)+(j_max-1-(j)) *(i_max-1); LHS(4,4) = (i) +(j_max-1-(j+1))*(i_max-1); LHS(4,5) = (i) +(j_max-1-(j-1))*(i_max-1);
%Examine the i and j indices of each of the 5 w terms on the LHS for w_term = 1:5
coeff = LHS(1,w_term); %the coefficient of this w term i_index = LHS(2,w_term); %the i index of this w term j_index = LHS(3,w_term); %the j index of this w term l_index = LHS(4,w_term); %the l index of this w term
%if this w term's indices represent an interior point if i_index >=1 && i_index <= i_max-1 && ... j_index >=1 && j_index <= j_max-1
%the coefficient of this w term should be placed in A A(point_num,l_index) = ... A(point_num,l_index) + coeff;
24-718 Computational Fluid Dynamics MAY 11, 2012 Final Report / Page 18 of 25
%else this w term's indices do not represent an interior
point else
%this is a BC that should be moved to the g vector g(point_num,1) = ... g(point_num,1) + (-coeff)*p(i_index+1,j_index+1,n+1);
end
end
end
end
%Finish building {g} using RHS of difference equation %RHS = -((delta_x)^2)*f(x(i),y(j))
for j = j_max-1:-1:1 for i = 1:i_max-1
l_value = (i) +(j_max-1-(j)) *(i_max-1);
inhomog_term = (1/delta_t)*(... ((F((i+1),(j+1))-F((i+1)-1,(j+1)))/(delta_x)) ... + ((G((i+1),(j+1))-G((i+1),(j+1)-1))/(delta_y)) ... );
g(l_value,1) = g(l_value,1) +... (-(delta_x^2))*(inhomog_term);
end end
%Poisson Step 7: Solve [A]{w} = {g} using Gauss-Seidel method with SOR
%Gauss-Seidel Step 1: Set iteration = 1 iter = 1;
%Gauss-Seidel Step 2: While iteration <= N, do Steps 3-6 w_old = zeros(num_int_pts,1);
while iter <= N
%Gauss-Seidel Step 3: For i = 1,l, apply Gauss-Seidel formula
for i = 1:num_int_pts %l = num_int_pts
A_w = 0; A_w_old = 0;
24-718 Computational Fluid Dynamics MAY 11, 2012 Final Report / Page 19 of 25
for j = 1:i-1 A_w = A_w + A(i,j)*w(j,1); end
for j = i+1:num_int_pts A_w_old = A_w_old + A(i,j)*w_old(j,1); end
w(i,1) = (1-omega)*w_old(i,1)+ ... (omega/A(i,i))*(g(i,1) - A_w - A_w_old);
end
%Gauss-Seidel Step 4: If norm of difference between current and old %numerical solution is less than the prescribed tolerance, %then stop iterating sum_w_wold = 0; for index = 1:size(w,1) sum_w_wold = sum_w_wold + (w(index)-w_old(index))^2; end
norm_w_wold = (sum_w_wold)^0.5;
if norm_w_wold < TOL break %Gauss-Seidel Step 7: stop the while loop and then output
{w} end
%Gauss-Seidel Step 5: Increment the iteration counter iter = iter+1;
%Gauss-Seidel Step 6: For i = 1,...,l set wold = wi for i = 1:num_int_pts w_old(i,1) = w(i,1); end
end
%Fill in internal nodes of u using w
w_row = 1; for u_col = j_max:-1:2 for u_row = 2:i_max % p(u_row,u_col,n+1) = 0; p(u_row,u_col,n+1) = w(w_row,1); w_row = w_row+1; end end
%%%
% p(:,:,n+1) = ... % p_progressive; %pressure at next time step (3D Matrix)
24-718 Computational Fluid Dynamics MAY 11, 2012 Final Report / Page 20 of 25
%Step 3: Compute the new velocity field u(n+1), v(n+1) %using (3.34), (3.35) %with the pressure values p(n+1) from Step 2.
%>>>Compute u for n+1 for i = 2:i_max-1 for j = 2:j_max u(i,j,n+1) = F(i,j) - ... (delta_t/delta_x)*(p(i+1,j,n+1)-p(i,j,n+1)); end end
%>>>Compute v for n+1 for i = 2:i_max for j = 2:j_max-1 v(i,j,n+1) = G(i,j) - ... (delta_t/delta_y)*(p(i,j+1,n+1)-p(i,j,n+1)); end end v_current = v(:,:,n+1);
%Step 3b: Stability condition: adjust the time step delta_t %according to Eq. (3.50)
u_max_pre = max(u(:,:,n+1)); u_max = max(u_max_pre'); v_max_pre = max(v(:,:,n+1)); v_max = max(v_max_pre');
val1 = (Re/2)*(((1/(delta_x^2))+(1/(delta_y^2)))^-1); val2 = delta_x/abs(u_max); val3 = delta_y/abs(v_max);
delta_t = tau*min([val1 val2 val3]) %delta_t = 0.05
t = t + delta_t
n = n + 1 %march
end
%Interpolate u,v for regular grid (from staggered grid)
%x as a function of i for the u nodes x_u = zeros(1,i_max); for i = 1:i_max x_u(i) = (i-1)*delta_x; end
24-718 Computational Fluid Dynamics MAY 11, 2012 Final Report / Page 21 of 25
%y as a function of j for the u nodes y_u = zeros(1,j_max+1); for j = 1:j_max+1 y_u(j) = ((j-1)-(1/2))*delta_y; end
%Calculate u for each x,y that is in the middle of a cell in the domain u_plot = zeros(i_max+1,j_max+1,1); for n_index = 1:n for i_index = 2:i_max for j_index = 2:j_max
%Regular grid coordinate of interest x = x_u(i_index); y = y_u(j_index);
%For a coordinate (x,y) compute the coordinates of the cell
corners %by first determining the appropriate (i,j) of the upper-right
cell %corner, encompassing (x,y) i = ceil(x/delta_x)+1; j = ceil((y+(delta_y/2))/(delta_y))+1;
%coordinates of encompassing cell corners x1 = (i-1)*delta_x; x2 = (i)*delta_x; y1 = ((j-1)-(1/2))*delta_y; y2 = (j-(1/2))*delta_y;
%four staggered x-velocities u1 = u(i-1,j-1,n_index); u2 = u(i,j-1,n_index); u3 = u(i-1,j,n_index); u4 = u(i,j,n_index);
%approximate the desired velocity u(x,y) at position (x,y) using %bilinear interpolation u_plot(i_index,j_index,n_index) = (1/(delta_x*delta_y))*(... (x2-x)*(y2-y)*u1... +(x-x1)*(y2-y)*u2... +(x2-x)*(y-y1)*u3... +(x-x1)*(y-y1)*u4... );
end end end
%x as a function of i for the v nodes x_v = zeros(1,i_max+1); for i = 1:i_max+1 x_v(i) = ((i-1)-(1/2))*delta_x; end
24-718 Computational Fluid Dynamics MAY 11, 2012 Final Report / Page 22 of 25
%y as a function of j for the v nodes y_v = zeros(1,j_max); for j = 1:j_max y_v(j) = ((j-1))*delta_y; end
%Calculate v for each x,y that is at the middle of a cell in the domain v_plot = zeros(i_max+1,j_max+1,1); for n_index = 1:n for i_index = 2:i_max for j_index = 2:j_max
%Regular grid coordinate of interest x = x_v(i_index); y = y_v(j_index);
%For a coordinate (x,y) compute the coordinates of the cell
corners %by first determining the appropriate (i,j) of the upper-right
cell %corner, encompassing (x,y) i = ceil((x+(delta_x/2))/(delta_x))+1; j = ceil(y/delta_y)+1;
%coordinates of encompassing cell corners x1 = ((i-1)-(1/2))*delta_x; x2 = (i-(1/2))*delta_x; y1 = (j-1)*delta_y; y2 = (j)*delta_y;
%four staggered y-velocities v1 = v(i-1,j-1,n_index); v2 = v(i,j-1,n_index); v3 = v(i-1,j,n_index); v4 = v(i,j,n_index);
%approximate the desired velocity v(x,y) at position (x,y) using %bilinear interpolation v_plot(i_index,j_index,n_index) = (1/(delta_x*delta_y))*(... (x2-x)*(y2-y)*v1... +(x-x1)*(y2-y)*v2... +(x2-x)*(y-y1)*v3... +(x-x1)*(y-y1)*v4... ); end
end v_now = v(:,:,n_index); %debug v_plot_now = v_plot(:,:,n_index); %debug end
%2D velocity plot over domain
%Coordinates for x and y plot
24-718 Computational Fluid Dynamics MAY 11, 2012 Final Report / Page 23 of 25
x_plot = zeros(1,i_max+1); for i = 1:i_max+1 x_plot(i) = ((i-1)-(1/2))*delta_x; end
y_plot = zeros(1,j_max+1); for j = 1:j_max+1 y_plot(j) = ((j-1)-(1/2))*delta_y; end
%Coordinates for x and y plot x_plot = zeros(1,i_max+1); for i = 1:i_max+1 x_plot(i) = ((i-1)-(1/2))*delta_x; end
y_plot = zeros(1,j_max+1); for j = 1:j_max+1 y_plot(j) = ((j-1)-(1/2))*delta_y; end
%Quiver plot and save for gif animation for n_index = 1:n
figure(1) scale = 1; quiver(x_plot,y_plot,(u_plot(:,:,n_index))',(v_plot(:,:,n_index))',scale) title(['Interpolated 2-D velocity over x-y domain, @ n = '
num2str(n_index)]) xlabel('x coordinate') ylabel('y coordinate') axis([0 Xlength 0 Ylength]) axis image
%save each plot as a .gif file (for use in creating an animation) saveas(1,'testing1.pgm'); w1=imread('testing1.pgm'); Wg1(:,:,1,n_index)=uint8(w1); S1=['CFD Project1 ' num2str(n_index) '.gif']; imwrite(Wg1(:,:,1,n_index),S1);
figure(2) scale = 1; z_plot = ( ( ((u_plot(:,:,n_index)).^2) + ((v_plot(:,:,n_index)).^2) )
.^0.5 ); surf(x_plot,y_plot,z_plot') title(['Interpolated 2-D velocity over x-y domain, @ n = '
num2str(n_index)]) xlabel('x coordinate') ylabel('y coordinate') axis([0 Xlength 0 Ylength]) axis image
24-718 Computational Fluid Dynamics MAY 11, 2012 Final Report / Page 24 of 25
%save each plot as a .gif file (for use in creating an animation) saveas(2,'testing2.pgm'); w2=imread('testing2.pgm'); Wg2(:,:,1,n_index)=uint8(w2); S2=['CFD Project2 ' num2str(n_index) '.gif']; imwrite(Wg2(:,:,1,n_index),S2);
%Plot of shear stress magnitude scale = 1; uu = u_plot(:,:,n_index); vv = v_plot(:,:,n_index);
figure(3) dv_dx = zeros(i_max-1,j_max-1); du_dy = zeros(i_max-1,j_max-1);
for i = 2:i_max for j = 2:j_max dv_dx(i-1,j-1) = (vv(i+1,j)-vv(i-1,j))/(2*delta_x); du_dy(i-1,j-1) = (uu(i+1,j)-uu(i-1,j))/(2*delta_y); end end visc = 0.003; tau_yx = visc.*(dv_dx+du_dy); z_plot2 = tau_yx;
x_plot2 = x_plot(2:i_max); %exclude ends y_plot2 = y_plot(2:j_max); %exclude ends
surf(x_plot2,y_plot2,z_plot2') title(['Interpolated shear stress over x-y domain, @ n = '
num2str(n_index)]) xlabel('x coordinate') ylabel('y coordinate') axis([0 Xlength 0 Ylength]) axis image
%save each plot as a .gif file (for use in creating an animation) saveas(3,'testing3.pgm'); w3=imread('testing3.pgm'); Wg3(:,:,1,n_index)=uint8(w3); S3=['CFD Project3 ' num2str(n_index) '.gif']; imwrite(Wg3(:,:,1,n_index),S3);
%Plot of pressure figure(4) scale = 1; z_plot3 = p(:,:,n_index); surf(x_plot,y_plot,z_plot3') title(['Interpolated pressure over x-y domain, @ n = ' num2str(n_index)]) xlabel('x coordinate') ylabel('y coordinate') axis([0 Xlength 0 Ylength])
24-718 Computational Fluid Dynamics MAY 11, 2012 Final Report / Page 25 of 25
axis image
%save each plot as a .gif file (for use in creating an animation) saveas(4,'testing4.pgm'); w4=imread('testing4.pgm'); Wg4(:,:,1,n_index)=uint8(w4); S4=['CFD Project4 ' num2str(n_index) '.gif']; imwrite(Wg4(:,:,1,n_index),S4);
end