|
[Sponsors] |
How to export patch face centre Coordinate during sampling ? |
|
LinkBack | Thread Tools | Search this Thread | Display Modes |
May 10, 2010, 11:15 |
How to export patch face centre Coordinate during sampling ?
|
#1 |
Senior Member
Jiang
Join Date: Oct 2009
Location: Japan
Posts: 186
Rep Power: 17 |
Dear foamers,
I want to export all face centre Coordinate in my "OUTLET" patch during sampling. In sampledPatchTemplates.C , it export patch fieldValues like this: template <class Type> Foam::tmp<Foam::Field<Type> > Foam::sampledPatch::sampleField ( const GeometricField<Type, fvPatchField, volMesh>& vField ) const { // One value per face tmp<Field<Type> > tvalues(new Field<Type>(patchFaceLabels_.size())); Field<Type>& values = tvalues(); if (patchIndex() != -1) { const Field<Type>& bField = vField.boundaryField()[patchIndex()]; forAll(patchFaceLabels_, elemI) { values[elemI] = bField[patchFaceLabels_[elemI]]; } } return tvalues; } I don't know how to export patch face centre coordinate, which correspond to these fieldValues. I write a utility like this: volVectorField::GeometricBoundaryField& fcpatches = fc.boundaryField(); label patchI = mesh.boundaryMesh().findPatchID("OUTLET"); fixedValueFvPatchVectorField& fcpatch = refCast<fixedValueFvPatchVectorField>(fcpatches[patchI]); const vectorField& faceCentres = mesh.Cf().boundaryField()[patchI]; forAll(faceCentres, facei) { scalar x = faceCentres[facei].x(); scalar y = faceCentres[facei].y(); scalar z = faceCentres[facei].z(); fcpatch[facei] = vector(x, y, z); } fc.write(); who can tell me if this is the coordinate which I want ? Thank you very much. |
|
August 1, 2011, 13:10 |
Dumping facing centres of a given patch
|
#2 |
Member
MSR CHANDRA MURTHY
Join Date: Mar 2009
Posts: 33
Rep Power: 17 |
I don't know whether this is useful to you or not. For the benifit of the community, i am keeping a small code to write the face centres of the given patch by its name.
#include <fstream> #include <iostream> //#include "fvMesh.H" #include "Time.H" //#include "primitiveMesh.H" #include "argList.H" #include "polyMesh.H" int main(int argc, char *argv[]) { # include "setRootCase.H" # include "createTime.H" # include "createPolyMesh.H" using namespace Foam; Info<< "Dump face centres of given patch\n" << endl; //change the patch name to your boundary name label patchI = mesh.boundaryMesh().findPatchID("bot_wall_inner"); forAll(mesh.boundaryMesh()[patchI].faceCentres(), faceI) { scalar x = mesh.boundaryMesh()[patchI].faceCentres()[faceI].x(); scalar y = mesh.boundaryMesh()[patchI].faceCentres()[faceI].y(); scalar z = mesh.boundaryMesh()[patchI].faceCentres()[faceI].z(); Info<<faceI<<" "<<x<<" "<<y<<" "<<z<<" "<<endl; } } Further file handling can be included with run time selectable patch names, something like faceCentreDict |
|
November 15, 2011, 03:34 |
|
#3 |
New Member
bruce
Join Date: Aug 2011
Posts: 3
Rep Power: 15 |
hello!
when finish the wmake, can you tell me how to output this data in the case (as specific as possible)? thank you very much! |
|
November 15, 2011, 04:02 |
|
#4 |
Member
MSR CHANDRA MURTHY
Join Date: Mar 2009
Posts: 33
Rep Power: 17 |
Just add file handling syntax in the above code, instead of printing to the console, it dumps to TEXT file. To achive this, you can use either Foam inbuild File handler IOobjet or in simplest way you can use C++ file stream.
|
|
November 15, 2011, 10:16 |
|
#5 |
New Member
bruce
Join Date: Aug 2011
Posts: 3
Rep Power: 15 |
yes, i got it !
I added this syntax into simpleFoam, which can be done well. try to modify like following: label PatchI = mesh.boundaryMesh().findPatchID("patchName"); // const vectorField& faceCentres = mesh.boundaryMesh()[patchI].faceCentres(); const fvPatchVectorField& faceCentres = mesh.C().boundaryField()[PatchI]; forAll(faceCentres, faceI) { // get coordinate for face centre const vector& c = faceCentres[faceI]; //c[0]:x coordinate, c[1]: y coordinate, c[2]: z coordinate Info << faceI <<"" << c[0] << " " << c[1] << " " << c[2] << ")" << endl; } it can get the same result (face centre coordinate). so i think that object mesh.C().boundaryField()[patchI] returns the corresponding geometric coordinate of patch face centres , that object U.boundaryField()[patchI] returns vector U of corresponding patch face centres. in a word, mesh.C() and U belong to geometicField<type> which has the function of boundaryField(). |
|
November 7, 2015, 16:17 |
|
#6 |
New Member
Nitish
Join Date: Oct 2015
Location: Delft, Netherlands
Posts: 5
Rep Power: 11 |
It was a very insightful thread, however, I still have trouble implementing it in my code. I would be grateful if anyone can post the controlDict file here.
|
|
January 11, 2017, 10:18 |
A simple application to extract patch face centre coordinates
|
#7 |
New Member
Yu Cheng
Join Date: Aug 2014
Posts: 15
Rep Power: 12 |
Following MURTHY's code in #2, I have create a simple application to extract patch face centre coordinates, I paste the main code here and attach the full code/test case behind this thread
Code:
#include "fvMesh.H" #include "volFields.H" #include "Time.H" #include "argList.H" using namespace Foam; int main(int argc, char *argv[]) { # include "addTimeOptions.H" argList::validArgs.append("patch"); # include "setRootCase.H" # include "createTime.H" # include "createMesh.H" Info<< "Dump face centres of given patch\n" << endl; const word patchName = args[1]; label patchI = mesh.boundaryMesh().findPatchID(patchName); const polyPatch& pp = mesh.boundaryMesh()[patchI]; Info<<pp.faceCentres().size()<<endl; Info<<"("<<endl; forAll(pp.faceCentres(), faceI) { scalar x = pp.faceCentres()[faceI].x(); scalar y = pp.faceCentres()[faceI].y(); scalar z = pp.faceCentres()[faceI].z(); Info<<"("<<x<<" "<<y<<" "<<z<<")"<<endl; } Info<<")"<<endl; return 0; } Yu Cheng |
|
February 12, 2018, 13:02 |
|
#8 |
New Member
Wei Meng
Join Date: May 2017
Posts: 12
Rep Power: 9 |
Hi Yu,
Thank you very much for the sharing! I am a new foamer and I got some problems when wmake the testSampleFaceCenter.C file. 1) I cannot find the 'Time.H' file. I searched in the computer, there is a file named 'time.h' located in '~/foam/foam-extend-4.0/ThirdParty/rpmBuild/BUILD/bison-2.7/lib$'. Is this the right one included in the .C file? 2) After replacing the 'Time.H' by 'time.h', I tried to wmake the .C file again. I got a syntx error about the function. It shows as follow. Code:
wei@wei-Aspire-M5910:~/foam/wei-4.0/run/testSampleFaceCenter$ wmake Making dependency list for source file sampleFaceCenter.C SOURCE=sampleFaceCenter.C ; g++ -m64 -Dlinux64 -DWM_DP -Wall -Wextra -Wno-unused-parameter -Wold-style-cast -Wnon-virtual-dtor -O3 -DNoRepository -ftemplate-depth-200 -I/home/wei/foam/foam-extend-4.0/src/finiteVolume/lnInclude -I/home/wei/foam/foam-extend-4.0/src/meshTools/lnInclude -I/home/wei/foam/foam-extend-4.0/src/surfMesh/lnInclude -IlnInclude -I. -I/home/wei/foam/foam-extend-4.0/src/foam/lnInclude -I/home/wei/foam/foam-extend-4.0/src/OSspecific/POSIX/lnInclude -fPIC -c $SOURCE -o Make/linux64GccDPOpt/sampleFaceCenter.o sampleFaceCenter.C: In function ‘int main(int, char**)’: sampleFaceCenter.C:18:32: error: no match for ‘operator[]’ (operand types are ‘Foam::argList’ and ‘int’) const word patchName = args[1]; ^ sampleFaceCenter.dep:519: recipe for target 'Make/linux64GccDPOpt/sampleFaceCenter.o' failed make: *** [Make/linux64GccDPOpt/sampleFaceCenter.o] Error 1 |
|
February 12, 2018, 16:01 |
|
#9 |
New Member
Wei Meng
Join Date: May 2017
Posts: 12
Rep Power: 9 |
Hi Yu,
By commenting the Time.H statement and replace the "args[1]" by "argv[1]", I have obtained the coordinates of a patch of faces. Thank you again for your sharing! Best, Wei |
|
February 24, 2018, 02:54 |
Different OpenFOAM version
|
#10 |
New Member
Yu Cheng
Join Date: Aug 2014
Posts: 15
Rep Power: 12 |
Hi Wei,
Sorry for the late reply and I am glad you have solved the problem. Plz note I used OpenFOAM and you used foam-extend, I am not familiar with foam-extend and this may lead to the problem. Best wishes, Yu |
|
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
[Netgen] Import netgen mesh to OpenFOAM | hsieh | OpenFOAM Meshing & Mesh Conversion | 32 | September 13, 2011 06:50 |
OpenFOAM on MinGW crosscompiler hosted on Linux | allenzhao | OpenFOAM Installation | 127 | January 30, 2009 20:08 |
[blockMesh] BlockMeshmergePatchPairs | hjasak | OpenFOAM Meshing & Mesh Conversion | 11 | August 15, 2008 08:36 |
fluent add additional zones for the mesh file | SSL | FLUENT | 2 | January 26, 2008 12:55 |
[blockMesh] Axisymmetrical mesh | Rasmus Gjesing (Gjesing) | OpenFOAM Meshing & Mesh Conversion | 10 | April 2, 2007 15:00 |