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

forAll does not loop over boundary cells

Register Blogs Community New Posts Updated Threads Search

Like Tree5Likes
  • 1 Post By gaza
  • 3 Post By Jibran
  • 1 Post By ELwardi

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   October 19, 2017, 13:30
Default forAll does not loop over boundary cells
  #1
Senior Member
 
Przemek
Join Date: Jun 2011
Posts: 249
Rep Power: 16
gaza is on a distinguished road
Hi All
I coded something like this
Code:
forAll(alfa, celli)
{
    alfa[celli] = scalar(2);
}
where alfa is volScalarField. Further in my code I divide by alfa
and I get run-time error that it is divided by zero. I found out that boundary cells of alfa are set to zero.

Do I have to do the second loop over boundary cells or there is a much finer solution to loop over internal and boundaryField in one loop?
dats likes this.
__________________
best regards
pblasiak
gaza is offline   Reply With Quote

Old   October 30, 2017, 06:07
Default
  #2
Member
 
Jibran
Join Date: Oct 2012
Location: UK
Posts: 61
Blog Entries: 1
Rep Power: 15
Jibran is on a distinguished road
Quote:
Originally Posted by gaza View Post
Hi All
I coded something like this
Code:
forAll(alfa, celli)
{
    alfa[celli] = scalar(2);
}
where alfa is volScalarField. Further in my code I divide by alfa
and I get run-time error that it is divided by zero. I found out that boundary cells of alfa are set to zero.

Do I have to do the second loop over boundary cells or there is a much finer solution to loop over internal and boundaryField in one loop?
Hello,

OpenFOAM treats internal and boundary fields separately. Generally, the boundary values are specified using an appropriate boundary condition in the '0' folder. However, you can still access and modify the boundary values within your solver.

Code:
forAll(mesh.boundary(), patchID) 
{
    forAll (mesh.boundary()[patchID],facei) 
    {
         alfa.boundaryField()[patchID][facei] = 2.0;
    }
}
Moreover, if you just want to perform operations on the internal field or boundary field, you can access them through alfa.internalField() or alfa.boundaryField() respectively.
gaza, tooran and dats like this.
__________________
Jibran Haider
Jibran is offline   Reply With Quote

Old   October 30, 2017, 06:23
Default
  #3
Senior Member
 
Przemek
Join Date: Jun 2011
Posts: 249
Rep Power: 16
gaza is on a distinguished road
Hi Jibran,
Thank you for your reply.
It means that I always has to do two loops, through internal and boundary field.
Ok, thank you for explanations.
__________________
best regards
pblasiak
gaza is offline   Reply With Quote

Old   August 29, 2019, 18:09
Default
  #4
Member
 
Elwardi Fadeli
Join Date: Dec 2016
Location: Boumerdes, Algeria
Posts: 41
Rep Power: 10
ELwardi is on a distinguished road
Yes, you have to treat internalField and boundaryField differently in most cases (or at least use field.correctBoundaryConditions() after the loop on internalField) especially if using some macro (like forAll) which will certainly hide C++ syntax, and most new programmers will become confused.


Of course, there are some containers that aren't compatible with forAll even though applying it on them seems logical.


Recent versions of OpenFOAM will accept volScalarField:perator[](int) for example to access "internalField" (either dimensioned or not, I don't remember ).


More on this in this blog post of mine if you intend to dig a little deeper.
tooran likes this.
ELwardi 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
Out File does not show Imbalance in % Mmaragann CFX 5 January 20, 2017 11:20
An error has occurred in cfx5solve: volo87 CFX 5 June 14, 2013 18:44
[snappyHexMesh] external flow with snappyHexMesh chelvistero OpenFOAM Meshing & Mesh Conversion 11 January 15, 2010 20:43
physical boundary error!! kris Siemens 2 August 3, 2005 01:32
Convective Heat Transfer - Heat Exchanger Mark CFX 6 November 15, 2004 16:55


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