-
Notifications
You must be signed in to change notification settings - Fork 0
/
init.c
executable file
·54 lines (40 loc) · 1.19 KB
/
init.c
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
#include "psim.h"
#include "init.h"
#include "util.h"
#include <stdio.h>
#include <stdlib.h>
const struct vector vc_zero = {0.0, 0.0};
const struct vector vc_one = {1.0, 1.0};
const struct state st_zero = {{0.0, 0.0}, {0.0, 0.0}, {0.0, 0.0}};
int init_uverse(struct universe* uverse, int mpcount) {
int bytes = sizeof(struct particle) * mpcount;
uverse->instant = 0;
uverse->pcount = 0;
uverse->mpcount = mpcount;
uverse->particles = realloc(uverse->particles, bytes);
return bytes;
}
void destroy_uverse(struct universe* uverse) {
init_uverse(uverse, 0);
}
void init_particle(struct particle* p) {
p->mass = 0.0;
p->charge = 0.0;
for(int i = 0; i < MAX_FORCES; i++)
p->forces[i] = vc_zero;
p->cstate = st_zero;
}
void add_particle(struct universe* uverse, struct particle* p) {
if(uverse->pcount == uverse->mpcount) {
fprintf(stderr, "\nERROR: Max particle count reached\n");
exit(1);
}
uverse->pcount++;
uverse->particles[uverse->pcount - 1] = *p;
}
void random_pos(struct state* s, int varia) {
s->pos = randvec(varia);
}
void set_force(int slot, struct particle* p, struct vector force) {
p->forces[slot] = force;
}