|
[Sponsors] |
June 1, 2018, 02:45 |
Partial Summation of a Field
|
#1 |
New Member
javad haqqani
Join Date: Dec 2017
Posts: 16
Rep Power: 8 |
Hi. I'm in need of summing up the values of a specific part of a scalar field. I've tried a for loop. The statement is as follows:
sum+=field[celli]; but I need the sum to be dimensioned and the above statement doesn't do that. is there a way I can use sum() or gSum for this purpose? |
|
June 1, 2018, 07:07 |
gSum does not include the dimension
|
#2 |
Senior Member
Yan Zhang
Join Date: May 2014
Posts: 120
Rep Power: 11 |
just like this:
Code:
template<class Type, class GeoMesh> dimensioned<Type> DimensionedField<Type, GeoMesh>::weightedAverage ( const DimensionedField<scalar, GeoMesh>& weightField ) const { return ( dimensioned<Type> ( this->name() + ".weightedAverage(weights)", this->dimensions(), gSum(weightField*field())/gSum(weightField) ) ); }
__________________
https://openfoam.top |
|
June 2, 2018, 22:45 |
Alternative method
|
#3 |
Senior Member
Fumiya Nozaki
Join Date: Jun 2010
Location: Yokohama, Japan
Posts: 266
Blog Entries: 1
Rep Power: 18 |
You can use the volFieldValue function object:
Code:
volFieldValue1 { type volFieldValue; libs ("libfieldFunctionObjects.so"); log true; writeControl writeTime; writeFields true; regionType cellZone; // Create your cellZone that the sum needs to be calculated name c0; // and set its name operation sum; fields ( p // List of fields to operate on ); }
__________________
[Personal]
|
|
June 2, 2018, 22:50 |
It's done
|
#4 |
New Member
javad haqqani
Join Date: Dec 2017
Posts: 16
Rep Power: 8 |
Thanks everybody. I've accomplished my goal.
|
|
Tags |
sum |
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Foam::error::PrintStack | almir | OpenFOAM Running, Solving & CFD | 91 | December 21, 2022 04:50 |
problems after decomposing for running | alessio.nz | OpenFOAM | 7 | March 5, 2021 04:49 |
creating an internal field? | maybee | OpenFOAM Programming & Development | 2 | February 4, 2021 17:15 |
Steady simulation does not iterate in Time=1 | agustinvo | OpenFOAM Running, Solving & CFD | 3 | November 19, 2015 04:57 |
Summation of all field values | maybee | OpenFOAM Programming & Development | 1 | April 1, 2014 08:20 |