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

Can I avoid loop over boundaries in forAll loop?

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   September 6, 2021, 05:30
Default Can I avoid loop over boundaries in forAll loop?
  #1
Senior Member
 
Przemek
Join Date: Jun 2011
Posts: 249
Rep Power: 15
gaza is on a distinguished road
Hi
I have a volScalarField defined in standard manner:
Code:
rho
    (
        IOobject
        (
            "rho",
            U.mesh().time().timeName(),
            U.mesh(),
            IOobject::NO_READ,
            IOobject::NO_WRITE
        ),
        U.mesh(),
        dimensionedScalar("rho", dimDensity, 0.0)
    )
Later in the code I calculate the values of rho for each cell using forAll loop.
However, in the program I get divide error because the forAll loop sets values only
in cells and at the boundaries the 0 is left. I solved it by applying the second forAll
loop over boundary patches but it slows down the calculations remarkably.
Is there any method to avoid the second loop over patches?
__________________
best regards
pblasiak
gaza is offline   Reply With Quote

Old   September 7, 2021, 00:09
Default
  #2
Member
 
Francisco T
Join Date: Nov 2011
Location: Melbourne, Australia
Posts: 64
Blog Entries: 1
Rep Power: 14
frantov is on a distinguished road
This reminded me a case where div by zero is fixed.

To prevent that code blows up due to a division by zero in a viscosity calculation, it is advised to add SMALL.

SMALL is a static constant scalar included in

https://www.openfoam.com/documentati...8H_source.html


for example

return nu0_/scalar(1) + pow(k_* strainRate() + SMALL, (1-n));


perhaps you can try a similar approach?


...................

(also, I just edited my response)

You can also write Zero

this is done in BC initialization

new Field<Type>(this->size(), Zero)


https://develop.openfoam.com/Develop...FvPatchField.C

Last edited by frantov; September 7, 2021 at 05:24.
frantov is offline   Reply With Quote

Old   September 7, 2021, 08:13
Default
  #3
Senior Member
 
Przemek
Join Date: Jun 2011
Posts: 249
Rep Power: 15
gaza is on a distinguished road
Quote:
Originally Posted by frantov View Post
This reminded me a case where div by zero is fixed.

To prevent that code blows up due to a division by zero in a viscosity calculation, it is advised to add SMALL.

SMALL is a static constant scalar included in

https://www.openfoam.com/documentati...8H_source.html


for example

return nu0_/scalar(1) + pow(k_* strainRate() + SMALL, (1-n));


perhaps you can try a similar approach?


...................

(also, I just edited my response)

You can also write Zero

this is done in BC initialization

new Field<Type>(this->size(), Zero)


https://develop.openfoam.com/Develop...FvPatchField.C

Hi Frantov,
Thank you very much for your hint.
It is good solution however it does not solve my problem.
I need to set the values at the boundaries in each iteration the same
as in the cells that adhere to the boundaries.


A while ago I found the solution:
1) added the line at the end of rho constructor
Code:
"zeroGradient"
2) instead of the second forAll (over boundaries) I wrote
Code:
rho.correctBoundaryConditions();
This solution is slightly faster than that with two forAll loops.
I hope it is correct and gives the same results
__________________
best regards
pblasiak

Last edited by gaza; September 7, 2021 at 11:16.
gaza 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
Glyph: how to avoid the plot of vectors perpendicular to boundaries? serena OpenFOAM Post-Processing 6 October 22, 2019 04:37
Need help setting up chtMultiRegion OskarT OpenFOAM Pre-Processing 1 September 25, 2019 15:51
[Gmsh] Problem with Gmsh nishant_hull OpenFOAM Meshing & Mesh Conversion 23 August 5, 2015 02:09
[ICEM] How to avoid single edges at boundaries in 2D models? Gandin ANSYS Meshing & Geometry 12 October 16, 2014 06:00
lid-driven cavity in matlab using BiCGStab Don456 Main CFD Forum 1 January 19, 2012 15:00


All times are GMT -4. The time now is 06:30.