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/)
-   -   why can not define a variable of "scalarFieldField tspecies(19)" (https://www.cfd-online.com/Forums/openfoam-programming-development/127399-why-can-not-define-variable-scalarfieldfield-tspecies-19-a.html)

zqlhzx December 10, 2013 09:25

why can not define a variable of "scalarFieldField tspecies(19)"
 
Hi foamer.
I want to define "scalarFieldField tspecies(19)",code as following:
Code:

#include "scalarFieldField.H" 
scalarFieldField tspecies(19);
    for (label i=0; i<Y.size(); i++)
    {
                  tspecies[i](tableProperties.lookup(Y[i].name()));
}

however,it gave me error:
Quote:

readTableProperties.H: In function ‘int main(int, char**)’:
readTableProperties.H:28:1: error: ‘scalarFieldField’ was not declared in this scope
readTableProperties.H:28:18: error: expected ‘;’ before ‘tspecies’
readTableProperties.H:34:19: error: ‘tspecies’ was not declared in this scope
How can I solve the problem?
Thank in advance!

Lieven December 10, 2013 10:38

The way I understand it, is that scalarFieldField does not define a type like e.g. scalarList. So you can't create objects of this type since it simply does not exist. Instead, the source files (scalarFieldField.C and .H) define how objects of the type FieldField<Field, scalar> should handle a number of basic operations. So if you want to create an object which behaves as a scalarFieldField you should create it as
Code:

FieldField<Field, scalar> tspecies(19);
At least that's what I think ...

zqlhzx December 10, 2013 12:09

Dear Lieven,
What you think is right!
It really works for me!Thank you for you help!Good luck!

zqlhzx December 10, 2013 12:58

Quote:

Originally Posted by Lieven (Post 465737)
The way I understand it, is that scalarFieldField does not define a type like e.g. scalarList. So you can't create objects of this type since it simply does not exist. Instead, the source files (scalarFieldField.C and .H) define how objects of the type FieldField<Field, scalar> should handle a number of basic operations. So if you want to create an object which behaves as a scalarFieldField you should create it as
Code:

FieldField<Field, scalar> tspecies(19);
At least that's what I think ...

Dear Lieven,
I wirte the following codes in my solver and it can be compiled successfully.Could I ask you another question?
Code:

Info<< "Reading table properties\n" << endl;
    IOdictionary tableProperties
    (
        IOobject
        (
            "tableProperties",
            runTime.constant(),
            mesh,
            IOobject::MUST_READ,
            IOobject::NO_WRITE
        )
    );
FieldField<Field,scalar> tspecies(19);
    for (label i=0; i<Y.size(); i++)
    {
                  scalarField A(tableProperties.lookup("Y[i].name()"));
                  tspecies[i]=A;
    }

What I'd like to ask you is something about "(tableProperties.lookup("Y[i].name()")".In my tableProperties ,it is :
Code:

FoamFile
{
version    2.0;
format      binary;
class      dictionary;
location    "constant";
object      tableProperties;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

CH4
(
0.0000    0.0120    0.0240    0.0360    0.0480    0.0060    0.0720    0.0840    0.0960    0.1080
0.1200    0.1320    0.1440    0.1560    0.1680    0.1800    0.1920    0.2040    0.2160    0.2280
0.2400    0.2520    0.2640    0.2760    0.2880    0.3000    0.3120    0.3240    0.3360    0.3480
0.3600    0.3720    0.3840    0.3960    0.4080    0.4200    0.4320    0.4440    0.4560    0.4680
0.4800    0.5000    0.5250    0.5500    0.5750    0.6000    0.6250    0.6500    0.6750    0.7000
0.7250    0.7500    0.7750    0.8000    0.8500    0.9000    0.9500    1.0001
);
O2
(
0.0000    0.0120    0.0240    0.0360    0.0480    0.0060    0.0720    0.0840    0.0960    0.1080
0.1200    0.1320    0.1440    0.1560    0.1680    0.1800    0.1920    0.2040    0.2160    0.2280
0.2400    0.2520    0.2640    0.2760    0.2880    0.3000    0.3120    0.3240    0.3360    0.3480
0.3600    0.3720    0.3840    0.3960    0.4080    0.4200    0.4320    0.4440    0.4560    0.4680
0.4800    0.5000    0.5250    0.5500    0.5750    0.6000    0.6250    0.6500    0.6750    0.7000
0.7250    0.7500    0.7750    0.8000    0.8500    0.9000    0.9500    1.0001
);
CO2
(
0.0000    0.0120    0.0240    0.0360    0.0480    0.0060    0.0720    0.0840    0.0960    0.1080
0.1200    0.1320    0.1440    0.1560    0.1680    0.1800    0.1920    0.2040    0.2160    0.2280
0.2400    0.2520    0.2640    0.2760    0.2880    0.3000    0.3120    0.3240    0.3360    0.3480
0.3600    0.3720    0.3840    0.3960    0.4080    0.4200    0.4320    0.4440    0.4560    0.4680
0.4800    0.5000    0.5250    0.5500    0.5750    0.6000    0.6250    0.6500    0.6750    0.7000
0.7250    0.7500    0.7750    0.8000    0.8500    0.9000    0.9500    1.0001
);
H2O
(
0.0000    0.0120    0.0240    0.0360    0.0480    0.0060    0.0720    0.0840    0.0960    0.1080
0.1200    0.1320    0.1440    0.1560    0.1680    0.1800    0.1920    0.2040    0.2160    0.2280
0.2400    0.2520    0.2640    0.2760    0.2880    0.3000    0.3120    0.3240    0.3360    0.3480
0.3600    0.3720    0.3840    0.3960    0.4080    0.4200    0.4320    0.4440    0.4560    0.4680
0.4800    0.5000    0.5250    0.5500    0.5750    0.6000    0.6250    0.6500    0.6750    0.7000
0.7250    0.7500    0.7750    0.8000    0.8500    0.9000    0.9500    1.0001
);

(In fact,the values in different species is different.I just show it as example).It should be that Y[0].name()=CH4,Y[1].name()=O2.Y[2].name()=CO2,Y[3].name()=H2O. I want to make "scalarFIeld A" is equal to the values for different species.
So lookup (Y[i].name).
If I use
Code:

scalarField A(tableProperties.lookup("CH4"))
it can work,and my case can run.However,if I use
Code:

scalarField A(tableProperties.lookup("Y[i].name()"))
then I run my case ,it give me error:
Quote:

keyword Y[i].name() is undefined in dictionary "/home/acer/OpenFOAM/acer-2.2.2/run/singlefirepoolx/constant/tableProperties"
Then I get rid of the "" like:
Code:

scalarField A(tableProperties.lookup(Y[i].name()))
it still gave me error:
Quote:

FOAM FATAL ERROR:
hanging pointer at index 0 (size 19), cannot dereference

From function PtrList::operator[]
in file /opt/openfoam222/src/OpenFOAM/lnInclude/PtrListI.H at line 150.
FOAM aborting
What do you think about my error?Could you give me some advises?Thank you !


All times are GMT -4. The time now is 01:31.