|
[Sponsors] |
February 24, 2020, 04:51 |
Access cell values in codeStream
|
#1 |
New Member
Tom Gegenbauer
Join Date: Feb 2020
Posts: 1
Rep Power: 0 |
Hello,
I am Tom, new to CFD/OpenFOAM and very happy about this Forum, which already helped me. Thank you all! I have a question which will be pretty simple, but I can't find a solution here or in the documentation. It is about codeStream. I use the rhoSimpleFoam/squareBend tutorial with rhoSimpleFoam. I set the longer path as heatWalls and I want to try some alphatWall calculations. So what I want to do is using a different calculation for alpha on a specific patchType. For this, I have a formula and I want to implement this via codeStream. This works with a set constant (e.g. alpha = 0.05). The next step is to use the cell pressure. For this I found out, that I can access these values with Code:
U.boundaryField()[patchi].patchInternalField() whereas patchi is found by const label patchi = mesh.boundaryMesh().findPatchID("bottom") Code:
const scalarField& UCells = U.internalField(); forAll(UCells,CellI) { UCells[CellI]; } My problem is, that I don't know how the cells, vectors etc. in OpenFOAM are handled. I want to use the cell average pressure to calculate the alphatWall. But since this is just at the wall, I don't know how to express that - or if using codeStream in 0/alphat is even the right thing to do. I can express my Solution in comments, maybe someone can help me translate this to code. Code:
// some constants & pre-calculations needed for formula f_d = 0.5; // just example f_w = 0.73*f_d; // the example formula is: alphat = (p^f_w)*(f_d^0.1) // // // from here on, I am not sure. Therefore I write in comments. // There should be a loop over all boundary (wall) cells, but I don't know // how to achieve this (wallCells/cellID etc.) forAll(wallCells, cellID) { // I have to read the value of p out of the iterated cell p_t = p.boundaryField()[patchi].patchInternalField() ? // Thats the whole patch, doesnt make sense to me. // Then I can calculate alpha alphat = pow(p_t,f_w)*pow(f_d,0.1) } I hope my problem is understandable and somebody can help me. If there is additional information material I am also interested. Thank you in advance! Best regards Tom Source from access velocity code: Access to the velocity at boundary cells |
|
March 11, 2020, 12:07 |
|
#2 |
Member
MNM
Join Date: Aug 2017
Posts: 69
Rep Power: 9 |
Hey Tom,
You are almost there. You just have to initialize the field (in your case Pressure) specifically for your patch. Code:
const fvMesh& mesh = refCast<const fvMesh>(d.db()); const label id = mesh.boundary().findPatchID("your_patch"); const fvPatch& patch = mesh.boundary()[id]; f_d = 0.5; f_w = 0.73*f_d; scalarField ptemp(patch.size(), scalar(0)); scalarField alphat(patch.size(), scalar(0)); forAll(alpha[i], i) { ptemp[i] = p[i]; alphat[i] = scalar(pow(ptemp[i],f_w)*pow(f_d,0.1)); } http://wiki.openfoam.com/Programming1 |
|
April 27, 2022, 05:30 |
|
#3 |
Member
Eric Segalerba
Join Date: Dec 2021
Location: Italy
Posts: 31
Rep Power: 5 |
Hi!
I'm facing a similar problem: I'm trying to get the average pressure value on a patch. So far I wrote the following: Code:
throat { type flowRateOutletVelocity; volumetricFlowRate #codeStream { codeInclude #{ #include "fvCFD.H" #}; codeOptions #{ -I$(LIB_SRC)/finiteVolume/lnInclude \ -I$(LIB_SRC)/meshTools/lnInclude #}; //libs needed to visualize BC in paraview codeLibs #{ -lmeshTools \ -lfiniteVolume #}; code #{ /* CYCLE EXPLAINED input = CPI = massFlowRate * deltaP 1. massFlowRate = CPI / deltaP; 2. compute first timestep with the massFlowRate just calculated; 3. compute deltaP (which is deltaP = p_amb - p_throat = 0 - p_throat = -p_throat); 4. correct massFlowRate with the new value of p_throat; 5. keep iterating... massFlowRate^(i+1) = - CPI / p_throat^(i) */ const IOdictionary& d = static_cast<const IOdictionary&> ( dict.parent().parent() ); const fvMesh& mesh = refCast<const fvMesh>(d.db()); const label id = mesh.boundary().findPatchID("throat"); const fvPatch& patch = mesh.boundary()[id]; vectorField U(patch.size(), vector(0, 0, 0)); // initialization of the vector field const CPI = xxx; // Power Input in Watt const surfaceVectorField& p = patch().lookupObject("p"); // get throat's pressure const massFlowRate = -CPI/average(p); // compute corresponding massFlowRate writeEntry(os,"", massFlowRate); #}; }; value uniform (0 0 0); } The problem is that I keep facing errors that are surely caused by errors in my code but I'm not able to fix it properly, do you have any guess on how to repair it? Thank you! |
|
Tags |
codestream, openfoam |
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Access volume field values at wall-adjacent cell centres | TsinghuaBoiler | OpenFOAM Programming & Development | 0 | May 5, 2017 19:52 |
Cells with t below lower limit | Purushothama | Siemens | 2 | May 31, 2010 22:58 |
Retrieving boundary patch values adjacent to a given cell | brooksmoses | OpenFOAM Post-Processing | 2 | December 8, 2008 11:00 |
Warning 097- | AB | Siemens | 6 | November 15, 2004 05:41 |
node based or cell centered Ts values | acboge | FLUENT | 0 | February 6, 2004 07:41 |