|
[Sponsors] |
error: cannot convert ‘Foam::tmp<Foam::GeometricField<double, Foam::fvPatchField, Foa |
|
LinkBack | Thread Tools | Search this Thread | Display Modes |
August 28, 2017, 10:16 |
error: cannot convert ‘Foam::tmp<Foam::GeometricField<double, Foam::fvPatchField, Foa
|
#1 |
New Member
|
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; } error: cannot convert ‘Foam::tmp<Foam::GeometricField<double, Foam::fvPatchField, Foam::volMesh> >’ to ‘double’ in assignment In the line of T[cellid] ..... Last edited by Tobi; August 28, 2017 at 15:41. Reason: Added code tags |
|
August 31, 2017, 11:21 |
T is probably declared as a temporary object
|
#2 |
New Member
Ehimen
Join Date: Jun 2016
Posts: 12
Rep Power: 9 |
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.
|
|
January 18, 2019, 17:33 |
Getting the same error while defining a new body force term
|
#3 |
Member
Join Date: Apr 2016
Posts: 30
Rep Power: 10 |
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]); } Your help in this matter is greatly appreciated. Thanks and Regards, Shantanu |
|
|
|
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 |