|
[Sponsors] |
July 18, 2007, 08:58 |
Hello,
I would like to hav
|
#1 |
New Member
PDA Platteeuw
Join Date: Mar 2009
Posts: 3
Rep Power: 17 |
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 |
|
July 18, 2007, 09:09 |
the following should work:
|
#2 |
Senior Member
Frank Bos
Join Date: Mar 2009
Location: The Netherlands
Posts: 340
Rep Power: 18 |
the following should work:
const volScalarField& xPos = mesh.C().component(vector::X) Frank
__________________
Frank Bos |
|
July 18, 2007, 09:19 |
Close (the above was a memory
|
#3 |
Senior Member
Hrvoje Jasak
Join Date: Mar 2009
Location: London, England
Posts: 1,907
Rep Power: 33 |
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 |
|
July 18, 2007, 09:32 |
Hi Hrv,
I thought:
1) A
|
#4 |
Senior Member
Frank Bos
Join Date: Mar 2009
Location: The Netherlands
Posts: 340
Rep Power: 18 |
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 |
|
July 18, 2007, 09:42 |
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 |
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 |
|
July 18, 2007, 09:52 |
Perfectly clear, but one more
|
#6 |
Senior Member
Frank Bos
Join Date: Mar 2009
Location: The Netherlands
Posts: 340
Rep Power: 18 |
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 |
|
July 18, 2007, 09:57 |
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 |
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 |
|
July 18, 2007, 10:01 |
thanks, totally clear!
Fran
|
#8 |
Senior Member
Frank Bos
Join Date: Mar 2009
Location: The Netherlands
Posts: 340
Rep Power: 18 |
thanks, totally clear!
Frank
__________________
Frank Bos |
|
|
|
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 |