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

Access cell values in codeStream

Register Blogs Community New Posts Updated Threads Search

Like Tree2Likes
  • 2 Post By SHUBHAM9595

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   February 24, 2020, 04:51
Default Access cell values in codeStream
  #1
New Member
 
Tom Gegenbauer
Join Date: Feb 2020
Posts: 1
Rep Power: 0
gomz is on a distinguished road
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")
or

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
gomz is offline   Reply With Quote

Old   March 11, 2020, 12:07
Default
  #2
Member
 
MNM
Join Date: Aug 2017
Posts: 69
Rep Power: 9
SHUBHAM9595 is on a distinguished road
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));
}
For additional info, you can refer the link below.
http://wiki.openfoam.com/Programming1
saeed jamshidi and TeddyL like this.
SHUBHAM9595 is offline   Reply With Quote

Old   April 27, 2022, 05:30
Default
  #3
Member
 
Eric Segalerba
Join Date: Dec 2021
Location: Italy
Posts: 31
Rep Power: 5
EricS is on a distinguished road
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 idea is to get the average pressure of the "throat" patch then use that value to compute a massFlowRate to correct the value step by step.
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!
EricS is offline   Reply With Quote

Reply

Tags
codestream, openfoam


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
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


All times are GMT -4. The time now is 11:12.