|
[Sponsors] |
November 17, 2010, 18:00 |
Accessing mesh dictionary from solver
|
#1 |
Member
Pascal
Join Date: Jun 2009
Location: Montreal
Posts: 65
Rep Power: 17 |
Hi all,
I have a very simple rectangular mesh (let say 8m X 4m X 2m) and I have nx, ny, nz cells (which are defined in blockMeshDict file) in each direction. I would like to access the nx variable within icoFoam solver. More precisely I would like to have a code inside icoFoam.C that says: Code:
int readnx(readInt(mesh.blockMeshDict().subDict("blocks").lookup("nx"))) I've been able to do successfully something similar for reading the PISO control: Code:
int monNCorr(readInt(mesh.solutionDict().subDict("PISO").lookup("nCorrectors"))) Pascal |
|
November 18, 2010, 02:29 |
|
#2 | |
Senior Member
Mark Olesen
Join Date: Mar 2009
Location: https://olesenm.github.io/
Posts: 1,714
Rep Power: 40 |
Quote:
This should help you understand why "mesh.blockMeshDict()" doesn't and shouldn't exist. Having said that, if you nonetheless wish to get values from the blockMeshDict (in the hope that it is somehow related to your mesh), you need to open the file yourself. For example, Code:
IOdictionary meshDict ( IOobject ( "blockMeshDict", runTime.constant(), polyMeshDir, runTime, IOobject::MUST_READ, IOobject::NO_WRITE, false ) ); Depending upon where you use this code snippet, you may wish to replace the variable 'runTime' with a time object from your mesh. |
||
November 18, 2010, 21:50 |
|
#3 |
Member
Pascal
Join Date: Jun 2009
Location: Montreal
Posts: 65
Rep Power: 17 |
Thank you for your help Mr. Olesen,
As you said I added in the solver: Code:
fileName polyMeshDir; IOdictionary meshDict ( IOobject ( "blockMeshDict", runTime.constant(), polyMeshDir, runTime, IOobject::MUST_READ, IOobject::NO_WRITE, false ) ); Code:
fileName polyMeshDir; Then, to know what "meshDic" contain I used the following line of code: Code:
Info<< meshDict.lookup("blocks") << endl; Code:
24 ( ( hex ( 0 1 2 3 4 5 6 7 ) ( 100 50 1 ) simpleGrading ( 1 1 1 ) ) ) Code:
Info<< meshDict.subDict("blocks") << endl; Code:
Info<< meshDict.subDict("blocks").lookup("hex") << endl; At the end I would like to have a line that allow me to create the variable Code:
int readNx(readInt(meshDict.subDict("blocks")[0].lookup("nx"))); Pascal |
|
November 19, 2010, 02:25 |
|
#4 | |
Senior Member
Mark Olesen
Join Date: Mar 2009
Location: https://olesenm.github.io/
Posts: 1,714
Rep Power: 40 |
Quote:
Code:
Foam::polyMesh::meshSubDir Code:
fileName polyMeshDir; if ( ... ) // multi-region { // constant/<region>/polyMesh/blockMeshDict polyMeshDir = regionName/polyMesh::meshSubDir; } else { // constant/polyMesh/blockMeshDict polyMeshDir = polyMesh::meshSubDir; } |
||
November 19, 2010, 02:40 |
|
#5 | |
Senior Member
Mark Olesen
Join Date: Mar 2009
Location: https://olesenm.github.io/
Posts: 1,714
Rep Power: 40 |
Quote:
This is definely a non-trival task. You can get at "block" itself fairly easily, but you'll notice it contains a list of entries that you'll need to process yourself. If we examine a general entry Code:
blocks ( hex (0 1 2 3 4 5 6 7) (5 50 1) simpleGrading (1 1 1) hex (1 8 9 2 5 10 11 6) (40 50 1) simpleGrading (1 1 1) hex (3 2 12 13 7 6 14 15) (5 50 1) simpleGrading (1 1 1) ); Code:
blocks ( word labelList labelList word labelList word labelList labelList word labelList word labelList labelList word labelList ); This is not a bit of effort, but you don't even have any assurance that the values you extract are related to your mesh! (as I mentioned in a previous post). I would thus view this entire approach as more than a slight waste of time. |
||
November 19, 2010, 04:29 |
|
#6 |
Senior Member
Laurence R. McGlashan
Join Date: Mar 2009
Posts: 370
Rep Power: 23 |
When I had to get a list of heights in a geometry so that I could do a lagrangian-style calculation, I used the STL to get a list of independent heights. I gave it a vector axialPositions that contained the relevant component of every cell:
Code:
std::sort(axialPositions.begin(), axialPositions.end()); axialPositions.erase(std::unique(axialPositions.begin(), axialPositions.end(), equalToTolerance), axialPositions.end()); At the time I couldn't think of anything better. .
__________________
Laurence R. McGlashan :: Website |
|
October 31, 2017, 07:26 |
|
#7 |
Member
Amir
Join Date: Jan 2017
Posts: 32
Rep Power: 9 |
Dear Foamers,
I am new to OpenFOAM and c++, I hope somebody helps me. Question: Can I replace findPatchIDs with patchSet? I want to use Code:
labelHashSet patchSet (const UList< wordRe > &patchNames, const bool warnNotFound=true, const bool usePatchGroups=true) const Code:
labelHashSet findPatchIDs()const 1. is it possible? 2. how can I obtain Code:
UList< wordRe > &patchNames Regards, Amir |
|
Tags |
read mesh |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
[ICEM] Generating Mesh for STL Car in Windtunnel Simulation | tommymoose | ANSYS Meshing & Geometry | 48 | April 15, 2013 04:24 |
Bug in turbulent dynamic Mesh Solver | thomas | OpenFOAM Running, Solving & CFD | 0 | October 29, 2008 03:48 |
LES with moving mesh solver | gtg627e | OpenFOAM Running, Solving & CFD | 2 | July 23, 2007 10:40 |
Problems using dynamic mesh and 6dof solver | Brett | FLUENT | 0 | March 3, 2006 17:45 |
compressible two phase flow in CFX4.4 | youngan | CFX | 0 | July 1, 2003 23:32 |