Vlasiator ebf0dd394 on dev (v5.4.0 + 1054 commits)
Loading...
Searching...
No Matches
map_test.cpp
Go to the documentation of this file.
1#include <stdio.h>
2#include "common.h"
4
5/*print all values in the vector valued values array. In this array
6 there are blocks_per_dim blocks with a width of WID*/
7void print_values(int step, Real *values, uint blocks_per_dim, Real v_min, Real dv){
8 char name[256];
9 sprintf(name,"dist_%03d.dat",step);
10
11 FILE* fp=fopen(name,"w");
12 for(int i=0; i < blocks_per_dim * WID; i++){
13 Real v = v_min + i*dv;
14 fprintf(fp,"%20.12g %20.12g\n", v, values[i + WID]);
15 }
16 fclose(fp);
17}
18
19
20void propagate(Real values[], uint blocks_per_dim, Real v_min, Real dv,
21 uint i_block, uint i_cell, uint j_block, uint j_cell,
23 Real a[MAX_BLOCKS_PER_DIM*WID][RECONSTRUCTION_ORDER + 1];
24 Real target[(MAX_BLOCKS_PER_DIM+2)*WID];
25
26
27#ifdef ACC_SEMILAG_PLM
28 compute_plm_coeff_explicit_column(values, blocks_per_dim, a);
29#endif
30#ifdef ACC_SEMILAG_PPM
31 compute_ppm_coeff_explicit_column(values, blocks_per_dim, a);
32#endif
33
34 /*clear temporary taret*/
35 for (uint k=0; k<WID* (blocks_per_dim + 2); ++k){
36 target[k] = 0.0;
37 }
38
39 /* intersection_min is the intersection z coordinate (z after
40 swaps that is) of the lowest possible z plane for each i,j
41 index
42 */
43 const Real intersection_min = intersection +
44 (i_block * WID + i_cell) * intersection_di +
45 (j_block * WID + j_cell) * intersection_dj;
46
47
48 /*compute some initial values, that are used to set up the
49 * shifting of values as we go through all blocks in
50 * order. See comments where they are shifted for
51 * explanations of their meening*/
52
53 /*loop through all blocks in column and compute the mapping as integrals*/
54 for (unsigned int k_block = 0; k_block<blocks_per_dim;k_block++){
55 for (uint k_cell=0; k_cell<WID; ++k_cell){
56 /*v_l, v_r are the left and right velocity coordinates of source cell*/
57 Real v_l = v_min + (k_block * WID + k_cell) * dv;
58 Real v_r = v_l + dv;
59 /*left(l) and right(r) k values (global index) in the target
60 lagrangian grid, the intersecting cells. Again old right is new left*/
61 const int target_gk_l = (int)((v_l - intersection_min)/intersection_dk);
62 const int target_gk_r = (int)((v_r - intersection_min)/intersection_dk);
63
64 for(int gk = target_gk_l; gk <= target_gk_r; gk++){
65 //the velocity limits for the integration to put mass
66 //in the targe cell. If both v_r and v_l are in same target cell
67 //then v_int_l,v_int_r should be between v_l and v_r.
68 //v_int_norm_l and v_int_norm_r normalized to be between 0 and 1 in the cell.
69 const Real v_int_l = min( max((Real)(gk) * intersection_dk + intersection_min, v_l), v_r);
70 const Real v_int_norm_l = (v_int_l - v_l)/dv;
71 const Real v_int_r = min((Real)(gk + 1) * intersection_dk + intersection_min, v_r);
72 const Real v_int_norm_r = (v_int_r - v_l)/dv;
73
74 /*compute left and right integrand*/
75#ifdef ACC_SEMILAG_PLM
76 Real target_density_l =
77 v_int_norm_l * a[k_block * WID + k_cell][0] +
78 v_int_norm_l * v_int_norm_l * a[k_block * WID + k_cell][1];
79 Real target_density_r =
80 v_int_norm_r * a[k_block * WID + k_cell][0] +
81 v_int_norm_r * v_int_norm_r * a[k_block * WID + k_cell][1];
82#endif
83#ifdef ACC_SEMILAG_PPM
84 Real target_density_l =
85 v_int_norm_l * a[k_block * WID + k_cell][0] +
86 v_int_norm_l * v_int_norm_l * a[k_block * WID + k_cell][1] +
87 v_int_norm_l * v_int_norm_l * v_int_norm_l * a[k_block * WID + k_cell][2];
88 Real target_density_r =
89 v_int_norm_r * a[k_block * WID + k_cell][0] +
90 v_int_norm_r * v_int_norm_r * a[k_block * WID + k_cell][1] +
91 v_int_norm_r * v_int_norm_r * v_int_norm_r * a[k_block * WID + k_cell][2];
92#endif
93 /*total value of integrand*/
94 target[gk + WID] += target_density_r - target_density_l;
95 }
96 }
97 }
98 /*copy target to values, and clear target array*/
99 for (unsigned int k_block = 0; k_block<blocks_per_dim;k_block++){
100 for (uint k=0; k<WID; ++k){
101 values[k_block * WID + k + WID] = target[k_block * WID + k + WID];
102 }
103 }
104}
105
106int main(void) {
107 const int dv = 20000;
108 const Real v_min = -4e6;
109 const int blocks_per_dim = 100;
110 const int i_block = 0; //x index of block, fixed in this simple test
111 const int j_block = 0; //y index of block, fixed in this simple test
112 const int i_cell = 0; // z index of cell within block (0..WID-1)
113 const int j_cell = 0; // y index of cell within block (0..WID-1)
114
115
116 Real values[(blocks_per_dim+2)*WID];
117
118 /*initial values*/
119
120 Real intersection = v_min + 0.6*dv;
121 Real intersection_di = dv/4.0;
123 Real intersection_dj = dv; //does not matter here, fixed j.
124
125 const int iterations=1000;
126
127 /*clear target & values array*/
128 for (uint k=0; k<WID* (blocks_per_dim + 2); ++k){
129 values[k] = 0.0;
130 }
131
132 /*Add square wave*/
133 for(int i=0; i < blocks_per_dim * WID; i++){
134 Real v=v_min + i * dv;
135 if (v > v_min + 0.8 * (blocks_per_dim * WID * dv) &&
136 v < v_min + 0.9 * (blocks_per_dim * WID * dv))
137 values[i + WID] = 1.0;
138 }
139
140
141/*loop over propagations*/
142 for(int step = 0; step < iterations; step++){
143 if(step % 10 ==0)
144 print_values(step,values,blocks_per_dim, v_min, dv);
145 propagate(values, blocks_per_dim, v_min, dv,
146 i_block, i_cell, j_block, j_cell,
148 }
149}
fclose(file)
for i
Definition Dispersion.m:24
void print_values(int step, Real *values, uint blocks_per_dim, Real v_min, Real dv)
Definition map_test.cpp:7
int main(void)
Definition map_test.cpp:106
void propagate(Real values[], uint blocks_per_dim, Real v_min, Real dv, uint i_block, uint i_cell, uint j_block, uint j_cell, Real intersection, Real intersection_di, Real intersection_dj, Real intersection_dk)
Definition map_test.cpp:20
#define WID
Definition common.h:514
#define MAX_BLOCKS_PER_DIM
Definition common.h:73
void compute_plm_coeff_explicit_column(Real *values, uint n_cblocks, Real a[][RECONSTRUCTION_ORDER+1])
void compute_ppm_coeff_explicit_column(Real *values, uint n_cblocks, Real a[][RECONSTRUCTION_ORDER+1])
float Real
Definition definitions.h:41
const Realf intersection
const Realf intersection_dk
__global__ void vmesh::VelocityMesh **__restrict__ ColumnOffsets split::SplitVector< vmesh::GlobalID > Hashinator::Hashmap< vmesh::GlobalID, vmesh::LocalID > const uint *__restrict__ const Realf const int const int const Realf v_min
const Realf intersection_di
__global__ void vmesh::VelocityMesh **__restrict__ ColumnOffsets split::SplitVector< vmesh::GlobalID > Hashinator::Hashmap< vmesh::GlobalID, vmesh::LocalID > const uint *__restrict__ const Realf const int const int const Realf const Realf dv
const Realf intersection_dj
const int k
static ARCH_HOSTDEV VecSimple< T > min(VecSimple< T > const &l, VecSimple< T > const &r)
static ARCH_HOSTDEV VecSimple< T > max(VecSimple< T > const &l, VecSimple< T > const &r)