CFD Online Discussion Forums

CFD Online Discussion Forums (http://www.cfd-online.com/Forums/)
-   OpenFOAM Programming & Development (http://www.cfd-online.com/Forums/openfoam-programming-development/)
-   -   Can a solver change the type of a boundary/patch ? (http://www.cfd-online.com/Forums/openfoam-programming-development/117918-can-solver-change-type-boundary-patch.html)

fredo490 May 17, 2013 06:17

Can a solver change the type of a boundary/patch ?
 
Dear all,
For convenience I would like to create a solver (which is actually a simple tool) that need to change the type of a boundary. For example, I have the temperature field with an adiabatic wall (type zeroGradient) and I would like to change it to a fixedValue with the value of the face correspond o the zero gradient solution

Before:
Code:

FoamFile
{
    version    2.0;
    format      ascii;
    class      volScalarField;
    location    "0.1";
    object      T;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

dimensions      [0 0 0 1 0 0 0];

internalField  nonuniform List<scalar>
...
...
...
...

    wall
    {
        type            zeroGradient;
    }

After:
Code:

FoamFile
{
    version    2.0;
    format      ascii;
    class      volScalarField;
    location    "0.1";
    object      T;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

dimensions      [0 0 0 1 0 0 0];

internalField  nonuniform List<scalar>
...
...
...
...

    wall
    {
        type            fixedValue;
        value          nonuniform List<scalar>
400
(
...
...
...
)
;
    }

I have tried the following code:
Code:

        volScalarField Tr // Create another field to avoid the self overwriting
        (
            IOobject
            (
                "Tr",
                runTime.timeName(),
                mesh
            ),
            mesh,
            dimensionedScalar("Tr", T.dimensions(), 0.0)
        );

        Tr.boundaryField()[patchWallID] = T.boundaryField()[patchWallID];
        T.boundaryField()[patchWallID] = Tr.boundaryField()[patchWallID];

        Tr.write();
        T.write();

but the Tr field boundary is of type "calculated" and the T boundary remains zeroGradient.

Anybody knows how to do ?

ngj May 21, 2013 04:38

Hi Fréderic,

I am not quite sure what you mean, but would it not be easier to have a custom boundary condition, which is derived from the mixed class? Then you can easily switch from zeroGradient to fixedValue during the simulation by a simple change in value of the keyword valueFraction.

Kind regards

Niels

fredo490 May 21, 2013 04:46

The boundary doesn't have to change during the simulation. I run a first simulation with a patch of type "zeroGradient" and later I want to run another simulation but this time the patch has to be of type "fixedValue".

When I say that a "solver" has to change the type it is actually wrong. What I need is more a "tool" than a solver. I don't run any calculation during this time, I only manipulate the files.

Now I do:
1) Computation 1: mySolverFoam
2) I need to manually change the type of the patch by editing the files
3) Computation 2: mySolver2Foam

What I want:
1) Computation 1: mySolverFoam
2) Automatically edit the files (by using a tool/solver)
3) Computation 2: mySolver2Foam

I can try to create a Python tool that would do the job but I also do some extra treatment that only a "solver" can do by calling the turbulence model and returning some specific variables.

ngj May 21, 2013 06:53

Okay, I see what your intentions are. As an example look in

Code:

src/thermophysicalModels/reactionThermo/combustionThermo/hCombustionThermo/hCombustionThermo.C
where you will find these lines of code:

Code:

    h_
    (
        IOobject
        (
            "h",
            mesh.time().timeName(),
            mesh,
            IOobject::NO_READ,
            IOobject::NO_WRITE
        ),
        mesh,
        dimensionSet(0, 2, -2, 0, 0),
        this->hBoundaryTypes()
    )

The important part is the fourth argument in the construction of the field. This is a wordList with boundary types, so your modified field merely needs to obtain a wordList of boundary types from the original field, where some of these are changed from zeroGradient to fixedValue. Finally, populate internal and boundary fields.

Kind regards

Niels

fredo490 May 21, 2013 06:56

Thx, I get it now !
Indeed, the fourth argument is what I was looking for ;)

I will work on it tonight.


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