|
[Sponsors] |
February 10, 2016, 19:50 |
Problem using '==' operator
|
#1 |
New Member
Sara
Join Date: Dec 2013
Posts: 10
Rep Power: 12 |
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’ 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 ); } -Sara |
|
February 10, 2016, 21:49 |
|
#2 |
Senior Member
Join Date: Aug 2013
Posts: 407
Rep Power: 15 |
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 |
|
February 11, 2016, 02:08 |
|
#3 |
Senior Member
Anton Kidess
Join Date: May 2009
Location: Germany
Posts: 1,377
Rep Power: 29 |
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. |
|
February 11, 2016, 14:40 |
|
#4 |
New Member
Sara
Join Date: Dec 2013
Posts: 10
Rep Power: 12 |
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.
|
|
February 11, 2016, 15:21 |
|
#5 | |
New Member
Sara
Join Date: Dec 2013
Posts: 10
Rep Power: 12 |
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:
Sincerely, Sara |
||
February 11, 2016, 21:15 |
|
#6 |
Senior Member
Join Date: Aug 2013
Posts: 407
Rep Power: 15 |
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) Hope this helps. Cheers, Antimony |
|
February 12, 2016, 02:13 |
|
#7 |
Senior Member
Anton Kidess
Join Date: May 2009
Location: Germany
Posts: 1,377
Rep Power: 29 |
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) ); } Code:
if (runTime.value()==0)
__________________
*On twitter @akidTwit *Spend as much time formulating your questions as you expect people to spend on their answer. |
|
February 12, 2016, 02:35 |
|
#8 |
Senior Member
|
@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(); Code:
if (equal(runTime.value(), 0)) { TEqn -= C } |
|
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
area does not match neighbour by ... % -- possible face ordering problem | St.Pacholak | OpenFOAM | 10 | February 7, 2024 21:50 |
UDF compiling problem | Wouter | Fluent UDF and Scheme Programming | 6 | June 6, 2012 04:43 |
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 |