Vlasiator ebf0dd394 on dev (v5.4.0 + 1054 commits)
Loading...
Searching...
No Matches
velocity_mesh_parameters.h
Go to the documentation of this file.
1/*
2 * This file is part of Vlasiator.
3 * Copyright 2010-2024 Finnish Meteorological Institute and University of Helsinki
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 * File: velocity_mesh_parameters.h
23 * Author: sandroos, mbattarbee
24 *
25 * Created on April 10, 2015, 12:44 PM
26 */
27
28#ifndef VELOCITY_MESH_PARAMETERS_H
29#define VELOCITY_MESH_PARAMETERS_H
30
31#include <vector>
32#include <array>
33#include "definitions.h"
34#include <iostream>
35
37#ifdef USE_GPU
38 #include "include/splitvector/splitvec.h"
39 #include "arch/gpu_base.hpp"
40#endif
41
42// One per particle population
43#define MAX_VMESH_PARAMETERS_COUNT 32
44
45namespace vmesh {
46
54 std::string name;
59
60 // ***** DERIVED PARAMETERS, CALCULATED BY INITVELOCITYMESHES ***** //
67
69 initialized = false;
70 }
71 };
72
73 struct MeshWrapper {
75 velocityMeshesCreation = new std::vector<vmesh::MeshParameters>(1);
77 }
79 delete velocityMeshes;
81 }
82 MeshWrapper(const MeshWrapper& other) {
83 velocityMeshesCreation = new std::vector<vmesh::MeshParameters>(*(other.velocityMeshesCreation));
84 }
86 delete velocityMeshes;
88 velocityMeshesCreation = new std::vector<vmesh::MeshParameters>(*(other.velocityMeshesCreation));
89 return *this;
90 }
91 std::vector<vmesh::MeshParameters> *velocityMeshesCreation;
92 // We also need an array so we can copy this data into direct GPU-device memory.
93 // On the CPU side we actually reserve enough room for
94 // MAX_VMESH_PARAMETERS_COUNT MeshParameters.
95 std::array<vmesh::MeshParameters,MAX_VMESH_PARAMETERS_COUNT> *velocityMeshes;
96 void initVelocityMeshes(const uint nMeshes);
98 };
99
100 void allocateMeshWrapper();
102 #ifdef USE_GPU
103 // To avoid using relocatable code builds, we use static instances of the GPU constant memory for the mesh wrapper.
104 // This means that each compilation unit will use its own. To make sure all instances are initialized with the same
105 // address, we use the Ctor of a static object to register all intances so that the allocated memory pointer
106 // could be copied to all of them.
107 __device__ __constant__ MeshWrapper* meshWrapperDevInstance;
108 ARCH_DEV static MeshWrapper* gpu_getMeshWrapper() { return meshWrapperDevInstance; };
109 // Static object and corresponding instance whose Ctor is used register all the instances of device meshWrapperDev
110 // symbols.
111 struct meshWrapperDevRegistor {
112 meshWrapperDevRegistor(MeshWrapper*&);
113 };
114 static meshWrapperDevRegistor meshWrapperDevRegistorInstance(meshWrapperDevInstance);
115
116 void deallocateMeshWrapper();
117 #endif
118
119 // Caller, inlined into other compilation units, will call either host or device getter
121 #if defined(USE_GPU)
122 #if (defined(__CUDA_ARCH__) || defined(__HIP_DEVICE_COMPILE__))
123 return gpu_getMeshWrapper();
124 #else
125 return host_getMeshWrapper();
126 #endif
127 #else
128 return host_getMeshWrapper();
129 #endif
130 }
131
132 ARCH_HOSTDEV inline void printVelocityMesh(const uint meshIndex) {
133 vmesh::MeshParameters *vMesh = &((*(getMeshWrapper()->velocityMeshes))[meshIndex]);
134 printf("\nPrintout of velocity mesh %d \n",meshIndex);
135 // printf("Meshwrapper address 0x%lx\n",getMeshWrapper());
136 // printf("array of meshes address 0x%lx\n",&(getMeshWrapper()->velocityMeshes));
137 // printf("Mesh address 0x%lx\n",vMesh);
138 printf("Mesh size\n");
139 printf(" %d %d %d \n",vMesh->gridLength[0],vMesh->gridLength[1],vMesh->gridLength[2]);
140 printf("Block size\n");
141 printf(" %d %d %d \n",vMesh->blockLength[0],vMesh->blockLength[1],vMesh->blockLength[2]);
142 printf("Mesh limits \n");
143 printf(" %f %f %f %f \n",vMesh->meshMinLimits[0],vMesh->meshLimits[0],vMesh->meshMaxLimits[0],vMesh->meshLimits[1]);
144 printf(" %f %f %f %f \n",vMesh->meshMinLimits[1],vMesh->meshLimits[2],vMesh->meshMaxLimits[1],vMesh->meshLimits[3]);
145 printf(" %f %f %f %f \n",vMesh->meshMinLimits[2],vMesh->meshLimits[4],vMesh->meshMaxLimits[2],vMesh->meshLimits[5]);
146 printf("Derived mesh parameters \n");
147 printf(" gridSize %f %f %f \n",vMesh->gridSize[0],vMesh->gridSize[1],vMesh->gridSize[2]);
148 printf(" blockSize %f %f %f \n",vMesh->blockSize[0],vMesh->blockSize[1],vMesh->blockSize[2]);
149 printf(" cellSize %f %f %f \n",vMesh->cellSize[0],vMesh->cellSize[1],vMesh->cellSize[2]);
150 printf(" max velocity blocks %d \n\n",vMesh->max_velocity_blocks);
151 }
152
153} // namespace vmesh
154
155#endif /* VELOCITY_MESH_PARAMETERS_H */
#define ARCH_DEV
#define ARCH_HOSTDEV
float Real
Definition definitions.h:41
ARCH_HOSTDEV void printVelocityMesh(const uint meshIndex)
MeshWrapper * host_getMeshWrapper()
uint32_t LocalID
Definition definitions.h:60
ARCH_HOSTDEV MeshWrapper * getMeshWrapper()
MeshWrapper(const MeshWrapper &other)
MeshWrapper & operator=(const MeshWrapper &other)
void initVelocityMeshes(const uint nMeshes)
std::vector< vmesh::MeshParameters > * velocityMeshesCreation
std::array< vmesh::MeshParameters, MAX_VMESH_PARAMETERS_COUNT > * velocityMeshes