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

Partial Summation of a Field

Register Blogs Community New Posts Updated Threads Search

Like Tree2Likes
  • 1 Post By zhangyan
  • 1 Post By fumiya

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   June 1, 2018, 02:45
Default Partial Summation of a Field
  #1
New Member
 
javad haqqani
Join Date: Dec 2017
Posts: 16
Rep Power: 8
maksjood is on a distinguished road
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?
maksjood is offline   Reply With Quote

Old   June 1, 2018, 07:07
Default gSum does not include the dimension
  #2
Senior Member
 
zhangyan's Avatar
 
Yan Zhang
Join Date: May 2014
Posts: 120
Rep Power: 11
zhangyan is on a distinguished road
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)
        )
    );
}
maksjood likes this.
__________________
https://openfoam.top
zhangyan is offline   Reply With Quote

Old   June 2, 2018, 22:45
Default Alternative method
  #3
Senior Member
 
fumiya's Avatar
 
Fumiya Nozaki
Join Date: Jun 2010
Location: Yokohama, Japan
Posts: 266
Blog Entries: 1
Rep Power: 18
fumiya is on a distinguished road
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
        );
    }
maksjood likes this.
__________________
[Personal]
fumiya is offline   Reply With Quote

Old   June 2, 2018, 22:50
Default It's done
  #4
New Member
 
javad haqqani
Join Date: Dec 2017
Posts: 16
Rep Power: 8
maksjood is on a distinguished road
Thanks everybody. I've accomplished my goal.
maksjood is offline   Reply With Quote

Reply

Tags
sum


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


All times are GMT -4. The time now is 23:22.