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

forAll doesn't consider all elements

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   August 27, 2019, 14:30
Default forAll doesn't consider all elements
  #1
New Member
 
Filipe Dias
Join Date: Jul 2019
Posts: 6
Rep Power: 7
FilipeDias93 is on a distinguished road
Good afternoon
I have recently needed to create some failsafes for my code, such that when a variable is zero, it is replaced by a small value different from zero, like so:

Code:
forAll (ENd, c)
{if (End[c]==0)
{ENd[c]=1;}}
However, afterwards I notice that there are still some values that are equal to zero. This occurs on the very first iteration, right before the operation that creates the floating point exception.

Is there a way to include all elements from the mesh? I tried to use mesh.C(), mesh.Sf(), mesh.Cf(), etc. All the ones that are present on the programmers guide, but still there is always a value equal to zero.

Thank you
FilipeDias93 is offline   Reply With Quote

Old   August 27, 2019, 16:44
Default
  #2
Senior Member
 
Daniel
Join Date: Mar 2013
Location: Noshahr, Iran
Posts: 348
Rep Power: 21
Daniel_Khazaei will become famous soon enough
Hi,

Can you show us the operation that results in a floating point exception?
Usually this situation can be avoided by proper usage of the SMALL variable which heavily depends on the operation to be performed, for example:

Code:
y = x / (x + SMALL)
in your case how the variable ENd is defined? if ENd is defined as a volScalarField then I think this should work:

Code:
scalarField& ENdInternal = ENd.internalField();

forAll (ENdInternal, c)
{
    if (ENdInternal[c] == 0)
    {
        ENdInternal[c] = 1;
    }
}
or if you are working with recent OpenFOAM versions:

Code:
scalarField& ENdInternal = ENd.primitiveFieldRef();

forAll (ENdInternal, c)
{
    if (ENdInternal[c] == 0)
    {
        ENdInternal[c] = 1;
    }
}
Note: I have just edited your code, I don't know what you are trying to do have any physical meaning.

Last edited by Daniel_Khazaei; August 27, 2019 at 18:11.
Daniel_Khazaei is offline   Reply With Quote

Old   August 28, 2019, 11:22
Default
  #3
New Member
 
Filipe Dias
Join Date: Jul 2019
Posts: 6
Rep Power: 7
FilipeDias93 is on a distinguished road
Thank you for your help.

The SMALL constant did work, but it would affect the results too much.

As for the second idea, it didn't compile, I believe it was due to the version of OpenFOAM I use.

However, I managed to solve the problem, inspired by the first solution.
The constant that is calculated from ENd should be zero when ENd=0, so I initiated the scalarField =0, and then I placed an if ENd>0 then *expression*.

Thank you for the help
FilipeDias93 is offline   Reply With Quote

Old   August 29, 2019, 18:17
Default
  #4
Member
 
Elwardi Fadeli
Join Date: Dec 2016
Location: Boumerdes, Algeria
Posts: 41
Rep Power: 9
ELwardi is on a distinguished road
I think this is due to some "fixedValue-like" BC setting some values at faces/cells to zero; It's a wild guess as we don't know what End is ... Anyway, this has nothing to do with the simple forAll macro: It only needs something that has a .size() method and an efficient indexing operator/member function to work as a charm. I chaim-lessly refer you to my earlier post on this macro https://foamscience.github.io/forall-openfoam-cpp/
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
3D Windturbine simulation in SU2 k.vimalakanthan SU2 15 October 12, 2023 06:53
Ansys SIG$ILL error loth ANSYS 3 December 24, 2015 06:31
[Gmsh] Vertex numbering is dense KateEisenhower OpenFOAM Meshing & Mesh Conversion 7 August 3, 2015 11:49
Penetrating elements in extruded mesh Michael P CFX 2 May 20, 2005 09:06
CFX4.3 -build analysis form Chie Min CFX 5 July 13, 2001 00:19


All times are GMT -4. The time now is 05:51.