Saras
Finite   Difference   Solver   for   Fluid   Dynamics   Simulations
plainsf.h
Go to the documentation of this file.
1/********************************************************************************************************************************************
2 * Saras
3 *
4 * Copyright (C) 2019, Mahendra K. Verma
5 *
6 * All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. Neither the name of the copyright holder nor the
16 * names of its contributors may be used to endorse or promote products
17 * derived from this software without specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
23 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
26 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 *
30 ********************************************************************************************************************************************
31 */
43#ifndef PLAINSF_H
44#define PLAINSF_H
45
46#include "plainvf.h"
47#include "sfield.h"
48#include "vfield.h"
49#include "grid.h"
50
51class plainsf {
52 private:
53 blitz::firstIndex i;
54 blitz::secondIndex j;
55 blitz::thirdIndex k;
56
57 const grid &gridData;
58
59 public:
60 blitz::Array<real, 3> F;
61
62 blitz::Range xColl, yColl, zColl;
63
64 plainsf(const grid &gridData, const sfield &refF);
65
66 mpidata *mpiHandle;
67
70
73
74 plainsf& operator *= (real a);
75
76 void operator = (plainsf &a);
77 void operator = (sfield &a);
78 void operator = (real a);
79
92 inline void gradient(plainvf &gradF, const vfield &V) {
93 gradF.Vx(V.Vx.fCore) = gridData.xi_xColloc(xColl)(i)*(F(V.Vx.fCRgt) - F(V.Vx.fCore))/gridData.dXi;
94#ifndef PLANAR
95 gradF.Vy(V.Vy.fCore) = gridData.et_yColloc(yColl)(j)*(F(V.Vy.fCBak) - F(V.Vy.fCore))/gridData.dEt;
96#endif
97 gradF.Vz(V.Vz.fCore) = gridData.zt_zColloc(zColl)(k)*(F(V.Vz.fCTop) - F(V.Vz.fCore))/gridData.dZt;
98 }
99
108 inline void syncData() {
109 mpiHandle->syncData();
110 }
111
123 inline real fxMax() {
124 real localMax, globalMax;
125
126 localMax = blitz::max(F(xColl, yColl, zColl));
127
128 MPI_Allreduce(&localMax, &globalMax, 1, MPI_FP_REAL, MPI_MAX, MPI_COMM_WORLD);
129
130 return globalMax;
131 }
132
144 inline real fxMean() {
145 real localMean, globalSum;
146
147 localMean = blitz::mean(F(xColl, yColl, zColl));
148
149 MPI_Allreduce(&localMean, &globalSum, 1, MPI_FP_REAL, MPI_SUM, MPI_COMM_WORLD);
150
151 return globalSum/gridData.rankData.nProc;
152 }
153
154 ~plainsf() { };
155};
156
166#endif
blitz::RectDomain< 3 > fCore
The core slice is a view of the field data excluding the ghost points surrounding it.
Definition: field.h:79
Contains all the global variables related to the grid, its slices, limits, and grid derivatives used ...
Definition: grid.h:53
blitz::Array< real, 1 > xi_xColloc
Array of the grid derivatives at collocated grid points, defined locally within each sub-domain.
Definition: grid.h:195
blitz::Array< real, 1 > et_yColloc
Array of the grid derivatives at collocated grid points, defined locally within each sub-domain.
Definition: grid.h:215
const parallel & rankData
A const reference to the global variables stored in the parallel class to access MPI related paramete...
Definition: grid.h:90
real dEt
Grid spacing in the transformed plane along the direction.
Definition: grid.h:120
real dXi
Grid spacing in the transformed plane along the direction.
Definition: grid.h:117
real dZt
Grid spacing in the transformed plane along the direction.
Definition: grid.h:123
blitz::Array< real, 1 > zt_zColloc
Array of the grid derivatives at collocated grid points, defined locally within each sub-domain.
Definition: grid.h:235
Class to store MPI derived datatypes for individual arrays.
Definition: mpidata.h:51
void syncData()
Function to send data across all sub-domain faces.
Definition: mpidata.cc:278
int nProc
The total number of cores available for computation.
Definition: parallel.h:63
Plain scalar field class to store simple scalar fields with no differentiation or interpolation.
Definition: plainsf.h:51
plainsf & operator-=(plainsf &a)
Overloaded operator to subtract a given plain scalar field.
Definition: plainsf.cc:103
plainsf & operator+=(plainsf &a)
Overloaded operator to add a given plain scalar field.
Definition: plainsf.cc:85
void gradient(plainvf &gradF, const vfield &V)
Operator to compute the gradient of the plain scalar field.
Definition: plainsf.h:92
void operator=(plainsf &a)
Overloaded operator to assign another plain scalar field to the plain scalar field.
Definition: plainsf.cc:172
real fxMean()
Function to compute the mean value from the plain scalar field.
Definition: plainsf.h:144
real fxMax()
Function to extract the maximum value from the plain scalar field.
Definition: plainsf.h:123
plainsf & operator*=(real a)
Overloaded operator to multiply a scalar value to the scalar field.
Definition: plainsf.cc:157
void syncData()
Function to synchronise data across all processors when performing parallel computations.
Definition: plainsf.h:108
plainsf(const grid &gridData, const sfield &refF)
Constructor of the plainsf class.
Definition: plainsf.cc:60
Plain vector field class to store simple vector fields with no additional operators like differentiat...
Definition: plainvf.h:49
Scalar field class to store and operate on scalar fields.
Definition: sfield.h:54
Vector field class to store and operate on vector fields.
Definition: vfield.h:54
Class declaration of grid.
Class declaration of plainvf - plain vector field.
Class declaration of sfield - scalar field.
Class declaration of vfield - vector field.