Vlasiator ebf0dd394 on dev (v5.4.0 + 1054 commits)
Loading...
Searching...
No Matches
Template.cpp
Go to the documentation of this file.
1/*
2 * This file is part of Vlasiator.
3 * Copyright 2010-2016 Finnish Meteorological Institute
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#include <cstdlib>
24#include <iostream>
25#include <cmath>
26
27#include "../../common.h"
32
33#include "Template.h"
34
35using namespace std;
36using namespace spatial_cell;
37
38namespace projects {
41
43 typedef Readparameters RP;
44 RP::add("Template.param", "This is my project's parameter. Default is 0.0", 0.0);
45 }
46
49
50 typedef Readparameters RP;
51 RP::get("Template.param", this->param);
52 }
53
55 this->param += 1.0;
56 return Project::initialize();
57 }
58
60 const uint popID,
61 const uint nRequested
62 ) const {
63 //const speciesParameters& sP = this->speciesParams[popID];
64 // Fetch spatial cell center coordinates
65 const Real x = cell->parameters[CellParams::XCRD] + 0.5*cell->parameters[CellParams::DX];
66 const Real y = cell->parameters[CellParams::YCRD] + 0.5*cell->parameters[CellParams::DY];
67 const Real z = cell->parameters[CellParams::ZCRD] + 0.5*cell->parameters[CellParams::DZ];
68
69 const Real mass = getObjectWrapper().particleSpecies[popID].mass;
70 creal initRho = 1.0;
71 creal initT = 1.0;
72 const std::array<Real, 3> V0 = this->getV0(x, y, z, popID)[0];
73 creal initV0X = V0[0];
74 creal initV0Y = V0[1];
75 creal initV0Z = V0[2];
76
77 #ifdef USE_GPU
80 #else
83 #endif
84 // Loop over blocks
85 Realf rhosum = 0;
87 {WID, WID, WID, nRequested},
88 ARCH_LOOP_LAMBDA (const uint i, const uint j, const uint k, const uint initIndex, Realf *lsum ) {
89 vmesh::GlobalID *GIDlist = vmesh->getGrid()->data();
90 Realf* bufferData = VBC->getData();
91 const vmesh::GlobalID blockGID = GIDlist[initIndex];
92 // Calculate parameters for new block
93 Real blockCoords[6];
94 vmesh->getBlockInfo(blockGID,&blockCoords[0]);
95 creal vxBlock = blockCoords[0];
96 creal vyBlock = blockCoords[1];
97 creal vzBlock = blockCoords[2];
98 creal dvxCell = blockCoords[3];
99 creal dvyCell = blockCoords[4];
100 creal dvzCell = blockCoords[5];
101 ARCH_INNER_BODY(i, j, k, initIndex, lsum) {
102 creal vx = vxBlock + (i+0.5)*dvxCell - initV0X;
103 creal vy = vyBlock + (j+0.5)*dvyCell - initV0Y;
104 creal vz = vzBlock + (k+0.5)*dvzCell - initV0Z;
105 const Realf value = MaxwellianPhaseSpaceDensity(vx,vy,vz,initT,initRho,mass);
106 bufferData[initIndex*WID3 + k*WID2 + j*WID + i] = value;
107 //lsum[0] += value;
108 };
109 }, rhosum);
110 return rhosum;
111 }
112
113 /* Evaluates local SpatialCell properties for the project and population,
114 then evaluates the phase-space density at the given coordinates.
115 Used as a probe for projectTriAxisSearch.
116 */
118 const uint popID,
119 Real vx_in, Real vy_in, Real vz_in
120 ) const {
121 const Real mass = getObjectWrapper().particleSpecies[popID].mass;
122 // Fetch spatial cell center coordinates
123 const Real x = cell->parameters[CellParams::XCRD] + 0.5*cell->parameters[CellParams::DX];
124 const Real y = cell->parameters[CellParams::YCRD] + 0.5*cell->parameters[CellParams::DY];
125 const Real z = cell->parameters[CellParams::ZCRD] + 0.5*cell->parameters[CellParams::DZ];
126 creal initRho = 1.0;
127 creal initT = 1.0;
128 const std::array<Real, 3> V0 = this->getV0(x, y, z, popID)[0];
129 creal initV0X = V0[0];
130 creal initV0Y = V0[1];
131 creal initV0Z = V0[2];
132 creal vx = vx_in - initV0X;
133 creal vy = vy_in - initV0Y;
134 creal vz = vz_in - initV0Z;
135 const Realf value = MaxwellianPhaseSpaceDensity(vx,vy,vz,initT,initRho,mass);
136 return value;
137 }
138
142 Dipole bgField;
143 bgField.initialize(8e15, 0.0, 0.0, 0.0, 0.0); //set dipole moment and location
144 setBackgroundField(bgField, bgb, technical, fsgrid);
145 }
146
147 vector<std::array<Real, 3>> Template::getV0(
148 creal x,
149 creal y,
150 creal z,
151 const uint popID
152 ) const {
153 vector<std::array<Real, 3>> centerPoints;
154 std::array<Real, 3> point {{0.0, 0.0, 0.0}};
155 if(x < 0.0) point[1] = 1.0;
156 centerPoints.push_back(point);
157 return centerPoints;
158 }
159
160} // namespace projects
for i
Definition Dispersion.m:24
#define ARCH_INNER_BODY(...)
#define ARCH_LOOP_LAMBDA
void setBackgroundField(const FieldFunction &bgFunction, fsgrids::bgbspan bgb, fsgrids::technicalspan technical, FieldSolverGrid &fsgrid, bool append)
void initialize(const double moment, const double center_x, const double center_y, const double center_z, const double tilt_angle)
Definition dipole.cpp:32
virtual bool initialize()
Definition project.cpp:113
virtual void setProjectBField(fsgrids::perbspan perb, fsgrids::bgbspan bgb, fsgrids::technicalspan technical, FieldSolverGrid &fsgrid) override
Definition Template.cpp:139
virtual void getParameters(void) override
Definition Template.cpp:47
virtual bool initialize(void) override
Definition Template.cpp:54
virtual Realf probePhaseSpace(spatial_cell::SpatialCell *cell, const uint popID, Real vx_in, Real vy_in, Real vz_in) const override
Definition Template.cpp:117
virtual std::vector< std::array< Real, 3 > > getV0(creal x, creal y, creal z, const uint popID) const override
Return a vector containing the velocity coordinate of the centre of each ion population in the distri...
Definition Template.cpp:147
virtual Realf fillPhaseSpace(spatial_cell::SpatialCell *cell, const uint popID, const uint nRequested) const override
Definition Template.cpp:59
static void addParameters(void)
Definition Template.cpp:42
virtual ~Template()
Definition Template.cpp:40
vmesh::VelocityMesh * get_velocity_mesh(const size_t &popID)
vmesh::VelocityBlockContainer * get_velocity_blocks(const size_t &popID)
std::array< Real, CellParams::N_SPATIAL_CELL_PARAMS > parameters
vmesh::VelocityBlockContainer * dev_get_velocity_blocks(const size_t &popID)
vmesh::VelocityMesh * dev_get_velocity_mesh(const size_t &popID)
#define WID
Definition common.h:514
const int WID3
Definition common.h:517
const int WID2
Definition common.h:516
float Real
Definition definitions.h:41
float Realf
Definition definitions.h:33
fsgrid::FsGrid< FS_STENCIL_WIDTH > FieldSolverGrid
Definition definitions.h:78
const float creal
Definition definitions.h:42
const int j
const int k
ObjectWrapper & getObjectWrapper()
Definition main.cpp:33
static void parallel_reduce(const uint(&limits)[NDim], Lambda loop_body, T &sum)
std::span< std::array< Real, fsgrids::bfield::N_BFIELD > > perbspan
Definition common.h:434
std::span< technical > technicalspan
Definition common.h:452
std::span< std::array< Real, bgbfield::N_BGB > > bgbspan
Definition common.h:444
ARCH_HOSTDEV Realf MaxwellianPhaseSpaceDensity(creal &vx, creal &vy, creal &vz, creal &T, creal &rho, creal &mass)
Definition project.h:45
uint32_t GlobalID
Definition definitions.h:59
std::vector< species::Species > particleSpecies
static void getParameters()
Get the global parameters.