|
[Sponsors] |
Get the coordinate of all 8 the points of the cells |
|
LinkBack | Thread Tools | Search this Thread | Display Modes |
December 19, 2016, 10:46 |
Get the coordinate of all 8 the points of the cells
|
#1 |
New Member
HuangXin
Join Date: Dec 2016
Posts: 7
Rep Power: 10 |
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 ! |
|
December 19, 2016, 18:06 |
|
#2 | |
Member
Arvind Jay
Join Date: Sep 2012
Posts: 97
Rep Power: 15 |
Quote:
Code:
mesh.cellPoints()[yourCellIndex] Cheers :-) |
||
December 22, 2016, 06:50 |
|
#3 | |
New Member
HuangXin
Join Date: Dec 2016
Posts: 7
Rep Power: 10 |
Quote:
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! |
||
December 22, 2016, 07:05 |
|
#4 | |
Senior Member
Kevin van As
Join Date: Sep 2014
Location: TU Delft, The Netherlands
Posts: 252
Rep Power: 21 |
Quote:
Code:
mesh.cellPoints()[1] |
||
December 22, 2016, 12:10 |
|
#5 | |
New Member
HuangXin
Join Date: Dec 2016
Posts: 7
Rep Power: 10 |
Quote:
Could you please tell me how to solve this problem? Thanks a lot! |
||
December 22, 2016, 12:31 |
|
#6 |
Senior Member
Kevin van As
Join Date: Sep 2014
Location: TU Delft, The Netherlands
Posts: 252
Rep Power: 21 |
You should post what exactly you tried, between [CODE]-tags.
|
|
December 23, 2016, 00:52 |
|
#7 |
New Member
HuangXin
Join Date: Dec 2016
Posts: 7
Rep Power: 10 |
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]' 附近有语法错误 |
|
December 23, 2016, 04:30 |
|
#8 | |
Senior Member
Kevin van As
Join Date: Sep 2014
Location: TU Delft, The Netherlands
Posts: 252
Rep Power: 21 |
Quote:
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". |
||
December 30, 2016, 05:29 |
|
#9 | |
New Member
HuangXin
Join Date: Dec 2016
Posts: 7
Rep Power: 10 |
Quote:
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!!! |
||
January 4, 2017, 17:44 |
|
#10 |
Senior Member
Kevin van As
Join Date: Sep 2014
Location: TU Delft, The Netherlands
Posts: 252
Rep Power: 21 |
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] 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; Code:
for ( const auto& item : mesh().cellPoints()[1] ) { Info<< item << ","; } Info<< endl; |
|
October 20, 2017, 11:16 |
|
#11 | |
New Member
Germilly Barreto
Join Date: Jul 2016
Location: Portugal
Posts: 25
Rep Power: 10 |
Quote:
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 |
||
Tags |
cell, coordinate, postprocessing |
|
|
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 |