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