Vlasiator ebf0dd394 on dev (v5.4.0 + 1054 commits)
Loading...
Searching...
No Matches
arch_moments.h
Go to the documentation of this file.
1/*
2 * This file is part of Vlasiator.
3 * Copyright 2024-2025 University of Helsinki, CSC
4 *
5 * For details of usage, see the COPYING file and read the "Rules of the Road"
6 * at http://www.physics.helsinki.fi/vlasiator/
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License along
19 * with this program; if not, write to the Free Software Foundation, Inc.,
20 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21 */
22
23#ifndef ARCH_MOMENTS_H
24#define ARCH_MOMENTS_H
25
26#include <vector>
27#include <limits>
28#include <dccrg.hpp>
29#include <dccrg_cartesian_geometry.hpp>
30
31#include "../definitions.h"
32#include "../common.h"
34
35using namespace spatial_cell;
36
37#define nMom1 4
38#define nMom2 6
39
40// ***** FUNCTION DECLARATIONS ***** //
41
42template<typename REAL, uint SIZE>
44 REAL (&array)[SIZE],
45 uint nBlocks);
46
47template<typename REAL, uint SIZE>
49 const REAL averageVX,
50 const REAL averageVY,
51 const REAL averageVZ,
52 REAL (&array)[SIZE],
53 uint nBlocks);
54
56 dccrg::Dccrg<SpatialCell,dccrg::Cartesian_Geometry>& mpiGrid,
57 const std::vector<CellID>& cells,
58 const bool& computeSecond,
59 const bool initialCompute=false
60);
61
63 dccrg::Dccrg<SpatialCell,dccrg::Cartesian_Geometry>& mpiGrid,
64 const std::vector<CellID>& cells,
65 const bool& computeSecond,
66 const bool initialCompute=false
67);
68
69
70// ***** TEMPLATE FUNCTION DEFINITIONS ***** //
71
82template<typename REAL, uint SIZE> inline
84 vmesh::VelocityBlockContainer *blockContainer,
85 REAL (&array)[SIZE],
86 uint nBlocks) {
87
89 ARCH_LOOP_LAMBDA (const uint i, const uint j, const uint k, const uint blockLID, Real *lsum ) {
90
91 Realf *data = blockContainer->getData();
92 Real *blockParameters = blockContainer->getParameters();
93 const Realf* avgs = &data[blockLID*WID3];
94 const Real* blockParamsZ = &blockParameters[blockLID*BlockParams::N_VELOCITY_BLOCK_PARAMS];
95 const Real DV3 = blockParamsZ[BlockParams::DVX]*blockParamsZ[BlockParams::DVY]*blockParamsZ[BlockParams::DVZ];
96 const Real HALF = 0.5;
97
98 ARCH_INNER_BODY(i, j, k, blockLID, lsum) {
99 const Real VX = blockParamsZ[BlockParams::VXCRD] + (i+HALF)*blockParamsZ[BlockParams::DVX];
100 const Real VY = blockParamsZ[BlockParams::VYCRD] + (j+HALF)*blockParamsZ[BlockParams::DVY];
101 const Real VZ = blockParamsZ[BlockParams::VZCRD] + (k+HALF)*blockParamsZ[BlockParams::DVZ];
102 lsum[0] += avgs[cellIndex(i,j,k)] * DV3;
103 lsum[1] += avgs[cellIndex(i,j,k)]*VX * DV3;
104 lsum[2] += avgs[cellIndex(i,j,k)]*VY * DV3;
105 lsum[3] += avgs[cellIndex(i,j,k)]*VZ * DV3;
106 };
107 }, array);
108}
109
122template<typename REAL, uint SIZE> inline
124 vmesh::VelocityBlockContainer *blockContainer,
125 const REAL averageVX,
126 const REAL averageVY,
127 const REAL averageVZ,
128 REAL (&array)[SIZE],
129 uint nBlocks) {
130
132 ARCH_LOOP_LAMBDA (const uint i, const uint j, const uint k, const uint blockLID, Real *lsum ) {
133
134 Realf *data = blockContainer->getData();
135 Real *blockParameters = blockContainer->getParameters();
136 const Realf* avgs = &data[blockLID*WID3];
137 const Real* blockParams = &blockParameters[blockLID*BlockParams::N_VELOCITY_BLOCK_PARAMS];
138 const Real DV3 = blockParams[BlockParams::DVX]*blockParams[BlockParams::DVY]*blockParams[BlockParams::DVZ];
139 const Real HALF = 0.5;
140
141 ARCH_INNER_BODY(i, j, k, blockLID, lsum) {
142 const Real VX = blockParams[BlockParams::VXCRD] + (i+HALF)*blockParams[BlockParams::DVX];
143 const Real VY = blockParams[BlockParams::VYCRD] + (j+HALF)*blockParams[BlockParams::DVY];
144 const Real VZ = blockParams[BlockParams::VZCRD] + (k+HALF)*blockParams[BlockParams::DVZ];
145 lsum[0] += avgs[cellIndex(i,j,k)] * (VX - averageVX) * (VX - averageVX) * DV3;
146 lsum[1] += avgs[cellIndex(i,j,k)] * (VY - averageVY) * (VY - averageVY) * DV3;
147 lsum[2] += avgs[cellIndex(i,j,k)] * (VZ - averageVZ) * (VZ - averageVZ) * DV3;
148 lsum[3] += avgs[cellIndex(i,j,k)] * (VY - averageVY) * (VZ - averageVZ) * DV3;
149 lsum[4] += avgs[cellIndex(i,j,k)] * (VX - averageVX) * (VZ - averageVZ) * DV3;
150 lsum[5] += avgs[cellIndex(i,j,k)] * (VX - averageVX) * (VY - averageVY) * DV3;
151 };
152 }, array);
153}
154
155#endif
for i
Definition Dispersion.m:24
#define ARCH_INNER_BODY(...)
#define ARCH_LOOP_LAMBDA
void calculateMoments_V(dccrg::Dccrg< SpatialCell, dccrg::Cartesian_Geometry > &mpiGrid, const std::vector< CellID > &cells, const bool &computeSecond, const bool initialCompute=false)
void blockVelocitySecondMoments(vmesh::VelocityBlockContainer *blockContainer, const REAL averageVX, const REAL averageVY, const REAL averageVZ, REAL(&array)[SIZE], uint nBlocks)
void calculateMoments_R(dccrg::Dccrg< SpatialCell, dccrg::Cartesian_Geometry > &mpiGrid, const std::vector< CellID > &cells, const bool &computeSecond, const bool initialCompute=false)
void blockVelocityFirstMoments(vmesh::VelocityBlockContainer *blockContainer, REAL(&array)[SIZE], uint nBlocks)
#define WID
Definition common.h:514
const int WID3
Definition common.h:517
float Real
Definition definitions.h:41
float Realf
Definition definitions.h:33
const Real HALF
Definition fs_common.h:49
const Real VY
const Real VZ
const int j
const Real *__restrict__ blockParameters
const Real VX
const int k
@ N_VELOCITY_BLOCK_PARAMS
Definition common.h:115
static void parallel_reduce(const uint(&limits)[NDim], Lambda loop_body, T &sum)