CFD Online Discussion Forums

CFD Online Discussion Forums (http://www.cfd-online.com/Forums/)
-   OpenFOAM (http://www.cfd-online.com/Forums/openfoam/)
-   -   C OpenFOAM data structures (http://www.cfd-online.com/Forums/openfoam/60848-c-openfoam-data-structures.html)

maka February 27, 2008 08:29

does scalarField accept to be
 
does scalarField accept to be build dynamically without specifying the size in the constructor. This is like saying a=[]; a(end+1)=3; in matlab.

grtabor February 27, 2008 08:35

No. You are unlikely to want t
 
No. You are unlikely to want to do this - the size of your scalarField _is_ the size of your mesh. If you need to create the object before constructing it you need to make a pointer and then reference it to the object when you do construct it. If you need a list of scalars which can grow, use ptrList.

Gavin

maka February 28, 2008 09:22

You are unlikely to want to do
 
Quote:

You are unlikely to want to do this - the size of your scalarField _is_ the size of your mesh.
.

I thought that this is the case in volScalarField. I used to think that scalarField is just punch of numbers that may correspond to the mesh or not, for example, they may represent a spatial average over homogeneous directions. Thanks for the tip regarding prtList, it is very useful.

I found the following solution:

scalarField sf(3,0.0);
sf.newElmt(4); Y[4] = 100;

Now, assume I have a scalar field y as:

scalarField y = patches()[patchI].Cf().component(vector::Y);

I looked for a member function to check if its value is constant but I did not find any. Any body aware of such a function.

Best regards,
Maka.

maka February 28, 2008 10:20

correction of the example:
 
correction of the example:

// this adds and element of value 100 to the end of scalar field sf.
scalarField sf(3,0.0);
sf.setSize(sf.size() + 1, 100);

/Maka.

maka March 5, 2008 10:58

C++ operation: I need to do t
 
C++ operation:
I need to do the following operation (the scope of pMean variable is important) but it does not work. I tried with and without tmp. Would you please explain how to do it.

IOobject pMeanHeader
(
"pMean",
runTime.times()[i].name(),
mesh,
//IOobject::MUST_READ
IOobject::READ_IF_PRESENT
);

volScalarField pMean;

if (pMeanHeader.headerOk())
{
pMean = tmp<volscalarfield(pmeanheader,mesh)>;

}

mattijs March 6, 2008 05:38

autoPtr pMeanP
 
autoPtr<volscalarfield> pMeanPtr;
..
// Set autoptr to valid field
pMeanPtr.reset(new volScalarField(...));
..
// Test if set
if (pMeanPtr.valid())

maka March 6, 2008 08:20

Many thanks Mattijs for your h
 
Many thanks Mattijs for your help. It works. For the beginners like myself one can dereference the autoPtr by:

volScalarField& pMean(*pMeanPtr.ptr());

Best regards,
Maka.


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