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

How pass dimensionedScalar vector for a function made in C language?.

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   May 16, 2014, 12:50
Default How pass dimensionedScalar vector for a function made in C language?.
  #1
New Member
 
bahia
Join Date: Jun 2013
Posts: 2
Rep Power: 0
leo malazart is on a distinguished road
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?
leo malazart is offline   Reply With Quote

Old   May 16, 2014, 14:10
Default
  #2
Senior Member
 
Alexey Matveichev
Join Date: Aug 2011
Location: Nancy, France
Posts: 1,938
Rep Power: 39
alexeym has a spectacular aura aboutalexeym has a spectacular aura about
Send a message via Skype™ to alexeym
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?
alexeym is offline   Reply With Quote

Old   May 16, 2014, 14:29
Default
  #3
New Member
 
bahia
Join Date: Jun 2013
Posts: 2
Rep Power: 0
leo malazart is on a distinguished road
Thanks for your attention, Alexey Matveichev,
My problem was solved. The function returns result1.
leo malazart is offline   Reply With Quote

Old   May 16, 2014, 17:56
Default
  #4
Senior Member
 
Alexey Matveichev
Join Date: Aug 2011
Location: Nancy, France
Posts: 1,938
Rep Power: 39
alexeym has a spectacular aura aboutalexeym has a spectacular aura about
Send a message via Skype™ to alexeym
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
alexeym is offline   Reply With Quote

Reply

Tags
c language, dimensionedscalar, ptrlist


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
whats the cause of error? immortality OpenFOAM Running, Solving & CFD 13 March 24, 2021 08:15
[blockMesh] Errors during blockMesh meshing Madeleine P. Vincent OpenFOAM Meshing & Mesh Conversion 51 May 30, 2016 11:51
is internalField(U) equivalent to zeroGradient? immortality OpenFOAM Running, Solving & CFD 7 March 29, 2013 02:27
Problem with rhoSimpleFoam matteo_gautero OpenFOAM Running, Solving & CFD 0 February 28, 2008 07:51
Droplet Evaporation Christian Main CFD Forum 2 February 27, 2007 07:27


All times are GMT -4. The time now is 22:18.