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

why can not define a variable of "scalarFieldField tspecies(19)"

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   December 10, 2013, 09:25
Default why can not define a variable of "scalarFieldField tspecies(19)"
  #1
Member
 
赵庆良
Join Date: Aug 2013
Posts: 56
Rep Power: 12
zqlhzx is on a distinguished road
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!
zqlhzx is offline   Reply With Quote

Old   December 10, 2013, 10:38
Default
  #2
Senior Member
 
Lieven
Join Date: Dec 2011
Location: Leuven, Belgium
Posts: 299
Rep Power: 22
Lieven will become famous soon enough
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 ...
Lieven is offline   Reply With Quote

Old   December 10, 2013, 12:09
Default
  #3
Member
 
赵庆良
Join Date: Aug 2013
Posts: 56
Rep Power: 12
zqlhzx is on a distinguished road
Dear Lieven,
What you think is right!
It really works for me!Thank you for you help!Good luck!
zqlhzx is offline   Reply With Quote

Old   December 10, 2013, 12:58
Default
  #4
Member
 
赵庆良
Join Date: Aug 2013
Posts: 56
Rep Power: 12
zqlhzx is on a distinguished road
Quote:
Originally Posted by Lieven View Post
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:perator[]
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 !

Last edited by zqlhzx; December 12, 2013 at 03:20.
zqlhzx 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
UDF: trying to implement a Kinetic Equation source term er.mkumar Fluent UDF and Scheme Programming 35 March 22, 2019 10:20
Plot of user defined variable in CFD Post dreamz Main CFD Forum 0 December 8, 2013 22:00
define variable spring stiffness by writing a macro or command or.. maralll Main CFD Forum 0 November 6, 2013 20:01
Installing OF 1.6 on Mac OS X gschaider OpenFOAM Installation 129 June 19, 2010 09:23
UDF FOR UNSTEADY TIME STEP mayur FLUENT 3 August 9, 2006 10:19


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