PLUTO  4.4-patch2
particles.h
Go to the documentation of this file.
1 /* ///////////////////////////////////////////////////////////////////// */
15 /* ///////////////////////////////////////////////////////////////////// */
16 
17 #define INTEGER 1 /* Used for particle deposition */
18 #define REAL 2
19 
20 #define PARTICLES_CREATE 1
21 #define PARTICLES_CREATE_WITH_ID 2
22 #define PARTICLES_TRANSFER 3
23 #define PARTICLES_RESTART 4
24 
25 #ifndef PARTICLES_LP_SPECTRA
26  #define PARTICLES_LP_SPECTRA NO
27 #endif
28 
29 #ifndef PARTICLES_SHAPE
30  #define PARTICLES_SHAPE 3 /* Weight functions: 1 = Nearestg Grid Point (NGP)
31  2 = Cloud-In-Cell (CIC)
32  3 = Triangular Shape Cloud (TSC) */
33 #endif
34 
35 /* *********************************************************************
36  Test/Debug directive
37  ********************************************************************* */
38 
39 #ifndef PARTICLES_DEPOSIT
40  #define PARTICLES_DEPOSIT REAL
41 #endif
42 
43 /* *********************************************************************
44  MPI Data type
45  Set PARTICLES_USE_MPI_DATATYPE to YES to define an appropriate
46  datatype for MPI send/recv of structure.
47  Set PARTICLES_USE_MPI_DATATYPE to NO to pass the structure as a
48  sequence of BYTEs (requires no specific datatype)
49  ********************************************************************* */
50 
51 #ifndef PARTICLES_USE_MPI_DATATYPE
52  #if PARTICLES == PARTICLES_LP
53  #define PARTICLES_USE_MPI_DATATYPE YES
54  #else
55  #define PARTICLES_USE_MPI_DATATYPE YES
56  #endif
57 #endif
58 
59 /* *********************************************************************
60  Particle type: COSMIC RAYS
61  ********************************************************************* */
62 
63 #if PARTICLES == PARTICLES_CR
64 
66  #ifndef PARTICLES_CR_GC
67  #define PARTICLES_CR_GC NO
68  #endif
69 
70  #if PARTICLES_CR_GC == YES
71 
72  #ifndef PARTICLES_CR_GC_INTEGRATOR
73  #define PARTICLES_CR_GC_INTEGRATOR RK_MIDPOINT
74  #endif
75  #ifndef PARTICLES_CR_GC_4VEL
76  #define PARTICLES_CR_GC_4VEL YES
77  #endif
78  #ifndef PARTICLES_CR_GC_DEBUG
79  #define PARTICLES_CR_GC_DEBUG NO
80  #endif
81 
82  #endif
83 
85  #ifndef PARTICLES_CR_C
86  #if PHYSICS == RMHD
87  #define PARTICLES_CR_C 1.0
88  #else
89  #define PARTICLES_CR_C 10000.0
90  #endif
91  #endif
92 
94  #ifndef PARTICLES_CR_E_MC
95  #define PARTICLES_CR_E_MC 1.0
96  #endif
97 
99  #ifndef PARTICLES_CR_E_MC_GAS
100  #define PARTICLES_CR_E_MC_GAS 1.0
101  #endif
102 
104  #ifndef PARTICLES_CR_FEEDBACK
105  #define PARTICLES_CR_FEEDBACK YES
106  #endif
107 
108  #if PARTICLES_CR_FEEDBACK == NO
109  #undef PARTICLES_CR_UPWIND_FLUX
110  #define PARTICLES_CR_UPWIND_FLUX NO
111 
112  /* Define the electric field indices for the test-particle approach
113  when the PHYSICS module is different from ResRMHD
114  These indices are directly taken from the Resistive RMHD module,
115  where the electric field is an independent variable. */
116  #if !(defined EX1) && (PARTICLES_SHAPE < 0)
117  #define EX1 8
118  #define EX2 9
119  #define EX3 10
120  #endif
121  #endif
122 
125  #ifndef PARTICLES_CR_LARMOR_EPS
126  #define PARTICLES_CR_LARMOR_EPS 0.3
127  #endif
128 
130  #ifndef PARTICLES_CR_NCELL_MAX
131  #define PARTICLES_CR_NCELL_MAX 1.8
132  #endif
133 
136  #ifndef PARTICLES_CR_NSUB
137  #if PARTICLES_CR_GC == YES
138  #define PARTICLES_CR_NSUB 1
139  #else
140  #define PARTICLES_CR_NSUB 5
141  #endif
142  #endif
143 
145  #ifndef PARTICLES_CR_PREDICTOR
146  #define PARTICLES_CR_PREDICTOR 2
147  #endif
148 
149  #ifndef PARTICLES_CR_UPWIND_FLUX
150  #define PARTICLES_CR_UPWIND_FLUX NO
151  #endif
152 
154  #ifndef PARTICLES_CR_MAX_FILE_SIZE
155  #define PARTICLES_CR_MAX_FILE_SIZE 1.9 /* In GB */
156  #endif
157 
158 #endif
159 
160 /* *********************************************************************
161  Particle type: DUST
162  ********************************************************************* */
163 
164 #if PARTICLES == PARTICLES_DUST
165 
167  #ifndef PARTICLES_DUST_FEEDBACK
168  #define PARTICLES_DUST_FEEDBACK YES
169  #endif
170 
171  #ifndef PARTICLES_DUST_SB_ETA_VK
172  #define PARTICLES_DUST_SB_ETA_VK 0.0
173  #endif
174 
176  #ifndef PARTICLES_DUST_TIME_STEPPING
177  #define PARTICLES_DUST_TIME_STEPPING EXP_MIDPOINT
178  #endif
179 
182  #ifndef PARTICLES_DUST_STOPPING_TIME
183  #define PARTICLES_DUST_STOPPING_TIME CONSTANT
184  #endif
185 
187  #ifndef PARTICLES_DUST_MAX_FILE_SIZE
188  #define PARTICLES_DUST_MAX_FILE_SIZE 1.9 /* In GB */
189  #endif
190 
191 #endif
192 
193 /* *********************************************************************
194  Particle type: LAGRANGIAN
195  ********************************************************************* */
196 
197 #if PARTICLES == PARTICLES_LP
198 
199  #ifndef PARTICLES_LP_NCOLORS
200  #define PARTICLES_LP_NCOLORS 4
201  #endif
202 
204  #ifndef PARTICLES_LP_MAX_FILE_SIZE
205  #define PARTICLES_LP_MAX_FILE_SIZE 1.9 /* In GB */
206  #endif
207 #endif
208 
209 
210 #if PARTICLES == PARTICLES_LP && PARTICLES_LP_SPECTRA == YES
211  #ifndef PARTICLES_LP_NEBINS /* --> PARTICLES_LP_NEBINS */
212  #define PARTICLES_LP_NEBINS 100
213  #endif
214 
215  #ifndef PARTICLES_LP_SHK_THRESHOLD
216  #define PARTICLES_LP_SHK_THRESHOLD 50
217  #endif
218 
219  #ifndef PARTICLES_LP_SPEC_ENERGY
220  #define PARTICLES_LP_SPEC_ENERGY (CONST_me*CONST_c*CONST_c) /* Unit energy [ergs] to scale spectra */
221  #endif
222 
223  #ifndef PARTICLES_LP_SHK_GRADP
224  #define PARTICLES_LP_SHK_GRADP 0.1 /* To ensure the particles dont cross the same shock twice */
225  #endif
226 
227  #ifndef PARTICLES_LP_NONTH_FRACN
228  #define PARTICLES_LP_NONTH_FRACN 0.1
229  #endif
230 
231  #ifndef PARTICLES_LP_NONTH_FRACE
232  #define PARTICLES_LP_NONTH_FRACE 0.1
233  #endif
234 
235  #ifndef PARTICLES_LP_MICROETA
236  #define PARTICLES_LP_MICROETA 1.4142135623730951
237  #endif
238 
239  #ifndef PARTICLES_LP_ICCMBZ
240  #define PARTICLES_LP_ICCMBZ 0.0
241  #endif
242 
243 #ifndef PARTICLES_LP_CONV_SPECTRA
244  #define PARTICLES_LP_CONV_SPECTRA YES
245 #endif
246 
247  #define UNIT_MAGFIELD (UNIT_VELOCITY*sqrt(4.0*CONST_PI*UNIT_DENSITY))
248  #define UNIT_TIME (UNIT_LENGTH/UNIT_VELOCITY)
249  #define SYNCHROTRON_CONST (0.0015829*UNIT_MAGFIELD*UNIT_MAGFIELD \
250  *PARTICLES_LP_SPEC_ENERGY*UNIT_TIME)
251 
252 
253 #endif
254 
255 /* *********************************************************************
256  Global variables (see globals.h for doc)
257  ********************************************************************* */
258 
259 extern long int p_nparticles;
260 extern long int p_idCounter;
261 extern int p_nrestart;
262 
263 /* *********************************************************************
264  Structure definitions
265  ********************************************************************* */
266 
267 #if PARTICLES == PARTICLES_CR
268 typedef struct Particle_{
269  double coord[3];
270  double speed[3];
271  double coord_old[3];
272  double speed_old[3];
273  double mass;
274  float tinj;
275  float color;
276  int cell[3];
277  uint32_t id;
278 } Particle;
279 #endif
280 
281 #if PARTICLES == PARTICLES_DUST
282 typedef struct Particle_{
283  double coord[3];
284  double speed[3];
285  double mass;
286  double tau_s;
287  float tinj;
288  float color;
289  int cell[3];
290  uint32_t id;
291 } Particle;
292 #endif
293 
294 #if (PARTICLES == PARTICLES_LP) && (PARTICLES_LP_SPECTRA == NO)
295 typedef struct Particle_{
296  double coord[3];
297  double speed[3];
298  double coord_old[3];
299  double speed_old[3];
300  double density;
301  float tinj;
302  float color[PARTICLES_LP_NCOLORS];
303  int cell[3];
304  uint32_t id;
305 } Particle;
306 #endif
307 
308 #if (PARTICLES == PARTICLES_LP) && (PARTICLES_LP_SPECTRA == YES)
309 typedef struct Particle_{
310  double coord[3];
311  double speed[3];
312  double coord_old[3];
313  double speed_old[3];
314  double density;
315 
316  double pressure;
317  double shk_gradp;
318  double cr;
319  double cmp_ratio; /* can we remove it ??? */
320  double lorG;
321  double nmicro;
322 
323  double Vshk_upst[NVAR];
324  double Vshk_dnst[NVAR];
325  double eng[PARTICLES_LP_NEBINS+1];
326  double chi[PARTICLES_LP_NEBINS];
327 
328  double mag[3]; /* can we remove it ??? */
329  float tinj;
330  float color[PARTICLES_LP_NCOLORS];
331  int cell[3];
332  uint32_t id;
334  char shkflag;
335 } Particle;
336 #endif
337 
338 typedef struct particleProbe_{
339  double vg[NVAR];
340  double lorentz;
341 } particleProbe;
342 
343 typedef struct particleNode_{
344  struct Particle_ p;
345  struct particleNode_ *next;
346  struct particleNode_ *prev;
347 } particleNode;
348 
349 
350 /* ***************************************************************
351  Macro definitions
352  *************************************************************** */
353 
354 #ifndef PARTICLES_USE_ARRAY
355  #define PARTICLES_USE_ARRAY NO
356 #endif
357 
358 /* Useful macro to loop over particles (ATTENTION: do *NOT* use this
359  macro inside loops involving creation / destruction of particles) */
360 #define PARTICLES_LOOP(a,b) for (a = b; a != NULL; a = a->next)
361 
362 /* ***************************************************************
363  Function Prototypes
364  *************************************************************** */
365 
366 void Particles_Boundary(Data *, Grid *);
368 int Particles_BoundaryCheck(Particle *p, Grid *grid);
369 long Particles_CheckAll (particleNode *, int, Grid *);
370 int Particles_CheckSingle(Particle *, int, Grid *);
371 
372 #if PARTICLES == PARTICLES_CR
373 void Particles_CR_ComputeCurrent(const Data *, Grid *);
374 void Particles_CR_ComputeForce(Data_Arr, const Data *, Grid *);
375 void Particles_CR_ConservativeFeedback(Data_Arr, Data_Arr, double, RBox *);
376 void Particles_CR_EMFields(double *, double *, double *);
377 void Particles_CR_Flux(const State *, int, int);
378 void Particles_CR_Predictor(Data *, double, Grid *);
379 void Particles_CR_States1DCopy(const Data *, const Sweep *, int, int);
380 void Particles_CR_StatesSource(const Sweep *, double, int, int, Grid *);
381 void Particles_CR_Update(Data *, timeStep *, double, Grid *);
382 #endif
383 
384 void Particles_Density(Particle *, double *);
385 void Particles_Deposit(particleNode *, void (*Func)(Particle *, double *),
386  Data_Arr, int, Grid *);
387 void Particles_DepositBoundaryExchange(Data_Arr, int, Grid *);
388 void Particles_Destroy(particleNode *, Data *);
389 void Particles_Display(Particle*);
390 
391 #if PARTICLES == PARTICLES_DUST
392 void Particles_Dust_ComputeForce (Data_Arr, Data *, Grid *);
393 void Particles_Dust_ConservativeFeedback(Data_Arr, Data_Arr, double, RBox *);
394 void Particles_Dust_StatesSource(Sweep *, Data_Arr, double, int, int, Grid *);
395 double Particles_Dust_StoppingTime(double *, Particle *);
396 void Particles_Dust_Update(Data *, timeStep *, double, Grid *);
397 #endif
398 
399 void Particles_GetWeights (Particle *, int *, double ***, Grid *);
400 
401 void Particles_Init(Data *, Grid *);
402 void Particles_Inject(Data *d, Grid *grid);
403 int Particles_Insert(Particle *, Data *, char, Grid *);
404 double Particles_Interpolate(double ***, double ***, int *);
405 void Particles_InterpolateArr(Data_Arr, int, double ***, int *, double *);
406 
407 void Particles_ListToArray (Data *d);
408 
409 void Particles_LoadRandom(double *xbeg, double *xend,
410  double (*DistribFunc)(double, double, double),
411  double coor[]);
412 void Particles_LoadUniform(int, int, double *, double *, double *);
413 
414 int Particles_LocateCell(double *, int *, Grid *);
415 
416 #if PARTICLES == PARTICLES_LP
417 void Particles_LP_Update (Data *, timeStep *, double, Grid *);
418 #if PARTICLES_LP_SPECTRA == YES
419 
420 void Particles_LP_ComputeShockNormalSpeed(Particle *, double *, double *);
421 void Particles_LP_FixValue(Particle *, particleProbe *, Data *, Grid *);
422 void Particles_LP_FlagShock(Data *, char ***, Grid *);
423 void Particles_LP_GradP(double*,int, double ***u[], Grid *, int indici[]);
424 double Particles_LP_GetEmaxAtShock(Particle *, particleProbe *, double, Grid *);
425 #if PARTICLES_LP_CONV_SPECTRA == NO
426 double Particles_LP_GetEminAtShock(Particle *, particleProbe *, double, double);
427 #endif
428 
429 void Particles_LP_Get_4vel(double *, double *, double *);
430 void Particles_LP_Get_3vel(double *, double *, double *);
431 void Particles_LP_Get_4mag(double *, double, double *);
432 void Particles_LP_Get_3mag(double *, double, double *);
433 
434 void Particles_LP_IC_Emissivity(Particle *, double, double, double *);
435 void Particles_LP_InitSpectra(Particle*);
436 void Particles_LP_IntegrateSpectra(Particle *, double, double *);
437 void Particles_LP_SampleShock (Particle *, particleProbe *, Grid *);
438 void Particles_LP_Spectra(Data *, float ***, Particle*, Grid *, double); // Useless
439 
440 #if PARTICLES_LP_CONV_SPECTRA
441 void Particles_LP_UpdateUpstreamSpectra(Particle*, Grid *, double, double,
442  long int, double, double);
443 #else
444 void Particles_LP_UpdateUpstreamSpectra(Particle* , double , double ,
445  double );
446 #endif
447 
448 void Particles_LP_UpdateSpectra(Data *, double, Grid *);
449 void Particles_LP_Sync_Emissivity(Particle*, double, double, double *, double *, double *);
450 #endif
451 #endif
452 
453 int Particles_Number(particleNode *);
454 void Particles_Restart(Data *, int, Grid *);
455 Particle *Particles_Select(particleNode *, int);
456 void Particles_Set(Data *, Grid *);
457 void Particles_SetID(particleNode *);
458 void Particles_SetOutput (Data *, Runtime *);
459 
460 void Particles_ShowList(particleNode *, int);
461 void Particles_UserDefBoundary(Data *d, int, Grid *);
462 
463 void Particles_WriteBinary(particleNode *, double, Output *, char *);
464 void Particles_WriteData(Data *d, Output *, Grid *);
465 void Particles_WriteTab (particleNode*, char filename[]);
466 void Particles_WriteTrajectory (Particle *, char);
467 void Particles_WriteVTK (particleNode*, Output *, char filename[]);
468 
469 #ifdef PARALLEL
470  extern MPI_Datatype MPI_PARTICLE;
471  extern MPI_Datatype PartOutputType;
472  void Particles_StructDatatype();
473 #endif
void Particles_Dust_ConservativeFeedback(Data_Arr, Data_Arr, double, RBox *)
Definition: particles_dust_feedback.c:94
void Particles_SetOutput(Data *, Runtime *)
Definition: particles_set_output.c:16
void Particles_LP_InitSpectra(Particle *)
Definition: particles_init.c:139
void Particles_LP_SampleShock(Particle *, particleProbe *, Grid *)
Definition: particles_lp_dsa.c:24
int Particles_Insert(Particle *, Data *, char, Grid *)
Definition: plist_tools.c:17
void Particles_Dust_StatesSource(Sweep *, Data_Arr, double, int, int, Grid *)
Definition: particles_dust_feedback.c:18
void Particles_Dust_Update(Data *, timeStep *, double, Grid *)
Definition: particles_dust_update_cart.c:21
int Particles_CheckSingle(Particle *, int, Grid *)
Definition: particles_tools.c:45
void Particles_LP_IntegrateSpectra(Particle *, double, double *)
Definition: particles_lp_tools.c:96
void Particles_Init(Data *, Grid *)
Definition: particles_init.c:22
void Particles_LP_UpdateSpectra(Data *, double, Grid *)
Definition: particles_lp_spectra.c:21
void Particles_Boundary(Data *, Grid *)
Definition: particles_boundary.c:22
void Particles_ListToArray(Data *d)
Definition: particles_boundary.c:422
Definition: structs.h:394
Definition: structs.h:124
void Particles_Restart(Data *, int, Grid *)
Definition: particles_lp_restart.c:20
Particle * Particles_Select(particleNode *, int)
Definition: particles_tools.c:264
Definition: structs.h:425
void Particles_CR_Predictor(Data *, double, Grid *)
Definition: particles_cr_predictor.c:20
void Particles_SetID(particleNode *)
Definition: particles_mpi_datatype.c:186
double Particles_Interpolate(double ***, double ***, int *)
Definition: particles_tools.c:82
void Particles_CR_StatesSource(const Sweep *, double, int, int, Grid *)
Definition: particles_cr_feedback.c:217
void Particles_CR_ComputeForce(Data_Arr, const Data *, Grid *)
Definition: particles_cr_force.c:31
void Particles_WriteTrajectory(Particle *, char)
Definition: particles_write_trajectory.c:14
double Particles_LP_GetEmaxAtShock(Particle *, particleProbe *, double, Grid *)
Definition: particles_lp_dsa.c:64
void Particles_WriteData(Data *d, Output *, Grid *)
Definition: particles_write_data.c:16
void Particles_WriteBinary(particleNode *, double, Output *, char *)
Definition: particles_lp_write_bin.c:30
void Particles_CR_Update(Data *, timeStep *, double, Grid *)
Definition: particles_cr_update.c:60
void Particles_LP_FixValue(Particle *, particleProbe *, Data *, Grid *)
Definition: particles_lp_tools.c:18
void Particles_InterpolateArr(Data_Arr, int, double ***, int *, double *)
Definition: particles_tools.c:115
void Particles_CR_ConservativeFeedback(Data_Arr, Data_Arr, double, RBox *)
Definition: particles_cr_feedback.c:23
Definition: structs.h:514
void Particles_LoadUniform(int, int, double *, double *, double *)
Definition: particles_load.c:61
void Particles_CR_Flux(const State *, int, int)
Definition: particles_cr_feedback.c:51
void Particles_LP_FlagShock(Data *, char ***, Grid *)
Definition: particles_lp_tools.c:128
void Particles_DepositBoundaryExchange(Data_Arr, int, Grid *)
Definition: particles_deposit.c:177
void Particles_Destroy(particleNode *, Data *)
Definition: plist_tools.c:128
void Particles_Set(Data *, Grid *)
Definition: particles_set.c:17
void Particles_LP_IC_Emissivity(Particle *, double, double, double *)
Definition: particles_lp_emissivity.c:443
Definition: structs.h:261
int Particles_LocateCell(double *, int *, Grid *)
Definition: particles_tools.c:152
void Particles_Display(Particle *)
Definition: plist_tools.c:160
void Particles_LP_Get_3mag(double *, double, double *)
Definition: particles_lp_spectra.c:708
int Particles_BoundaryCheck(Particle *p, Grid *grid)
Definition: particles_boundary.c:490
void Particles_Density(Particle *, double *)
Definition: particles_deposit.c:367
void Particles_Inject(Data *d, Grid *grid)
Definition: particles_init.c:209
void Particles_ShowList(particleNode *, int)
Definition: plist_tools.c:206
void Particles_CR_States1DCopy(const Data *, const Sweep *, int, int)
Definition: particles_cr_feedback.c:141
void Particles_LP_ComputeShockNormalSpeed(Particle *, double *, double *)
Definition: particles_lp_dsa.c:112
void Particles_WriteVTK(particleNode *PHeadRef, Output *output, char filename[128])
Definition: particles_write_vtk.c:49
void Particles_LP_UpdateUpstreamSpectra(Particle *pl, Grid *grid, double q, double eng_max, long int TotpartSHK, double TotpartE, double TotpartN)
Definition: particles_lp_dsa.c:255
void Particles_BoundaryExchange(Data *, Grid *)
Definition: particles_boundary.c:198
void Particles_LP_Get_4vel(double *, double *, double *)
Definition: particles_lp_spectra.c:645
int Particles_Number(particleNode *)
Definition: plist_tools.c:185
Definition: structs.h:201
Definition: structs.h:363
void Particles_LoadRandom(double *qbeg, double *qend, double(*DistribFunc)(double, double, double), double *q)
Definition: particles_load.c:14
void Particles_CR_ComputeCurrent(const Data *, Grid *)
Definition: particles_cr_force.c:110
void Particles_LP_Update(Data *, timeStep *, double, Grid *)
Definition: particles_lp_update.c:19
void Particles_GetWeights(Particle *, int *, double ***, Grid *)
Definition: particles_weights.c:36
long Particles_CheckAll(particleNode *, int, Grid *)
Definition: particles_tools.c:16
void Particles_LP_Sync_Emissivity(Particle *, double, double, double *, double *, double *)
Definition: particles_lp_emissivity.c:122
Definition: structs.h:289
void Particles_Deposit(particleNode *, void(*Func)(Particle *, double *), Data_Arr, int, Grid *)
Definition: particles_deposit.c:40