A Mathematica-Based Hydrodynamics Model

0 downloads 0 Views 941KB Size Report
numerical modeling, partial differential equations. 1. Introduction. Adapting ... governing equations of fluid dynamics in Mathematica. I will then use these ideas to .... Dynamics, McGraw-Hill, Schaum's Outline Series. [4] Wolfram Research ...
A Mathematica-Based Hydrodynamics Model George E. Hrabovsky1 1 Madison-Area Science and Technology (MAST), Madison, Wisconsin, USA Abstract— This paper describes the development of hydrodynamics code in the software environment Mathematica. Keywords: Fluid dynamics, computational science, Mathematica, numerical modeling, partial differential equations.

1. Introduction

The second equation of fluid motion is the momentum equation; for the pressure field, p, the internal body forces, Bi , the viscosity coefficients µ and ζ, and the Kronecker delta δij , we write µ

Adapting computers to solving fluid dynamics problems is nothing new. The first modern computers were almost immediately pressed into service for the task of solving hydrodynamics problems related to the development of the hydrogen bomb. There is a rich literature of modern books and papers that have turned computational fluid dynamics into an industry in its own right. It is surprising that there has not been more work on adapting Mathematica to fluid dynamics, particularly with the advent of parallel computing environments specifically for this software system. There seem to be only two major resources for this [1] [2]. The ease of coding and visualization in Mathematica seem to outweigh any issues of run times that might compare unfavorably with existing systems. Indeed, the coding, as you will see, is fairly easy. In this paper I will begin by showing how to code the governing equations of fluid dynamics in Mathematica. I will then use these ideas to construct a one-dimensional fluid dynamics model. The important aspect of the coding is that I am producing the model as I write the paper. The entire modeling process is taking place over a period of about two hours.

2. The Continuity Equation The first equation of fluid motion we will write is the continuity equation. For a given density, ρ, and a velocity field ui we have, ∂ρ + ∂xi ρui = 0 (1) ∂t We prepare to code this in Mathematica by first writing this out in its components, ∂ρ ∂ρ +u = 0. ∂t ∂x We then write the following code D[ρ[x, t], t] + D[ρ[x, t] u[x, t], x] == 0.

3. The Momentum Equation

(2)

ρ

¶ ∂ui ∂ui + uj = ∂t ∂xj · µ ¶¸ ∂ ∂ui ∂uj 2 ∂uk ∂p + Bi + µ + − δij − ∂xi ∂x ∂xj ∂xi 3 ∂xk µ ¶ j ∂ ∂uk + ζ . (3) ∂xi ∂xk

We write this out in the components, µ ρ

¶ ∂u ∂u +u = ∂t ∂x · µ ¶¸ ∂p ∂ ∂u 2 ∂u − + Bx + µ 2 − ∂x ∂x ∂x 3 ∂x µ ¶ ∂ ∂u + ζ . ∂x ∂x

(4)

We then write the following code, ignoring the body forces, dropping the second derivatives of velocity, and assuming the viscosity coefficients to be 1 each, D[u[x,t],t]+u[x,t] D[u[x,t]x])==-D[p[x,t],x]/ρ[x,t]

4. The Energy Equation The third equation is the thermal energy equation; given the specific heat at constant volume, cv , the temperature, T , the heat flux vector (this is usually 0 for most fluids), qi , the thermal conductivity, κ, the rate of internal heat generation per unit volume (also 0 for most fluids), q”’, and the dissipation function, Φ, we write, µ

¶ ∂T ∂T ρcv + ui = ∂t ∂xi ∂ui ∂2T ∂qi −p +κ − + Φi + q”’. ∂xi ∂xi 2 ∂xi The dissipation function is given by

(5)

∂uj , (6) ∂xi where σij0 is the deviatoric stress tensor. The dissipation function is, itself, the rate at which such deviatoric stresses do work. Thus, (5) becomes, Φi = σij0

Velocity

Density

µ



∂ui ∂2T ∂T ∂T ∂uj + ui = −p +κ + σij0 . ∂t ∂xi ∂xi ∂xi 2 ∂xi This in turn becomes, for our components, ρcv

µ ρcv

∂T ∂T +u ∂t ∂x

(7)

0.2

2.2 2.1 2.0 1.9

, 0.1 40

0



20

10 20

=

µ ¶2 µ ¶2 ∂2T ∂u ∂u ∂u + κ 2 + 2µ +λ . (8) ∂x ∂x ∂x ∂x For our purposes this can be rewritten in the form, µ ¶ ∂p 5/3p ∂ρ ∂ρ ∂p +u = +u . (9) ∂t ∂x ρ ∂t ∂x The Mathematica code for this becomes, again dropping the second derivatives of velocity, and assuming cv and κ to be 1. D[p[x,t],t]+u[x,t]D[p[x,t],x]== (5/3)p[x,t]/ρ[x,t](D[ρ[x,t],t]+u[x,t] D[ρ[x,t],x])

30

Assume that we choose to produce a model that will sit in a 30 cell space. We choose periodic boundary conditions in x. We code this, ρ[0,t]==ρ[30,t], p[0,t]==p[30,t], u[0,t]==u[30,t]. We can set up initial conditions, too. In this case, we assume that a sinusoidal pressure wave kicks things off. ρ[x,0]==2, p[x,0]==10+Sin[2 π x/30], u[x,0]==0. We now construct and solve our model. soln= NDSolve[D[ρ[x,t]+D[ρ[x,t] u[x,t],x]==0, D[u[x,t],t]+u[x,t] D[u[x,t],x]==-D[p[x,t],x]/ ρ[x,t], D[p[x,t],t]+u[x,t]D[p[x,t],x]== (5/3)p[x,t]/ρ[x,t](D[ρ[x,t],t]+u[x,t]D[ρ[x,t],x]), ρ[0,t]==ρ[30,t], p[0,t]==p[30,t],u[0,t]==u[30,t],ρ[x,0]==2, p[x,0]==10+Sin[2 π x/30],u[x,0]==0, ρ[x,t],p[x,t],u[x,t], x,0,30,t,0,50,Method->"ExplicitRungeKutta", "DifferenceOrder" -> 8] The solution takes the form of interpolating functions. ρ[x,t]->InterpolatingFunction[0.0,30.0,0.0,50.0,][x,t], p[x,t]->InterpolatingFunction[0.0,30.0,0.0,50.0,][x,t], u[x,t]->InterpolatingFunction[0.0,30.0,0.0,50.0,][x,t] We can plot the density, pressure, and velocity using the code, GraphicsGrid[ Plot3D[ρ[x, t] /. soln, x, 0, 30, t, 0, 50,PlotLabel -> Density], Plot3D[u[x, t] /. soln, x, 0, 30, t, 0, 50,PlotLabel -> Velocity], Plot3D[p[x, t] /. soln, x, 0, 30, t, 0, 50,PlotLabel -> Pressure]] See Fig. 1 for the output of this model.

40 20

10 20

0

30

0

Pressure

−p

5. A Simple Model

,

0.0 -0.1 -0.2 0

11 10 9 0

40 20

10 20 30

0

Fig. 1: Here is Mathematica graphics output for density, velocity, and pressure for the model presented above.

6. Conclusions Mathematica makes a very nice platform for the development of numerical fluid dynamics code for prototyping and small-scale modeling on a desktop machine, to large-scale modeling on a parallel machine, such as a Tesla machine. Development time is measured in hours, instead of weeks or months, and visualization tools are built in. The ability to process symbolic and numerical expressions increases the capability for development of novel code. Additionally, this document was written in Mathematica using its built-in typesetting system.

7. References [1] Sergay P. Kirilov, Evgenii V. Vorozhtsov, Vasily M. Fomin, (1999), Foundations of Fluid Mechanics with Applications, Birkhãuser Boston. [2] Antonia Romano, Renato Lancellotta, Addolorata Marasco, (2006), Continuum Mechanics using Mathematica, Birkhãuser Boston. [3] William F. Hughes, John A. Brighton, (1999), Fluid Dynamics, McGraw-Hill, Schaum’s Outline Series. [4] Wolfram Research, (2009), Mathematica version 7. [5] George E. Hrabovsky, Christopher J. Winfield, James Firmiss, (2010), A Baby Hydrodynamics Model, Unpublished Internal Document.