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

weighted average of a volScalarField

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   December 8, 2021, 06:09
Default weighted average of a volScalarField
  #1
New Member
 
Usama Niaz
Join Date: Oct 2019
Location: Pakistan
Posts: 7
Rep Power: 7
Niazi is on a distinguished road
Hi Foamers,

I am trying to read the pressure field from the mesh and then take a weighted average of pressure and using that I want to find the velocity on the inlet patch. to read the Pressure field I am using the following,

const volScalarField& pIn=db().lookupObject<volScalarField>("p");

then to take the weightedaverage
const volScalarField pAverage = pIn.weightedAverage(patch().boundaryMesh().mesh(). V());

and for velocity calculation

vectorField :: operator=(n_*pow(p1-pAverage)/rho,0.5));

but as I am new to OpenFOAM I don't understand how to properly implement that. I get the following error,


conversion from ‘Foam::dimensioned<double>’ to non-scalar type ‘const volScalarField’ {aka ‘const Foam::GeometricField<double, Foam::fvPatchField, Foam::volMesh>’} requested
175 | const volScalarField pAverage = pIn.weightedAverage(patch().boundaryMesh().mesh(). V());

Can anyone please help me out here, I will be greatly thankful.
Niazi is offline   Reply With Quote

Old   December 10, 2021, 04:21
Default
  #2
New Member
 
Usama Niaz
Join Date: Oct 2019
Location: Pakistan
Posts: 7
Rep Power: 7
Niazi is on a distinguished road
Thanks to Alexeym, I was able to figure out the problem.
Quote:
Originally Posted by alexeym
You call value method of the result of weightedAverage, i.e. pIn.weightedAverage(internalField().mesh().V()).va lue().

As I said pIn.mesh().C() is an array of cell centres, which are vectors, so if you call component method, you get component of a vector. If you want a value of a field, you use v() method.

This starts being personal consulting, which is not the aim of this forum. So, this is my last answer in private messages. Add you question in a forum post, so other people can benefit from answers.

Quote:
Originally Posted by Niazi
How I am supposed to call value(), like this?
scalar pAverage = pIn.value().weightedAverage(internalField().mesh() .V())
this gives me an error,

"
error: ‘const volScalarField’ {aka ‘const class Foam::GeometricField<double, Foam::fvPatchField, Foam::volMesh>’} has no member named ‘value’
180 | scalar pAverage = pIn.value().weightedAverage(internalField().mesh() .V());

"
for cell value, I want to read the pressure (any volScalarField for generic) value at a specific cell say 500th, as pressure is a scalar field, why am I required to give a compoenent?


Quote:
Originally Posted by alexeym
Well, it says in almost plain English: result of weighted average has dimensions and cannot be assigned to simple scalar value. So either you make pAverage dimensionedScalar or call value() method of weighted average result. The second way would be easier, since you plan to use pAverage in non-dimensional way later.

pIn.mesh().C() is an array of cell centres, so with pIn.mesh().C()[500].component(0) you extract X component of centre vector of 500-th cell. What value you would like to read from a cell?

Quote:
Originally Posted by Niazi
Thank you so much for your response, Alexeym. I try to implement that but I am still confused, basically what I want is to read the volScalarField from the mesh, for that purpose I used the following,

const volScalarField& pIn=db().lookupObject<volScalarField>("p");

then to calculate the weighted average, I used the following

scalar pAverage = pIn.weightedAverage(internalField().mesh().V());

I get this error
"
error: cannot convert ‘Foam::dimensioned<double>’ to ‘Foam::scalar’ {aka ‘double’} in initialization
179 | scalar pAverage = pIn.weightedAverage(internalField().mesh().V());
| ~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
| |
| Foam::dimensioned<double>

"
To be honest, I don't know what syntax I must use to find the weighted average, can you please write a generic syntax? Another thing I stuck at is to read the value from a certain cell, now as I am reading the volScalarField I am using the following,

const scalar pi=pIn.mesh().C()[500].component(0);

but I am confused, because as it is a scalar field why we define the component, otherwise it fails and gives the following error,

"error: conversion from ‘const Foam::Vector<double>’ to non-scalar type ‘const scalarField’ {aka ‘const Foam::Field<double>’} requested
181 | const scalarField pi=pIn.mesh().C()[i];"


I will be very thankful for your help. Thanks once again.

Quote:
Originally Posted by alexeym
Hi,

Weighted average is a scalar value (single number) and you try to assign this weigher average to a field.

Quote:
Originally Posted by Niazi
Hi Alexeym,

I hope you are in good health. I need your help in finding the weighted average of a volScalarField in writing a boundary condition. Here is my thread,

I am trying to read the pressure field from the mesh and then take a weighted average of pressure and using that I want to find the velocity on the inlet patch. to read the Pressure field I am using the following,

const volScalarField& pIn=db().lookupObject<volScalarField>("p");

then to take the weightedaverage
const volScalarField pAverage = pIn.weightedAverage(patch().boundaryMesh().mesh(). V());

and for velocity calculation

vectorField :: operator=(n_*pow(p1-pAverage)/rho,0.5));

but as I am new to OpenFOAM I don't understand how to properly implement that. I get the following error,


conversion from ‘Foam::dimensioned<double>’ to non-scalar type ‘const volScalarField’ {aka ‘const Foam::GeometricField<double, Foam::fvPatchField, Foam::volMesh>’} requested
175 | const volScalarField pAverage = pIn.weightedAverage(patch().boundaryMesh().mesh(). V());

I will be very grateful for your help. Thanks for your time and consideration.

Regards,
Niazi
Niazi is offline   Reply With Quote

Reply

Tags
boundaryconditon, internalfields, openfoam, program development, weighted average


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
y+ and u+ values with low-Re RANS turbulence models: utility + testcase florian_krause OpenFOAM 114 August 23, 2023 06:37
Converging Diverging Nozzle with dbnsTurbFoam Saleh Abuhanieh OpenFOAM Running, Solving & CFD 4 December 13, 2019 11:26
Near wall treatment in k-omega SST Arnoldinho OpenFOAM Running, Solving & CFD 38 March 8, 2017 14:48
area weighted average or mass weighted average sa har Main CFD Forum 0 January 5, 2016 14:16
writing execFlowFunctionObjects immortality OpenFOAM Post-Processing 30 September 15, 2013 07:16


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