Vlasiator ebf0dd394 on dev (v5.4.0 + 1054 commits)
Loading...
Searching...
No Matches
common.h
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#ifndef COMMON_H
24#define COMMON_H
25
26#include <limits>
27#include <string>
28#include <vector>
29#include <span>
30#include "definitions.h"
31
32// Include architecture specific definitions
34
35#ifdef DEBUG_SOLVERS
36#define CHECK_FLOAT(x) \
37 if ((x) != (x)) {\
38 std::cerr << __FILE__ << ":" << __LINE__ << " Illegal value: " << x << std::endl;\
39 abort();\
40 }
41#else
42#define CHECK_FLOAT(x) {}
43#endif
44
45void bailout(
46 const bool condition,
47 const std::string& message
48);
49void bailout(
50 const bool condition,
51 const char * const file,
52 const int line
53);
54void bailout(
55 const bool condition,
56 const std::string& message,
57 const char * const file,
58 const int line
59);
60
61[[ noreturn ]] void abort_mpi(const std::string str, const int err_type = 0);
62
63#define sqr(x) ((x)*(x))
64#define pow2(x) sqr(x)
65#define pow3(x) ((x)*(x)*(x))
66
67#define MASTER_RANK 0
68
69
70/* Maximum number of blocks in each dimension in velocity space. The
71 size of velocity space defined in cfg can at maximum be this large
72*/
73#define MAX_BLOCKS_PER_DIM 256
74
103
104
118
232
250
251namespace vderivatives {
252 // Essentially a copy from dmoments
253 enum {
264 };
265}
266
273namespace fsgrids {
280
287
303
310
322
341
372
373 // NOTE This contains the BGB derivatives as they do not change either
401
402 // NOTE This contains the PERBVOL derivatives
424
433
434 typedef std::span<std::array<Real, fsgrids::bfield::N_BFIELD>> perbspan;
435 typedef std::span<const std::array<Real, fsgrids::bfield::N_BFIELD>> constperbspan;
436 typedef std::span<std::array<Real, fsgrids::efield::N_EFIELD>> efieldspan;
437 typedef std::span<const std::array<Real, fsgrids::efield::N_EFIELD>> constefieldspan;
438 typedef std::span<std::array<Real, fsgrids::ehall::N_EHALL>> ehallspan;
439 typedef std::span<const std::array<Real, fsgrids::ehall::N_EHALL>> constehallspan;
440 typedef std::span<std::array<Real, fsgrids::egradpe::N_EGRADPE>> egradpespan;
441 typedef std::span<const std::array<Real, fsgrids::egradpe::N_EGRADPE>> constegradpespan;
442 typedef std::span<std::array<Real, fsgrids::dperb::N_DPERB>> dperbspan;
443 typedef std::span<const std::array<Real, fsgrids::dperb::N_DPERB>> constdperbspan;
444 typedef std::span<std::array<Real, bgbfield::N_BGB>> bgbspan;
445 typedef std::span<const std::array<Real, bgbfield::N_BGB>> constbgbspan;
446 typedef std::span<std::array<Real, fsgrids::moments::N_MOMENTS>> momentsspan;
447 typedef std::span<const std::array<Real, fsgrids::moments::N_MOMENTS>> constmomentsspan;
448 typedef std::span<std::array<Real, fsgrids::dmoments::N_DMOMENTS>> dmomentsspan;
449 typedef std::span<const std::array<Real, fsgrids::dmoments::N_DMOMENTS>> constdmomentsspan;
450 typedef std::span<std::array<Real, fsgrids::volfields::N_VOL>> volspan;
451 typedef std::span<const std::array<Real, fsgrids::volfields::N_VOL>> constvolspan;
452 typedef std::span<technical> technicalspan;
453 typedef std::span<const technical> consttechnicalspan;
454
455}
456
457// Ionosphere node parameters
480
497
498namespace compute {
499 const uint BX = (1 << 0); // 1
500 const uint BY = (1 << 1); // 2
501 const uint BZ = (1 << 2); // 4
502 const uint EX = (1 << 3); // 8
503 const uint EY = (1 << 4); // 16
504 const uint EZ = (1 << 5); // 32
505}
506
511};
512
513#ifndef WID
514#define WID (4)
515#endif
516const int WID2 = WID*WID;
517const int WID3 = WID2*WID;
518
522template<typename INT> ARCH_HOSTDEV inline INT cellIndex(const INT& i,const INT& j,const INT& k) {
523 return k*WID2 + j*WID + i;
524}
525
526const int SIZE_VELBLOCK = WID3;
527
528template<typename T> inline int sign(const T& value) {
529 const T ZERO = 0.0;
530 if (value < ZERO) return -1;
531 return 1;
532}
533
538 static int bailingOut;
539 static bool writeRestart;
540 static bool writeRecover;
541 static bool balanceLoad;
542 static bool doRefine;
544};
545
546namespace donow {
547 enum {
553 };
554}
555
556
560namespace hook {
561 enum {
563 };
564}
565
566
567// Natural constants
569 const Real EPS_0 = 8.85418782e-12;
570 const Real MU_0 = 1.25663706e-6;
571 const Real K_B = 1.3806503e-23;
572 const Real CHARGE = 1.60217653e-19;
573 const Real MASS_ELECTRON = 9.10938188e-31;
574 const Real MASS_PROTON = 1.67262158e-27;
575 const Real R_E = 6.3712e6;
576}
577
578const std::vector<CellID>& getLocalCells();
579
580#endif
Binary file
Definition Dispersion.m:11
for i
Definition Dispersion.m:24
#define ARCH_HOSTDEV
const std::vector< CellID > & getLocalCells()
Definition main.cpp:39
ionosphereParameters
Definition common.h:458
@ SOURCE
Definition common.h:459
@ SIGMAP
Definition common.h:464
@ SOLUTION
Definition common.h:472
@ SIGMA22
Definition common.h:461
@ PPARAM
Definition common.h:477
@ NODE_BX
Definition common.h:470
@ BEST_SOLUTION
Definition common.h:473
@ SIGMAPARALLEL
Definition common.h:466
@ PPPARAM
Definition common.h:477
@ SIGMA32
Definition common.h:462
@ RESIDUAL
Definition common.h:474
@ ZZPARAM
Definition common.h:476
@ N_IONOSPHERE_PARAMETERS
Definition common.h:478
@ UPMAPPED_BX
Definition common.h:471
@ ZPARAM
Definition common.h:476
@ SIGMA31
Definition common.h:462
@ SIGMA21
Definition common.h:461
@ NODE_BY
Definition common.h:470
@ SIGMA12
Definition common.h:460
@ RRESIDUAL
Definition common.h:475
@ SIGMA13
Definition common.h:460
@ SIGMAH
Definition common.h:465
@ UPMAPPED_BZ
Definition common.h:471
@ PRECIP
Definition common.h:467
@ SIGMA33
Definition common.h:462
@ TEMPERATURE
Definition common.h:469
@ RHON
Definition common.h:468
@ SIGMA23
Definition common.h:461
@ SIGMA
Definition common.h:460
@ UPMAPPED_BY
Definition common.h:471
@ NODE_BZ
Definition common.h:470
#define WID
Definition common.h:514
int sign(const T &value)
Definition common.h:528
@ RK_ORDER2_STEP1
Definition common.h:509
@ RK_ORDER1
Definition common.h:508
@ RK_ORDER2_STEP2
Definition common.h:510
const int WID3
Definition common.h:517
const int WID2
Definition common.h:516
void bailout(const bool condition, const std::string &message)
A function to stop the simulation if the boolean condition is true. Raises a flag which gets MPI_Redu...
Definition common.cpp:82
const int SIZE_VELBLOCK
Definition common.h:526
void abort_mpi(const std::string str, const int err_type=0)
Definition common.cpp:90
#define str(s)
float Real
Definition definitions.h:41
const Real ZERO
Definition fs_common.h:59
const int j
const int k
@ N_VELOCITY_BLOCK_PARAMS
Definition common.h:115
@ CURVATUREZ
Definition common.h:213
@ CONNECTION_BW_Y
Definition common.h:209
@ CONNECTION_BW_X
Definition common.h:208
@ CONNECTION_FW_X
Definition common.h:205
@ BULKV_FORCING_X
Definition common.h:225
@ FSGRID_BOUNDARYTYPE
Definition common.h:201
@ REFINEMENT_LEVEL
Definition common.h:203
@ RECENTLY_REFINED
Definition common.h:224
@ CURVATUREX
Definition common.h:211
@ FSGRID_RANK
Definition common.h:200
@ CURVATUREY
Definition common.h:212
@ N_SPATIAL_CELL_PARAMS
Definition common.h:229
@ CONNECTION_FW_Z
Definition common.h:207
@ BULKV_FORCING_Z
Definition common.h:227
@ AMR_ALPHA2
Definition common.h:221
@ CONNECTION_FW_Y
Definition common.h:206
@ ISCELLSAVINGF
Definition common.h:199
@ CONNECTION
Definition common.h:204
@ P_ANISOTROPY
Definition common.h:222
@ AMR_ALPHA1
Definition common.h:220
@ LBWEIGHTCOUNTER
Definition common.h:198
@ BULKV_FORCING_Y
Definition common.h:226
@ AMR_VORTICITY
Definition common.h:223
@ CONNECTION_BW_Z
Definition common.h:210
@ SYSBOUNDARIES
Definition common.h:84
@ VLASOV_SOLVER_Z
Definition common.h:80
@ VLASOV_SOLVER_TARGET_X
Definition common.h:81
@ VLASOV_SOLVER_X
Definition common.h:78
@ VLASOV_SOLVER
Definition common.h:77
@ SYSBOUNDARIES_EXTENDED
Definition common.h:85
@ VLASOV_SOLVER_TARGET_Z
Definition common.h:83
@ VLASOV_SOLVER_Y_GHOST
Definition common.h:96
@ VLASOV_SOLVER_GHOST_REQNEIGH
Definition common.h:99
@ N_NEIGHBORHOODS
Definition common.h:100
@ VLASOV_SOLVER_TARGET_Y
Definition common.h:82
@ VLASOV_SOLVER_Y
Definition common.h:79
@ VLASOV_SOLVER_GHOST
Definition common.h:98
@ VLASOV_SOLVER_X_GHOST
Definition common.h:95
@ VLASOV_SOLVER_Z_GHOST
Definition common.h:97
const uint EZ
Definition common.h:504
const uint EY
Definition common.h:503
const uint EX
Definition common.h:502
const uint BZ
Definition common.h:501
const uint BX
Definition common.h:499
const uint BY
Definition common.h:500
@ DORC
Definition common.h:549
@ SAVE
Definition common.h:548
@ DOMR
Definition common.h:551
@ N_DONOW
Definition common.h:552
@ DOLB
Definition common.h:550
@ BGBYVOL
Definition common.h:379
@ BGBZVDCORR
Definition common.h:383
@ dBGBYVOLdx
Definition common.h:393
@ dBGBZVOLdx
Definition common.h:396
@ BGBY
Definition common.h:376
@ dBGBxdz
Definition common.h:385
@ dBGBydx
Definition common.h:386
@ BGBZ
Definition common.h:377
@ BGBYVDCORR
Definition common.h:382
@ dBGBYVOLdz
Definition common.h:395
@ BGBXVOL
Definition common.h:378
@ N_BGB
Definition common.h:399
@ dBGBXVOLdx
Definition common.h:390
@ dBGBydz
Definition common.h:387
@ dBGBZVOLdz
Definition common.h:398
@ dBGBZVOLdy
Definition common.h:397
@ BGBX
Definition common.h:375
@ dBGBXVOLdy
Definition common.h:391
@ dBGBzdx
Definition common.h:388
@ dBGBYVOLdy
Definition common.h:394
@ dBGBxdy
Definition common.h:384
@ BGBXVDCORR
Definition common.h:381
@ dBGBzdy
Definition common.h:389
@ dBGBXVOLdz
Definition common.h:392
@ BGBZVOL
Definition common.h:380
std::span< std::array< Real, fsgrids::bfield::N_BFIELD > > perbspan
Definition common.h:434
std::span< const std::array< Real, fsgrids::dmoments::N_DMOMENTS > > constdmomentsspan
Definition common.h:449
@ EZGRADPE
Definition common.h:307
@ EYGRADPE
Definition common.h:306
@ N_EGRADPE
Definition common.h:308
@ EXGRADPE
Definition common.h:305
std::span< const std::array< Real, bgbfield::N_BGB > > constbgbspan
Definition common.h:445
std::span< const std::array< Real, fsgrids::efield::N_EFIELD > > constefieldspan
Definition common.h:437
std::span< const std::array< Real, fsgrids::moments::N_MOMENTS > > constmomentsspan
Definition common.h:447
std::span< std::array< Real, fsgrids::moments::N_MOMENTS > > momentsspan
Definition common.h:446
std::span< std::array< Real, fsgrids::egradpe::N_EGRADPE > > egradpespan
Definition common.h:440
std::span< std::array< Real, fsgrids::dmoments::N_DMOMENTS > > dmomentsspan
Definition common.h:448
@ N_MOMENTS
Definition common.h:320
@ P_22
Definition common.h:318
@ P_33
Definition common.h:319
@ RHOM
Definition common.h:312
@ P_11
Definition common.h:317
@ RHOQ
Definition common.h:313
std::span< technical > technicalspan
Definition common.h:452
std::span< const std::array< Real, fsgrids::ehall::N_EHALL > > constehallspan
Definition common.h:439
@ EZHALL_010_011
Definition common.h:295
@ N_EHALL
Definition common.h:301
@ EYHALL_101_111
Definition common.h:299
@ EYHALL_100_110
Definition common.h:292
@ EXHALL_010_110
Definition common.h:294
@ EZHALL_110_111
Definition common.h:296
@ EZHALL_000_001
Definition common.h:291
@ EYHALL_001_011
Definition common.h:298
@ EXHALL_001_101
Definition common.h:297
@ EYHALL_000_010
Definition common.h:290
@ EXHALL_000_100
Definition common.h:289
@ EXHALL_011_111
Definition common.h:300
@ EZHALL_100_101
Definition common.h:293
std::span< std::array< Real, bgbfield::N_BGB > > bgbspan
Definition common.h:444
std::span< std::array< Real, fsgrids::dperb::N_DPERB > > dperbspan
Definition common.h:442
std::span< const technical > consttechnicalspan
Definition common.h:453
volfields
Definition common.h:403
@ dPERBZVOLdx
Definition common.h:413
@ dPERBXVOLdz
Definition common.h:409
@ dPERBZVOLdy
Definition common.h:414
@ dPERBZVOLdz
Definition common.h:415
@ PERBYVOL
Definition common.h:405
@ EZVOL
Definition common.h:418
@ dPERBYVOLdx
Definition common.h:410
@ EXVOL
Definition common.h:416
@ dPERBYVOLdy
Definition common.h:411
@ dPERBXVOLdy
Definition common.h:408
@ N_VOL
Definition common.h:422
@ CURVATUREZ
Definition common.h:421
@ dPERBYVOLdz
Definition common.h:412
@ CURVATUREX
Definition common.h:419
@ PERBXVOL
Definition common.h:404
@ CURVATUREY
Definition common.h:420
@ dPERBXVOLdx
Definition common.h:407
@ EYVOL
Definition common.h:417
@ PERBZVOL
Definition common.h:406
@ dVydz
Definition common.h:363
@ dPedz
Definition common.h:369
@ dp11dz
Definition common.h:351
@ dVydx
Definition common.h:361
@ dp22dy
Definition common.h:353
@ drhomdy
Definition common.h:344
@ dp33dy
Definition common.h:356
@ dVzdz
Definition common.h:366
@ dVzdx
Definition common.h:364
@ dp11dy
Definition common.h:350
@ drhoqdz
Definition common.h:348
@ dp22dx
Definition common.h:352
@ dVxdy
Definition common.h:359
@ dp22dz
Definition common.h:354
@ dp11dx
Definition common.h:349
@ drhomdz
Definition common.h:345
@ dp33dz
Definition common.h:357
@ dPedx
Definition common.h:367
@ dPedy
Definition common.h:368
@ dp33dx
Definition common.h:355
@ dVxdz
Definition common.h:360
@ drhoqdx
Definition common.h:346
@ drhomdx
Definition common.h:343
@ dVzdy
Definition common.h:365
@ drhoqdy
Definition common.h:347
@ dVydy
Definition common.h:362
@ N_DMOMENTS
Definition common.h:370
@ dVxdx
Definition common.h:358
std::span< std::array< Real, fsgrids::efield::N_EFIELD > > efieldspan
Definition common.h:436
@ N_BFIELD
Definition common.h:278
@ PERBY
Definition common.h:276
@ PERBZ
Definition common.h:277
@ PERBX
Definition common.h:275
std::span< std::array< Real, fsgrids::volfields::N_VOL > > volspan
Definition common.h:450
std::span< const std::array< Real, fsgrids::volfields::N_VOL > > constvolspan
Definition common.h:451
std::span< const std::array< Real, fsgrids::bfield::N_BFIELD > > constperbspan
Definition common.h:435
std::span< const std::array< Real, fsgrids::egradpe::N_EGRADPE > > constegradpespan
Definition common.h:441
std::span< std::array< Real, fsgrids::ehall::N_EHALL > > ehallspan
Definition common.h:438
@ dPERBzdxy
Definition common.h:338
@ dPERBzdy
Definition common.h:329
@ dPERBzdyy
Definition common.h:337
@ dPERBzdxx
Definition common.h:336
@ dPERBydxx
Definition common.h:333
@ dPERBydx
Definition common.h:326
@ dPERBydxz
Definition common.h:335
@ dPERBzdx
Definition common.h:328
@ dPERBxdzz
Definition common.h:331
@ dPERBxdyz
Definition common.h:332
@ dPERBydzz
Definition common.h:334
@ dPERBxdy
Definition common.h:324
@ dPERBxdyy
Definition common.h:330
@ dPERBxdz
Definition common.h:325
@ dPERBydz
Definition common.h:327
@ N_DPERB
Definition common.h:339
std::span< const std::array< Real, fsgrids::dperb::N_DPERB > > constdperbspan
Definition common.h:443
@ N_EFIELD
Definition common.h:285
Definition common.h:560
@ END_OF_TIME_STEP
Definition common.h:562
const Real CHARGE
Definition common.h:572
const Real K_B
Definition common.h:571
const Real MU_0
Definition common.h:570
const Real MASS_ELECTRON
Definition common.h:573
const Real EPS_0
Definition common.h:569
const Real R_E
Definition common.h:575
const Real MASS_PROTON
Definition common.h:574
@ N_SYSBOUNDARY_CONDITIONS
Definition common.h:494
@ OUTER_BOUNDARY_PADDING
Definition common.h:493
@ N_V_DERIVATIVES
Definition common.h:263
static bool balanceLoad
Definition common.h:541
static bool ionosphereJustSolved
Definition common.h:543
static int bailingOut
Definition common.h:538
static bool doRefine
Definition common.h:542
static bool writeRecover
Definition common.h:540
static bool writeRestart
Definition common.h:539