how to implement an application · 2018-09-13 · cfd with opensource software, 2018 håkan...

37
CFD with OpenSource Software, 2018 Håkan Nilsson, Chalmers / Mechanics and Maritime Sciences / Fluid Dynamics 1 How to implement an application

Upload: others

Post on 16-Jul-2020

13 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: How to implement an application · 2018-09-13 · CFD with OpenSource Software, 2018 Håkan Nilsson, Chalmers / Mechanics and Maritime Sciences / Fluid Dynamics 3 How to implement

CFD with OpenSource Software, 2018

Håkan Nilsson, Chalmers / Mechanics and Maritime Sciences / Fluid Dynamics 1

How to implement an application

Page 2: How to implement an application · 2018-09-13 · CFD with OpenSource Software, 2018 Håkan Nilsson, Chalmers / Mechanics and Maritime Sciences / Fluid Dynamics 3 How to implement

CFD with OpenSource Software, 2018

Håkan Nilsson, Chalmers / Mechanics and Maritime Sciences / Fluid Dynamics 2

How to implement an application

Prerequisites

• You are familiar with the directory structure of OpenFOAM applications.

• You are familiar with user compilation procedures of applications.

• You are familiar with the fundamental high-level components of application codes, and how

new classes can be introduced to an application.

Learning outcomes

• You will practice high-level coding and modification of solvers.

• You will adapt case set-ups according to the new solver.

• You will improve your understanding of classes and object orientation, from a high-level

perspective.

Page 3: How to implement an application · 2018-09-13 · CFD with OpenSource Software, 2018 Håkan Nilsson, Chalmers / Mechanics and Maritime Sciences / Fluid Dynamics 3 How to implement

CFD with OpenSource Software, 2018

Håkan Nilsson, Chalmers / Mechanics and Maritime Sciences / Fluid Dynamics 3

How to implement an application

Contents

• You will implement a simple two-equation solver from scratch, and validate it with a test

case.

• You will add an additional transport equation to an existing solver.

• You will add an additional class to an existing solver, and that way extend the solver func-

tionality. You will as well realize that the added class requires modifications to the case,

and you will do those modifications.

Note that you will be asked to pack up your final cleaned-up directories and submit them for

assessment of completion.

Page 4: How to implement an application · 2018-09-13 · CFD with OpenSource Software, 2018 Håkan Nilsson, Chalmers / Mechanics and Maritime Sciences / Fluid Dynamics 3 How to implement

CFD with OpenSource Software, 2018

Håkan Nilsson, Chalmers / Mechanics and Maritime Sciences / Fluid Dynamics 4

Example: Electric conduction in a rod surrounded by air

Governing equations

Maxwell’s equation:

∇× E = 0 (1)

where E is the electric field strength.

∇ · B = 0 (2)

where B is the magnetic flux density.

∇×H = J (3)

where H is the magnetic field strength and

J is current density.

Charge continuity:

∇ · J = 0 (4)

Ohm’s law:

J = σE (5)

where σ is the electric conductivity.

Constitutive law:

B = µ0H (6)

where µ0 is the magnetic permeability of

vacuum.

Combining Equations (1)-(6) and assuming Coulomb gauge condition (∇ · A = 0) leads to a

Poisson equation for the magnetic potential and a Laplace equation for the electric potential...

Page 5: How to implement an application · 2018-09-13 · CFD with OpenSource Software, 2018 Håkan Nilsson, Chalmers / Mechanics and Maritime Sciences / Fluid Dynamics 3 How to implement

CFD with OpenSource Software, 2018

Håkan Nilsson, Chalmers / Mechanics and Maritime Sciences / Fluid Dynamics 5

Governing equations in OpenFoam

Magnetic potential:

∇2A = µ0σ(∇φ) (7)

OpenFOAM representation:

solve

(

fvm::laplacian(A) ==

sigma*muMag*(fvc::grad(ElPot))

);

Electric potential:

∇ · [σ(∇φ)] = 0 (8)

OpenFOAM representation:

solve

(

fvm::laplacian(sigma,ElPot)

);

We see that A depends on φ, but not vice-versa.

Page 6: How to implement an application · 2018-09-13 · CFD with OpenSource Software, 2018 Håkan Nilsson, Chalmers / Mechanics and Maritime Sciences / Fluid Dynamics 3 How to implement

CFD with OpenSource Software, 2018

Håkan Nilsson, Chalmers / Mechanics and Maritime Sciences / Fluid Dynamics 6

Implementing the rodFoam solver

Create the basic files in your user directory:

cd $WM_PROJECT_USER_DIR

mkdir -p applications/solvers/electromagnetics/rodFoam

cd applications/solvers/electromagnetics/rodFoam

foamNewSource App rodFoam

tree

We see:

.

|-- Make

| |-- files

| `-- options

`-- rodFoam.C

Make sure that the binary file ends up in your user directory:

sed -i s/FOAM_APPBIN/FOAM_USER_APPBIN/g Make/files

Try compiling, and it will probably fail. Have a look at Make/options of e.g.

$FOAM_SOLVERS/basic/laplacianFoam/Make/options to see that you should also add

meshTools. This is a bug (or missing feature) in foamNewSource.

Page 7: How to implement an application · 2018-09-13 · CFD with OpenSource Software, 2018 Håkan Nilsson, Chalmers / Mechanics and Maritime Sciences / Fluid Dynamics 3 How to implement

CFD with OpenSource Software, 2018

Håkan Nilsson, Chalmers / Mechanics and Maritime Sciences / Fluid Dynamics 7

Add a few lines to rodFoam.CWe need a mesh to discretize our equations on, and we need to initialize properties and fields.

After #include "createTime.H", add:

#include "createMesh.H" //In the OpenFOAM installation

#include "createFields.H" //Must be implemented - see next slides

Continue adding (after the above), our equations:

solve ( fvm::laplacian(sigma, ElPot) );

solve ( fvm::laplacian(A)==sigma*muMag*(fvc::grad(ElPot)) );

Add some additional things that can be computed when we know A and ElPot:

B = fvc::curl(A);

Je = -sigma*(fvc::grad(ElPot));

We also want to write out the results to a new time directory.

Continue adding:

runTime++;

sigma.write();

ElPot.write();

A.write();

B.write();

Je.write();

Page 8: How to implement an application · 2018-09-13 · CFD with OpenSource Software, 2018 Håkan Nilsson, Chalmers / Mechanics and Maritime Sciences / Fluid Dynamics 3 How to implement

CFD with OpenSource Software, 2018

Håkan Nilsson, Chalmers / Mechanics and Maritime Sciences / Fluid Dynamics 8

The createFields.H file (1/6)We need to construct and initialize muMag, sigma, Elpot, A, B, and Je.

Edit the createFields.H file.

Read muMag from a dictionary:

Info<< "Reading physicalProperties\n" << endl;

IOdictionary physicalProperties

(

IOobject

(

"physicalProperties",

runTime.constant(),

mesh,

IOobject::MUST_READ,

IOobject::NO_WRITE

)

);

dimensionedScalar muMag

(

physicalProperties.lookup("muMag")

);

Page 9: How to implement an application · 2018-09-13 · CFD with OpenSource Software, 2018 Håkan Nilsson, Chalmers / Mechanics and Maritime Sciences / Fluid Dynamics 3 How to implement

CFD with OpenSource Software, 2018

Håkan Nilsson, Chalmers / Mechanics and Maritime Sciences / Fluid Dynamics 9

The createFields.H file (2/6)

Construct volScalarField sigma:

Info<< "Reading field sigma\n" << endl;

volScalarField sigma

(

IOobject

(

"sigma",

runTime.timeName(),

mesh,

IOobject::MUST_READ,

IOobject::AUTO_WRITE

),

mesh

);

Page 10: How to implement an application · 2018-09-13 · CFD with OpenSource Software, 2018 Håkan Nilsson, Chalmers / Mechanics and Maritime Sciences / Fluid Dynamics 3 How to implement

CFD with OpenSource Software, 2018

Håkan Nilsson, Chalmers / Mechanics and Maritime Sciences / Fluid Dynamics 10

The createFields.H file (3/6)

Construct volScalarField Elpot:

volScalarField ElPot

(

IOobject

(

"ElPot",

runTime.timeName(),

mesh,

IOobject::MUST_READ,

IOobject::AUTO_WRITE

),

mesh

);

Page 11: How to implement an application · 2018-09-13 · CFD with OpenSource Software, 2018 Håkan Nilsson, Chalmers / Mechanics and Maritime Sciences / Fluid Dynamics 3 How to implement

