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

Problem with 'operator<'

Register Blogs Members List Search Today's Posts Mark Forums Read

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   September 18, 2016, 13:39
Default Problem with 'operator<'
  #1
Member
 
Lee Jung Hoo
Join Date: Dec 2015
Posts: 37
Rep Power: 10
Jung hoo is on a distinguished road
Hello, foamers. I'm making a new boundary using ParabolicVelocity as base code.

In my equation, there is sqrt function.

for example,

Quote:
scalarField a;
scalarField b;
scalarField c = sqrt(a-b);
The resulting values seem to be reasonable.
Everything is Okay, but the calculating process is stopped in case of 'b>a'.

I think that it is because the value in the sqrt can't be negative.

So, I modified the code as below.

Quote:
scalarField a;
scalarField b;
scalarField c = a-b;

if(c<0)
{
c=0;
}
scalarField d = sqrt(c);
But I failed the compiling.

The error message is

Quote:
error: no match for 'operator<' in 'c<0'
fields/fvPatchFields/derived/cbVelocity2/cbVelocityFvPatchVectorField2.C:226:13: note: candidates are:
/home/lee/foam/foam-extend-3.1/src/foam/lnInclude/UList.C:179:6: note: bool Foam::UList<T>:perator<(const Foam::UList<T>&) const [with T = double]
I'm not goot at programming related to Openfoam yet..

Can anyone explain me how to make that 'if' function feasible?

Thanks!
Jung hoo is offline   Reply With Quote

Old   September 21, 2016, 09:02
Default
  #2
Member
 
Join Date: Jul 2011
Posts: 54
Rep Power: 14
A_Pete is on a distinguished road
You are correct that (a-b) can't be negative when using sqrt(a-b). You could also use sqrt(max((a-b), 0)) to make sure your smalles value below the sqrt is a "0".

For your if statement you should maybe put some whitespaces in there. The problem is maybe arising, because you are trying to compare a whole field to one single scalar value. If you want to compare all the values in the field to "0" maybe go like this:

Code:
forAll(c, i)
{
    if (c[i] < 0)
    {
        c[i] = 0;
    }
}
An easier way to do this is the one that I stated above.
A_Pete is offline   Reply With Quote

Old   September 23, 2016, 05:42
Default
  #3
Member
 
Lee Jung Hoo
Join Date: Dec 2015
Posts: 37
Rep Power: 10
Jung hoo is on a distinguished road
Hi, Pete. Thank you for your kind reply.

I modified the code like below

Quote:
scalarField a = asd; // 'asd' is a previously calculated scalarField in the code
scalarField b = qwe; // 'qwe' is a previously calculated scalarField in the code
scalarField vv=shields; // 'shields' is a previously calculated scalarField in the code

forAll(b, i)
{
if(a[i]<0)
{
b[i]=0;
}

else
{
b[i]=sqrt(a[i]);
}
}
On this case, there is not any problem. The compile and running application is Okay, but when I modified the code as below

Quote:
forAll(b, i)
{
if(a[i]==0)
{
b[i]=0;
}

else
{
b[i]=1/a[i];
}
}
I got an error message like this.

Quote:
time step continuity errors : sum local = 9.906e-07, global = -9.6315e-08, cumulative = -3.72647e-07
DILUPBiCG: Solving for epsilon, Initial residual = 0.603832, Final residual = 2.12043e-05, No Iterations 1
DILUPBiCG: Solving for k, Initial residual = 0.59472, Final residual = 2.44661e-05, No Iterations 1
Time = 0.00612753
3D_2D Absorption BC on patch bottom
Floating point exception (core dumped)
Is there something wrong in my code about 'follAll'?

my purpose is to avoid negative value in the sqrt, and zero value in denominator.

The 'if' function seems to be successful in sqrt, but not in denominator.

Thank you for your help!!

Last edited by Jung hoo; September 23, 2016 at 13:30.
Jung hoo is offline   Reply With Quote

Old   September 29, 2016, 07:09
Default
  #4
Member
 
Join Date: Jul 2011
Posts: 54
Rep Power: 14
A_Pete is on a distinguished road
Small numbers that are not exactly zero, but very small (1e-300) will also produce a floating point exception. Your if condition "a[i] == 0" is not sufficient in this case. Maybe you should do something like
Code:
if (mag(a[i]) < VSMALL)
{
bla
}
This is not really OF related, though. This is basic programming stuff.
A_Pete is offline   Reply With Quote

Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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
UDF compiling problem Wouter Fluent UDF and Scheme Programming 6 June 6, 2012 04:43
Gambit - meshing over airfoil wrapping (?) problem JFDC FLUENT 1 July 11, 2011 05:59
natural convection problem for a CHT problem Se-Hee CFX 2 June 10, 2007 06:29
Adiabatic and Rotating wall (Convection problem) ParodDav CFX 5 April 29, 2007 19:13
Is this problem well posed? Thomas P. Abraham Main CFD Forum 5 September 8, 1999 14:52


All times are GMT -4. The time now is 21:31.