PSCF v1.3
rpc/field/Mask.tpp
1#ifndef RPC_MASK_TPP
2#define RPC_MASK_TPP
3
4/*
5* PSCF - Polymer Self-Consistent Field
6*
7* Copyright 2015 - 2025, The Regents of the University of Minnesota
8* Distributed under the terms of the GNU General Public License.
9*/
10
11#include "Mask.h"
12
13namespace Pscf {
14namespace Rpc
15{
16
17 using namespace Util;
18 using namespace Pscf::Prdc;
19 using namespace Pscf::Prdc::Cpu;
20
21 /*
22 * Return volume fraction of the unit cell occupied by the
23 * polymers/solvents.
24 */
25 template <int D>
26 double Mask<D>::rGridAverage() const
27 {
29
30 // Sum up elements of r-grid mask field.
31 // Use Kahan summation to reduce accumulation of error
32 double sum(0.0), err(0.0), tempVal, tempSum;
33 int n = rg.capacity();
34 for (int i = 0; i < n; ++i) {
35 tempVal = rg[i] - err;
36 tempSum = sum + tempVal;
37 err = tempSum - sum - tempVal;
38 sum = tempSum;
39 }
40
41 return (sum / ((double)rg.capacity()));
42 }
43
44} // namespace Rpc
45} // namespace Pscf
46#endif
Field of real double precision values on an FFT mesh.
Definition cpu/RField.h:29
File input/output operations and format conversions for fields.
Prdc::Cpu::RField< D > const & rgrid() const
Get the field in r-grid format.
double rGridAverage() const override
Calculate the average value of the rgrid_ member.
int capacity() const
Return allocated size.
Definition Array.h:159
Fields and FFTs for periodic boundary conditions (CPU)
Definition CField.cpp:12
Periodic fields and crystallography.
Definition CField.cpp:11
Real periodic fields, SCFT and PS-FTS (CPU).
Definition param_pc.dox:2
PSCF package top-level namespace.
Definition param_pc.dox:1