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

Method to change boundary condition (BC) type on the fly

Register Blogs Members List Search Today's Posts Mark Forums Read

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   March 21, 2025, 06:57
Default Method to change boundary condition (BC) type on the fly
  #1
Senior Member
 
Dr. Alexander Vakhrushev
Join Date: Mar 2009
Posts: 257
Blog Entries: 1
Rep Power: 20
makaveli_lcf is on a distinguished road
Send a message via ICQ to makaveli_lcf
Hi everyone,

I recently ran into what seemed like a trivial issue: dynamically changing the boundary condition of a field, e.g., from 'calculated' to 'fixedValue'. As you know, you can't solve equations in OpenFOAM for fields with 'calculated' type patches, so I needed to explicitly switch them to 'fixedValue'.

Although I expected the solution to be simple and concise, it actually took me quite some time to sort it out, and surprisingly, I couldn't find a clear answer online, even though I remember doing something similar over a decade ago.

I’ve currently tested this approach with OpenFOAM 10, but it should be fairly straightforward to adapt it for use in other versions as well.

So, I’d like to share the working code snippet here in case it saves someone else the trouble:

Code:
//  Set boundary type to fixedValue
dictionary dict;
dict.add("value", "uniform (0 0 0)");

forAll(U.boundaryFieldRef(), patchi)
{
    U.boundaryFieldRef().set
    (
        patchi,
        new fixedValueFvPatchVectorField
        (
            mesh.boundary()[patchi],    //  fvPatch reference
            U.ref(),                    //  Internal field reference
            dict
        )
    );
}
Hope this helps someone down the road!

Cheers,
__________________
Best regards,

Dr. Alexander VAKHRUSHEV

Christian Doppler Laboratory for "Metallurgical Applications of Magnetohydrodynamics"

Simulation and Modelling of Metallurgical Processes
Department of Metallurgy
University of Leoben

http://smmp.unileoben.ac.at
makaveli_lcf is offline   Reply With Quote

Reply

Tags
change boundary condition, fvpatch, type

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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
chtmultiRegion case is not generating sets folder in postprocessing boffin5 OpenFOAM Running, Solving & CFD 14 April 19, 2024 17:40
Openfoam Turbulent Car Simulation meganrw OpenFOAM Running, Solving & CFD 0 July 5, 2021 15:50
[OpenFOAM.org] compile error in dynamicMesh and thermophysicalModels libraries NickG OpenFOAM Installation 3 December 30, 2019 00:21
Divergent temperature in chtMultiRegion(Simple)Foam akrasemann OpenFOAM Running, Solving & CFD 13 March 24, 2014 02:54
[swak4Foam] Air Conditioned room groovyBC Sebaj OpenFOAM Community Contributions 7 October 31, 2012 14:16


All times are GMT -4. The time now is 14:37.