CFD with OpenSource Software, 2018

Håkan Nilsson, Chalmers / Mechanics and Maritime Sciences / Fluid Dynamics 11

The createFields.H file (4/6)

Construct volVectorField A:

Info<< "Reading field A\n" << endl;

volVectorField A

(

IOobject

(

"A",

runTime.timeName(),

mesh,

IOobject::MUST_READ,

IOobject::AUTO_WRITE

),

mesh

);

Page 12: How to implement an application · 2018-09-13 · CFD with OpenSource Software, 2018 Håkan Nilsson, Chalmers / Mechanics and Maritime Sciences / Fluid Dynamics 3 How to implement

CFD with OpenSource Software, 2018

Håkan Nilsson, Chalmers / Mechanics and Maritime Sciences / Fluid Dynamics 12

The createFields.H file (5/6)

Construct and initialize volVectorField B:

Info << "Calculating magnetic field B \n" << endl;

volVectorField B

(

IOobject

(

"B",

runTime.timeName(),

mesh,

IOobject::NO_READ,

IOobject::AUTO_WRITE

),

fvc::curl(A)

);

Page 13: How to implement an application · 2018-09-13 · CFD with OpenSource Software, 2018 Håkan Nilsson, Chalmers / Mechanics and Maritime Sciences / Fluid Dynamics 3 How to implement

CFD with OpenSource Software, 2018

Håkan Nilsson, Chalmers / Mechanics and Maritime Sciences / Fluid Dynamics 13

The createFields.H file (6/6)

Construct and initialize volVectorField Je:

volVectorField Je

(

IOobject

(

"Je",

runTime.timeName(),

mesh,

IOobject::NO_READ,

IOobject::AUTO_WRITE

),

-sigma*(fvc::grad(ElPot))

);

Page 14: How to implement an application · 2018-09-13 · CFD with OpenSource Software, 2018 Håkan Nilsson, Chalmers / Mechanics and Maritime Sciences / Fluid Dynamics 3 How to implement

CFD with OpenSource Software, 2018

Håkan Nilsson, Chalmers / Mechanics and Maritime Sciences / Fluid Dynamics 14

Compile the solver

We have implemented a solver, which is compiled by:

wmake

If successful, the output should end something like:

-o /chalmers/users/hani/OpenFOAM/oscfd-plus/platforms/linux64GccDPInt32Opt/bin/rodFoam

We now need a case to use the solver on. It is provided to you (rodFoamCase.tgz), since it

is too much to describe in slides. Unpack and run using:

(NOTE, you may have to do sudo apt install gv first, for showing the plots at the end)

tar xzf rodFoamCase.tgz; cd rodFoamCase; ./Allrun 2>&1 | tee log_Allrun

Page 15: How to implement an application · 2018-09-13 · CFD with OpenSource Software, 2018 Håkan Nilsson, Chalmers / Mechanics and Maritime Sciences / Fluid Dynamics 3 How to implement

CFD with OpenSource Software, 2018

Håkan Nilsson, Chalmers / Mechanics and Maritime Sciences / Fluid Dynamics 15

Geometry and mesh, the rodFoamCase case

Electric rod.Computational domain

In paraFoam

A 2D axi-symmetric case, with a wedge mesh

Zoom-up of rod.

For 2D wedge, the symmetry axis must be

aligned with the x-axis, the wedge angle

should be 5 degrees, with half on each side of

the z = 0 plane.

Page 16: How to implement an application · 2018-09-13 · CFD with OpenSource Software, 2018 Håkan Nilsson, Chalmers / Mechanics and Maritime Sciences / Fluid Dynamics 3 How to implement

CFD with OpenSource Software, 2018

Håkan Nilsson, Chalmers / Mechanics and Maritime Sciences / Fluid Dynamics 16

View the results in paraFoam

Electric potential (φ) Magnitude of magnetic potential vector (A)

Page 17: How to implement an application · 2018-09-13 · CFD with OpenSource Software, 2018 Håkan Nilsson, Chalmers / Mechanics and Maritime Sciences / Fluid Dynamics 3 How to implement

CFD with OpenSource Software, 2018

Håkan Nilsson, Chalmers / Mechanics and Maritime Sciences / Fluid Dynamics 17

Validation

x-component of magnetic potential

vector A vs radius of the domain.

z-component of the magnetic

field B vs radius of the domain

