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

Get the coordinate of all 8 the points of the cells

Register Blogs Community New Posts Updated Threads Search

Like Tree5Likes
  • 2 Post By arvindpj
  • 1 Post By floquation
  • 1 Post By floquation
  • 1 Post By floquation

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   December 19, 2016, 10:46
Default Get the coordinate of all 8 the points of the cells
  #1
New Member
 
HuangXin
Join Date: Dec 2016
Posts: 7
Rep Power: 10
Hxchange is on a distinguished road
My case used snappyMesh and chtMultiRegionSimpleFoam solver, I m trying to postprocessing it and I want to get the coordinate of all the cells ,8 points for each cells, instead of only the cell centre points. I want to make these informations into a file that can list the cells' 8 points' coordinate and their temperature .But I can only get the cell centre cooridates by using "writeCellcentre" .How can it write the coordinate of all the 8 points of the cells ?
I ll be very preciated if someone can help me !
Hxchange is offline   Reply With Quote

Old   December 19, 2016, 18:06
Default
  #2
Member
 
Arvind Jay
Join Date: Sep 2012
Posts: 97
Rep Power: 15
arvindpj is on a distinguished road
Quote:
Originally Posted by Hxchange View Post
My case used snappyMesh and chtMultiRegionSimpleFoam solver, I m trying to postprocessing it and I want to get the coordinate of all the cells ,8 points for each cells, instead of only the cell centre points. I want to make these informations into a file that can list the cells' 8 points' coordinate and their temperature .But I can only get the cell centre cooridates by using "writeCellcentre" .How can it write the coordinate of all the 8 points of the cells ?
I ll be very preciated if someone can help me !
You could use thin in a simple code:
Code:
 mesh.cellPoints()[yourCellIndex]
More details here!

Cheers
:-)
babakflame and cdunn6754 like this.
arvindpj is offline   Reply With Quote

Old   December 22, 2016, 06:50
Default
  #3
New Member
 
HuangXin
Join Date: Dec 2016
Posts: 7
Rep Power: 10
Hxchange is on a distinguished road
Quote:
Originally Posted by arvindpj View Post
You could use thin in a simple code:
Code:
 mesh.cellPoints()[yourCellIndex]
More details here!

Cheers
:-)
Thanks for replying! But I m still confused that what does "yourCellIndex"means?
If I want to get cell 1 ,which should I type?
I had tried "mesh.cellPoints()[Cell1]" or "mesh.cellPoints()[1]", it turned out to be wrong .
And what if I want to get the coordinates of the cells from 1 to 200 ? Thanks a lot!
Hxchange is offline   Reply With Quote

Old   December 22, 2016, 07:05
Default
  #4
Senior Member
 
floquation's Avatar
 
Kevin van As
Join Date: Sep 2014
Location: TU Delft, The Netherlands
Posts: 252
Rep Power: 21
floquation will become famous soon enough
Quote:
Originally Posted by Hxchange View Post
Thanks for replying! But I m still confused that what does "yourCellIndex"means?
If I want to get cell 1 ,which should I type?
I had tried "mesh.cellPoints()[Cell1]" or "mesh.cellPoints()[1]", it turned out to be wrong .
And what if I want to get the coordinates of the cells from 1 to 200 ? Thanks a lot!
The index is an integer number, so this is correct:
Code:
mesh.cellPoints()[1]
However, then you extract the indices of the points, not the coordinates of the points. See this post if you wish to obtain the coordinates.
arvindpj likes this.
floquation is offline   Reply With Quote

Old   December 22, 2016, 12:10
Default
  #5
New Member
 
