CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > Software User Forums > OpenFOAM

Assign Boundary conditions using utility

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   July 21, 2011, 12:06
Default Assign Boundary conditions using utility
  #1
Member
 
Tony
Join Date: Jun 2010
Posts: 54
Rep Power: 15
tonyuprm is on a distinguished road
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;
}


// ************************************************************************* //
tonyuprm is offline   Reply With Quote

Old   July 21, 2011, 13:42
Default
  #2
Senior Member
 
mturcios777's Avatar
 
Marco A. Turcios
Join Date: Mar 2009
Location: Vancouver, BC, Canada
Posts: 740
Rep Power: 28
mturcios777 will become famous soon enough
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?
mturcios777 is offline   Reply With Quote

Old   July 21, 2011, 16:38
Default
  #3
Member
 
Tony
Join Date: Jun 2010
Posts: 54
Rep Power: 15
tonyuprm is on a distinguished road
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
tonyuprm is offline   Reply With Quote

Old   July 21, 2011, 17:37
Default
  #4
Senior Member
 
mturcios777's Avatar
 
Marco A. Turcios
Join Date: Mar 2009
Location: Vancouver, BC, Canada
Posts: 740
Rep Power: 28
mturcios777 will become famous soon enough
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!
mturcios777 is offline   Reply With Quote

Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
mesh file for flow over a circular cylinder Ardalan Main CFD Forum 7 December 15, 2020 13:06
Impinging Jet Boundary Conditions Anindya Main CFD Forum 25 February 27, 2016 12:58
Boundary conditions for 2D Navie-Stockes simulation L1011 OpenFOAM 5 December 13, 2012 08:17
how to assign radiation boundary conditions? Jinfeng CFX 0 January 10, 2009 17:18
A problem about setting boundary conditions lyang Main CFD Forum 0 September 19, 1999 18:29


All times are GMT -4. The time now is 23:56.