CFD Online Discussion Forums

CFD Online Discussion Forums (http://www.cfd-online.com/Forums/)
-   OpenFOAM Programming & Development (http://www.cfd-online.com/Forums/openfoam-programming-development/)
-   -   convert dimensioned<double>’ to ‘double’ (http://www.cfd-online.com/Forums/openfoam-programming-development/78918-convert-dimensioned-double-double.html)

nimasam August 5, 2010 16:49

convert dimensioned<double>’ to ‘double’
 
cannot convert ‘const Foam::dimensioned<double>’ to ‘double’ in assignment

hi friends i have following code what can i do for above compiling error ?

T[i]=TSat;
T is volscalarfield and Tsat is a dimensioned scalar ,

olesen August 6, 2010 04:22

Quote:

Originally Posted by nimasam (Post 270457)
cannot convert ‘const Foam::dimensioned<double>’ to ‘double’ in assignment

hi friends i have following code what can i do for above compiling error ?

T[i]=TSat;
T is volscalarfield and Tsat is a dimensioned scalar ,

If you just need the value without the dimensions:
Code:

T[i ]= TSat.value();
should work.
This method is covered in the doxygen for dimensioned types:
http://foam.sourceforge.net/doc/Doxy...mensioned.html

Pritika August 8, 2010 12:15

hey
i'm facing a similar problem while trying to build a new drag model
i need to calcuate Eotvos number (E) which i have defined as a volScalarField.

volScalarField E = Gravity.value()*(phaseb_.rho()-phasea_.rho())*pow(phasea_.d(),2.0)/sigma.value();

i needed to define g and sigma. i am defining them as dimensionedScalars but when i give them in the formula i get an error

Models/SchillerNaumann/SchillerNaumann.C:89: error: conversion from ‘Foam::dimensioned<double>’ to non-scalar type ‘Foam::volScalarField’ requested

Any suggestions how to get over this problem? i tried the variable.value() as suggested above but the error still remains.

thanks.

Pritika

nimasam August 8, 2010 13:21

hi paritika
above solution works for me,
whats ur volscalarField variable in the right hand of equation?

Pritika August 8, 2010 15:11

hey

there is no volScalarField on the right side of the equation. they are all constants basically. rho (the density) and d (the diameter) are being read form the Phase model( i think as dimensioned scalars itself).
gravity and sigma i have defined as dimensioned scalars.

nimasam August 8, 2010 15:54

hi Pritika
so use the following code :
volScalarField E;
forAll (E,celli)
{
E[celli] = Gravity.value()*(phaseb_.rho()-phasea_.rho())*pow(phasea_.d(),2.0)/sigma.value();
}
could you tell me why do u define E as volScalarField ?

Pritika August 9, 2010 02:26

hey nima

i need E as a volScalarField as i need to compare it with reynolds number in an if condition and reynolds number is a volscalarField due to velocity.

thanks for the help

Pritika August 9, 2010 05:20

hey nima

i tried your suggested code but now i face a new error

error: cannot convert ‘Foam::dimensioned<double>’ to ‘double’ in assignment.

any suggestions? thanks again

olesen August 9, 2010 06:20

Quote:

Originally Posted by nimasam (Post 270723)
hi Pritika
so use the following code :
volScalarField E;
forAll (E,celli)
{
E[celli] = Gravity.value()*(phaseb_.rho()-phasea_.rho())*pow(phasea_.d(),2.0)/sigma.value();
}

If you use the zero-sized volScalarField 'E' as above, you are headed for a segfault.
You need to allocate/dimension it beforehand.

If all of the values are indeed constants, then I'd think you'd use something like this:

Code:

dimensionedScalar constE
(
    "E",
    someDimensions,
    (phaseb_.rho() - phasea_.rho()) * sqr(phasea_.d()) / sigma
);


volScalarField E
(
    IOobject
    (
        "E",
        runTime.timeName(),
        mesh,
        IOobject::NO_READ,
        IOobject::NO_WRITE
    ),
    mesh,
    constE
);

// or combined:

volScalarField E
(
    IOobject
    (
        "E",
        runTime.timeName(),
        mesh,
        IOobject::NO_READ,
        IOobject::NO_WRITE
    ),
    mesh,
    dimensionedScalar
    (
        "E",
        someDimensions,
        (phaseb_.rho() - phasea_.rho()) * sqr(phasea_.d()) / sigma
    )
);

You'll need to work a bit on getting the dimensions correct, or else simply define everything to be dimensionless. This is for you to decide.

Pritika August 19, 2010 08:18

hey
i tried the above suggested method but i get the following errors

error: ‘runTime’ was not declared in this scope
dragModels/SchillerNaumann/SchillerNaumann.C:94: error: ‘mesh’ was not declared in this scope
dragModels/SchillerNaumann/SchillerNaumann.C:105: error: no matching function for call to ‘Foam::dimensioned<double>::dimensioned(const char [4], Foam::dimensionSet, Foam::dimensioned<double>)’


i have tried something different now, instead of defining E as vol scalar i do the following

dimensionedScalar E
(
"E",
dimensionSet(0,0,0,0,0,0,0),
Gravity.value()*(phaseb_.rho() - phasea_.rho()) * sqr(phasea_.d()) / sigma.value()
);


dimensionedScalar Cd2
(
"Cd2",
dimensionSet(0,0,0,0,0,0,0),
8.0*(E.value()/E.value()+4)/3.0
);
then compare Cd2 as follows

forAll(Re, celli)
{
if(Cds[celli] < Cd2)
{
Cds[celli] = Cd2;
}
}
but i am still find an error

error: no matching function for call to ‘Foam::dimensioned<double>::dimensioned(const char [2], Foam::dimensionSet, Foam::dimensioned<double>)’

any suggestions on this one?

Sherlock_1812 October 24, 2013 09:56

Hello all,

I have the following piece of code that I wrote for a boundary condition.
Code:

    const scalarField& x = patch().Cf().component(0);
    const vectorField modGrad; // creating a vectorField called modGrad
   
// Assigning values to the scalarFields
    forAll(modGrad, patchi)
    {
    scalar Ux = scalarCoeff_*x[patchi];
    scalar Uy = 0;
    scalar Uz = 0;

    modGrad[patchi] = vector(Ux, Uy, Uz);
    }

When i compile it I get the following ---> "error: cannot convert ‘Foam::tmp<Foam::Field<double> >’ to ‘Foam::scalar {aka double}’ in initialization.

Can you tell me where I'm going wrong. Apologies if it is a basic mistake.

wyldckat October 26, 2013 13:44

Greetings Srivaths,

I can't figure out in which line that error is occurring. To which line is that message referring to?

In addition, of what kind is the variable "scalarCoeff_"?

Best regards,
Bruno

Sherlock_1812 October 27, 2013 09:12

Hi Bruno,

Apologies, my bad! The error comes in the line where i assign Ux = scalarCoeff_*x[patchi].
And scalarCoeff is a ratio of two scalars that is to be given as input.

In this BC, i'm trying to re-define the expression for refGradient with the vectorField 'modGrad'. I want to assign the first component of refGrad as the scalarCoeff_*(x-value of the face centre of each patch) on which this BC is applied.

Am i making a basic mistake of assigning a scalarField to a scalar?

wyldckat October 27, 2013 09:20

Hi Srivaths,

If I'm not mistaken, I saw this just this past Friday. You're missing the forAll loop for the faces inside the patch.

Let me see if I can find a piece of OpenFOAM code that does this... after a very quick search, have look into the file "src/finiteVolume/fields/fvPatchFields/derived/supersonicFreestream/supersonicFreestreamFvPatchVectorField.C" and/or look for other files that use the variable "facei".

Best regards,
Bruno

Sherlock_1812 October 27, 2013 12:59

That was a quick reply. Thank you Bruno! I'll have a look at that BC.

Thamali December 18, 2013 08:06

Dear Sherlock,
did you get through your problem?
I am getting an error similar to one of yours,
"cannot convert 'Foam::tmp<Foam::GeometricField<Foam::vector<doubl e>,Foam::fvPatchField,Foam::volMesh>>' to 'int' in return"
Please see whether somwone can help me......:)

Thanks in advance

Bernhard December 18, 2013 08:18

It means that your function is returning the wrong type. Without code, it is difficult to say anything else.

Thamali December 18, 2013 10:06

1 Attachment(s)
what I wanted is to create an anisotropic thermal conductivity field using 2volScalarFields and zero("0") for other direction.
my code is as follows(followed fromheSolidThermo.C)
I tried 2 methods and neither of them worked.
document is attaching.
Method 1: is from line 800-892(which gives mentioned error)
Method 2: is from line 762-798
2 volScalarFields are calculated using the equation k=(ko+.5*Re*Pr) and (ko+0.1*Re*Pr)

Thanks

Thamali December 19, 2013 00:07

although any of the 2 methods did not work.I managed to do that in following manner.(still I have to give BCs using 0 folder)
((ko ko 0)+(.1 .5 0)*Pr*Re)
I think OF does not let generating a vectorField using 2 or 3 scalarfields as I have tried in earlier document attached.so,I used vector fields to generate the same.
"wmake" is running but dont know what will arise when running the case file.
However I would like to know your opinions on my early effort and this one too.

Thamali December 23, 2013 08:04

Dear Foamers,
 
I am stucked with an error for some days and could not manage to solve it.As I mentioned earlier in my post.I resolved making the volVectorField.But this time it seems difficult to solve this without a help.
my error after runnign wmake is as follows.Please try to help.


Code:

g++ -m32 -Dlinux -DWM_DP -Wall -Wextra -Wno-unused-parameter  -Wold-style-cast -O3  -DNoRepository -ftemplate-depth-100  -I/opt/openfoam222/src/finiteVolume/lnInclude  -I/opt/openfoam222/src/fvOptions/lnInclude  -I/opt/openfoam222/src/meshTools/lnInclude  -I/opt/openfoam222/src/ODE/lnInclude  -IlnInclude -I.  -I/opt/openfoam222/src/OpenFOAM/lnInclude  -I/opt/openfoam222/src/OSspecific/POSIX/lnInclude  -fPIC -Xlinker  --add-needed -Xlinker --no-as-needed Make/linuxGccDPOpt/my_fireFoam.o  -L/opt/openfoam222/platforms/linuxGccDPOpt/lib \
        -lfiniteVolume -lfvOptions -lmeshTools -lODE  -lOpenFOAM -ldl    -lm -o  /home/thamali/OpenFOAM/thamali-2.2.2/platforms/linuxGccDPOpt/bin/my_fireFoam
Make/linuxGccDPOpt/my_fireFoam.o: In function  `Foam::fv::laplacianScheme<double, Foam::Vector<double>  >::New(Foam::fvMesh const&, Foam::Istream&)':
my_fireFoam.C:(.text._ZN4Foam2fv15laplacianSchemeI    dNS_6VectorIdEEE3NewERKNS_6fvMeshERNS_7IstreamE[Foam::fv::laplacianScheme<double,  Foam::Vector<double> >::New(Foam::fvMesh const&,  Foam::Istream&)]+0x53): undefined reference to  `Foam::fv::laplacianScheme<double, Foam::Vector<double>  >::IstreamConstructorTablePtr_'
my_fireFoam.C:(.text._ZN4Foam2fv15laplacianSchemeI    dNS_6VectorIdEEE3NewERKNS_6fvMeshERNS_7IstreamE[Foam::fv::laplacianScheme<double,  Foam::Vector<double> >::New(Foam::fvMesh const&,  Foam::Istream&)]+0x1a5): undefined reference to  `Foam::fv::laplacianScheme<double, Foam::Vector<double>  >::IstreamConstructorTablePtr_'
my_fireFoam.C:(.text._ZN4Foam2fv15laplacianSchemeI    dNS_6VectorIdEEE3NewERKNS_6fvMeshERNS_7IstreamE[Foam::fv::laplacianScheme<double,  Foam::Vector<double> >::New(Foam::fvMesh const&,  Foam::Istream&)]+0x1d5): undefined reference to  `Foam::fv::laplacianScheme<double, Foam::Vector<double>  >::IstreamConstructorTablePtr_'
collect2: ld returned 1 exit status
make: *** [/home/thamali/OpenFOAM/thamali-2.2.2/platforms/linuxGccDPOpt/bin/my_fireFoam] Error 1

Thanks.


All times are GMT -4. The time now is 10:15.