CFD Online Discussion Forums

CFD Online Discussion Forums (http://www.cfd-online.com/Forums/)
-   OpenFOAM Running, Solving & CFD (http://www.cfd-online.com/Forums/openfoam-solving/)
-   -   Saving Patch cell centres as an IOobject (http://www.cfd-online.com/Forums/openfoam-solving/59613-saving-patch-cell-centres-ioobject.html)

jaswi June 27, 2007 07:01

Dear OpenFoam Users I need
 
Dear OpenFoam Users

I need to save a boundary patch as an IOobject. This is what I am adding to createFields.H:


1-->label patchID = mesh.boundaryMesh().findPatchID("walls");

2-->const fvPatch& cPatch = mesh.boundaryMesh()[patchID];

3-->const vectorField& faceCentres = cPatch.Cf();

The above changes have been suggested in :
http://www.cfd-online.com/OpenFOAM_D...ges/1/174.html

to access faceCentres and save it as a vectorField but compiling this gives following error and it comes from line # 2:

createFields.H:105: error: invalid initialization of reference of type 'const Foam::fvPatch&' from expression of type 'const Foam::polyPatch'

Once I have the faceCentres, i would like to save it as an IOobject and this is what i have in mind

surfaceVectorField WALLPOS=faceCentres
(
IOobject
(
"WALLPOS",
runTime.timeName(),
mesh,
IOobject::NO_READ,
IOobject::AUTO_WRITE
),
mesh
);


Please take a look and suggest what am I doing wrong.

With Best Regards
Jaswinder

gschaider June 27, 2007 08:57

Hi Jaswinder! For your comp
 
Hi Jaswinder!

For your compilation problem:

Try this line:

const fvPatch& cPatch = mesh.boundary()[patchID];

cosimobianchini June 27, 2007 09:08

mesh.boundaryMesh() calls the
 
mesh.boundaryMesh() calls the inherited method polyMesh::boundaryMesh() which returns a polyBoundaryMesh that is a List<polypatch>.

To let it work you just need to change line 2 to:

const fvPatch& cPatch = mesh.boundary()[patchID];

and everything should work.

I guess you are working with OF-1.4 or OF-1.3: the suggestion in the other thread refers to an older version.

Hope this might help
Cosimo

jaswi June 27, 2007 09:24

Hi Bernhard, Cosimo Thanks
 
Hi Bernhard, Cosimo

Thanks alot

It works partially !!!!

After adding :
1--> label patchID = mesh.boundaryMesh().findPatchID("walls");

2--> const fvPatch& cPatch = mesh.boundary()[patchID]; <-- Corrected as per suggestion


3-->const vectorField& faceCentres = cPatch.Cf();

I do get a vectorField faceCentres but when I try to save it as an IOobject in this way :

surfaceVectorField WALLPOS=faceCentres
(
IOobject
(
"WALLPOS",
runTime.timeName(),
mesh,
IOobject::NO_READ,
IOobject::AUTO_WRITE
),
mesh
);

I get following error

createFields.H: In function 'int main(int, char**)':
createFields.H:124: error: no match for call to '(const Foam::Field<foam::vector<double> >) (Foam::IOobject, Foam::fvMesh&)'


Please take a look and suggest what I am doing wrong.

Thanks alot
With Best Regards
Jaswinder

cosimobianchini June 27, 2007 10:01

It depends on what you want to
 
It depends on what you want to do: faceCentres is defined only on a single patch while WALLPOS is defined on all faces.
If you want to build up a surfaceVectorField storing all faces centre vectors, it might be easier to instantiate it in this way:

surfaceVectorField WALLPOS
(
IOobject
(
"WALLPOS",
runTime.timeName(),
mesh,
IOobject::NO_READ,
IOobject::AUTO_WRITE
),
mesh.Cf()
);

otherwise if you want have a null field everywhere apart from the patch you might want to do something like:

surfaceVectorField WALLPOS
(
IOobject
(
"WALLPOS",
runTime.timeName(),
mesh,
IOobject::NO_READ,
IOobject::AUTO_WRITE
),
mesh,
dimensionedVector("null",dimensionSet(0, 0, 0, 0, 0), vector::zero)
);

WALLPOS.boundaryField()[patchID] = faceCentres;

Hopefully these should work
good luck


All times are GMT -4. The time now is 03:25.