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

Can a solver change the type of a boundary/patch ?

Register Blogs Community New Posts Updated Threads Search

Like Tree2Likes
  • 2 Post By Tobi

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   May 17, 2013, 06:17
Default Can a solver change the type of a boundary/patch ?
  #1
Senior Member
 
HECKMANN Frédéric
Join Date: Jul 2010
Posts: 249
Rep Power: 16
fredo490 is on a distinguished road
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 ?
fredo490 is offline   Reply With Quote

Old   May 21, 2013, 04:38
Default
  #2
ngj
Senior Member
 
Niels Gjoel Jacobsen
Join Date: Mar 2009
Location: Copenhagen, Denmark
Posts: 1,900
Rep Power: 37
ngj will become famous soon enoughngj will become famous soon enough
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
ngj is offline   Reply With Quote

Old   May 21, 2013, 04:46
Default
  #3
Senior Member
 
HECKMANN Frédéric
Join Date: Jul 2010
Posts: 249
Rep Power: 16
fredo490 is on a distinguished road
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.
fredo490 is offline   Reply With Quote

Old   May 21, 2013, 06:53
Default
  #4
ngj
Senior Member
 
Niels Gjoel Jacobsen
Join Date: Mar 2009
Location: Copenhagen, Denmark
Posts: 1,900
Rep Power: 37
ngj will become famous soon enoughngj will become famous soon enough
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
ngj is offline   Reply With Quote

Old   May 21, 2013, 06:56
Default
  #5
Senior Member
 
HECKMANN Frédéric
Join Date: Jul 2010
Posts: 249
Rep Power: 16
fredo490 is on a distinguished road
Thx, I get it now !
Indeed, the fourth argument is what I was looking for

I will work on it tonight.
fredo490 is offline   Reply With Quote

Old   June 24, 2021, 08:37
Default
  #6
Super Moderator
 
Tobi's Avatar
 
Tobias Holzmann
Join Date: Oct 2010
Location: Tussenhausen
Posts: 2,708
Blog Entries: 6
Rep Power: 51
Tobi has a spectacular aura aboutTobi has a spectacular aura aboutTobi has a spectacular aura about
Send a message via ICQ to Tobi Send a message via Skype™ to Tobi
Old topic but I want to ask if it is possible to change the patch types after we called the constructor. Searching Doxygen does not provide any function which I would be able to use for changing the boundary types after we created the GeometricField. To clarify:
Code:
    myField_                                                                        
    (                                                                           
        IOobject                                                                
        (                                                                       
            "myField",
            mesh.time().timeName(),                                             
            mesh,                                                               
            IOobject::READ_IF_PRESENT,                                                  
            IOobject::NO_WRITE                                                  
        ),                                                                      
        mesh,                                                                   
        dimless
    )
As this constructor will create the boundary types to be calculated, I would like to change it afterward. Why? I am initializing this field by using another field, e.g., in the humidity thermodynamic lib we solve for the specificHumidity quantity. However, for initialization it is recommended to use the relative humidity field rather than the specific one (simpler set-up as we don't have to recalculate the quantities). So while starting the simulation, the specificHumidity field is not present and we initialize it by using the relativeHumidity field. However, we need to make sure that the boundary conditions are set to the same type.

I could work with pointers here which would give me the possibility to create the specificHumidity field at the right position (when we know the BC of the relativeHumidity field) but I am sure that we can change that fields even without using pointers. E.g.,

Code:
const wordList& patchTypes = relativeHumidity.boundaryField().types();

// Something such as:
myField.changeBoundaryTypes() = patchTypes;
__________________
Keep foaming,
Tobias Holzmann
Tobi is offline   Reply With Quote

Old   June 24, 2021, 11:14
Default
  #7
Super Moderator
 
Tobi's Avatar
 
Tobias Holzmann
Join Date: Oct 2010
Location: Tussenhausen
Posts: 2,708
Blog Entries: 6
Rep Power: 51
Tobi has a spectacular aura aboutTobi has a spectacular aura aboutTobi has a spectacular aura about
Send a message via ICQ to Tobi Send a message via Skype™ to Tobi
I will just answer my own question:

Code:
// Assign the same boundary conditions                                      
volScalarField::Boundary& specHumBf = specHum.boundaryFieldRef();                                                                 
const volScalarField::Boundary& relHumBf = this->relHum_.boundaryField();   

forAll(specHumBf, patchi)                                                   
{                                                                                                                 
     specHumBf.set(patchi, relHumBf[patchi]);                                
}
Keep in mind, that you also put the values to the field. So maybe you need to update it. I guess there is a better workaround.
peyman.havaej and fly_light like this.
__________________
Keep foaming,
Tobias Holzmann
Tobi 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
Free jet simulation msarkar OpenFOAM Running, Solving & CFD 39 May 11, 2021 13:21
Higher order convection schemes with unstructured grids vkrastev OpenFOAM 29 April 5, 2018 03:23
interFoam/kOmegaSST tank filling with printStackError/Mules simpomann OpenFOAM Running, Solving & CFD 3 February 17, 2014 17:06
Need help with boundary conditions: open to atmosphere Wolle OpenFOAM 2 April 11, 2011 07:32
pipe flow with heat transfer Fabian OpenFOAM 2 December 12, 2009 04:53


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