CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   OpenFOAM Running, Solving & CFD (https://www.cfd-online.com/Forums/openfoam-solving/)
-   -   flow rate correction in timeVaryingMappedFixedValue (https://www.cfd-online.com/Forums/openfoam-solving/226835-flow-rate-correction-timevaryingmappedfixedvalue.html)

vishalS May 9, 2020 07:45

flow rate correction in timeVaryingMappedFixedValue
 
Hi all, hope everyone is doing good.

I am using timeVaryingMappedFixedValue BC within pisoFoam to introduce turbulence at an inlet. The problem is that due to spatial interpolation the flow rate (Q) varies slightly with every time step and I'd like to keep it fixed by rescaling the velocity field by a factor (Q_ideal/Q_calculated). Could someone please let me know if such a BC already exists. If not, is there an example on how to calculate the flow rate ( surfaceIntegral(v.dA) ) in an OpenFoam BC?

Please consider me a beginner in OpenFoam code implementation.

Thank you.

HPE May 9, 2020 09:45

Hi,

- I don't know any such BC - but I think it is a good idea.
- An alternative may be using one of the "coded" boundary conditions. Please have a look at available documentation for these.
- Just very rough, untested ideas below. Please be cautious.
- First you need to compute the first time-step flow rate, and keep it throughout your simulation in order to refer back at future time steps. For example, a function (I haven't test it - it is just to give some idea, I'm afraid):

Code:

scalar computeInitFlowRate(const vector& UReference)
{
    // Compute patch normal across all processors
    const vector patchNormal
    (
        (-gAverage(patch().nf()) ).normalise()
    );

    // Compute initial flow rate based on an input "UReference" velocity
    return gSum
    (
        (UReference & patchNormal)*patch().magSf()
    );
}

Then at a new time-step, you need to correct the new "U" field during the simulation back to the flow rate based on "UReference", for example, with a following function - or something similar:

Code:

void correctFlowRate(vectorField& U, const vector& UReference)
{
    const scalar initFlowRate = computeInitFlowRate(UReference);

    U *= (initFlowRate/gSum(U & -patch().Sf()));
}

Hope this may give a tiny insight for a good start, and good luck.

vishalS May 10, 2020 09:16

1 Attachment(s)
Hi HPE,

Thanks very much for your answer.

- I am not using the available BCs because my inlet is non-planar. It is a cylindrical strip instead (see attachment), so it is easier for me to read in the time files.
- Non-planar inlet also means that I need local area vectors to calculate \int_A u \cdot \mathrm{d}A.

As a first step, I am trying to print out the inlet flow rate at the current time step. With a very rusty openFoam knowledge, I have tried the following in accordance with what you suggested and the original timeVaryingMappedFixedValue BC:
Code:

template<class Type>
void Foam::timeVaryingMappedFixedValueFixedQFvPatchField<Type>::calcFlowRate(vectorField& U)
{
  const vectorField& areaVec = this->patch().Sf();  // area vectors
  Pout << "Test Flow Rate: " << gSum( U & -areaVec ) ;  // summation of dot product
}

and then call it in updateCoeffs() as:
Code:

calcFlowRate(Uvec);
However I do not know how to declare Uvec in updateCoeffs(). May be something like Field<Type>& Uvec = xxx ; but not exactly sure.

What do you think of the overall approach and could you/someone help regarding the declaration bit please?

Thanks again,
Vishal

vishalS May 13, 2020 06:13

Hi all,

I had to create a specialisation of the template. Things seem to work now. Thanks to HPE and Marta from this post https://www.cfd-online.com/Forums/op...-registry.html

Have a nice one.

HPE May 13, 2020 16:46

Hi

- Just as a side note, the code in my previous post should be applicable to non-planar patches as well - since the average considers only the patch-normal distance.

Hope this helps.

chen112p December 14, 2021 15:03

Hello HPE, do you mind to give a bit more hint on where and how to implement this modify? Many thanks!


All times are GMT -4. The time now is 18:04.