Problem using '==' operator
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) -Sara |
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 |
You don't need to explicitly set the right hand side. Just remove "== 0". See laplacianFoam: https://github.com/OpenFOAM/OpenFOAM...aplacianFoam.C
|
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.
|
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 |
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 |
Yes, I meant (which I now see was not the offending code):
Code:
if(runTime.timeName() == 0) Code:
if (runTime.value()==0) |
@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 Code:
if (equal(runTime.value(), 0)) |
All times are GMT -4. The time now is 08:21. |