CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > OpenFOAM Running, Solving & CFD

Problem using '==' operator

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

Reply
 
LinkBack Thread Tools Display Modes
Old   February 10, 2016, 20:50
Default Problem using '==' operator
  #1
New Member
 
Sara
Join Date: Dec 2013
Posts: 8
Rep Power: 4
karma15 is on a distinguished road
Hi all,

The answer to this is probably trivial, but I am just confused as to what is going on with this. So I am trying to build a simple scalar transport system with an instantaneous release of the scalar value. Thus, I have built a for loop in which if the runtime is 0, then the scalar value is the scalar value 'C' at a given location in the system, otherwise the scalar value is 0 at the source. However, I keep getting the following error:

Code:
no match for ‘operator==’ in ‘Foam::Time::timeName() const() == 0’
My for loop for the scalar transport portion of my application code is the following:

Code:
if(runTime.timeName() == 0)
        {            
          solve(
              fvm::ddt(T) +  
              fvm::div(phi,T) -
              fvm::laplacian(diff,T) ==
              C
            );
       }
       else{
            solve(
              fvm::ddt(T) +  
              fvm::div(phi,T) -
              fvm::laplacian(diff,T) ==
              0
            );
        }
Your help is greatly appreciated.

-Sara
karma15 is offline   Reply With Quote

Old   February 10, 2016, 22:49
Default
  #2
Senior Member
 
Join Date: Aug 2013
Posts: 180
Rep Power: 4
Antimony is on a distinguished road
Hi,

Can you try with this instead:
runTime.timeName()==word(0)

My guess is that runTime.timeName() returns a word and so when you compare it to 0, it doesn't work because they are of two different types.

Hope this helps.

Cheers,
Antimony
Antimony is offline   Reply With Quote

Old   February 11, 2016, 03:08
Default
  #3
Senior Member
 
akidess's Avatar
 
Anton Kidess
Join Date: May 2009
Location: Delft, Netherlands
Posts: 1,121
Rep Power: 20
akidess will become famous soon enough
You don't need to explicitly set the right hand side. Just remove "== 0". See laplacianFoam: https://github.com/OpenFOAM/OpenFOAM...aplacianFoam.C
__________________
*On twitter @akidTwit
*Spend as much time formulating your questions as you expect people to spend on their answer.
*Join the OpenFOAM stackexchange Q&A site: http://area51.stackexchange.com/prop...oHPxcPqde7HtA2
akidess is offline   Reply With Quote

Old   February 11, 2016, 15:40
Default
  #4
New Member
 
Sara
Join Date: Dec 2013
Posts: 8
Rep Power: 4
karma15 is on a distinguished road
So the only thing is that I have two different solvers: one I want to run when the time is at zero, and the other I want to run the rest of the time. I don't see how to do that with the example you provided.
karma15 is offline   Reply With Quote

Old   February 11, 2016, 16:21
Default
  #5
New Member
 
Sara
Join Date: Dec 2013
Posts: 8
Rep Power: 4
karma15 is on a distinguished road
Hi Antimony,

Thank you for your help. I was suspecting that was the issue, however, I tried your suggestion and I am still getting an error. This is now what it is saying:

Quote:
error: no match for ‘operator==’ in ‘Foam:perator-(const Foam::tmp<Foam::fvMatrix<Type> >&, const Foam::tmp<Foam::fvMatrix<Type> >&) [with Type = double]((*(const Foam::tmp<Foam::fvMatrix<double> >*)(& Foam::fvm::laplacian(const Foam::dimensioned<Type2>&, const Foam::GeometricField<Type, Foam::fvPatchField, Foam::volMesh>&) [with Type = double, GType = double]((*(const Foam::GeometricField<double, Foam::fvPatchField, Foam::volMesh>*)(& T)))))) == 0’
Any thoughts would be greatly appreciated.

Sincerely,
Sara
karma15 is offline   Reply With Quote

Old   February 11, 2016, 22:15
Default
  #6
Senior Member
 
Join Date: Aug 2013
Posts: 180
Rep Power: 4
Antimony is on a distinguished road
Hi,

If I understand akidess correctly, I believe what he/she is saying is that you can remove the ==0 part and your code will still work. By default, the if condition will check that the term is not equal to 0 and so you don't need to state it explicitly.

However, if you want to be able to change it for any arbitrary time, then you can do this instead:
Code:
if (atoi(runTime.timeName().c_str())==0)
For the case of zero, you can omit the ==0, but for the other times, you will need to put in the value to be compared against.

Hope this helps.

Cheers,
Antimony
Antimony is offline   Reply With Quote

Old   February 12, 2016, 03:13
Default
  #7
Senior Member
 
akidess's Avatar
 
Anton Kidess
Join Date: May 2009
Location: Delft, Netherlands
Posts: 1,121
Rep Power: 20
akidess will become famous soon enough
Yes, I meant (which I now see was not the offending code):
Code:
if(runTime.timeName() == 0)
        {            
          solve(
              fvm::ddt(T) +  
              fvm::div(phi,T) -
              fvm::laplacian(diff,T) ==
              C
            );
       }
       else{
            solve(
              fvm::ddt(T) +  
              fvm::div(phi,T) -
              fvm::laplacian(diff,T)
            );
        }
Antimony, your code won't work properly as you are throwing away all decimals. What you want is
Code:
if (runTime.value()==0)
__________________
*On twitter @akidTwit
*Spend as much time formulating your questions as you expect people to spend on their answer.
*Join the OpenFOAM stackexchange Q&A site: http://area51.stackexchange.com/prop...oHPxcPqde7HtA2
akidess is offline   Reply With Quote

Old   February 12, 2016, 03:35
Default
  #8
Senior Member
 
Alexey Matveichev
Join Date: Aug 2011
Location: Nancy, France
Posts: 1,409
Rep Power: 24
alexeym will become famous soon enoughalexeym will become famous soon enough
@karma15,

Could we reformulate your "if the runtime is 0" as "if we are at the first time step"? You know (http://foam.sourceforge.net/docs/cpp/a02595.html), Time class has not only timeName (which is word, so you should compare is with word, i.e. "0") but also has timeIndex method (http://foam.sourceforge.net/docs/cpp...10d657a2a6e600) which returns label, and you can compare it with 0.

Also your code could be rewritten as

Code:
fvScalarMatrix TEqn
(
    fvm::ddt(T)
  + fvm::div(phi, T)
  - fvm::laplacian(diff, T)
);

if (runTime.timeIndex() == 0)
{
   TEqn -= C
}

TEqn.solve();
Update. No, reformulation is not correct for the case of simulation restart. So you have to compare value() (http://foam.sourceforge.net/docs/cpp...72acceec615aaa) and 0 as akidess proposed. I.e.

Code:
if (equal(runTime.value(), 0))
{
   TEqn -= C
}
alexeym is offline   Reply With Quote

Reply

Thread Tools
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 On
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
area does not match neighbour by ... % -- possible face ordering problem St.Pacholak OpenFOAM 9 November 22, 2011 11:02
Problem in implementing cht tilek CFX 3 May 8, 2011 08:39
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:08.