Page 18: How to implement an application · 2018-09-13 · CFD with OpenSource Software, 2018 Håkan Nilsson, Chalmers / Mechanics and Maritime Sciences / Fluid Dynamics 3 How to implement

CFD with OpenSource Software, 2018

Håkan Nilsson, Chalmers / Mechanics and Maritime Sciences / Fluid Dynamics 18

Boundary and initial conditions

• We solve for the magnetic potential A (A) and the electric potential ElPot (φ), so

we need boundary conditions:

block 0, sides block 1, sides block1, top

A ∇A = 0 ∇A = 0 A = 0

φ φleft = 707,φright = 0 ∇φ = 0 ∇φ = 0

and we initialize the fields to zero.

• The internal field of the electric conductivity sigma (σ) is nonuniform:

σ =

{

2700 if x < R where R -radius of the block 1

1e− 5 otherwise

so we use a volScalarField and setFields to set the internal field.

• The magnetic permeability of vacuum (µ0) is read from the

constant/physicalProperties dictionary.

Page 19: How to implement an application · 2018-09-13 · CFD with OpenSource Software, 2018 Håkan Nilsson, Chalmers / Mechanics and Maritime Sciences / Fluid Dynamics 3 How to implement

CFD with OpenSource Software, 2018

Håkan Nilsson, Chalmers / Mechanics and Maritime Sciences / Fluid Dynamics 19

Validation of components of A and B using Gnuplot

• Our numerical results should be validated with analytical results

• For this we need to extract the components and extract the values along a line:

postProcess -func 'components(A)' -time 1

postProcess -func 'components(B)' -time 1

postProcess -func singleGraph -time 1

• The results are validated with the analytical solution using Gnuplot:

gnuplot rodComparisonAxBz.plt

• Visualize using:

gv rodAxVSy.ps

gv rodBzVSy.ps

Page 20: How to implement an application · 2018-09-13 · CFD with OpenSource Software, 2018 Håkan Nilsson, Chalmers / Mechanics and Maritime Sciences / Fluid Dynamics 3 How to implement

CFD with OpenSource Software, 2018

Håkan Nilsson, Chalmers / Mechanics and Maritime Sciences / Fluid Dynamics 20

Analytic solution

• Analytic solution for x component of magnetic potential vector A

Ax =

{

Ax(0)−µ0Jx

2

4if r < R,

Ax(0)−µ0JR

2

2[0.5 + ln(r/R)] otherwise

where Ax(0) = 0.000606129, J = 19.086e + 7 is the current density and R is the

radius of the electric rod.

• Analytic solution for z component of magnetic field B

Bz =

{

µ0Jx2

if r < R,µ0JR

2

2r otherwise

where J = 19.086e+7 is the current density and R is the radius of the electric rod.

• Have a look in rodComparisonAxBz.plt to see how to plot a function in Gnu-

plot.

Page 21: How to implement an application · 2018-09-13 · CFD with OpenSource Software, 2018 Håkan Nilsson, Chalmers / Mechanics and Maritime Sciences / Fluid Dynamics 3 How to implement

CFD with OpenSource Software, 2018

Håkan Nilsson, Chalmers / Mechanics and Maritime Sciences / Fluid Dynamics 21

How to modify an existing application

• The applications are located in the $WM_PROJECT_DIR/applications directory

(equivalent to $FOAM_APP. Go there using alias app).

• Copy an application that is similar to what you would like to do and modify it for yourpurposes. In this case we will make our own copy of the icoFoam solver and put it in our$WM_PROJECT_USER_DIR with the same file structure as in the OpenFOAM installation:

foam

cp -r --parents applications/solvers/incompressible/icoFoam $WM_PROJECT_USER_DIR

cd $WM_PROJECT_USER_DIR/applications/solvers/incompressible

mv icoFoam passiveScalarFoam

cd passiveScalarFoam

wclean

mv icoFoam.C passiveScalarFoam.C

• Modify Make/files (most portable way):

string="passiveScalarFoam.C\nEXE = \$(FOAM_USER_APPBIN)/passiveScalarFoam"

printf "%b\n" "$string" > Make/files

• Compile with wmake in the passiveScalarFoam directory. rehash if necessary.

• Test that it works on the cavity case...

Page 22: How to implement an application · 2018-09-13 · CFD with OpenSource Software, 2018 Håkan Nilsson, Chalmers / Mechanics and Maritime Sciences / Fluid Dynamics 3 How to implement

CFD with OpenSource Software, 2018

Håkan Nilsson, Chalmers / Mechanics and Maritime Sciences / Fluid Dynamics 22

Test on cavity case

We will quickly visit the run directory to test...

pushd $FOAM_RUN #so that we can easily go back to the current directory

rm -r cavity

cp -r $FOAM_TUTORIALS/incompressible/icoFoam/cavity/cavity .

blockMesh -case cavity

passiveScalarFoam -case cavity

After checking that it worked, go back to the passiveScalarFoam directory:

popd #brings you back to the directory where you typed the pushd command

You can also do everything ’remotely’:

rm -r $FOAM_RUN/cavity

cp -r $FOAM_TUTORIALS/incompressible/icoFoam/cavity/cavity $FOAM_RUN

blockMesh -case $FOAM_RUN/cavity

passiveScalarFoam -case $FOAM_RUN/cavity

Page 23: How to implement an application · 2018-09-13 · CFD with OpenSource Software, 2018 Håkan Nilsson, Chalmers / Mechanics and Maritime Sciences / Fluid Dynamics 3 How to implement

CFD with OpenSource Software, 2018

Håkan Nilsson, Chalmers / Mechanics and Maritime Sciences / Fluid Dynamics 23

Add a passive scalar transport equation (1/3)

• Let’s add, to passiveScalarFoam, the passive scalar transport equation

∂s

∂t+∇ · (u s) = 0

• We must modify the solver:

− Create volumeScalarField s (do the same as for p in createFields.H, since

both are scalar fields)

− Add the equation solve(fvm::ddt(s) + fvm::div(phi, s));

before runTime.write(); in passiveScalarFoam.C.

− Compile passiveScalarFoam using wmake

• We must modify the case - next slide ...

Page 24: How to implement an application · 2018-09-13 · CFD with OpenSource Software, 2018 Håkan Nilsson, Chalmers / Mechanics and Maritime Sciences / Fluid Dynamics 3 How to implement

CFD with OpenSource Software, 2018

Håkan Nilsson, Chalmers / Mechanics and Maritime Sciences / Fluid Dynamics 24

Add a passive scalar transport equation (2/3)

• We must modify the case:

− Use the icoFoam/cavity case as a base:

run

cp -r $FOAM_TUTORIALS/incompressible/icoFoam/cavity/cavity passiveCavity

cd passiveCavity

− Copy the 0/p file to 0/s and modify p to s in that file. Choose approprate dimensions

for the scalar field (not important now).

− In fvSchemes, add (if you don’t, it will complain):

div(phi,s) Gauss linearUpwind Gauss;

− In fvSolution, copy the solution settings from U (since the equations for velocity

and s are similar), and just change U to s. (if you use PCG, as for p, it will complain

- try it yourself!)

• We must initialize and run the case - next slide ...

Page 25: How to implement an application · 2018-09-13 · CFD with OpenSource Software, 2018 Håkan Nilsson, Chalmers / Mechanics and Maritime Sciences / Fluid Dynamics 3 How to implement

CFD with OpenSource Software, 2018

Håkan Nilsson, Chalmers / Mechanics and Maritime Sciences / Fluid Dynamics 25

Add a passive scalar transport equation (3/3)

• We must initialize s:

− cp $FOAM_TUTORIALS/multiphase/interFoam/laminar/damBreak/damBreak/system/setFieldsDict system

− Set defaultFieldValues:

volScalarFieldValue s 0

− Modify the bounding box to:

box (0.03 0.03 -1) (0.06 0.06 1);

− Set fieldValues:

volScalarFieldValue s 1

• Run the case:

blockMesh

setFields

passiveScalarFoam >& log

paraFoam - mark s in Volume Fields, color by s (cell value) and run an animation.

• You can see that although there is no diffusion term in the equation, there is massive diffu-

sion in the results. This is due to mesh resolution, numerical scheme etc. The interfoam

solver has a special treatment to reduce this kind of diffusion.

Page 26: How to implement an application · 2018-09-13 · CFD with OpenSource Software, 2018 Håkan Nilsson, Chalmers / Mechanics and Maritime Sciences / Fluid Dynamics 3 How to implement

CFD with OpenSource Software, 2018

Håkan Nilsson, Chalmers / Mechanics and Maritime Sciences / Fluid Dynamics 26

Add particles to the interFoam/damBreak case

Add the solidParticleCloud class to the interFoam/damBreak tutorial by doing the following,

and you will have some nice animation to view.

Copy the interFoam solver, clean up, re-name and compile:

cd $WM_PROJECT_DIR

cp -r --parents applications/solvers/multiphase/interFoam $WM_PROJECT_USER_DIR

cd $WM_PROJECT_USER_DIR/applications/solvers/multiphase

mv interFoam solidParticleInterFoam

cd solidParticleInterFoam

rm -r interMixingFoam overInterDyMFoam

wclean

rm -rf Make/linux*

mv interFoam.C solidParticleInterFoam.C

sed -i.orig s/interFoam/solidParticleInterFoam/g Make/files

sed -i s/FOAM_APPBIN/FOAM_USER_APPBIN/g Make/files

sed -i s/"..\/VoF"/"\$(FOAM_SOLVERS)\/multiphase\/VoF"/g Make/options

wmake

At this point you can check that the code still works for the damBreak tutorial.

Page 27: How to implement an application · 2018-09-13 · CFD with OpenSource Software, 2018 Håkan Nilsson, Chalmers / Mechanics and Maritime Sciences / Fluid Dynamics 3 How to implement

CFD with OpenSource Software, 2018

Håkan Nilsson, Chalmers / Mechanics and Maritime Sciences / Fluid Dynamics 27

Add particles to the interFoam/damBreak case

Now we will add functionality from the solidParticleCloud class.

Modify solidParticleInterFoam.C:

Include the class declarations of solidParticleCloud.H.

At the header, add:

#include "solidParticleCloud.H"

Create a solidParticleCloud object.

After #include "setInitialDeltaT.H", add after the if-statement:

solidParticleCloud particles(mesh);

Move the particles.

Before runTime.write();, add:

particles.move(g);

Page 28: How to implement an application · 2018-09-13 · CFD with OpenSource Software, 2018 Håkan Nilsson, Chalmers / Mechanics and Maritime Sciences / Fluid Dynamics 3 How to implement

CFD with OpenSource Software, 2018

Håkan Nilsson, Chalmers / Mechanics and Maritime Sciences / Fluid Dynamics 28

Add particles to the interFoam/damBreak caseWe need to add some libraries when we compile.Make sure that Make/options has the following lines (where ’...’ is the original lines):

EXE_INC = \

... \

-I$(LIB_SRC)/lagrangian/basic/lnInclude \

-I$(LIB_SRC)/lagrangian/solidParticle/lnInclude

EXE_LIBS = \

... \

-llagrangian \

-lsolidParticle

Compile:

wmake

Page 29: How to implement an application · 2018-09-13 · CFD with OpenSource Software, 2018 Håkan Nilsson, Chalmers / Mechanics and Maritime Sciences / Fluid Dynamics 3 How to implement

CFD with OpenSource Software, 2018

Håkan Nilsson, Chalmers / Mechanics and Maritime Sciences / Fluid Dynamics 29

Add particles to the interFoam/damBreak caseWe need to set up a case, based on the original damBreak case:

run

cp -r $FOAM_TUTORIALS/multiphase/interFoam/RAS/damBreak/damBreak solidParticleDamBreak

cd solidParticleDamBreak

The modifations that need to be made are not obvious. There are no examples using the solid-

Particle class in the original code. I looked at examples for similar classes, as well as the source

code. Some time between v1706 and v1806 there was a significant change in the required files,

and here we set it up for v1806.

Create a directory for info of the particles:

mkdir -p 0/lagrangian/defaultCloud

We will add files for diameter (d), positions (positions), velocity (U), original ID (origId) and

original processor ID (origProcId).

Create a directory for the particle cloud properties, which we will only use to specify the format

of positions of the particles (the default in v1806 seems to be coordinates, be but we will use

the old positions):

mkdir -p 0/uniform/lagrangian/defaultCloud

We will set the particle properties in constant/particleProperties.

Page 30: How to implement an application · 2018-09-13 · CFD with OpenSource Software, 2018 Håkan Nilsson, Chalmers / Mechanics and Maritime Sciences / Fluid Dynamics 3 How to implement

CFD with OpenSource Software, 2018

Håkan Nilsson, Chalmers / Mechanics and Maritime Sciences / Fluid Dynamics 30

Add particles to the interFoam/damBreak case

We will set up a case with 2 particles. That number is determined by the solver by the number

of entries in the lists in the following files.Diameter file (0/lagrangian/defaultCloud/d):

/*--------------------------------*- C++ -*----------------------------------*\

| ========= | |

| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox |

| \\ / O peration | Version: v1806 |

| \\ / A nd | Web: www.OpenFOAM.com |

| \\/ M anipulation | |

\*---------------------------------------------------------------------------*/

FoamFile

{

version 2.0;

format ascii;

class scalarField;

location "0/lagrangian/defaultCloud";

object d;

}

// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

2{2.0e-3}

// ************************************************************************* //

The number of particles is 2, and since they have the same diameter their diameters are in a

list given by the curly brackets.

Page 31: How to implement an application · 2018-09-13 · CFD with OpenSource Software, 2018 Håkan Nilsson, Chalmers / Mechanics and Maritime Sciences / Fluid Dynamics 3 How to implement

CFD with OpenSource Software, 2018

Håkan Nilsson, Chalmers / Mechanics and Maritime Sciences / Fluid Dynamics 31

Add particles to the interFoam/damBreak casePositions file (0/lagrangian/defaultCloud/positions):/*--------------------------------*- C++ -*----------------------------------*\

| ========= | |

| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox |

| \\ / O peration | Version: v1806 |

| \\ / A nd | Web: www.OpenFOAM.com |

| \\/ M anipulation | |

\*---------------------------------------------------------------------------*/

FoamFile

{

version 2.0;

format ascii;

class Cloud<solidParticle>;

location "0/lagrangian/defaultCloud";

object positions;

}

// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

2

(

(2e-2 0.56 0.005) -1

(3e-2 0.56 0.005) -1

)

// ************************************************************************* //

The particles start at different positions, so the list is given with regular brackets. The -1 at

the end of the line means that the class will have to find the cells that they are located in. In

the time directories it will be stated which cell they are in.

Page 32: How to implement an application · 2018-09-13 · CFD with OpenSource Software, 2018 Håkan Nilsson, Chalmers / Mechanics and Maritime Sciences / Fluid Dynamics 3 How to implement

CFD with OpenSource Software, 2018

Håkan Nilsson, Chalmers / Mechanics and Maritime Sciences / Fluid Dynamics 32

Add particles to the interFoam/damBreak caseVelocity file (0/lagrangian/defaultCloud/U):

/*--------------------------------*- C++ -*----------------------------------*\

| ========= | |

| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox |

| \\ / O peration | Version: v1806 |

| \\ / A nd | Web: www.OpenFOAM.com |

| \\/ M anipulation | |

\*---------------------------------------------------------------------------*/

FoamFile

{

version 2.0;

format ascii;

class vectorField;

location "0/lagrangian/defaultCloud";

object U;

}

// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

2

(

(1.7e-1 0 0)

(1.7 0 0)

)

// ************************************************************************* //

The particles start with different velocities.

Page 33: How to implement an application · 2018-09-13 · CFD with OpenSource Software, 2018 Håkan Nilsson, Chalmers / Mechanics and Maritime Sciences / Fluid Dynamics 3 How to implement

CFD with OpenSource Software, 2018

Håkan Nilsson, Chalmers / Mechanics and Maritime Sciences / Fluid Dynamics 33

Add particles to the interFoam/damBreak caseOriginal ID file (0/lagrangian/defaultCloud/origId):

/*--------------------------------*- C++ -*----------------------------------*\

| ========= | |

| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox |

| \\ / O peration | Version: v1806 |

| \\ / A nd | Web: www.OpenFOAM.com |

| \\/ M anipulation | |

\*---------------------------------------------------------------------------*/

FoamFile

{

version 2.0;

format ascii;

class labelField;

location "0/lagrangian/defaultCloud";

object origId;

}

// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

2

(

0

1

)

// ************************************************************************* //

The particles are numbered with labels.

Page 34: How to implement an application · 2018-09-13 · CFD with OpenSource Software, 2018 Håkan Nilsson, Chalmers / Mechanics and Maritime Sciences / Fluid Dynamics 3 How to implement

CFD with OpenSource Software, 2018

Håkan Nilsson, Chalmers / Mechanics and Maritime Sciences / Fluid Dynamics 34

Add particles to the interFoam/damBreak caseOriginal processor ID file (0/lagrangian/defaultCloud/origProcId):

/*--------------------------------*- C++ -*----------------------------------*\

| ========= | |

| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox |

| \\ / O peration | Version: v1806 |

| \\ / A nd | Web: www.OpenFOAM.com |

| \\/ M anipulation | |

\*---------------------------------------------------------------------------*/

FoamFile

{

version 2.0;

format ascii;

class labelField;

location "0/lagrangian/defaultCloud";

object origProcId;

}

// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

2{0}

// ************************************************************************* //

Both particles originate in the processor0 region (I only tested this running sequentially, so I

have not checked how this is affected when running in parallel).

Page 35: How to implement an application · 2018-09-13 · CFD with OpenSource Software, 2018 Håkan Nilsson, Chalmers / Mechanics and Maritime Sciences / Fluid Dynamics 3 How to implement

CFD with OpenSource Software, 2018

Håkan Nilsson, Chalmers / Mechanics and Maritime Sciences / Fluid Dynamics 35

Add particles to the interFoam/damBreak casecloudProperties file (0/uniform/lagrangian/defaultCloud/cloudProperties):

/*--------------------------------*- C++ -*----------------------------------*\

| ========= | |

| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox |

| \\ / O peration | Version: v1806 |

| \\ / A nd | Web: www.OpenFOAM.com |

| \\/ M anipulation | |

\*---------------------------------------------------------------------------*/

FoamFile

{

version 2.0;

format ascii;

class dictionary;

location "0/uniform/lagrangian/defaultCloud";

object cloudProperties;

}

// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

geometry positions;

// ************************************************************************* //

I interpret the purpose of this file (for this class) to define if we use a positions file or a

coordinates file for the particle positions. It may be the case that the case set-up would be

simpler with the coordinates option, but I have not checked that up. The class writes out

coordinates files in addition to the positions files in the time directories.

Page 36: How to implement an application · 2018-09-13 · CFD with OpenSource Software, 2018 Håkan Nilsson, Chalmers / Mechanics and Maritime Sciences / Fluid Dynamics 3 How to implement

CFD with OpenSource Software, 2018

Håkan Nilsson, Chalmers / Mechanics and Maritime Sciences / Fluid Dynamics 36

Add particles to the interFoam/damBreak caseParticle properties file (constant/particleProperties):

/*--------------------------------*- C++ -*----------------------------------*\

| ========= | |

| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox |

| \\ / O peration | Version: v1806 |

| \\ / A nd | Web: www.OpenFOAM.com |

| \\/ M anipulation | |

\*---------------------------------------------------------------------------*/

FoamFile

{

version 2.0;

format ascii;

class dictionary;

object particleProperties;

}

// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

rhop rhop [ 1 -3 0 0 0 0 0] 1000;

e e [ 0 0 0 0 0 0 0] 0.8;

mu mu [ 0 0 0 0 0 0 0] 0.2;

// ************************************************************************* //

These are the particle density, and the coefficients of normal and tangential restitution as the

particles hit the walls. The class does not include particle-particle collisions. You would have to

use the kinematicParticle class or some more advanced class.

Page 37: How to implement an application · 2018-09-13 · CFD with OpenSource Software, 2018 Håkan Nilsson, Chalmers / Mechanics and Maritime Sciences / Fluid Dynamics 3 How to implement

CFD with OpenSource Software, 2018

Håkan Nilsson, Chalmers / Mechanics and Maritime Sciences / Fluid Dynamics 37

Add particles to the interFoam/damBreak case

Run and animate using foamToVTK and paraview:

blockMesh

setFields

solidParticleInterFoam 2>&1 | tee log_solidParticleInterFoam

foamToVTK

paraview

• File/open: VTK/solidParticeDamBreak_..vtk

• File/open: VTK/lagrangian/defaultCloud/defaultCloud_..vtk

• For the solidParticleDamBreak object: Display: Opacity 0,3. Color By: alpha.water

(cell values)

• For the defaultCloud object: Create box glyphs (length: 10/10/10, Scale Mode off)

to visualize the particles.

• Run the animation and enjoy...

Note that with the OpenFOAM reader for Paraview distributed with v1806 it is possible to skip

the VTK step and do the same procedure with the Paraview Part lagrangian/defaultCloud.