Ejemplo n.º 1
0
def _createFields(runTime, mesh):

    ref.ext_Info() << "Reading field U\n" << ref.nl
    U = man.volVectorField(
        man.IOobject(ref.word("U"), ref.fileName(runTime.timeName()), mesh,
                     ref.IOobject.MUST_READ, ref.IOobject.AUTO_WRITE), mesh)

    ref.ext_Info() << "Creating face flux\n" << ref.nl
    phi = man.surfaceScalarField(
        man.IOobject(ref.word("phi"), ref.fileName(runTime.timeName()), mesh,
                     ref.IOobject.NO_READ, ref.IOobject.NO_WRITE), mesh,
        ref.dimensionedScalar(ref.word("zero"),
                              mesh.Sf().dimensions() * U.dimensions(), 0.0))

    laminarTransport = man.singlePhaseTransportModel(U, phi)

    turbulence = man.incompressible.RASModel.New(U, phi, laminarTransport)

    transportProperties = man.IOdictionary(
        man.IOobject(ref.word("transportProperties"),
                     ref.fileName(runTime.constant()), mesh,
                     ref.IOobject.MUST_READ, ref.IOobject.NO_WRITE))
    Ubar = ref.dimensionedVector(transportProperties.lookup(ref.word("Ubar")))

    flowDirection = (Ubar / Ubar.mag()).ext_value()
    flowMask = flowDirection.sqr()

    gradP = ref.dimensionedVector(ref.word("gradP"),
                                  ref.dimensionSet(0.0, 1.0, -2.0, 0.0, 0.0),
                                  ref.vector(0.0, 0.0, 0.0))

    return U, phi, laminarTransport, turbulence, Ubar, gradP, flowDirection, flowMask
Ejemplo n.º 2
0
def createGradP( runTime ):
    gradP = ref.dimensionedScalar( ref.word( "gradP" ),
                                   ref.dimensionSet( 0.0, 1.0, -2.0, 0.0, 0.0 ),
                                   0.0 )

    gradPFile = ref.IFstream( runTime.path()/ref.fileName( runTime.timeName() )/ref.fileName( "uniform" )/ ref.fileName( "gradP.raw" ) )
    
    if gradPFile.good():
       gradPFile >> gradP
       ref.ext_Info() << "Reading average pressure gradient" << ref.nl << ref.nl
       pass
    else:
       ref.ext_Info() << "Initializing with 0 pressure gradient" << ref.nl << ref.nl
       pass
    
    return gradP, gradPFile
Ejemplo n.º 3
0
def _createFields( runTime, mesh ):
        
    ref.ext_Info() << "Reading field U\n" << ref.nl
    U = man.volVectorField( man.IOobject( ref.word( "U" ),
                                          ref.fileName( runTime.timeName() ),
                                          mesh,
                                          ref.IOobject.MUST_READ,
                                          ref.IOobject.AUTO_WRITE ),
                            mesh ) 
    
    ref.ext_Info() << "Creating face flux\n" << ref.nl
    phi = man.surfaceScalarField( man.IOobject( ref.word( "phi" ),
                                                ref.fileName( runTime.timeName() ),
                                                mesh,
                                                ref.IOobject.NO_READ,
                                                ref.IOobject.NO_WRITE ),
                                  mesh,
                                  ref.dimensionedScalar( ref.word( "zero" ), mesh.Sf().dimensions()*U.dimensions(), 0.0) )

    
    laminarTransport = man.singlePhaseTransportModel( U, phi )
    
    turbulence = man.incompressible.RASModel.New( U, phi, laminarTransport )
    
    transportProperties = man.IOdictionary( man.IOobject( ref.word( "transportProperties" ),
                                                          ref.fileName( runTime.constant() ),
                                                          mesh,
                                                          ref.IOobject.MUST_READ,
                                                          ref.IOobject.NO_WRITE ) )
    Ubar = ref.dimensionedVector( transportProperties.lookup( ref.word( "Ubar" ) ) )
    
    flowDirection = ( Ubar / Ubar.mag() ).ext_value()
    flowMask = flowDirection.sqr()
    
    gradP = ref.dimensionedVector( ref.word( "gradP" ),
                                   ref.dimensionSet( 0.0, 1.0, -2.0, 0.0, 0.0 ),
                                   ref.vector( 0.0, 0.0, 0.0) )

    
    
              
    return U, phi, laminarTransport, turbulence, Ubar, gradP, flowDirection, flowMask
