|
[Sponsors] |
August 27, 2019, 14:30 |
forAll doesn't consider all elements
|
#1 |
New Member
Filipe Dias
Join Date: Jul 2019
Posts: 6
Rep Power: 7 |
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;}} 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 |
|
August 27, 2019, 16:44 |
|
#2 |
Senior Member
Daniel
Join Date: Mar 2013
Location: Noshahr, Iran
Posts: 348
Rep Power: 21 |
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) Code:
scalarField& ENdInternal = ENd.internalField(); forAll (ENdInternal, c) { if (ENdInternal[c] == 0) { ENdInternal[c] = 1; } } Code:
scalarField& ENdInternal = ENd.primitiveFieldRef(); forAll (ENdInternal, c) { if (ENdInternal[c] == 0) { ENdInternal[c] = 1; } } Last edited by Daniel_Khazaei; August 27, 2019 at 18:11. |
|
August 28, 2019, 11:22 |
|
#3 |
New Member
Filipe Dias
Join Date: Jul 2019
Posts: 6
Rep Power: 7 |
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 |
|
August 29, 2019, 18:17 |
|
#4 |
Member
Elwardi Fadeli
Join Date: Dec 2016
Location: Boumerdes, Algeria
Posts: 41
Rep Power: 9 |
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/
|
|
|
|
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 |