CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > Software User Forums > OpenFOAM > OpenFOAM Programming & Development

error: cannot convert ‘Foam::tmp<Foam::GeometricField<double, Foam::fvPatchField, Foa

Register Blogs Community New Posts Updated Threads Search

Like Tree9Likes
  • 3 Post By krishna_kant_IITH
  • 5 Post By Elliptic CFD
  • 1 Post By shanvach

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   August 28, 2017, 10:16
Default error: cannot convert ‘Foam::tmp<Foam::GeometricField<double, Foam::fvPatchField, Foa
  #1
New Member
 
krishna kant
Join Date: Aug 2017
Location: hyderabad
Posts: 4
Rep Power: 8
krishna_kant_IITH is on a distinguished road
Send a message via Skype™ to krishna_kant_IITH
Hello Foamers

I am trying to solve a laplace equation without using laplacian function.
so I have written the following code

Code:
#include "fvCFD.H"
#include "simpleControl.H"

// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
scalar calculateTemperature(scalar x,int id);

int main(int argc, char *argv[])
{
    #include "setRootCase.H"
    #include "createTime.H"
    #include "createMesh.H"
    
    simpleControl simple(mesh);
    
    #include "createFields.H"
    //#include "initContinuityErrs.H"

    // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

    Info<< "\nStarting time loop\n" << endl;
    scalar x[1]={0};
    scalar y[1]={0};
    scalar z[1]={0};

    while (simple.loop())
    {
        Info<< "Time = " << runTime.timeName() << nl << endl;
    
        while (simple.correctNonOrthogonal())
        {
      gradT=fvc::grad(T);
        for (label cellid= 0; cellid <mesh.C().size(); cellid++)
        {
          for (label faceid= 0; faceid <mesh.owner().size(); faceid++)
          {
        x[0]=mesh.Sf()[faceid].x();
        y[0]=mesh.Sf()[faceid].y();
        z[0]=mesh.Sf()[faceid].z();
             T[cellid]=T[cellid]-runTime.deltaTValue()*1.00*(gradT.component(0)*x[0]+gradT.component(1)*y[0]+gradT.component(2)*z[0]);
          }
        }
        }

        runTime.write();

        Info<< "ExecutionTime = " << runTime.elapsedCpuTime() << " s"
            << "  ClockTime = " << runTime.elapsedClockTime() << " s"
            << nl << endl;
    }

    Info<< "End\n" << endl;

    return 0;
}
I am getting the following error :
error: cannot convert ‘Foam::tmp<Foam::GeometricField<double, Foam::fvPatchField, Foam::volMesh> >’ to ‘double’ in assignment
In the line of T[cellid] .....
Kummi, Gang Wang and ali moeni like this.

Last edited by Tobi; August 28, 2017 at 15:41. Reason: Added code tags
krishna_kant_IITH is offline   Reply With Quote

Old   August 31, 2017, 11:21
Default T is probably declared as a temporary object
  #2
New Member
 
Ehimen
Join Date: Jun 2016
Posts: 12
Rep Power: 9
Elliptic CFD is on a distinguished road
I suspect that your variable T is a temporary object. Hence, you only have a read only access. To modify the variable, you need to access the non-const reference of the variable with T.ref(). If you are using an older version of OpenFOAM, you can use the non-const deference operator T()(). I will advise you to take a look at tmp.H located in OpenFOAM/memory. Hopefully, that solves the problem.
Phicau, daire6, kk415 and 2 others like this.
Elliptic CFD is offline   Reply With Quote

Old   January 18, 2019, 17:33
Default Getting the same error while defining a new body force term
  #3
Member
 
Join Date: Apr 2016
Posts: 30
Rep Power: 10
shanvach is on a distinguished road
Hi all,

I am trying to add two body force terms in twoPhaseEulerFoam.

Code:
volVectorField gr_alpha = fvc::grad(alpha2);
volTensorField grU_2 = fvc::grad(U2);
volScalarField sc = grU_2 && (grU_2 + grU_2.T());
const scalar csid = 25;
const scalar a  = 4e-6;
//const scalar k = .1;
const scalar eps = 0.206;
//Lift force
//dimensionedScalar up = ("up", [0 0 -1 0 0 0 0], 1.0);
//const scalar up  =1.0;
volScalarField up = .1629 + (.2088/(.1476+(Foam::sqrt(sc))));
//volScalarField up = 1.0*sc/(sc + ROOTSMALL) ;
const scalar cl = 1.2;

volVectorField fsid = U2; // copy of the field;
volVectorField fl = U2;
volScalarField dis = wallDist(mesh).y();
volVectorField ncap = wallDist(mesh).n();

Random rnm;
forAll(fsid, cellI)
{
    scalar rn = rnm.GaussNormal<scalar>();

    fsid[cellI][0] = (Foam::sqrt(sc[cellI]))*alpha2[cellI]*a*eps*rn*csid*-((gr_alpha[cellI][0])/(mag((gr_alpha[cellI][0]))+ROOTSMALL));
    fsid[cellI][1] = (Foam::sqrt(sc[cellI]))*alpha2[cellI]*a*eps*rn*csid*-((gr_alpha[cellI][1])/(mag((gr_alpha[cellI][1]))+ROOTSMALL));
    fsid[cellI][2] = (Foam::sqrt(sc[cellI]))*alpha2[cellI]*a*eps*rn*csid*-((gr_alpha[cellI][2])/(mag((gr_alpha[cellI][2]))+ROOTSMALL));
}
forAll(fl,cellI)
{
	fl[cellI][0] = cl*(up)*(sc[cellI]*a*a*a)/((dis[cellI])+ROOTSMALL)*(ncap[cellI][0]);
	fl[cellI][1] = cl*(up)*(sc[cellI]*a*a*a)/((dis[cellI])+ROOTSMALL)*(ncap[cellI][1]);
	fl[cellI][2] = cl*(up)*(sc[cellI]*a*a*a)/((dis[cellI])+ROOTSMALL)*(ncap[cellI][2]);
}
I am getting the error because of the bolded statement. How do I rectify that?

Your help in this matter is greatly appreciated.

Thanks and Regards,
Shantanu
neilk likes this.
shanvach is offline   Reply With Quote

Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Help with if statement CHARLES OpenFOAM Programming & Development 17 August 22, 2021 03:14
Elementwise multiplication operator johndeas OpenFOAM Running, Solving & CFD 3 March 9, 2019 13:03
adding compressible option to ptot immortality OpenFOAM Programming & Development 13 June 15, 2015 15:00
A stupid question luckyluke OpenFOAM Running, Solving & CFD 14 August 13, 2007 04:25


All times are GMT -4. The time now is 17:00.