CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   OpenFOAM Programming & Development (https://www.cfd-online.com/Forums/openfoam-programming-development/)
-   -   How pass dimensionedScalar vector for a function made in C language?. (https://www.cfd-online.com/Forums/openfoam-programming-development/135705-how-pass-dimensionedscalar-vector-function-made-c-language.html)

leo malazart May 16, 2014 11:50

How pass dimensionedScalar vector for a function made in C language?.
 
i'm just a new user of openfoam.
I am trying to implement a function. This function code was implemented in C language. Firstly, I initialize a list of dimensionedScalar, as can be seen below:

Code:

//   
const wordList criticaNames(criticaDict.toc());

    wordList criticaNames
    (
        criticaDict.lookup("componentes")
    );


    PtrList<dimensionedScalar> Tc(criticaNames.size());
    PtrList<dimensionedScalar> Pc(criticaNames.size());
    PtrList<dimensionedScalar> wc(criticaNames.size());
    PtrList<dimensionedScalar> PM(criticaNames.size());

    forAll(criticaNames, i)
    {
        const word& criticaName = criticaNames[i];
        const dictionary& subDict = criticaDict.subDict(criticaName);

        Tc.set
        (
            i,
            new dimensionedScalar(subDict.lookup("Tc"))
        );
        Pc.set
        (
            i,
            new dimensionedScalar(subDict.lookup("Pc"))
        );
        wc.set
        (
            i,
            new dimensionedScalar(subDict.lookup("wc"))
        );
        PM.set
        (
            i,
            new dimensionedScalar(subDict.lookup("PM"))
        );
    Info<< "Reading field Fugacidade\n" << endl;

    volScalarField fug
    (
        IOobject
        (
            "Fug",
            runTime.timeName(),
            mesh,
            IOobject::NO_READ,
            IOobject::AUTO_WRITE
        ),
        mesh
    );

    #include "fug.H"

and I pass the Tc,Pc and wc for a function made in C code. This function is called in "fug.H":
Code:


forAll(fug, cellI)
            {

                fugacidade(thermo1.T()[cellI],Tc,Pc,wc,fug[cellI]);

            }

and the my functions code is
Code:

double fugacidade(double T, PtrList<dimensionedScalar> Tc, PtrList<dimensionedScalar> Pc, PtrList<dimensionedScalar> wc, double result1)

result1 = (Tc[0].value+Pc[0].value+wc[0].value)/T)
  return (result1);
}

However, the code won't compile. When I compile the error in debug output on OpenFoam 2.2 is:
Code:

/home/leonardo/OpenFOAM/OpenFOAM-2.2.0/src/OpenFOAM/lnInclude/PtrList.C: In instantiation of ‘Foam::PtrList<T>::PtrList(const Foam::PtrList<T>&) [with T = Foam::dimensioned<double>]’:
fug.H:4:114:  required from here
/home/leonardo/OpenFOAM/OpenFOAM-2.2.0/src/OpenFOAM/lnInclude/PtrList.C:54:18: error: ‘const class Foam::dimensioned<double>’ has no member named ‘clone’
        ptrs_[i] = (a[i]).clone().ptr();
                  ^
make: ** [Make/linuxGccDPOpt/MixtcompressibleTwoPhaseEulerFoam.o] Erro 1

what am I doing wrong?

alexeym May 16, 2014 13:10

Hi,

as in fact you don't need a copy of PtrList, you can pass constant reference to the function, i.e.

Code:

double fugacidade(const double& T, const PtrList<dimensionedScalar>& Tc, const PtrList<dimensionedScalar>& Pc, const PtrList<dimensionedScalar>& wc, double& result1)
Also why would you like to pass result1 to function?

leo malazart May 16, 2014 13:29

Thanks for your attention, Alexey Matveichev,
My problem was solved. The function returns result1.

alexeym May 16, 2014 16:56

Well,

if you return value from function, you don't need to pass return value as a parameter to the function. If you'd like to do it FORTRAN style, it's your choice. I mean instead of

Code:

fugacidade(thermo1.T()[cellI],Tc,Pc,wc,fug[cellI]);
you can do it

Code:

fug[cellI] = fugacidade(thermo1.T()[cellI],Tc,Pc,wc);
Think you'll be a little bit easier to read and understand ;)


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