CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   OpenFOAM Running, Solving & CFD (https://www.cfd-online.com/Forums/openfoam-solving/)
-   -   Problem using '==' operator (https://www.cfd-online.com/Forums/openfoam-solving/166506-problem-using-operator.html)

karma15 February 10, 2016 19:50

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’
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

Antimony February 10, 2016 21:49

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

akidess February 11, 2016 02:08

You don't need to explicitly set the right hand side. Just remove "== 0". See laplacianFoam: https://github.com/OpenFOAM/OpenFOAM...aplacianFoam.C

karma15 February 11, 2016 14:40

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 February 11, 2016 15:21

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::operator-(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

Antimony February 11, 2016 21: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)
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

akidess February 12, 2016 02:13

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)

alexeym February 12, 2016 02:35

@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
}



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