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