Exemplo n.º 1
0
def testCreateField():
    vector1= ref.vector( 1.0,1.0,1.0 )
    vector2= ref.vector( 2.0,2.0,2.0 )

    vector_Field = ref.vectorField( 2 )
    vector_Field[0] = vector1
    vector_Field[1] = vector2
Exemplo n.º 2
0
def testCreateField():
    vector1 = ref.vector(1.0, 1.0, 1.0)
    vector2 = ref.vector(2.0, 2.0, 2.0)

    vector_Field = ref.vectorField(2)
    vector_Field[0] = vector1
    vector_Field[1] = vector2
Exemplo n.º 3
0
def readGravitationalAcceleration(runTime, mesh):
    ref.ext_Info() << "\nReading gravitationalProperties" << ref.nl

    gravitationalProperties = man.IOdictionary(
        man.IOobject(
            ref.word("gravitationalProperties"),
            ref.fileName(runTime.constant()),
            mesh,
            ref.IOobject.MUST_READ_IF_MODIFIED,
            ref.IOobject.NO_WRITE,
        )
    )

    g = ref.dimensionedVector(gravitationalProperties.lookup(ref.word("g")))
    rotating = ref.Switch(gravitationalProperties.lookup(ref.word("rotating")))

    if rotating:
        Omega = ref.dimensionedVector(gravitationalProperties.lookup(ref.word("Omega")))
    else:
        Omega = ref.dimensionedVector(ref.word("Omega"), -ref.dimTime, ref.vector(0, 0, 0))

    magg = g.mag()
    gHat = g / magg

    return gravitationalProperties, g, rotating, Omega, magg, gHat
Exemplo n.º 4
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
Exemplo n.º 5
0
def testFieldIterator():
    vector1 = ref.vector(1.0, 1.0, 1.0)

    vector_Field = ref.vectorField(2)
    vector_Field[0] = vector1
    vector_Field[1] = vector1
    for item in vector_Field:
        eq_(item.x(), vector1.x())
        eq_(item.y(), vector1.y())
        eq_(item.z(), vector1.z())
        pass
Exemplo n.º 6
0
def testFieldIterator():
    vector1= ref.vector( 1.0,1.0,1.0 )

    vector_Field = ref.vectorField( 2 )
    vector_Field[ 0 ] = vector1
    vector_Field[ 1 ] = vector1
    for item in vector_Field:
       eq_(item.x(),vector1.x())
       eq_(item.y(),vector1.y())
       eq_(item.z(),vector1.z())
       pass
def zeroCells(vf, cells):
    from Foam.template import GeometricField

    value = None
    if vf.__class__ == GeometricField(ref.scalar, ref.volMesh) or vf.__class__ == man.GeometricField(
        ref.scalar, ref.volMesh
    ):
        value = 0.0

    if vf.__class__ == GeometricField(ref.vector, ref.volMesh) or vf.__class__ == man.GeometricField(
        ref.vector, ref.volMesh
    ):
        value = ref.vector(0.0, 0.0, 0.0)

    for element in range(cells.size()):
        vf[cells[element]] = value
        pass
    pass
def zeroCells(vf, cells):
    from Foam.template import GeometricField

    value = None
    if vf.__class__ == GeometricField(
            ref.scalar, ref.volMesh) or vf.__class__ == man.GeometricField(
                ref.scalar, ref.volMesh):
        value = 0.0

    if vf.__class__ == GeometricField(
            ref.vector, ref.volMesh) or vf.__class__ == man.GeometricField(
                ref.vector, ref.volMesh):
        value = ref.vector(0.0, 0.0, 0.0)

    for element in range(cells.size()):
        vf[cells[element]] = value
        pass
    pass
Exemplo n.º 9
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
Exemplo n.º 10
0
def readGravitationalAcceleration(runTime, mesh):
    ref.ext_Info() << "\nReading gravitationalProperties" << ref.nl

    gravitationalProperties = man.IOdictionary(
        man.IOobject(ref.word("gravitationalProperties"),
                     ref.fileName(runTime.constant()), mesh,
                     ref.IOobject.MUST_READ_IF_MODIFIED,
                     ref.IOobject.NO_WRITE))

    g = ref.dimensionedVector(gravitationalProperties.lookup(ref.word("g")))
    rotating = ref.Switch(gravitationalProperties.lookup(ref.word("rotating")))

    if rotating:
        Omega = ref.dimensionedVector(
            gravitationalProperties.lookup(ref.word("Omega")))
    else:
        Omega = ref.dimensionedVector(ref.word("Omega"), -ref.dimTime,
                                      ref.vector(0, 0, 0))

    magg = g.mag()
    gHat = g / magg

    return gravitationalProperties, g, rotating, Omega, magg, gHat
Exemplo n.º 11
0
                        ref.dimensionedScalar(ref.word(), ref.dimensionSet(0.0, 2.0, -2.0, 0.0, 0.0, 0.0, 0.0), 101.325),
                        pPatchTypes )

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

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

U = man.volVectorField ( man.IOobject( ref.word("U"),
                                       ref.fileName(runTime.timeName()),
                                       mesh,
                                       ref.IOobject.NO_READ,
                                       ref.IOobject.AUTO_WRITE),
                         mesh,
                         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 ) ),
                         UPatchTypes )

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

phi = man.createPhi( runTime, mesh, U )

# Write all dictionaries to file
runTime.writeNow()

from icoFlux.embedded import solver as icoFoam
icoSolver = icoFoam(runTime, U, p, phi, transportProperties)

pRes = [] #initial pressure residual
uRes = [] #initial velocity residual
Exemplo n.º 12
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