HuangXin
Join Date: Dec 2016
Posts: 7
Rep Power: 10
Hxchange is on a distinguished road
Quote:
Originally Posted by floquation View Post
The index is an integer number, so this is correct:
Code:
mesh.cellPoints()[1]
However, then you extract the indices of the points, not the coordinates of the points. See this post if you wish to obtain the coordinates.
Thank you! But it dosen't work... It told me that "bash: 未预期的符号 `[1]' 附近有语法错误",which means that there is a grammatical mistake around `[1]' ,it is a inexpectant symbol .
Could you please tell me how to solve this problem? Thanks a lot!
Hxchange is offline   Reply With Quote

Old   December 22, 2016, 12:31
Default
  #6
Senior Member
 
floquation's Avatar
 
Kevin van As
Join Date: Sep 2014
Location: TU Delft, The Netherlands
Posts: 252
Rep Power: 21
floquation will become famous soon enough
You should post what exactly you tried, between [CODE]-tags.
floquation is offline   Reply With Quote

Old   December 23, 2016, 00:52
Default
  #7
New Member
 
HuangXin
Join Date: Dec 2016
Posts: 7
Rep Power: 10
Hxchange is on a distinguished road
Quote:
Originally Posted by floquation View Post
You should post what exactly you tried, between [CODE]-tags.
Firstly, I moved to the root directory of my case at ~/OpenFOAM/OpenFOAM-2.4.0/tutorials/heatTransfer/Change_chtMultiRegionSimpleFoam/tmodel
('tmodel' is the directory that has '0' '1000' 'constant' 'system' and soon on )
then I write mesh.cellPoints()[1]
Like :
hx1@hx1-virtual-machine:~/OpenFOAM/OpenFOAM-2.4.0/tutorials/heatTransfer/Change_chtMultiRegionSimpleFoam/tmodel$ mesh.cellPoints()[1]

Then it told me that bash: 未预期的符号 `[1]' 附近有语法错误

The whole process are posted here:

hx1@hx1-virtual-machine:~$ cd OpenFOAM/OpenFOAM-2.4.0/tutorials/heatTransfer/Change_chtMultiRegionSimpleFoam/tmodel/
hx1@hx1-virtual-machine:~/OpenFOAM/OpenFOAM-2.4.0/tutorials/heatTransfer/Change_chtMultiRegionSimpleFoam/tmodel$ mesh.cellPoints()[1]
bash: 未预期的符号 `[1]' 附近有语法错误
Hxchange is offline   Reply With Quote

Old   December 23, 2016, 04:30
Default
  #8
Senior Member
 
floquation's Avatar
 
Kevin van As
Join Date: Sep 2014
Location: TU Delft, The Netherlands
Posts: 252
Rep Power: 21
floquation will become famous soon enough
Quote:
Originally Posted by Hxchange View Post
then I write mesh.cellPoints()[1]
Like :
hx1@hx1-virtual-machine:~/OpenFOAM/OpenFOAM-2.4.0/tutorials/heatTransfer/Change_chtMultiRegionSimpleFoam/tmodel$ mesh.cellPoints()[1]

