Example #1
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
Example #2
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
Example #3
0
def _createFields(runTime, mesh, potentialFlow):

    ref.ext_Info() << "Reading field p\n" << ref.nl
    p = man.volScalarField(
        man.IOobject(
            ref.word("p"), ref.fileName(runTime.timeName()), mesh, ref.IOobject.MUST_READ, ref.IOobject.NO_WRITE
        ),
        mesh,
    )

    p << ref.dimensionedScalar(ref.word("zero"), p.dimensions(), 0.0)

    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,
    )

    U << ref.dimensionedVector(ref.word("0"), U.dimensions(), ref.vector.zero)

    phi = man.surfaceScalarField(
        man.IOobject(
            ref.word("phi"), ref.fileName(runTime.timeName()), mesh, ref.IOobject.NO_READ, ref.IOobject.AUTO_WRITE
        ),
        man.fvc.interpolate(U) & man.surfaceVectorField(mesh.Sf(), man.Deps(mesh)),
    )

    pRefCell = 0
    pRefValue = 0.0

    pRefCell, pRefValue = ref.setRefCell(p, potentialFlow, pRefCell, pRefValue)

    return p, U, phi, pRefCell, pRefValue
Example #4
0
def _createFields(runTime, mesh, potentialFlow, args):

    ref.ext_Info() << "Reading field p\n" << ref.nl
    p = man.volScalarField(
        man.IOobject(ref.word("p"), ref.fileName(runTime.timeName()), mesh,
                     ref.IOobject.MUST_READ, ref.IOobject.NO_WRITE), mesh)

    p << ref.dimensionedScalar(ref.word("zero"), p.dimensions(), 0.0)

    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)

    U << ref.dimensionedVector(ref.word("0"), U.dimensions(), ref.vector.zero)

    phi = man.surfaceScalarField(
        man.IOobject(ref.word("phi"), ref.fileName(runTime.timeName()), mesh,
                     ref.IOobject.NO_READ, ref.IOobject.AUTO_WRITE),
        man.fvc.interpolate(U)
        & man.surfaceVectorField(mesh.Sf(), man.Deps(mesh)))

    if args.optionFound(ref.word("initialiseUBCs")):
        U.correctBoundaryConditions()
        phi << (ref.fvc.interpolate(U) & mesh.Sf())
        pass

    pRefCell = 0
    pRefValue = 0.0

    pRefCell, pRefValue = ref.setRefCell(p, potentialFlow, pRefCell, pRefValue)

    return p, U, phi, pRefCell, pRefValue
Example #5
0
def _createFields(runTime, mesh, Omega, gHat):

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

    ref.ext_Info() << "Reading field h0 if present\n" << ref.nl
    h0 = man.volScalarField(
        man.IOobject(
            ref.word("h0"),
            ref.fileName(runTime.findInstance(ref.fileName(ref.word("polyMesh")), ref.word("points"))),
            mesh,
            ref.IOobject.READ_IF_PRESENT,
        ),
        mesh,
        ref.dimensionedScalar(ref.word("h0"), ref.dimLength, 0.0),
    )

    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 field hU\n" << ref.nl
    hU = man.volVectorField(
        man.IOobject(ref.word("hU"), ref.fileName(runTime.timeName()), mesh), h * U, U.ext_boundaryField().types()
    )

    ref.ext_Info() << "Creating field hTotal for post processing\n" << ref.nl
    hTotal = man.volScalarField(
        man.IOobject(
            ref.word("hTotal"),
            ref.fileName(runTime.timeName()),
            mesh,
            ref.IOobject.READ_IF_PRESENT,
            ref.IOobject.AUTO_WRITE,
        ),
        h + h0,
    )

    hTotal.write()

    phi = createPhi(runTime, hU, mesh)

    ref.ext_Info() << "Creating Coriolis Force" << ref.nl

    F = ref.dimensionedVector(ref.word("F"), ((2.0 * Omega) & gHat) * gHat)

    return h, h0, U, hU, hTotal, phi, F
Example #6
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
Example #7
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
Example #8
0
def readTransportProperties( runTime, mesh):
    ref.ext_Info() << "\nReading transportProperties\n" << ref.nl
    
    transportProperties = man.IOdictionary( man.IOobject( ref.word( "transportProperties" ),
                                                          ref.fileName( runTime.constant() ),
                                                          mesh,
                                                          ref.IOobject.MUST_READ_IF_MODIFIED,
                                                          ref.IOobject.NO_WRITE,
                                                          False ) )
    
    nu = ref.dimensionedScalar( transportProperties.lookup( ref.word( "nu" ) ) )
    
    #  Read centerline velocity for channel simulations
    Ubar = ref.dimensionedVector( transportProperties.lookup( ref.word( "Ubar" ) ) )

    magUbar = Ubar.mag()
    flowDirection = ( Ubar / magUbar ).ext_value()
    
    return transportProperties, nu, Ubar, magUbar, flowDirection
Example #9
0
def _createFields(runTime, mesh, Omega, gHat):

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

    ref.ext_Info() << "Reading field h0 if present\n" << ref.nl
    h0 = man.volScalarField(
        man.IOobject(
            ref.word("h0"),
            ref.fileName(
                runTime.findInstance(ref.fileName(ref.word("polyMesh")),
                                     ref.word("points"))), mesh,
            ref.IOobject.READ_IF_PRESENT), mesh,
        ref.dimensionedScalar(ref.word("h0"), ref.dimLength, 0.0))

    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 field hU\n" << ref.nl
    hU = man.volVectorField(
        man.IOobject(ref.word("hU"), ref.fileName(runTime.timeName()), mesh),
        h * U,
        U.ext_boundaryField().types())

    ref.ext_Info() << "Creating field hTotal for post processing\n" << ref.nl
    hTotal = man.volScalarField(
        man.IOobject(ref.word("hTotal"), ref.fileName(runTime.timeName()),
                     mesh, ref.IOobject.READ_IF_PRESENT,
                     ref.IOobject.AUTO_WRITE), h + h0)

    hTotal.write()

    phi = createPhi(runTime, hU, mesh)

    ref.ext_Info() << "Creating Coriolis Force" << ref.nl

    F = ref.dimensionedVector(ref.word("F"), ((2.0 * Omega) & gHat) * gHat)

    return h, h0, U, hU, hTotal, phi, F
                        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
Example #11
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