CFD Online Discussion Forums

CFD Online Discussion Forums (http://www.cfd-online.com/Forums/)
-   OpenFOAM (http://www.cfd-online.com/Forums/openfoam/)
-   -   Assign Boundary conditions using utility (http://www.cfd-online.com/Forums/openfoam/90827-assign-boundary-conditions-using-utility.html)

tonyuprm July 21, 2011 12:06

Assign Boundary conditions using utility
 
Hi all,

Im trying to create a utility which will initialize my fields and set the boundary conditions on my fields. I am having trouble assigning the boundary conditions because even though I assign "fixedValue" it will show as "calculated" instead when written to the 0 directory. Here is my code. How can I assign the boundary condition and have it write out correctly?

Thanks,

Tony

Code:

/*---------------------------------------------------------------------------*\
  =========                |
  \\      /  F ield        | OpenFOAM: The Open Source CFD Toolbox
  \\    /  O peration    |
    \\  /    A nd          | Copyright (C) 1991-2010 OpenCFD Ltd.
    \\/    M anipulation  |
-------------------------------------------------------------------------------
License
    This file is part of OpenFOAM.

    OpenFOAM is free software: you can redistribute it and/or modify it
    under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
    ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    for more details.

    You should have received a copy of the GNU General Public License
    along with OpenFOAM.  If not, see <http://www.gnu.org/licenses/>.

Application
    engineSwirl

Description
    Generates a swirling flow for engine calulations

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

#include "fvCFD.H"
#include "wallDist.H"
#include "fixedGradientFvPatchFields.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

int main(int argc, char *argv[])
{

//argList::validArgs.append("boundary layer thickness");
#  include "setRootCase.H"
#  include "createTime.H"
#  include "createMesh.H"

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

Info << "Reading field U" << endl ;

volVectorField U
(
    IOobject
    (
        "U",
        runTime.timeName(),
        mesh,
        IOobject::READ_IF_PRESENT,
        IOobject::NO_WRITE
    ),
    mesh,
    dimensionedVector("U",dimensionSet(0, 1, -1, 0, 0, 0, 0),vector(15.0,0,0))
);

Info << "Reading field T" << endl ;
volScalarField T
(
    IOobject
    (
        "T",
        runTime.timeName(),
        mesh,
        IOobject::READ_IF_PRESENT,
        IOobject::NO_WRITE
    ),
    mesh,
    dimensionedScalar("T",dimensionSet(0, 0, 0, 1, 0, 0, 0),300.0)
);

Info << "Reading field p" << endl ;
volScalarField p
(
    IOobject
    (
        "p",
        runTime.timeName(),
        mesh,
        IOobject::READ_IF_PRESENT,
        IOobject::NO_WRITE
    ),
    mesh,
    dimensionedScalar("p",dimensionSet(0, 1, -2, 0, 0, 0, 0),0.0)
);
Info << "Reading field nuSgs" << endl ;
volScalarField nuSgs
(
    IOobject
    (
        "nuSgs",
        runTime.timeName(),
        mesh,
        IOobject::READ_IF_PRESENT,
        IOobject::NO_WRITE
    ),
    mesh,
    dimensionedScalar("nuSgs",dimensionSet(0, 2, -1, 0, 0, 0, 0),0.0)
);

label patchID = mesh.boundaryMesh().findPatchID("top");

U.boundaryField()[patchID].type() ==  fixedValueFvPatchVectorField::typeName;

Info<<U.boundaryField()[patchID].type()<<endl;
Info<<fixedValueFvPatchVectorField::typeName<<endl;

forAll(U.boundaryField()[patchID],i)
{
    U.boundaryField()[patchID][i].x()=8;
    U.boundaryField()[patchID][i].y()=0;
    U.boundaryField()[patchID][i].z()=0;
    p.boundaryField()[patchID][i]=0;
    nuSgs.boundaryField()[patchID][i]=0;
    T.boundaryField()[patchID][i]=300;
}

U.boundaryField()[patchID].type() ==  fixedValueFvPatchVectorField::typeName;

Info<< "Writing U" << endl;
U.write();

Info<< "Writing T" << endl;
T.write();

Info<< "Writing p" << endl;
p.write();

Info<< "Writing nuSgs" << endl;
nuSgs.write();
return 0;
}


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


mturcios777 July 21, 2011 13:42

The utility engineSwirl initializes a swirling field, but it may not do exactly what you need. Try change the reading of the U field to use AUTO_WRITE instead of NO_WRITE.

Also, are your fields uniformly zero, or is zero specified for every cell?

tonyuprm July 21, 2011 16:38

Hi Marco and thanks for your reply. I tried changing it to AUTO_WRITE but still no luck. The utility will write the correct value I try to assign to the fields but instead of setting the boundary condition it will write "type calculated;" instead of the one I have on my blockMeshDict file.

Thanks,

Tony

mturcios777 July 21, 2011 17:37

If you only need the field to be written as an initial condition, then it may be more useful to install swak4Foam and use the included funkySetFields utility. Read more about swak4Foam on the wiki:

http://openfoamwiki.net/index.php/Contrib/swak4Foam

From your code it looks like funkySetFields will do exactly what you want: you can set the boundary "top" to be fixedValue, and the value will be written exactly as you want it.

Good luck!


All times are GMT -4. The time now is 18:07.