Then it told me that bash: 未预期的符号 `[1]' 附近有语法错误
"mesh.cellPoints()[1]" is written in a programming language called C++. This is the language that OpenFoam uses.
You typed this C++ snippet inside your terminal, which uses a programming language called Sh (bash, tcsh, ...). Clearly, you cannot type a piece of C++ code in an environment that doesn't speak C++. That is like you copying Chinese (?) characters to me: they are nonsensical to me. Net zoals jij deze woorden niet zal begrijpen.
Besides, even if your terminal would "speak" C++, it wouldn't know OpenFoam-specific C++. For instance, "mesh" is a class inside OpenFoam, it is not "normal" C++. Better yet, it doesn't exist at all while OpenFoam is not running.

If you do wish to execute that command, you will have to inject it into OpenFoam. Have a look at: "codedFunctionObject".
Germilly likes this.
floquation is offline   Reply With Quote

Old   December 30, 2016, 05:29
Default
  #9
New Member
 
HuangXin
Join Date: Dec 2016
Posts: 7
Rep Power: 10
Hxchange is on a distinguished road
Quote:
Originally Posted by floquation View Post
"mesh.cellPoints()[1]" is written in a programming language called C++. This is the language that OpenFoam uses.
You typed this C++ snippet inside your terminal, which uses a programming language called Sh (bash, tcsh, ...). Clearly, you cannot type a piece of C++ code in an environment that doesn't speak C++. That is like you copying Chinese (?) characters to me: they are nonsensical to me. Net zoals jij deze woorden niet zal begrijpen.
Besides, even if your terminal would "speak" C++, it wouldn't know OpenFoam-specific C++. For instance, "mesh" is a class inside OpenFoam, it is not "normal" C++. Better yet, it doesn't exist at all while OpenFoam is not running.

If you do wish to execute that command, you will have to inject it into OpenFoam. Have a look at: "codedFunctionObject".

I m so ashamed of the wrong comprehension of the code.
After reading the web site you posted "OpenFOAM 2.0.0: Run-time Control
Run-time Code Compilation", I try to add the code into the controlDict file, which was used to write out the average pressure to the terminal during a simulation , just like the example in that web site.
My controlDict becomes:

application chtMultiRegionSimpleFoam;

startFrom startTime;

…………………………
…………………………

functions
(
pAverage
{
functionObjectLibs ("libutilityFunctionObjects.so");
type coded;
redirectType average;
outputControl outputTime;
code
#{
const volScalarField& p =
mesh().lookupObject("p");
Info<<"p avg:" << average(p) << endl;
#};
}
);

Then it turn out to be wrong ,the log.chtMultiRegionSimpleFoam said at last:

Using dynamicCode for functionObject pAverage at line 53 in ".pAverage"
Creating new library in "dynamicCode/average/platforms/linuxGccDPOpt/lib/libaverage_984f6edcf2cd9ef8b47d889e97e44a3cadff88d b.so"
Invoking "wmake -s libso /home/hx1/OpenFOAM/OpenFOAM-2.4.0/tutorials/heatTransfer/Change_chtMultiRegionSimpleFoam/ceshi/dynamicCode/average"
wmakeLnInclude: linking include files to ./lnInclude
Making dependency list for source file functionObjectTemplate.C
Making dependency list for source file FilterFunctionObjectTemplate.C
.pAverage: In member function ‘virtual void Foam::averageFunctionObject::write()’:
.pAverage:60:40: error: no matching function for call to ‘Foam::fvMesh::lookupObject(const char [2]) const’

.pAverage:60:40: note: candidate is:
In file included from /home/hx1/OpenFOAM/OpenFOAM-2.4.0/src/OpenFOAM/lnInclude/Time.H:42:0,
from functionObjectTemplate.C:27:
/home/hx1/OpenFOAM/OpenFOAM-2.4.0/src/OpenFOAM/lnInclude/objectRegistry.H:181:25: note: template<class Type> const Type& Foam:bjectRegistry::lookupObject(const Foam::word&) const
const Type& lookupObject(const word& name) const;
^
/home/hx1/OpenFOAM/OpenFOAM-2.4.0/src/OpenFOAM/lnInclude/objectRegistry.H:181:25: note: template argument deduction/substitution failed:
.pAverage:60:40: note: couldn't deduce template parameter ‘Type’
make: *** [Make/linuxGccDPOpt/functionObjectTemplate.o] 错误 1

--------------------------------------------------------------------------
MPI_ABORT was invoked on rank 0 in communicator MPI_COMM_WORLD
with errorcode 1.

NOTE: invoking MPI_ABORT causes Open MPI to kill all MPI processes.
You may or may not see output from other processes, depending on
exactly when Open MPI kills them.
--------------------------------------------------------------------------
[0]
[0]
[0] --> FOAM FATAL IO ERROR:
[0] Failed wmake "dynamicCode/average/platforms/linuxGccDPOpt/lib/libaverage_984f6edcf2cd9ef8b47d889e97e44a3cadff88d b.so"
[0]
[0]
[0] file: .pAverage from line 53 to line 58.
[0]
[0] From function codedBase::createLibrary(..)
[0] in file db/dynamicLibrary/codedBase/codedBase.C at line 213.
[0]
FOAM parallel run exiting
[0]
--------------------------------------------------------------------------
mpirun has exited due to process rank 0 with PID 4881 on
node hx1-virtual-machine exiting improperly. There are two reasons this could occur:

1. this process did not call "init" before exiting, but others in
the job did. This can cause a job to hang indefinitely while it waits
for all processes to call "init". By rule, if one process calls "init",
then ALL processes must call "init" prior to termination.

2. this process called "init", but exited without calling "finalize".
By rule, all processes that call "init" MUST call "finalize" prior to
exiting or it will be considered an "abnormal termination"

This may have caused other processes in the application to be
terminated by signals sent by mpirun (as reported here).
--------------------------------------------------------------------------



Then I tried to change the code into yours . The controlDict becomes:

application chtMultiRegionSimpleFoam;

startFrom startTime;

…………………………
…………………………


functions
(
GetPoint
{
functionObjectLibs ("libutilityFunctionObjects.so");
type coded;
redirectType cellPoints;
outputControl outputTime;
code
#{
mesh.cellPoints()[1]
#};
}
);


Then it turn out to be wrong ,the log.chtMultiRegionSimpleFoam said at last:

Using dynamicCode for functionObject GetPoint at line 53 in ".GetPoint"
Creating new library in "dynamicCode/cellPoints/platforms/linuxGccDPOpt/lib/libcellPoints_a230fab1bbd6af3d2a10a8d6f936f47881e9 3f58.so"
Invoking "wmake -s libso /home/hx1/OpenFOAM/OpenFOAM-2.4.0/tutorials/heatTransfer/Change_chtMultiRegionSimpleFoam/ceshi/dynamicCode/cellPoints"
wmakeLnInclude: linking include files to ./lnInclude
Making dependency list for source file functionObjectTemplate.C
Making dependency list for source file FilterFunctionObjectTemplate.C
.GetPoint: In member function ‘virtual void Foam::cellPointsFunctionObject::write()’:
.GetPoint:59:5: error: ‘((Foam::cellPointsFunctionObject*)this)->Foam::cellPointsFunctionObject::mesh’ does not have class type
.GetPoint:61:1: error: expected ‘;’ before ‘}’ token

make: *** [Make/linuxGccDPOpt/functionObjectTemplate.o] 错误 1
[0]
[0]
[0] --> FOAM FATAL IO ERROR:
[0] Failed wmake "dynamicCode/cellPoints/platforms/linuxGccDPOpt/lib/libcellPoints_a230fab1bbd6af3d2a10a8d6f936f47881e9 3f58.so"
[0]
[0]
[0] file: .GetPoint from line 53 to line 58.
[0]
[0] From function codedBase::createLibrary(..)
[0] in file db/dynamicLibrary/codedBase/codedBase.C at line 213.
[0]
FOAM parallel run exiting
[0]
--------------------------------------------------------------------------
MPI_ABORT was invoked on rank 0 in communicator MPI_COMM_WORLD
with errorcode 1.

NOTE: invoking MPI_ABORT causes Open MPI to kill all MPI processes.
You may or may not see output from other processes, depending on
exactly when Open MPI kills them.
--------------------------------------------------------------------------
--------------------------------------------------------------------------
mpirun has exited due to process rank 0 with PID 6544 on
node hx1-virtual-machine exiting improperly. There are two reasons this could occur:

1. this process did not call "init" before exiting, but others in
the job did. This can cause a job to hang indefinitely while it waits
for all processes to call "init". By rule, if one process calls "init",
then ALL processes must call "init" prior to termination.

2. this process called "init", but exited without calling "finalize".
By rule, all processes that call "init" MUST call "finalize" prior to
exiting or it will be considered an "abnormal termination"

This may have caused other processes in the application to be
terminated by signals sent by mpirun (as reported here).
--------------------------------------------------------------------------


So, I want to know where to put your codes into ?
And if it is really in the controlDict ,what is the " redirectType
",what should I write?

Really Really thanks a lot!!!
Hxchange is offline   Reply With Quote

Old   January 4, 2017, 17:44
Default
  #10
Senior Member
 
floquation's Avatar
 
Kevin van As
Join Date: Sep 2014
Location: TU Delft, The Netherlands
Posts: 252
Rep Power: 21
floquation will become famous soon enough
I'm not sure why your first snippet (from the tutorial) fails. I can't test it -- holidays.

"My" code was a continuation to what @arvindpj said, which works inside a solver - not inside a codedFunctionObject. Trivially, you should change "mesh" to "mesh()": from the variable "mesh" (which is known inside a solver) to the function call "mesh()" that retrieves the mesh.
Code:
mesh().cellPoints()[1]
But then you still do not have a complete code. This was just the function call to retrieve the corner indices: if I recall correctly, it returns a List<int>.
You probably want to display the content of this List, don't you?
Sadly, you cannot print a List to the screen, but you can loop over its content and print each individual item.

I don't have my IDE here and I have too little experience to type the correct code by hand, so you will have to do some work:
See this topic to find out how to loop over a List.
And use such a statement for printing the content to your display:
Code:
Info<< variableName << endl;
The result is something like (again, I cannot test it now):
Code:
for ( const auto& item : mesh().cellPoints()[1] )
{
  Info<< item << ",";
}
Info<< endl;
arvindpj likes this.
floquation is offline   Reply With Quote

Old   October 20, 2017, 11:16
Default
  #11
New Member
 
Germilly Barreto
Join Date: Jul 2016
Location: Portugal
Posts: 25
Rep Power: 10
Germilly is on a distinguished road
Quote:
Originally Posted by Hxchange View Post
My case used snappyMesh and chtMultiRegionSimpleFoam solver, I m trying to postprocessing it and I want to get the coordinate of all the cells ,8 points for each cells, instead of only the cell centre points. I want to make these informations into a file that can list the cells' 8 points' coordinate and their temperature .But I can only get the cell centre cooridates by using "writeCellcentre" .How can it write the coordinate of all the 8 points of the cells ?
I ll be very preciated if someone can help me !
Hello

In your case directory, try to write the following command: "writeMeshObj -cell cellID", where cellID is the cell number (0, 1, 2 ...).

This command will generate a file called "meshPoints_0_cellID.obj" at the same directory. It contains the points of the cellID.

If you want the coordinates of many cellID, you can create a shell Script containig, for exemple:
----------------------------------
#!/bin/bash

for i in {0..nCell}; do
writeMeshObj -cell $i$
done
----------------------------------
where nCell is the total number of cells that you want.

Germilly
Germilly is offline   Reply With Quote

Reply

Tags
cell, coordinate, postprocessing


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
[snappyHexMesh] Error snappyhexmesh - Multiple outside loops avinashjagdale OpenFOAM Meshing & Mesh Conversion 53 March 8, 2019 10:42
[ICEM] Problem with prism cells sidharath ANSYS Meshing & Geometry 0 September 1, 2015 08:09
[DesignModeler] DM's JScript: FPoint()'s GetPoint(i) function picks points backwards? ANT ANSYS Meshing & Geometry 2 July 23, 2012 16:25
[snappyHexMesh] snappyHexMesh won't work - zeros everywhere! sc298 OpenFOAM Meshing & Mesh Conversion 2 March 27, 2011 22:11
physical boundary error!! kris Siemens 2 August 3, 2005 01:32


All times are GMT -4. The time now is 16:47.