Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
T
tp_8_galaxy
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
arnaud.devevey
tp_8_galaxy
Commits
868c8ae9
Commit
868c8ae9
authored
6 years ago
by
arnaud.devevey
Browse files
Options
Downloads
Patches
Plain Diff
11h30
parent
414f9686
No related branches found
No related tags found
No related merge requests found
Pipeline
#6094
failed
6 years ago
Stage: test
Changes
3
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
perso/galaxy.c
+37
-14
37 additions, 14 deletions
perso/galaxy.c
perso/star.c
+33
-12
33 additions, 12 deletions
perso/star.c
perso/star.h
+4
-0
4 additions, 0 deletions
perso/star.h
with
74 additions
and
26 deletions
perso/galaxy.c
+
37
−
14
View file @
868c8ae9
...
...
@@ -40,9 +40,11 @@ int main(int argc, char **argv) {
printf
(
"
\n\n
"
);
tests
();
double
zone
=
1e10
;
Box
box_initial
=
new_box
(
-
zone
,
zone
,
zone
,
-
zone
);
//
Galaxy* galaxy = create_and_init_galaxy(nb_stars, box_initial, DELTA_T);
Galaxy
*
galaxy
=
create_and_init_galaxy
(
nb_stars
,
box_initial
,
DELTA_T
);
...
...
@@ -61,7 +63,7 @@ int main(int argc, char **argv) {
destruction_galaxie();
*/
free_galaxy
(
galaxy
);
}
else
{
printf
(
"
\n
Nombre d'arguments non valide
\n\n
"
);
...
...
@@ -80,7 +82,7 @@ int main(int argc, char **argv) {
* * * * * * * * * * * * * * * * */
Galaxy
*
create_and_init_galaxy
(
int
nb_bodies
,
Box
box
,
double
delta_t
)
{
Star
*
list_stars
=
malloc
(
sizeof
(
Star
)
*
nb_bodies
);
Star
*
*
list_stars
=
malloc
(
sizeof
(
Star
*
)
*
nb_bodies
);
Vector
*
v_null
=
new_vec
(
0
,
0
);
Star
*
temp
;
...
...
@@ -92,17 +94,20 @@ Galaxy* create_and_init_galaxy(int nb_bodies, Box box, double delta_t) {
}
else
{
double
m_i
=
random_mass
();
Vector
r_i
=
random_position
();
// si pos est dans box
Vector
v_i
=
random_speed
(
r_i
,
m_i
);
Vector
r_i
;
do
{
r_i
=
random_position
();
}
while
(
!
is_inside
(
box
,
r_i
));
temp
=
new_star_vel
(
r_i
,
v_i
,
*
v_null
,
m_i
,
0
.
0
);
}
list_stars
[
i
]
=
*
temp
;
list_stars
[
i
]
=
temp
;
// on regarde comment cette étoile se fait attirer par le "soleil"
//
update_acc(list_stars[i], list_stars[0]);
update_acc
(
list_stars
[
i
],
list_stars
[
0
]);
}
...
...
@@ -111,6 +116,7 @@ Galaxy* create_and_init_galaxy(int nb_bodies, Box box, double delta_t) {
galaxy
->
stars
=
list_stars
;
galaxy
->
box
=
box
;
return
galaxy
;
}
...
...
@@ -120,9 +126,6 @@ void reset_acc_galaxy(Galaxy* galaxy) {
for
(
int
i
=
0
;
i
<
galaxy
->
nb_bodies
;
i
++
)
{
galaxy
->
stars
[
i
].
acc
=
*
v_null
;
/*if (galaxy -> stars[i] != NULL) {
}*/
}
free
(
v_null
);
...
...
@@ -137,11 +140,13 @@ void update_pos_galaxy(Galaxy* galaxy, double delta_t) {
void
free_galaxy
(
Galaxy
*
galaxy
)
{
/*
for
(
int
i
=
0
;
i
<
galaxy
->
nb_bodies
;
i
++
)
{
free(galaxy -> stars[i]);
if
(
!
is_inside
(
galaxy
->
box
,
galaxy
->
stars
[
i
].
pos
))
{
free
(
&
(
galaxy
->
stars
[
i
]));
galaxy
->
nb_bodies
--
;
}
*/
}
}
...
...
@@ -160,6 +165,24 @@ void tests() {
tests_vector
();
tests_box
();
tests_star
();
tests_galaxy
();
// tests_quadtree();
// tests_galaxy();
}
/* * * * * * * * * * * * * * * * *
* *
* --- TESTS --- *
* *
* * * * * * * * * * * * * * * * */
void
tests_galaxy
()
{
printf
(
"TESTS GALAXY :
\n
"
);
printf
(
"
\n
"
);
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
perso/star.c
+
33
−
12
View file @
868c8ae9
...
...
@@ -142,20 +142,21 @@ Vector* resultante(Vector* list_stars, int size_list) {
int G_mi_mj = FORCE_GRAVITATION * list_stars[i] -> mass * list_stars[j] -> mass;
Vector* temp = mul_vec(rj_ri, G_mi_mj);
Fi = add_vec(Fi, temp)
Fi = add_vec(Fi, temp)
;
*/
}
}
}
Fi
->
x
/=
size_list
;
Fi
->
y
/=
size_list
;
return
Fi
;
}
void
new_position
(
Star
*
star
,
Vector
resultante
)
{
star
->
acc
=
*
(
add_vec
(
&
(
star
->
acc
),
&
resultante
));
Vector
*
acc_tmp
=
add_vec
(
&
(
star
->
acc
),
&
resultante
);
star
->
acc
=
*
acc_tmp
;
free
(
acc_tmp
);
acc_tmp
=
NULL
;
}
...
...
@@ -187,9 +188,10 @@ void tests_star() {
Vector
*
acceleration
=
new_vec
(
4
.
0
,
5
.
0
);
Star
*
s1
=
new_star_vel
(
*
position
,
*
speed
,
*
acceleration
,
MASSE_MIN
,
DELTA_T
);
// print_star(s1);
tests_star_new
(
s1
);
// tests_star_acc(s1); LEAK
// tests_stars_res(s1); ERREUR
free
(
s1
);
...
...
@@ -198,19 +200,38 @@ void tests_star() {
free
(
acceleration
);
printf
(
"
\n
"
);
}
void
tests_star_new
(
Star
*
s
)
{
Star
star_test
;
double
x
=
4
.
0
;
double
y
=
5
.
0
;
//star_test.previous_pos = ;
//star_test.acc = ;
//star_test.mass = ;
TEST
(
s
->
pos
.
x
==
x
&&
s
->
pos
.
y
==
y
&&
\
s
->
previous_pos
.
x
==
x
&&
s
->
previous_pos
.
y
==
y
&&
\
s
->
previous_pos
.
x
==
(
4e10
-
x
)
&&
s
->
previous_pos
.
y
==
(
5e10
-
y
)
&&
\
s
->
acc
.
x
==
x
&&
s
->
acc
.
y
==
y
&&
\
s
->
mass
==
1e20
);
}
void
tests_star_acc
(
Star
*
s
)
{
Vector
*
v_test
=
new_vec
(
1
.
0
,
1
.
0
);
Star
star_test
;
star_test
.
pos
=
*
v_test
;
star_test
.
mass
=
1e20
;
update_acc
(
s
,
&
star_test
);
free
(
v_test
);
}
void
tests_star_pos
()
{
}
void
tests_stars_res
(
Star
*
star
)
{
Vector
*
v_test
=
new_vec
(
-
5
.
0
,
4
.
0
);
new_position
(
star
,
*
v_test
);
TEST
(
star
->
pos
.
x
==
-
1
.
0
&&
star
->
pos
.
y
==
9
.
0
);
free
(
v_test
);
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
perso/star.h
+
4
−
0
View file @
868c8ae9
...
...
@@ -80,5 +80,9 @@ double random_1();
void
tests_star
();
void
tests_star_new
(
Star
*
s
);
void
tests_stars_res
(
Star
*
star
);
#endif
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment