forked from evanocathain/EMBOX
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinitialise.c
More file actions
60 lines (53 loc) · 1.45 KB
/
initialise.c
File metadata and controls
60 lines (53 loc) · 1.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#include"particles.h"
#include"grid.h"
#include"initialise.h"
#include"embox_funcs.h"
void initialise_distn_box(struct particles *charges,
int nparticles,
int size,
double dx,
double dy,
double dz,
FILE *charges_fp){
int i; // loop variable
for (i=0; i<nparticles; i++){
// initialise all particles
charges[i].x[0]=(size)*dx*pick_rand();
charges[i].x[1]=(size)*dy*pick_rand();
charges[i].x[2]=(size)*dz*pick_rand();
charges[i].u[0]=0;
charges[i].u[1]=0;
charges[i].u[2]=0;
charges[i].q=1.0;
}
}
void initialise_distn_sphere(struct particles *charges,
int nparticles,
int size,
double dx,
FILE *charges_fp){
int i; // loop variable
double offset = size*dx*0.5;
double radius=dx,phi,theta;
for (i=0; i<nparticles; i++){
phi=(2*M_PI*pick_rand()); // between 0 and 2*M_PI
theta=(M_PI*pick_rand()); // between 0 and +M_PI
charges[i].x[0]=offset+radius*cos(phi)*sin(theta);
charges[i].x[1]=offset+radius*sin(phi)*sin(theta);
charges[i].x[2]=offset+radius*cos(theta);
charges[i].u[0]=0.0;
charges[i].u[1]=0.0;
charges[i].u[2]=0.0;
// charges[i].q=1.0;
if (pick_rand() >= 0.5){
charges[i].q=1.0;
}else{
charges[i].q=-1.0;
}
fprintf(charges_fp,"%f\n",charges[i].q);
}
}