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/)
-   -   What happen with this square root?? (https://www.cfd-online.com/Forums/openfoam-solving/123807-what-happen-square-root.html)

darlopez September 21, 2013 12:30

What happen with this square root??
 
Hi everybody!

I want to write a simple operation in my solver:

Tension = zF*sqrt(1-(calcDistance0-0.5)/2.4*(calcDistance0-0.5)/2.4); + forceStatic*(calcDistance0-0.5)/2.4;

Where Tension, zF, calcDistance0 and forceStatic are scalars (static scalar ...)
When I try to compile I find this error:

solveForceBalance.H:154: error: call of overloaded 'sqrt(Foam::scalar)' is ambiguous
/usr/include/bits/mathcalls.h:157: note: candidates are: double sqrt(double)


Help me please!!!

darlopez September 21, 2013 12:40

Solved!

scalar aux = Foam:: sqrt(....)

fedvasu May 16, 2018 21:15

Quote:

Originally Posted by darlopez (Post 452891)
Solved!

scalar aux = Foam:: sqrt(....)

Thank you I didn't think it was a namespace issue. I thought it was a library overload issue.

sippanspojk November 7, 2019 03:59

I have a similar problem. I tried to simplify it to see if sqrt() works at all for me so now I am basically writing sqrt(4) to a vector and that's it. It still doesn't work and I get the following error message:

Code:

error: no matching function for call to ‘Foam::Vector<double>::Vector(<brace-enclosed initializer list>)’
    Foam::Vector<double> testVec{1, 2, sqrt(4)};

It is worth mentioning that I am new to coding in OpenFOAM and also to C++ so I am most likely doing something very trivial wrong.
Can someone tell me what I am doing wrong here?

fedvasu November 7, 2019 17:52

Quote:

Originally Posted by sippanspojk (Post 749126)
I have a similar problem. I tried to simplify it to see if sqrt() works at all for me so now I am basically writing sqrt(4) to a vector and that's it. It still doesn't work and I get the following error message:

Code:

error: no matching function for call to ‘Foam::Vector<double>::Vector(<brace-enclosed initializer list>)’
    Foam::Vector<double> testVec{1, 2, sqrt(4)};

It is worth mentioning that I am new to coding in OpenFOAM and also to C++ so I am most likely doing something very trivial wrong.
Can someone tell me what I am doing wrong here?

Problem isn't with sqrt, error says problem is with {}.

And also use Foam::sqrt for clarity

quarkz March 12, 2020 02:59

Hi,

I got the same error and I'm trying to do my correction. However, it doesn't seem to work.

I need to change the Turbulent frequency equation from :

fvm::ddt(alpha, rho, omega_)
+ fvm::div(alphaRhoPhi, omega_)
- fvm::laplacian(alpha*rho*DomegaEff(F1), omega_)

...

to

fvm::ddt(alpha, rho, omega_)
+ fvm::div(alphaRhoPhi, omega_)
- fvm::laplacian(alpha*sqrt(rho)*DomegaEff(F1), sqrt(rho)*omega_)

I got the error and I changed to:

fvm::ddt(alpha, rho, omega_)
+ fvm::div(alphaRhoPhi, omega_)
- fvm::laplacian(alpha*Foam::sqrt(rho)*DomegaEff(F1), Foam::sqrt(rho)*omega_)

but the error remains. So how should I change it?

Thanks.

quarkz March 12, 2020 03:56

Hi, I followed the corrections recommended here too:

https://openfoamwiki.net/index.php/F...9_is_ambiguous

Possible solutions, instead of simply using sqrt(2.0):

::sqrt(2.0)
scalar(::sqrt(2.0))
::sqrt(scalar(2.0))

but it still can't work, although the error msg has changed:

In file included from ../turbulenceModels/lnInclude/kOmegaSSTBase.H:350:0,
from ../turbulenceModels/lnInclude/kOmegaSST.H:111,
from turbulentTransportModels/turbulentTransportModels.C:73:
../turbulenceModels/lnInclude/kOmegaSSTBase.C: In instantiation of ‘void Foam::kOmegaSSTBase<BasicEddyViscosityModel>::corr ect() [with BasicEddyViscosityModel = Foam::LESModels::DESModel<Foam::IncompressibleTurb ulenceModel<Foam::transportModel> >]’:
turbulentTransportModels/turbulentTransportModels.C:130:29: required from here
../turbulenceModels/lnInclude/kOmegaSSTBase.C:469:95: error: no matching function for call to ‘laplacian(Foam::tmp<Foam::GeometricField<dou ble, Foam::fvPatchField, Foam::volMesh> >, Foam::tmp<Foam::GeometricField<double, Foam::fvPatchField, Foam::volMesh> >)’
- fvm::laplacian(alpha*::sqrt(scalar(rho))*DomegaEff (F1), ::sqrt(scalar(rho))*omega_)
^
../turbulenceModels/lnInclude/kOmegaSSTBase.C:469:95: note: candidates are:
In file included from /home/users/nus/tsltaywb/OpenFOAM/OpenFOAM-v1706_mod/src/finiteVolume/lnInclude/fvmLaplacian.H:188:0,
from /home/users/nus/tsltaywb/OpenFOAM/OpenFOAM-v1706_mod/src/finiteVolume/lnInclude/fvm.H:46,
from ../turbulenceModels/lnInclude/linearViscousStress.C:28,
from ../turbulenceModels/lnInclude/linearViscousStress.H:114,
from ../turbulenceModels/lnInclude/Stokes.H:39,
from ../turbulenceModels/lnInclude/laminarModel.C:27,
from ../turbulenceModels/lnInclude/laminarModel.H:201,
from turbulentTransportModels/turbulentTransportModels.H:31,
from turbulentTransportModels/turbulentTransportModels.C:26:
/home/users/nus/tsltaywb/OpenFOAM/OpenFOAM-v1706_mod/src/finiteVolume/lnInclude/fvmLaplacian.C:45:1: note: template<class Type> Foam::tmp<Foam::fvMatrix<Type> > Foam::fvm::laplacian(const Foam::GeometricField<Type, Foam::fvPatchField, Foam::volMesh>&, const Foam::word&)
laplacian
^
/home/users/nus/tsltaywb/OpenFOAM/OpenFOAM-v1706_mod/src/finiteVolume/lnInclude/fvmLaplacian.C:45:1: note: template argument deduction/substitution failed:
In file included from ../turbulenceModels/lnInclude/kOmegaSSTBase.H:350:0,
from ../turbulenceModels/lnInclude/kOmegaSST.H:111,
from turbulentTransportModels/turbulentTransportModels.C:73:
../turbulenceModels/lnInclude/kOmegaSSTBase.C:469:95: note: ‘Foam::tmp<Foam::GeometricField<double, Foam::fvPatchField, Foam::volMesh> >’ is not derived from ‘const Foam::GeometricField<Type, Foam::fvPatchField, Foam::volMesh>’
- fvm::laplacian(alpha*::sqrt(scalar(rho))*DomegaEff (F1), ::sqrt(scalar(rho))*omega_)

fedvasu March 14, 2020 19:16

Quote:

Originally Posted by quarkz (Post 761383)
Hi,

I got the same error and I'm trying to do my correction. However, it doesn't seem to work.

I need to change the Turbulent frequency equation from :

fvm::ddt(alpha, rho, omega_)
+ fvm::div(alphaRhoPhi, omega_)
- fvm::laplacian(alpha*rho*DomegaEff(F1), omega_)

...

to

fvm::ddt(alpha, rho, omega_)
+ fvm::div(alphaRhoPhi, omega_)
- fvm::laplacian(alpha*sqrt(rho)*DomegaEff(F1), sqrt(rho)*omega_)

I got the error and I changed to:

fvm::ddt(alpha, rho, omega_)
+ fvm::div(alphaRhoPhi, omega_)
- fvm::laplacian(alpha*Foam::sqrt(rho)*DomegaEff(F1), Foam::sqrt(rho)*omega_)

but the error remains. So how should I change it?

Thanks.

Code:

- fvm::laplacian(alpha*sqrt(rho)*DomegaEff(F1), sqrt(rho)*omega_)
This above line is the problem, you are changing an unknown variable 'omega_' to 'sqrt(rho)*omega_' and it is dimensionally inconsistent with your other terms.

Code:

- fvm::laplacian(alpha*Foam::sqrt(2.0)*DomegaEff(F1), omega_)
as you are only multiplying a (non-dim) scalar to the coefficient and not changing the variable, so the above line will work.

Code:

- fvc::laplacian(alpha*Foam::sqrt(2.0)*DomegaEff(F1), Foam::sqrt(2.0)*omega_)
This COULD work, test it out, as you are calculating the term explicitly, 'fvc' not 'fvm'

quarkz March 18, 2020 21:54

I realised that actually using

::sqrt(rho)
scalar(::sqrt(rho))
::sqrt(scalar(rho))

for the sqrt part can work.

My error is due to representing the Laplacian as:

fvm::laplacian(alpha*::sqrt(rho)*DomegaEff(F1), ::sqrt(rho)*omega_)

The omega and sqrt(rho) are grouped together.

Someone seems to have similar enquires:

https://www.cfd-online.com/Forums/op...ple-terms.html

Anyone has a solution?


All times are GMT -4. The time now is 19:33.