Skip to content

mayaviFoam: A postprocessing script for OpenFOAM

April 21, 2011

mayaviFoam:

Hi, I have created a Postprocessing script called mayaviFoam. It is the a reader module to run with Mayavi2, an open-source, visualization application. It will convert OpenFOAM natural data format into VTK data format and the VTK data is loaded into Mayavi2 using VTKFileReader.

#!/usr/bin/env mayavi2

import os
import glob
from os.path import join, abspath, dirname
from enthought.mayavi.scripts import mayavi2
from enthought.mayavi.sources.vtk_file_reader import VTKFileReader
from enthought.mayavi.modules.surface import Surface

def setup_data(fname):
    """Given a VTK file name `fname`, this creates a mayavi2
    reader for it and adds it to the pipeline.  It returns the reader
    created.
    """
    r = VTKFileReader()
    r.initialize(fname)
    mayavi.add_source(r)
    return r

def surface():
    """Sets up the mayavi pipeline for the visualization.
    """
    # Create an outline for the data.
    s = Surface()
    mayavi.add_module(s)

def load_vtk_file():
    mayavi.new_scene()
    filepath = glob.glob("VTK/*_0.vtk")
    vtk_file_name = os.path.basename(filepath[0])
    data_dir = "VTK"
    fname = join(data_dir, vtk_file_name)
    r = setup_data(fname)
    surface()

@mayavi2.standalone
def main():
    if os.path.exists("VTK"):
        load_vtk_file()

    else:
        os.system('foamToVTK -ascii')
        load_vtk_file()

if __name__ == '__main__':
    main()

Save it as mayaviFoam.py

Procedure:

Open your terminal
1.

cd openfoam_tutorials/multiphase/interFoam/laminar/damBreak

2.

blockMesh

3.

setFields

4. Refere here

python dambreak.py

5.

python mayaviFoam.py

See the output like below

Dambreak simulation using OpenFOAM, Pythonflu, Mayavi2

April 17, 2011

In this tutorial am going to demonstrate dambreak simulation using Openfoam, pythonflu, mayavi2 in Ubuntu 10.10.

Install following required package

