|
[Sponsors] |
Division by zero exception - loop over scalarField |
|
LinkBack | Thread Tools | Search this Thread | Display Modes |
August 6, 2013, 19:04 |
Division by zero exception - loop over scalarField
|
#1 |
Member
Patrick Wollny
Join Date: Apr 2010
Posts: 58
Rep Power: 16 |
Hiho,
I´m programming a tool for the post processing in openFOAM. In this code I divide a value by the denominator ( fvc::interpolate(T) - T_ref) which is a surfaceScalarField. To prevent the code from a division by zero, I do this: Code:
surfaceScalarField dT = ( fvc::interpolate(T) - T_ref ); forAll(dT.internalField(),i) { if(dT.internalField()[i] < 1e-10) { dT.internalField()[i] = 1e-10; } }; forAll(dT.boundaryField(),patchi) { forAll(dT.boundaryField()[patchi],i) { if(dT.boundaryField()[patchi][i] < 1e-10) { dT.boundaryField()[patchi][i] = 1e-10; } }; }; Best regards, Patrick |
|
August 7, 2013, 06:05 |
|
#3 | |
Senior Member
Bernhard
Join Date: Sep 2009
Location: Delft
Posts: 790
Rep Power: 22 |
Quote:
Code:
max(dT, dimensionedScalar("minDt", dimless, SMALL); |
||
August 7, 2013, 08:32 |
|
#4 |
Member
Patrick Wollny
Join Date: Apr 2010
Posts: 58
Rep Power: 16 |
Thank you very much!
I´ve replaced the related part by: Code:
dT = max(dT, dimensionedScalar("minDT", dT.dimensions(), SMALL)); |
|
August 7, 2013, 17:39 |
|
#5 | |
Senior Member
Laurence R. McGlashan
Join Date: Mar 2009
Posts: 370
Rep Power: 23 |
Quote:
Choice of cutoff is not always so simple. I would lean towards making the function behave better towards zero or add the constant directly to the denominator of the function rather than change variables themselves.
__________________
Laurence R. McGlashan :: Website |
||
February 16, 2017, 08:32 |
|
#6 |
New Member
fluidflowsteel
Join Date: Jun 2016
Posts: 21
Rep Power: 10 |
Hi guys,
X is a vol scalar field variable. I would like to take the value of X if X is greater than SMALL otherwise i will take the value SMALL if X is less than SMALL. I wrote in the following way X = max(X, dimensionedScalar("minX", X.dimensions(), SMALL)) but getting the error in OF V3.0 /opt/openfoam30/src/OpenFOAM/lnInclude/Scalar.H:44:15: error: ‘Scalar’ was not declared in this scope class pTraits<Scalar> ^ /opt/openfoam30/src/OpenFOAM/lnInclude/Scalar.H:44:21: error: template argument 1 is invalid class pTraits<Scalar> ^ /opt/openfoam30/src/OpenFOAM/lnInclude/Scalar.H:101:17: error: ‘Scalar’ does not name a type word name(const Scalar); ^ /opt/openfoam30/src/OpenFOAM/lnInclude/Scalar.H:101:17: error: ISO C++ forbids declaration of ‘parameter’ with no type [-fpermissive] /opt/openfoam30/src/OpenFOAM/lnInclude/Scalar.H:104:8: error: ‘Scalar’ does not name a type inline Scalar& setComponent(Scalar& s, const direction) ^ /opt/openfoam30/src/OpenFOAM/lnInclude/Scalar.H:110:8: error: ‘Scalar’ does not name a type inline Scalar component(const Scalar s, const direction) ^ /opt/openfoam30/src/OpenFOAM/lnInclude/Scalar.H:116:8: error: ‘Scalar’ does not name a type inline Scalar sign(const Scalar s) ^ /opt/openfoam30/src/OpenFOAM/lnInclude/Scalar.H:122:8: error: ‘Scalar’ does not name a type inline Scalar pos(const Scalar s) ^ /opt/openfoam30/src/OpenFOAM/lnInclude/Scalar.H:128:8: error: ‘Scalar’ does not name a type inline Scalar neg(const Scalar s) ^ /opt/openfoam30/src/OpenFOAM/lnInclude/Scalar.H:134:8: error: ‘Scalar’ does not name a type inline Scalar posPart(const Scalar s) ^ /opt/openfoam30/src/OpenFOAM/lnInclude/Scalar.H:140:8: error: ‘Scalar’ does not name a type inline Scalar negPart(const Scalar s) ^ /opt/openfoam30/src/OpenFOAM/lnInclude/Scalar.H:146:25: error: ‘Scalar’ does not name a type inline bool equal(const Scalar& s1, const Scalar& s2) ^ /opt/openfoam30/src/OpenFOAM/lnInclude/Scalar.H:146:33: error: ISO C++ forbids declaration of ‘s1’ with no type [-fpermissive] inline bool equal(const Scalar& s1, const Scalar& s2) ^ /opt/openfoam30/src/OpenFOAM/lnInclude/Scalar.H:146:43: error: ‘Scalar’ does not name a type inline bool equal(const Scalar& s1, const Scalar& s2) ^ /opt/openfoam30/src/OpenFOAM/lnInclude/Scalar.H:146:51: error: ISO C++ forbids declaration of ‘s2’ with no type [-fpermissive] inline bool equal(const Scalar& s1, const Scalar& s2) ^ /opt/openfoam30/src/OpenFOAM/lnInclude/Scalar.H: In function ‘bool Foam::equal(const int&, const int&)’: /opt/openfoam30/src/OpenFOAM/lnInclude/Scalar.H:148:28: error: ‘ScalarVSMALL’ was not declared in this scope return mag(s1 - s2) <= ScalarVSMALL; ^ /opt/openfoam30/src/OpenFOAM/lnInclude/Scalar.H: At global scope: /opt/openfoam30/src/OpenFOAM/lnInclude/Scalar.H:152:28: error: ‘Scalar’ does not name a type inline bool notEqual(const Scalar s1, const Scalar s2) ^ /opt/openfoam30/src/OpenFOAM/lnInclude/Scalar.H:152:35: error: ISO C++ forbids declaration of ‘s1’ with no type [-fpermissive] inline bool notEqual(const Scalar s1, const Scalar s2) ^ /opt/openfoam30/src/OpenFOAM/lnInclude/Scalar.H:152:45: error: ‘Scalar’ does not name a type inline bool notEqual(const Scalar s1, const Scalar s2) ^ /opt/openfoam30/src/OpenFOAM/lnInclude/Scalar.H:152:52: error: ISO C++ forbids declaration of ‘s2’ with no type [-fpermissive] inline bool notEqual(const Scalar s1, const Scalar s2) ^ /opt/openfoam30/src/OpenFOAM/lnInclude/Scalar.H: In function ‘bool Foam::notEqual(int, int)’: /opt/openfoam30/src/OpenFOAM/lnInclude/Scalar.H:154:27: error: ‘ScalarVSMALL’ was not declared in this scope return mag(s1 - s2) > ScalarVSMALL; ^ /opt/openfoam30/src/OpenFOAM/lnInclude/Scalar.H: At global scope: /opt/openfoam30/src/OpenFOAM/lnInclude/Scalar.H:158:8: error: ‘Scalar’ does not name a type inline Scalar limit(const Scalar s1, const Scalar s2) ^ /opt/openfoam30/src/OpenFOAM/lnInclude/Scalar.H:164:8: error: ‘Scalar’ does not name a type inline Scalar minMod(const Scalar s1, const Scalar s2) ^ /opt/openfoam30/src/OpenFOAM/lnInclude/Scalar.H:170:8: error: ‘Scalar’ does not name a type inline Scalar magSqr(const Scalar s) ^ /opt/openfoam30/src/OpenFOAM/lnInclude/Scalar.H:176:8: error: ‘Scalar’ does not name a type inline Scalar sqr(const Scalar s) ^ /opt/openfoam30/src/OpenFOAM/lnInclude/Scalar.H:182:8: error: ‘Scalar’ does not name a type inline Scalar sqrtSumSqr(const Scalar a, const Scalar b) ^ /opt/openfoam30/src/OpenFOAM/lnInclude/Scalar.H:198:8: error: ‘Scalar’ does not name a type inline Scalar pow3(const Scalar s) ^ /opt/openfoam30/src/OpenFOAM/lnInclude/Scalar.H:204:8: error: ‘Scalar’ does not name a type inline Scalar pow4(const Scalar s) ^ /opt/openfoam30/src/OpenFOAM/lnInclude/Scalar.H:210:8: error: ‘Scalar’ does not name a type inline Scalar pow5(const Scalar s) ^ /opt/openfoam30/src/OpenFOAM/lnInclude/Scalar.H:216:8: error: ‘Scalar’ does not name a type inline Scalar pow6(const Scalar s) ^ /opt/openfoam30/src/OpenFOAM/lnInclude/Scalar.H:222:8: error: ‘Scalar’ does not name a type inline Scalar pow025(const Scalar s) ^ /opt/openfoam30/src/OpenFOAM/lnInclude/Scalar.H:228:8: error: ‘Scalar’ does not name a type inline Scalar inv(const Scalar s) ^ /opt/openfoam30/src/OpenFOAM/lnInclude/Scalar.H:234:8: error: ‘Scalar’ does not name a type inline Scalar dot(const Scalar s1, const Scalar s2) ^ /opt/openfoam30/src/OpenFOAM/lnInclude/Scalar.H:240:8: error: ‘Scalar’ does not name a type inline Scalar cmptMultiply(const Scalar s1, const Scalar s2) ^ /opt/openfoam30/src/OpenFOAM/lnInclude/Scalar.H:246:8: error: ‘Scalar’ does not name a type inline Scalar cmptPow(const Scalar s1, const Scalar s2) ^ /opt/openfoam30/src/OpenFOAM/lnInclude/Scalar.H:252:8: error: ‘Scalar’ does not name a type inline Scalar cmptDivide(const Scalar s1, const Scalar s2) ^ /opt/openfoam30/src/OpenFOAM/lnInclude/Scalar.H:258:8: error: ‘Scalar’ does not name a type inline Scalar cmptMax(const Scalar s) ^ /opt/openfoam30/src/OpenFOAM/lnInclude/Scalar.H:264:8: error: ‘Scalar’ does not name a type inline Scalar cmptMin(const Scalar s) ^ /opt/openfoam30/src/OpenFOAM/lnInclude/Scalar.H:270:8: error: ‘Scalar’ does not name a type inline Scalar cmptAv(const Scalar s) ^ /opt/openfoam30/src/OpenFOAM/lnInclude/Scalar.H:276:8: error: ‘Scalar’ does not name a type inline Scalar cmptMag(const Scalar s) ^ /opt/openfoam30/src/OpenFOAM/lnInclude/Scalar.H:283:10: error: expected constructor, destructor, or type conversion before ‘(’ token transFunc(sqrt) ^ mySolverFoam.C:128:1: error: expected ‘}’ at end of input } ^ Can anyone help ? With regards |
|
February 18, 2017, 06:57 |
|
#7 | |
Senior Member
Przemek
Join Date: Jun 2011
Posts: 249
Rep Power: 16 |
Quote:
My dT is a volScalarField. I used your code but it works only for internalField cells. How to access boundaryField?
__________________
best regards pblasiak |
||
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
[openSmoke] libOpenSMOKE | Tobi | OpenFOAM Community Contributions | 562 | January 25, 2023 10:21 |
[Gmsh] Problem with Gmsh | nishant_hull | OpenFOAM Meshing & Mesh Conversion | 23 | August 5, 2015 03:09 |
[CAD formats] my stl surface is seen as just a line | rcastilla | OpenFOAM Meshing & Mesh Conversion | 2 | January 6, 2010 02:30 |
ScalarField division | maka | OpenFOAM Pre-Processing | 2 | August 27, 2007 06:10 |
NACA0012 geometry/design software needed | Franny | Main CFD Forum | 13 | July 7, 2007 16:57 |