Ejemplo n.º 4
0
def main_standalone( argc, argv ):

    ref.argList.addBoolOption( ref.word( "writep" ), "write the final pressure field" )
    ref.argList.addBoolOption( ref.word( "initialiseUBCs" ), "initialise U boundary conditions" )
    
    args = ref.setRootCase( argc, argv )

    runTime = man.createTime( args )
    
    mesh = man.createMesh( runTime )
    
    potentialFlow, nNonOrthCorr = readControls( mesh )

    p, U, phi, pRefCell, pRefValue = _createFields( runTime, mesh, potentialFlow,args )

    ref.ext_Info() << ref.nl << "Calculating potential flow" << ref.nl
    
    # Since solver contains no time loop it would never execute
    # function objects so do it ourselves.
    runTime.functionObjects().start()
    
    ref.adjustPhi(phi, U, p)
    
    for nonOrth in range( nNonOrthCorr + 1):
        pEqn = ( ref.fvm.laplacian( ref.dimensionedScalar( ref.word( "1" ), ref.dimTime / p.dimensions() * ref.dimensionSet( 0.0, 2.0, -2.0, 0.0, 0.0 ), 1.0 ), p ) 
                == ref.fvc.div( phi ) )
        
        pEqn.setReference( pRefCell, pRefValue )
        pEqn.solve()

        if nonOrth == nNonOrthCorr:
           phi -= pEqn.flux()
           pass
        pass
    
    ref.ext_Info() << "continuity error = " << ref.fvc.div( phi ).mag().weightedAverage( mesh.V() ).value() << ref.nl

    U << ref.fvc.reconstruct( phi )
    U.correctBoundaryConditions()
    ref.ext_Info() << "Interpolated U error = " << ( ( ( ref.fvc.interpolate( U ) & mesh.Sf() ) - phi ).sqr().sum().sqrt()  /mesh.magSf().sum() ).value() << ref.nl

    # Force the write
    U.write()
    phi.write()
    
    if args.optionFound( ref.word( "writep" ) ):
       p.write()
       pass
       
    runTime.functionObjects().end()
    
    ref.ext_Info() << "ExecutionTime = " << runTime.elapsedCpuTime() << " s" << \
              "  ClockTime = " << runTime.elapsedClockTime() << " s" << ref.nl << ref.nl
        
    ref.ext_Info() << "End\n" << ref.nl 

    import os
    return os.EX_OK
Ejemplo n.º 5
0

# Create time - without reading controlDict from file
# Note - controlDict not written to file using this method
a_controlDict = _createControlDict()

runTime = man.Time(a_controlDict, root, case)

# Create transport properties
transportProperties = ref.IOdictionary(ref.IOobject(ref.word("transportProperties"),
                                                    runTime.caseConstant(),
                                                    runTime,
                                                    ref.IOobject.NO_READ,
                                                    ref.IOobject.NO_WRITE))

nu = ref.dimensionedScalar(ref.word("nu"), ref.dimensionSet(0.0, 2.0, -1.0, 0.0, 0.0, 0.0, 0.0), 1e-6)
transportProperties.add(ref.word("nu"), nu);


# Create fvSchemes and fvSolution dictionaries
fvSchemesDict = createFvSchemesDict(runTime);
fvSoln = createFvSolution(runTime);

# Write all dictionaries to file
# Note, we currently need fvSchemes and fvSolution to reside in the case directory
# since it is used during the solution... so we now write them to file
runTime.writeNow()