1. OpenFOAM (see the link: https://dhastha.wordpress.com/2011/03/28/openfoam-introduction/)

2. Mayavi2 (link: https://dhastha.wordpress.com/2010/12/18/mayavi2-introduction/)

3. Pythonflu (link: https://dhastha.wordpress.com/2011/04/17/pythonflu-intro/)

copy  /opt/openfoam171/tutorials  into specified folder.

Open your terminal and type

cd tutorials/multiphase/interFoam/laminar/damBreak

then type following commands

blockMesh

setFields

Copy the following python code and run it as “python dambreak.py”

#!/usr/bin/env python

#----------------------------------------------------------------------------
def _createFields( runTime, mesh ):
    from Foam.OpenFOAM import ext_Info, nl
    from Foam.OpenFOAM import IOdictionary, IOobject, word, fileName
    from Foam.finiteVolume import volScalarField
        
    ext_Info() << "Reading field p\n" << nl
    p_rgh = volScalarField( IOobject( word( "p_rgh" ),
                                  fileName( runTime.timeName() ),
                                  mesh,
                                  IOobject.MUST_READ,
                                  IOobject.AUTO_WRITE ),
                        mesh )
    
    ext_Info() << "Reading field alpha1\n" << nl
    alpha1 = volScalarField( IOobject( word( "alpha1" ),
                                  fileName( runTime.timeName() ),
                                  mesh,
                                  IOobject.MUST_READ,
                                  IOobject.AUTO_WRITE ),
                                mesh )
    
    ext_Info() << "Reading field U\n" << nl
    from Foam.finiteVolume import volVectorField
    U = volVectorField( IOobject( word( "U" ),
                                  fileName( runTime.timeName() ),
                                  mesh,
                                  IOobject.MUST_READ,
                                  IOobject.AUTO_WRITE ),
                        mesh )
                        
    from Foam.finiteVolume.cfdTools.incompressible import createPhi
    phi = createPhi( runTime, mesh, U )
    
    
    ext_Info() << "Reading transportProperties\n" << nl
    from Foam.transportModels import twoPhaseMixture
    twoPhaseProperties = twoPhaseMixture(U, phi)
    
    rho1 = twoPhaseProperties.rho1()
    rho2 = twoPhaseProperties.rho2()
    
    # Need to store rho for ddt(rho, U)
    rho = volScalarField( IOobject( word( "rho" ),
                                    fileName( runTime.timeName() ),
                                    mesh,
                                    IOobject.READ_IF_PRESENT ),
                          alpha1 * rho1 + ( 1.0 - alpha1 ) * rho2,
                          alpha1.ext_boundaryField().types() )
    rho.oldTime()
    
    # Mass flux
    # Initialisation does not matter because rhoPhi is reset after the
    # alpha1 solution before it is used in the U equation.
    from Foam.finiteVolume import surfaceScalarField
    rhoPhi = surfaceScalarField( IOobject( word( "rho*phi" ),
                                           fileName( runTime.timeName() ),
                                           mesh,
                                           IOobject.NO_READ,
                                           IOobject.NO_WRITE ),
                                 rho1 * phi )
    
    # Construct interface from alpha1 distribution
    from Foam.transportModels import interfaceProperties
    interface = interfaceProperties( alpha1, U, twoPhaseProperties )


    # Construct incompressible turbulence model
    from Foam import incompressible
    turbulence = incompressible.turbulenceModel.New( U, phi, twoPhaseProperties ) 
    
    from Foam.finiteVolume.cfdTools.general.include import readGravitationalAcceleration
    g = readGravitationalAcceleration( runTime, mesh)

    
    #dimensionedVector g0(g);

    #Read the data file and initialise the interpolation table
    #interpolationTable timeSeriesAcceleration( runTime.path()/runTime.caseConstant()/"acceleration.dat" );
    
    ext_Info() << "Calculating field g.h\n" << nl
    gh = volScalarField( word( "gh" ), g & mesh.C() )
    ghf = surfaceScalarField( word( "ghf" ), g & mesh.Cf() )
    
    p = volScalarField( IOobject( word( "p" ),
                        fileName( runTime.timeName() ),
                        mesh,
                        IOobject.NO_READ,
                        IOobject.AUTO_WRITE ),
                        p_rgh + rho * gh )

    pRefCell = 0
    pRefValue = 0.0
    
    from Foam.finiteVolume import setRefCell, getRefCellValue
    pRefCell, pRefValue = setRefCell( p, mesh.solutionDict().subDict( word( "PISO" ) ), pRefCell, pRefValue )
    
    if p_rgh.needReference():
       p.ext_assign( p + dimensionedScalar( word( "p" ),
                                           p.dimensions(),
                                           pRefValue - getRefCellValue(p, pRefCell) ) )
       p_rgh.ext_assign( p - rho * gh )
       pass

    return p_rgh, p, alpha1, U, phi, rho1, rho2, rho, rhoPhi, twoPhaseProperties, pRefCell, pRefValue, interface, turbulence, g, gh, ghf
    

#--------------------------------------------------------------------------------------
def setDeltaT( runTime, adjustTimeStep, maxCo, CoNum, maxAlphaCo, alphaCoNum, maxDeltaT ):
    from Foam.OpenFOAM import SMALL
    if adjustTimeStep:
       maxDeltaTFact = min( maxCo / ( CoNum + SMALL ), maxAlphaCo / ( alphaCoNum + SMALL ) )
       deltaTFact = min(min(maxDeltaTFact, 1.0 + 0.1*maxDeltaTFact), 1.2);
       
       runTime.setDeltaT( min( deltaTFact * runTime.deltaT().value(), maxDeltaT ) )
       from Foam.OpenFOAM import ext_Info, nl
       ext_Info() << "deltaT = " <<  runTime.deltaT().value() << nl
       pass
    return runTime


#--------------------------------------------------------------------------------------
def alphaCourantNo( runTime, mesh, alpha1, phi ):
    from Foam.OpenFOAM import readScalar, word
    maxAlphaCo = readScalar( runTime.controlDict().lookup(word( "maxAlphaCo" ) ) )
    
    alphaCoNum = 0.0
    meanAlphaCoNum = 0.0
    
    if mesh.nInternalFaces():
       from Foam import fvc
       alphaf = fvc.interpolate(alpha1)

       SfUfbyDelta = (alphaf - 0.01).pos() * ( 0.99 - alphaf ).pos() * mesh.deltaCoeffs() * phi.mag()
       alphaCoNum = ( SfUfbyDelta/mesh.magSf() ).ext_max().value() * runTime.deltaT().value()
       meanAlphaCoNum = ( SfUfbyDelta.sum() / mesh.magSf().sum() ).value() * runTime.deltaT().value()
       pass
    
    from Foam.OpenFOAM import ext_Info, nl
    ext_Info() << "Interface Courant Number mean: " << meanAlphaCoNum << " max: " << alphaCoNum << nl
    
    return maxAlphaCo, alphaCoNum, meanAlphaCoNum


#----------------------------------------------------------------------------------------
def correctPhi( runTime, mesh, phi, p, p_rgh, rho, U, cumulativeContErr, nNonOrthCorr, pRefCell, pRefValue ):
    
    from Foam.finiteVolume.cfdTools.incompressible import continuityErrs
    cumulativeContErr = continuityErrs( mesh, phi, runTime, cumulativeContErr )
    from Foam.OpenFOAM import wordList
    from Foam.finiteVolume import zeroGradientFvPatchScalarField
    pcorrTypes = wordList( p_rgh.ext_boundaryField().size(), zeroGradientFvPatchScalarField.typeName )
    
    from Foam.finiteVolume import fixedValueFvPatchScalarField
    for i in range( p.ext_boundaryField().size() ):
       if p_rgh.ext_boundaryField()[i].fixesValue():
          pcorrTypes[i] = fixedValueFvPatchScalarField.typeName
          pass
       pass
    
    from Foam.OpenFOAM import IOdictionary, IOobject, word, fileName, dimensionedScalar
    from Foam.finiteVolume import volScalarField
    pcorr = volScalarField( IOobject( word( "pcorr" ),
                                      fileName( runTime.timeName() ),
                                      mesh,
                                      IOobject.NO_READ,
                                      IOobject.NO_WRITE ),
                            mesh,
                            dimensionedScalar( word( "pcorr" ), p_rgh.dimensions(), 0.0 ),
                            pcorrTypes  )
    
    from Foam.OpenFOAM import dimTime
    rAUf = dimensionedScalar( word( "(1|A(U))" ), dimTime / rho.dimensions(), 1.0)
    
    from Foam.finiteVolume import adjustPhi
    adjustPhi(phi, U, pcorr)
    
    from Foam import fvc, fvm
    for nonOrth in range( nNonOrthCorr + 1 ):
        pcorrEqn = fvm.laplacian( rAUf, pcorr ) == fvc.div( phi )

        pcorrEqn.setReference(pRefCell, pRefValue)
        pcorrEqn.solve()

        if nonOrth == nNonOrthCorr:
           phi.ext_assign( phi  - pcorrEqn.flux() )
           pass
    
    from Foam.finiteVolume.cfdTools.incompressible import continuityErrs
    cumulativeContErr = continuityErrs( mesh, phi, runTime, cumulativeContErr )
    
    pass
    

#--------------------------------------------------------------------------------------
def alphaEqn( mesh, phi, alpha1, rhoPhi, rho1, rho2, interface, nAlphaCorr ):
    from Foam.OpenFOAM import word 
    alphaScheme = word( "div(phi,alpha)" )
    alpharScheme = word( "div(phirb,alpha)" )
    
    from Foam.finiteVolume import surfaceScalarField
    phic = surfaceScalarField( ( phi / mesh.magSf() ).mag() )
    phic.ext_assign( ( interface.cAlpha() * phic ).ext_min( phic.ext_max() ) )
    phir = phic * interface.nHatf()
    
    from Foam import fvc
    from Foam import MULES

    for aCorr in range( nAlphaCorr ):
       phiAlpha = fvc.flux( phi, alpha1, alphaScheme ) + fvc.flux( -fvc.flux( -phir, 1.0 - alpha1, alpharScheme ), alpha1, alpharScheme )
       MULES.explicitSolve( alpha1, phi, phiAlpha, 1, 0 )
       
       rhoPhi.ext_assign( phiAlpha * ( rho1 - rho2 ) + phi * rho2 )

       pass
    from Foam.OpenFOAM import ext_Info, nl
    ext_Info() << "Liquid phase volume fraction = " << alpha1.weightedAverage( mesh.V() ).value() \
               << "  Min(alpha1) = " << alpha1.ext_min().value() \
               << "  Max(alpha1) = " << alpha1.ext_max().value() < 1):
       totalDeltaT = runTime.deltaT()
       rhoPhiSum = 0.0 * rhoPhi
       from Foam.finiteVolume import subCycle_volScalarField
       alphaSubCycle = subCycle_volScalarField(alpha1, nAlphaSubCycles)
       for item in alphaSubCycle: 
           alphaEqn( mesh, phi, alpha1, rhoPhi, rho1, rho2, interface, nAlphaCorr )
           rhoPhiSum.ext_assign( rhoPhiSum + ( runTime.deltaT() / totalDeltaT ) * rhoPhi )
           pass
       # To make sure that variable in the local scope will be destroyed
       # - during destruction of this variable it performs some important actions
       # - there is a difference between C++ and Python memory management, namely
       # if C++ automatically destroys stack variables when they exit the scope,
       # Python relay its memory management of some "garbage collection" algorithm
       # that do not provide predictable behavior on the "exit of scope"
       del alphaSubCycle
       
       rhoPhi.ext_assign( rhoPhiSum )
    else:
       alphaEqn( mesh, phi, alpha1, rhoPhi, rho1, rho2, interface, nAlphaCorr )
       pass
    interface.correct()
    
    rho == alpha1 * rho1 + ( 1.0 - alpha1 ) * rho2

    pass


#--------------------------------------------------------------------------------------
def _UEqn( mesh, alpha1, U, p, p_rgh, ghf, rho, rhoPhi, turbulence, g, twoPhaseProperties, interface, momentumPredictor ):
    from Foam.OpenFOAM import word
    from Foam.finiteVolume import surfaceScalarField
    from Foam import fvc
    muEff = surfaceScalarField( word( "muEff" ),
                                twoPhaseProperties.muf() + fvc.interpolate( rho * turbulence.ext_nut() ) )
    from Foam import fvm

    UEqn = fvm.ddt( rho, U ) + fvm.div( rhoPhi, U ) - fvm.laplacian( muEff, U ) - ( fvc.grad( U ) & fvc.grad( muEff ) )
    
    UEqn.relax()

    if momentumPredictor:
       from Foam.finiteVolume import solve
       solve( UEqn == \
                   fvc.reconstruct( ( fvc.interpolate( interface.sigmaK() ) * fvc.snGrad( alpha1 ) - ghf * fvc.snGrad( rho ) \
                                                                                                 - fvc.snGrad( p_rgh ) ) * mesh.magSf() ) )
       pass
    
    return UEqn


#--------------------------------------------------------------------------------------
def _pEqn( runTime, mesh, UEqn, U, p, p_rgh, gh, ghf, phi, alpha1, rho, g, interface, corr, nCorr, nNonOrthCorr, pRefCell, pRefValue, cumulativeContErr ):
    rAU = 1.0/UEqn.A()
     
    from Foam import fvc
    rAUf = fvc.interpolate( rAU )
    
    U.ext_assign( rAU * UEqn.H() )
    
    from Foam.finiteVolume import surfaceScalarField
    from Foam.OpenFOAM import word
    phiU = surfaceScalarField( word( "phiU" ),
                               ( fvc.interpolate( U ) & mesh.Sf() ) + fvc.ddtPhiCorr( rAU, rho, U, phi ) )
                               
    from Foam.finiteVolume import adjustPhi
    adjustPhi(phiU, U, p)
    
    phi.ext_assign( phiU + ( fvc.interpolate( interface.sigmaK() ) * fvc.snGrad( alpha1 ) - ghf * fvc.snGrad( rho ) )*rAUf*mesh.magSf() )

    from Foam import fvm
    for nonOrth in range( nNonOrthCorr + 1 ):
        p_rghEqn = fvm.laplacian( rAUf, p_rgh ) == fvc.div( phi ) 
        p_rghEqn.setReference( pRefCell, pRefValue )

        p_rghEqn.solve( mesh.solver( p_rgh.select(corr == nCorr-1 and nonOrth == nNonOrthCorr) ) )
        
        if nonOrth == nNonOrthCorr:
           phi.ext_assign( phi - p_rghEqn.flux() )
           pass
        pass
    
    U.ext_assign( U + rAU * fvc.reconstruct( ( phi - phiU ) / rAUf ) )
    U.correctBoundaryConditions()

    from Foam.finiteVolume.cfdTools.incompressible import continuityErrs
    cumulativeContErr = continuityErrs( mesh, phi, runTime, cumulativeContErr )
    
    p == p_rgh + rho * gh

    if p_rgh.needReference():
       from Foam.OpenFOAM import pRefValue
       p.ext_assign( p + dimensionedScalar( word( "p" ),
                                            p.dimensions(),
                                            pRefValue - getRefCellValue(p, pRefCell) ) )
       p_rgh.ext_assign( p - rho * gh )
       pass
    pass
    
    
#--------------------------------------------------------------------------------------
def main_standalone( argc, argv ):

    from Foam.OpenFOAM.include import setRootCase
    args = setRootCase( argc, argv )

    from Foam.OpenFOAM.include import createTime
    runTime = createTime( args )

    from Foam.OpenFOAM.include import createMesh
    mesh = createMesh( runTime )
    
    from Foam.finiteVolume.cfdTools.general.include import readPISOControls
    piso, nCorr, nNonOrthCorr, momentumPredictor, transonic, nOuterCorr = readPISOControls( mesh )
    
    from Foam.finiteVolume.cfdTools.general.include import initContinuityErrs
    cumulativeContErr = initContinuityErrs()
    
    p_rgh, p, alpha1, U, phi, rho1, rho2, rho, rhoPhi, twoPhaseProperties, pRefCell, \
                                    pRefValue, interface, turbulence, g, gh, ghf = _createFields( runTime, mesh )

    from Foam.finiteVolume.cfdTools.general.include import readTimeControls
    adjustTimeStep, maxCo, maxDeltaT = readTimeControls( runTime )
    
    correctPhi( runTime, mesh, phi, p, p_rgh, rho, U, cumulativeContErr, nNonOrthCorr, pRefCell, pRefValue)
    
    from Foam.finiteVolume.cfdTools.incompressible import CourantNo
    CoNum, meanCoNum = CourantNo( mesh, phi, runTime )
    
    from Foam.finiteVolume.cfdTools.general.include import setInitialDeltaT
    runTime = setInitialDeltaT( runTime, adjustTimeStep, maxCo, maxDeltaT, CoNum )
    
    from Foam.OpenFOAM import ext_Info, nl
    ext_Info() << "\nStarting time loop\n" << nl
    
    while runTime.run() :
                
        piso, nCorr, nNonOrthCorr, momentumPredictor, transonic, nOuterCorr = readPISOControls( mesh )
        adjustTimeStep, maxCo, maxDeltaT = readTimeControls( runTime )
        CoNum, meanCoNum = CourantNo( mesh, phi, runTime )        
        maxAlphaCo, alphaCoNum, meanAlphaCoNum = alphaCourantNo( runTime, mesh, alpha1, phi )
        runTime = setDeltaT(  runTime, adjustTimeStep, maxCo, CoNum, maxAlphaCo, alphaCoNum, maxDeltaT )
        
        runTime.increment()
        ext_Info() << "Time = " << runTime.timeName() << nl << nl
        
        twoPhaseProperties.correct()
     
        alphaEqnSubCycle( runTime, piso, mesh, phi, alpha1, rho, rhoPhi, rho1, rho2, interface )
        
        UEqn = _UEqn( mesh, alpha1, U, p, p_rgh, ghf, rho, rhoPhi, turbulence, g, twoPhaseProperties, interface, momentumPredictor )

        # --- PISO loop
        for corr in range( nCorr ):
            _pEqn( runTime, mesh, UEqn, U, p, p_rgh, gh, ghf, phi, alpha1, rho, g, interface, corr, nCorr, nNonOrthCorr, pRefCell, pRefValue, cumulativeContErr )
            pass
        
        from Foam.finiteVolume.cfdTools.incompressible import continuityErrs
        cumulativeContErr = continuityErrs( mesh, phi, runTime, cumulativeContErr )

        turbulence.correct()

        runTime.write()

        ext_Info() << "ExecutionTime = " << runTime.elapsedCpuTime() << " s" << \
              "  ClockTime = " << runTime.elapsedClockTime() << " s" << nl << nl
        
        pass

    ext_Info() << "End\n" <=", "010700" ):
   if __name__ == "__main__" :
      argv = sys.argv
      if len( argv ) > 1 and argv[ 1 ] == "-test":
         argv = None
         test_dir= os.path.join( os.environ[ "PYFOAM_TESTING_DIR" ],'cases', 'propogated', 'r1.7.0',  'multiphase','interFoam', 'laminar', 'damBreak' )
         argv = [ __file__, "-case", test_dir ]
         pass
      os._exit( main_standalone( len( argv ), argv ) )


#--------------------------------------------------------------------------------------

then convert the openfoam data into VTK data by typing following command

foamToVTK

It will create a VTK files. then

cd VTK
mayavi2 damBreak_0.vtk

It will load vtk files into mayavi2. Then add surface module

select Visualize->Modules->Surface

Use Mayavi object editor to change various timestep and see the instance changes

Followings are the images at different timestep

Pythonflu: Intro

April 17, 2011
Pythonflu:

Pythonflu is a python front-end to OpenFOAM(Open source CFD toolbox). It indent to define a new level of flexibility and user interaction scenario for numerical simulation software.

Installation from binaries
  • Identify the following installation parameters :
    • OpenFOAM version you have ( 1.7.1 or 1.6-ext )
    • Linux distribution you use ( OpenSUSE 11.3Ubuntu Maverick or Lucid )
    • CPU type you posses ( i386 or amd64 )
  • Make sure you have already installed corresponding version of OpenFOAM binary package (OpenCFD or Extended)
  • Choose and download proper pythonFlu binary package from SourceForge
  • Run the native package manager on the target package :
sudo rpm -i <URL to pythonFlu binary package>.rpm # for OpenSUSE
sudo dpkg --install <path pythonFlu binary package>.deb # for Ubuntu
User Configuration

Before using pythonFlu do not forget to configure OpenFOAM itself

source /opt/openfoam171/etc/bashrc # for OpenCFD OpenFOAM-1.7.1
source /usr/lib/OpenFOAM-1.6-ext/etc/bashrc # for Extended OpenFOAM-1.6
Getting Started

Create a working directory dedicated to the installed version of OpenFOAM:

mkdir -p ${FOAM_RUN}

Copy the tutorial examples directory from the OpenFOAM distribution to your working directory :

cp -r ${FOAM_TUTORIALS} ${FOAM_RUN}

Run the first example case of incompressible laminar flow in a cavity:

cd ${FOAM_RUN}/tutorials/incompressible/icoFoam/cavity
blockMesh
icoFlux

					

PyFoam: Installation

April 11, 2011

Pre-requisites

* Make sure that OpenFOAM is installed (http://www.openfoam.com/download/ubuntu.php)

* Make sure that Python installed

* Install Boost library (

sudo apt-get install libboost-dev libboost-doc

)

Then follow the instructions below in order to build and install the “pyFoam” – Python  OpenFOAM binding.

Basic Installation

Current version (0.5.5)

  1. Untar it
  2. Go to the directory PyFoam-0.5.5
  3. Install it with the command
 
python setup.py install

Testing the installation

To test whether the installation of PyFoam is working start the interactive Python shell with

 
python

(The shell can be left with Control-D). In that shell type

 
import PyFoam
import PyFoam.FoamInformation
print PyFoam.FoamInformation.foamTutorials()

If the last command produces an output similar to

 
/home/nonroot/OpenFOAM/OpenFOAM-1.2-devel/tutorials

everything is well.

pyFoam: an Introduction

April 11, 2011

PyFoam

pyFoam is a Python front-end to the OpenFOAM (Open Source CFD Toolbox). pyFoam intends to define a new level of flexibility and user interaction scenario for numerical simulation software; it brings innovative ideas to break the long-standing wall between the solver developers and the end-users.

– If you are a careful analyst, you will be able easily understand what your solver is doing and why.

– If you are an experienced guy, it will provide you the full control over the solver execution – you will be able to

* couple different solvers you have,

* write customization subroutines,

* define your benchmarking and pre/post processing procedures.

– If you are a solver developer, you will clearly understand why users need all this features; users will be able to adopt your code to their needs even without you!

– If you are thoughtful project manager, you will appreciate this software because it increases team productivity by

* alignment of the user experience communication; solver developers and end-users will speak in the same terms and in the same language

* ability to formalize and automate most of the analyst tasks as well, as quickly be adopted to new non-standard demands

* improving quality of the calculations, because through this software your team will obtain not just solver engines, but the general way to standardize your routines

* applying the best software for every subtask you do; pyFoam will be able glue them all into one application / environment.

 

Why Python

– Python is mostly used in scientific and engineering programming

– Python code is easy to read, understand and learn to program

– Python support all the modern programming features

– Python code is typically 5-10 times shorter than equivalent C++ code

– Python programmer can finish in two months what two C++ programmers can’t complete in a year

– Python comes with a vast collection of libraries (as standard, as third-party)

– Object Oriented Programming (classes, inheritance, virtual functions e.t.c)

– Operators customization (user can write your own definition for ‘+’ or ‘-‘)

– Exception based error handling

 

Why OpenFOAM

In principle, the technology pyFoamuses (SWIG) to deliver its functionality, can be applied to any library and solver framework. At the same time pyFoam choose OpenFOAM as its source by the following reasons:

– OpenFOAM uses advanced, robust and proven numerical simulation engine

– OpenFoam allows the user to use syntax that closely resemble the partial
differential equations being solved. For example:

solve( fvm.ddt( rho, U ) + fvm.div( phi, U ) – fvm.laplacian( mu, U )  == – fvc.grad( p ) )

– It comes with a growing collection of pre-written solvers applicable to a wide range of problems

– First and most capable general purpose CFD package to be released under an open-source license

 

OpenFOAM: Introduction

March 28, 2011

OpenFOAM:

OpenFOAM (Open Field Operation and Manipulation) is primarily a C++ toolbox for the customisation and extension of numerical solvers for continuum mechanics problems, including computational fluid dynamics (CFD).

Capabilities of OpenFOAM:

It has

  • a plugin (paraFoam) for visualisation of solution data and meshes in ParaView.
  • a wide range of mesh converters allowing import from a number of leading commercial packages
  • an automatic hexahedral mesher to mesh engineering configurations

It also comes with a library and solvers for efficiently tracking particles in a multiphase flow using the lagrangian approach.

Standard Solvers include:

  • Basic CFD
  • Incompressible flows
  • Compressible flows
  • Multiphase flows
  • DNS and LES
  • Particle-tracking flows
  • Combustion
  • Heat transfer
  • Molecular dynamics
  • Direct simulation Monte Carlo
  • Electromagnetics
  • Solid dynamics
  • Finance

How to install in Ubuntu:

OpenFOAM and Paraview are currently available for the following versions of Ubuntu:

  • 10.04 LTS, codename lucid
  • 10.10, codename maverick

Installation

OpenFOAM and Paraview can be simply installed using the apt package management tool. The user will need to provide superuser password authentication when executing the following commands with sudo

  1. In a terminal window, add OpenFOAM to the list of repository locations for apt to search, by copying and pasting the following in a terminal prompt (Applications -> Accessories -> Terminal):
    VERS=`grep CODENAME /etc/lsb-release | cut -d= -f2`
    sudo sh -c “echo deb http://www.openfoam.com/download/ubuntu $VERS main >> /etc/apt/sources.list&#8221;
    • Note 1: Line 1 stores the version name of your Ubuntu distribution (e.g. maverick) under $VERS, which is used in line 2
    • Note 2: This only needs to be done once for a given system
  2. Update the apt package list to account for the new download repository location
    sudo apt-get update
  3. Install OpenFOAM (171 in the name refers to version 1.7.1):
    sudo apt-get install openfoam171
  4. Install Paraview (381 in the name refers to version 3.8.1):
    sudo apt-get install paraviewopenfoam381

OpenFOAM-1.7.1 and Paraview-3.8.1 are now installed in the /opt directory.

User Configuration

In order to use the installed OpenFOAM package, complete the following

  1. Open the .bashrc file in the user’s home directory in an editor, e.g. by typing in a terminal window (note the dot)
    gedit ~/.bashrc
  2. At the bottom of that file, add the following line 1   \relax \special {t4ht= (note the dot) and save the file
    . /opt/openfoam171/etc/bashrc
  3. This change to the .bashrc file will be
    . ~/.bashrc
  4. Open a new2   \relax \special {t4ht= terminal window and test that the icoFoam application, from the OpenFOAM package, is working by typing
    icoFoam -help
  5. A “Usage” message should appear. Your installation and user configuration is complete.

Getting Started

Create a project directory within the $HOME/OpenFOAM directory named <USER>-1.7.1 (e.g. chris-1.7.1 for user chris and OpenFOAM version 1.7.1) and create a directory named run within it, e.g. by typing:

  • mkdir -p $FOAM_RUN

Copy the tutorial examples directory in the OpenFOAM distribution to the run directory. If the OpenFOAM environment variables are set correctly, then the following command will be correct:

  • cp -r $FOAM_TUTORIALS $FOAM_RUN

Run the first example case of incompressible laminar flow in a cavity:

  • cd $FOAM_RUN/tutorials/incompressible/icoFoam/cavity
  • blockMesh
  • icoFoam
  • paraFoam

Fluid visualization and Methods

March 11, 2011

Visualization:

This term refers to presenting data and summary information using graphics, animation, 3-D displays.

Fluid Visualization:

It is used to make the flow pattern visible in order to get qualitative or quantitative information on fluids

Method of Fluid visualization:

1. Surface flow visualization

It is the visualization of the interaction of fluid flow with solid body


2. Particle tracer method

Particles, such as smoke or ink, can be added to a flow to trace the fluid motion


3. Optical method

Some flows reveal their patterns by way of changes in their optical refractive index. These are visualized by optical methods known as the shadowgraph, schlieren photography, and interferometry.