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

Xcoordinate of cell centre in volScalarField

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   July 18, 2007, 08:58
Default Hello, I would like to hav
  #1
pda
New Member
 
PDA Platteeuw
Join Date: Mar 2009
Posts: 3
Rep Power: 17
pda is on a distinguished road
Hello,

I would like to have a volScalarField variable which contains the x-position of each cell centre. After looking around for hours, I don't know how to do this. I tried with cellCentres and others, but I cannot find the commands I am looking for.

Any help is greatly appreciated,

PJ
pda is offline   Reply With Quote

Old   July 18, 2007, 09:09
Default the following should work:
  #2
Senior Member
 
Frank Bos
Join Date: Mar 2009
Location: The Netherlands
Posts: 340
Rep Power: 18
lr103476 is on a distinguished road
the following should work:

const volScalarField& xPos = mesh.C().component(vector::X)

Frank
__________________
Frank Bos
lr103476 is offline   Reply With Quote

Old   July 18, 2007, 09:19
Default Close (the above was a memory
  #3
Senior Member
 
Hrvoje Jasak
Join Date: Mar 2009
Location: London, England
Posts: 1,907
Rep Power: 33
hjasak will become famous soon enough
Close (the above was a memory violation):


volScalarField xPos = mesh.C().component(vector::X);

Hrv
__________________
Hrvoje Jasak
Providing commercial FOAM/OpenFOAM and CFD Consulting: http://wikki.co.uk
hjasak is offline   Reply With Quote

Old   July 18, 2007, 09:32
Default Hi Hrv, I thought: 1) A
  #4
Senior Member
 
Frank Bos
Join Date: Mar 2009
Location: The Netherlands
Posts: 340
Rep Power: 18
lr103476 is on a distinguished road
Hi Hrv,

I thought:

1) A reference &, since you don't want a real copy of the cell centres, only the right to have a look at it.

2) A const, since you're not allowed to change the value of the cell centres.

Why memory violation?

Regards, Frank
__________________
Frank Bos
lr103476 is offline   Reply With Quote

Old   July 18, 2007, 09:42
Default All you said is correct, but y
  #5
Senior Member
 
Hrvoje Jasak
Join Date: Mar 2009
Location: London, England
Posts: 1,907
Rep Power: 33
hjasak will become famous soon enough
All you said is correct, but you cannot decide on the return type: the function does that for you. Function signature says:


//- Return a component of the field
tmp<geometricfield<cmpttype,> > component
(
const direction
) const;


In other words, the function will return a tmp<volscalarfield>. If you take a reference and not a copy, nobody is holding the original object and tmp will delete the memory in its destructor. You are now left holding something called a reference to a temporary, ie. looking at a piece of memory that has been deleted and is waiting for re-use. If somebody else uses that memory, you get garbage: memory violation.

Clear?

Hrv
__________________
Hrvoje Jasak
Providing commercial FOAM/OpenFOAM and CFD Consulting: http://wikki.co.uk
hjasak is offline   Reply With Quote

Old   July 18, 2007, 09:52
Default Perfectly clear, but one more
  #6
Senior Member
 
Frank Bos
Join Date: Mar 2009
Location: The Netherlands
Posts: 340
Rep Power: 18
lr103476 is on a distinguished road
Perfectly clear, but one more thing.... I just remembered a piece of code which you showed at the lunch training in Zagreb (with const and a ref &):

const volVectorField& centres = mesh.C();
point origin(0.5,0.5,0.05);
vector axis(0,0,-1);
U.internalField() = axis ^ (centres.internalField() - origin);

What is the difference? Is it the component function?

Frank
__________________
Frank Bos
lr103476 is offline   Reply With Quote

Old   July 18, 2007, 09:57
Default Easy. Have a look in the libr
  #7
Senior Member
 
Hrvoje Jasak
Join Date: Mar 2009
Location: London, England
Posts: 1,907
Rep Power: 33
hjasak will become famous soon enough
Easy. Have a look in the library and find out what the return type is for a function mesh.C(). The file is fvMesh.H and the function signature is:


//- Return cell centres as volVectorField
const volVectorField& C() const;


As you can see, this one returns a const volVectorField& and I can accept it as such. In the other, I have no choice - I have to take a copy.

Clear?

Hrv
__________________
Hrvoje Jasak
Providing commercial FOAM/OpenFOAM and CFD Consulting: http://wikki.co.uk
hjasak is offline   Reply With Quote

Old   July 18, 2007, 10:01
Default thanks, totally clear! Fran
  #8
Senior Member
 
Frank Bos
Join Date: Mar 2009
Location: The Netherlands
Posts: 340
Rep Power: 18
lr103476 is on a distinguished road
thanks, totally clear!

Frank
__________________
Frank Bos
lr103476 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
Is there a way to change the name a volScalarField liu OpenFOAM Running, Solving & CFD 2 October 18, 2007 18:49
centre of pressure emanuele FLUENT 0 October 11, 2006 18:15
centre of pressure shabah FLUENT 1 March 30, 2004 10:55
data centre michelle FLUENT 0 June 16, 2003 05:18
CELL CENTRE OUTSIDE OF THE CELL rogeha Siemens 0 May 23, 2002 06:41


All times are GMT -4. The time now is 15:02.