# Clean up unused variables
fvSchemesDict = 0
fvSoln = 0
Ejemplo n.º 6
0
    def __init__(self, the_case_dir, the_post_processor=None):
        """
        Constructs instance of this class
        """
        import os, os.path

        #  To identify the canonical pathes of the specified filenames,
        # eliminating any symbolic links encountered in the pathes
        the_case_dir = os.path.realpath(the_case_dir)

        # Definiton of the "root" and OpenFOAM "case"
        a_root_dir, a_case = os.path.split(the_case_dir)
        print_d('a_root_dir = "%s", a_case = "%s"' % (a_root_dir, a_case))

        a_controlDict = self._createControlDict()
        # Create time - without reading controlDict from file
        # Note - controlDict not written to file using this method

        self.run_time = ref.Time(a_controlDict, ref.fileName(a_root_dir), ref.fileName(a_case))

        print_d("self.run_time.caseConstant() = %s" % self.run_time.caseConstant())

        # Create transport properties
        self.transportProperties = ref.IOdictionary(
            ref.IOobject(
                ref.word("transportProperties"),
                self.run_time.caseConstant(),
                self.run_time,
                ref.IOobject.NO_READ,
                ref.IOobject.NO_WRITE,
            )
        )

        nu = ref.dimensionedScalar(ref.word("nu"), ref.dimensionSet(0.0, 2.0, -1.0, 0.0, 0.0, 0.0, 0.0), 1e-6)
        self.transportProperties.add(ref.word("nu"), nu)

        # Create fvSchemes and fvSolution dictionaries
        fvSchemesDict = self._createFvSchemesDict()
        fvSoln = self._createFvSolution()

        # Write all dictionaries to file
        # Note, we currently need fvSchemes and fvSolution to reside in the case directory
        # since it is used during the solution... so we now write them to file
        self.run_time.writeNow()

        # Clean up unused variables
        fvSchemesDict = 0
        fvSoln = 0

        # Create mesh
        self.mesh, self.patches = self._createFvMesh()
        # mesh.write()

        # Create pressure field
        pPatchTypes = pyWordList(["zeroGradient", "fixedValue", "fixedValue", "zeroGradient"])

        a_value = ref.dimensionedScalar(ref.word(), ref.dimensionSet(0.0, 2.0, -2.0, 0.0, 0.0, 0.0, 0.0), 101.325)

        self.p = ref.volScalarField(
            ref.IOobject(
                ref.word("p"),
                ref.fileName(self.run_time.timeName()),
                self.mesh,
                ref.IOobject.NO_READ,
                ref.IOobject.AUTO_WRITE,
            ),
            self.mesh,
            a_value,
            pPatchTypes,
        )

        self.p.ext_boundaryField()[1] << 101.325
        self.p.ext_boundaryField()[2] << 101.325

        # Create velocity field
        UPatchTypes = pyWordList(["fixedValue", "zeroGradient", "zeroGradient", "fixedValue"])

        a_value = ref.dimensionedVector(
            ref.word(), ref.dimensionSet(0.0, 1.0, -1.0, 0.0, 0.0, 0.0, 0.0), ref.vector(0.0, 0.0, 0.0)
        )

        self.U = ref.volVectorField(
            ref.IOobject(
                ref.word("U"),
                ref.fileName(self.run_time.timeName()),
                self.mesh,
                ref.IOobject.NO_READ,
                ref.IOobject.AUTO_WRITE,
            ),
            self.mesh,
            a_value,
            UPatchTypes,
        )

        self.U.ext_boundaryField()[0] << ref.vector(0.0, 0.1, 0.0)
        self.U.ext_boundaryField()[3] << ref.vector(0.0, 0.0, 0.0)

        self.phi = ref.createPhi(self.run_time, self.mesh, self.U)

        # Write all dictionaries to file
        self.run_time.writeNow()

        # Define the post processor engine
        if the_post_processor == None:
            the_post_processor = TDummyPostProcessor
            pass

        # Construction of the post processor engine
        self.post_processor = the_post_processor(the_case_dir, a_case)

        # To dump controlDict to be able to run "foamToVTK" utility
        self._writeControlDict(a_controlDict)

        # Post processing of the first step
        self.post_processor.process(self.run_time.value())

        # Initialization of the engine
        self.solver = icoFoam(self.run_time, self.U, self.p, self.phi, self.transportProperties)
        pass
Ejemplo n.º 7
0
def main_standalone(argc, argv):

    ref.argList.addBoolOption(ref.word("writep"),
                              "write the final pressure field")
    ref.argList.addBoolOption(ref.word("initialiseUBCs"),
                              "initialise U boundary conditions")

    args = ref.setRootCase(argc, argv)

    runTime = man.createTime(args)

    mesh = man.createMesh(runTime)

    potentialFlow, nNonOrthCorr = readControls(mesh)

    p, U, phi, pRefCell, pRefValue = _createFields(runTime, mesh,
                                                   potentialFlow, args)

    ref.ext_Info() << ref.nl << "Calculating potential flow" << ref.nl

    # Since solver contains no time loop it would never execute
    # function objects so do it ourselves.
    runTime.functionObjects().start()

    ref.adjustPhi(phi, U, p)

    for nonOrth in range(nNonOrthCorr + 1):
        pEqn = (ref.fvm.laplacian(
            ref.dimensionedScalar(
                ref.word("1"), ref.dimTime / p.dimensions() *
                ref.dimensionSet(0.0, 2.0, -2.0, 0.0, 0.0), 1.0),
            p) == ref.fvc.div(phi))

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

        if nonOrth == nNonOrthCorr:
            phi -= pEqn.flux()
            pass
        pass

    ref.ext_Info() << "continuity error = " << ref.fvc.div(
        phi).mag().weightedAverage(mesh.V()).value() << ref.nl

    U << ref.fvc.reconstruct(phi)
    U.correctBoundaryConditions()
    ref.ext_Info() << "Interpolated U error = " << (
        ((ref.fvc.interpolate(U) & mesh.Sf()) - phi).sqr().sum().sqrt() /
        mesh.magSf().sum()).value() << ref.nl

    # Force the write
    U.write()
    phi.write()

    if args.optionFound(ref.word("writep")):
        p.write()
        pass

    runTime.functionObjects().end()

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

    ref.ext_Info() << "End\n" << ref.nl

    import os
    return os.EX_OK