Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
N
N Body Simulation
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Issue analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
Armin Damon Riess
N Body Simulation
Commits
827b23e2
Commit
827b23e2
authored
2 years ago
by
Armin Damon Riess
Browse files
Options
Downloads
Patches
Plain Diff
change particles_ to positions_
parent
a76e120c
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
lib/node.cpp
+20
-22
20 additions, 22 deletions
lib/node.cpp
lib/node.hpp
+4
-3
4 additions, 3 deletions
lib/node.hpp
lib/tree.cpp
+3
-3
3 additions, 3 deletions
lib/tree.cpp
lib/tree.hpp
+2
-2
2 additions, 2 deletions
lib/tree.hpp
with
29 additions
and
30 deletions
lib/node.cpp
+
20
−
22
View file @
827b23e2
...
...
@@ -18,9 +18,10 @@ Node::Node() {
}
*/
Node
::
Node
(
double
*
masses
,
double
*
p
article
s
,
unsigned
nParticles
,
unsigned
depth
,
Node
::
Node
(
double
*
masses
,
double
*
p
osition
s
,
unsigned
nParticles
,
unsigned
depth
,
double
size
,
Vector
center
,
List
localParticles
,
unsigned
nLocalParticles
)
{
masses_
=
masses
;
positions_
=
positions
;
nParticles_
=
nParticles
;
depth_
=
depth
;
...
...
@@ -44,9 +45,9 @@ Node::Node(double* masses, double* particles, unsigned nParticles, unsigned dept
}
else
{
isLeaf_
=
false
;
//
array of Lists is empty -> segmentation fault #####################
#####################
#
//
##################### segmentation fault in line 52
#####################
// for each local particle, determine which octant it is in
List
*
particleDivision
=
new
List
[
nLocalParticles
]
;
List
particleDivision
[
8
]
=
{
List
{}}
;
for
(
unsigned
i
=
0
;
i
<
nLocalParticles
;
++
i
)
{
particleDivision
[
getOctant
(
localParticles_
[
i
])].
push_back
(
i
);
}
...
...
@@ -61,11 +62,10 @@ Node::Node(double* masses, double* particles, unsigned nParticles, unsigned dept
for
(
unsigned
j
=
0
;
j
<
3
;
++
j
)
{
childCenter
[
j
]
=
center_
[
j
]
+
(
i
&
(
1
<<
j
)
?
childSize
:
-
childSize
);
}
children_
[
i
]
=
new
Node
(
masses
,
p
article
s
,
nParticles
,
depth
+
1
,
children_
[
i
]
=
new
Node
(
masses
,
p
osition
s
,
nParticles
,
depth
+
1
,
childSize
,
childCenter
,
particleDivision
[
i
],
particleDivision
[
i
].
size
());
}
}
delete
[]
particleDivision
;
}
}
...
...
@@ -76,7 +76,7 @@ Node::~Node() {
}
Node
&
Node
::
operator
=
(
const
Node
&
other
)
{
p
article
s_
=
other
.
p
article
s_
;
p
osition
s_
=
other
.
p
osition
s_
;
nParticles_
=
other
.
nParticles_
;
depth_
=
other
.
depth_
;
size_
=
other
.
size_
;
...
...
@@ -96,7 +96,7 @@ void Node::update(List& localParticles, unsigned nLocalParticles) {
// for each local particle, determine which octant it is in
// get the mass in this node while we're at it
mass_
=
0
;
List
*
particleDivision
=
new
List
[
nLocalParticles_
]
;
List
particleDivision
[
8
]
=
{
List
{}}
;
for
(
unsigned
i
=
0
;
i
<
nLocalParticles_
;
++
i
)
{
particleDivision
[
getOctant
(
localParticles_
[
i
])].
push_back
(
i
);
mass_
+=
masses_
[
localParticles_
[
i
]];
...
...
@@ -122,23 +122,21 @@ void Node::update(List& localParticles, unsigned nLocalParticles) {
for
(
unsigned
j
=
0
;
j
<
3
;
++
j
)
{
childCenter
[
j
]
=
center_
[
j
]
+
(
i
&
(
1
<<
j
)
?
childSize
:
-
childSize
);
}
children_
[
i
]
=
new
Node
(
masses_
,
p
article
s_
,
nParticles_
,
depth_
+
1
,
children_
[
i
]
=
new
Node
(
masses_
,
p
osition
s_
,
nParticles_
,
depth_
+
1
,
childSize
,
childCenter
,
particleDivision
[
i
],
particleDivision
[
i
].
size
());
isLeaf_
=
false
;
}
}
}
delete
[]
particleDivision
;
}
Vector
Node
::
calculateForce
(
unsigned
particle
)
{
Vector
force
(
3
);
for
(
unsigned
i
=
0
;
i
<
3
;
++
i
)
force
[
i
]
=
0
;
// calculate theta
double
dx
=
center_
[
0
]
-
p
article
s_
[
3
*
particle
+
0
];
double
dy
=
center_
[
1
]
-
p
article
s_
[
3
*
particle
+
1
];
double
dz
=
center_
[
2
]
-
p
article
s_
[
3
*
particle
+
2
];
double
dx
=
center_
[
0
]
-
p
osition
s_
[
3
*
particle
+
0
];
double
dy
=
center_
[
1
]
-
p
osition
s_
[
3
*
particle
+
1
];
double
dz
=
center_
[
2
]
-
p
osition
s_
[
3
*
particle
+
2
];
double
lambda
=
std
::
sqrt
(
dx
*
dx
+
dy
*
dy
+
dz
*
dz
);
double
theta
=
size_
/
lambda
;
...
...
@@ -152,16 +150,16 @@ Vector Node::calculateForce(unsigned particle) {
for
(
unsigned
i
:
localParticles_
)
{
if
(
i
!=
particle
)
{
double
dx
=
p
article
s_
[
3
*
i
+
0
]
-
p
article
s_
[
3
*
particle
+
0
];
double
dy
=
p
article
s_
[
3
*
i
+
1
]
-
p
article
s_
[
3
*
particle
+
1
];
double
dz
=
p
article
s_
[
3
*
i
+
2
]
-
p
article
s_
[
3
*
particle
+
2
];
double
dx
=
p
osition
s_
[
3
*
i
+
0
]
-
p
osition
s_
[
3
*
particle
+
0
];
double
dy
=
p
osition
s_
[
3
*
i
+
1
]
-
p
osition
s_
[
3
*
particle
+
1
];
double
dz
=
p
osition
s_
[
3
*
i
+
2
]
-
p
osition
s_
[
3
*
particle
+
2
];
double
r
=
std
::
sqrt
(
dx
*
dx
+
dy
*
dy
+
dz
*
dz
);
double
r3
=
r
*
r
*
r
;
double
m
=
masses_
[
i
];
for
(
unsigned
j
=
0
;
j
<
3
;
++
j
)
{
force
[
j
]
+=
m
*
(
p
article
s_
[
3
*
i
+
j
]
-
p
article
s_
[
3
*
particle
+
j
])
/
r3
;
force
[
j
]
+=
m
*
(
p
osition
s_
[
3
*
i
+
j
]
-
p
osition
s_
[
3
*
particle
+
j
])
/
r3
;
}
}
}
...
...
@@ -192,7 +190,7 @@ Vector Node::calculateForce(unsigned particle) {
double
m
=
mass_
;
for
(
unsigned
j
=
0
;
j
<
3
;
++
j
)
{
force
[
j
]
+=
m
*
(
centerOfMass_
[
j
]
-
p
article
s_
[
3
*
particle
+
j
])
/
r3
;
force
[
j
]
+=
m
*
(
centerOfMass_
[
j
]
-
p
osition
s_
[
3
*
particle
+
j
])
/
r3
;
}
}
...
...
@@ -206,13 +204,13 @@ void Node::calculateCenterOfMass() {
for
(
unsigned
i
:
localParticles_
)
for
(
unsigned
j
=
0
;
j
<
3
;
++
j
)
centerOfMass_
[
j
]
+=
p
article
s_
[
3
*
i
+
j
]
/
nLocalParticles_
;
centerOfMass_
[
j
]
+=
p
osition
s_
[
3
*
i
+
j
]
/
nLocalParticles_
;
}
unsigned
Node
::
getOctant
(
unsigned
particle
)
{
double
px
=
p
articles_
[
localP
article
s_
[
0
]
];
double
py
=
p
articles_
[
localP
article
s_
[
1
]
];
double
pz
=
p
articles_
[
localP
article
s_
[
2
]
];
double
px
=
p
ositions_
[
3
*
p
article
+
0
];
double
py
=
p
ositions_
[
3
*
p
article
+
1
];
double
pz
=
p
ositions_
[
3
*
p
article
+
2
];
if
(
px
<
center_
[
0
])
{
if
(
py
<
center_
[
1
])
{
if
(
pz
<
center_
[
2
])
{
...
...
This diff is collapsed.
Click to expand it.
lib/node.hpp
+
4
−
3
View file @
827b23e2
...
...
@@ -12,7 +12,7 @@ public:
Node
()
=
default
;
// Whoever creates the node is responsible for deciding which particles are in which octant and for allocating the localParticles array
// Node will write to localParticles array
Node
(
double
*
masses
,
double
*
p
article
s
,
unsigned
nParticles
,
unsigned
depth
,
Node
(
double
*
masses
,
double
*
p
osition
s
,
unsigned
nParticles
,
unsigned
depth
,
double
size
,
Vector
center
,
List
localParticles
,
unsigned
nLocalParticles
);
// Destuctor
~
Node
();
...
...
@@ -26,7 +26,8 @@ public:
Vector
calculateForce
(
unsigned
particle
);
// Calculate center of mass
void
calculateCenterOfMass
();
// Function that takes a particle and returns the octant it is in. This function doesn't check if the particle is actually in the node.
// Function that takes a particle index in the global particles_ array and returns the octant it is in relative to the center fo the current node
// this function doesn't check if the particle is actually in the node.
unsigned
getOctant
(
unsigned
particle
);
private:
...
...
@@ -35,7 +36,7 @@ private:
Node
*
children_
[
8
];
double
*
masses_
;
double
*
p
article
s_
;
double
*
p
osition
s_
;
unsigned
nParticles_
;
unsigned
depth_
;
...
...
This diff is collapsed.
Click to expand it.
lib/tree.cpp
+
3
−
3
View file @
827b23e2
...
...
@@ -4,8 +4,8 @@
#include
<vector>
#include
<iostream>
Tree
::
Tree
(
double
*
masses
,
double
*
p
article
s
,
double
*
forces
,
unsigned
nParticles
,
double
size
,
Vector
center
)
{
p
articles_
=
particle
s
;
Tree
::
Tree
(
double
*
masses
,
double
*
p
osition
s
,
double
*
forces
,
unsigned
nParticles
,
double
size
,
Vector
center
)
{
p
ositions_
=
position
s
;
forces_
=
forces
;
nParticles_
=
nParticles
;
size_
=
size
;
...
...
@@ -17,7 +17,7 @@ Tree::Tree(double* masses, double* particles, double* forces, unsigned nParticle
allParticles_
=
List
(
nParticles_
);
for
(
unsigned
i
=
0
;
i
<
nParticles_
;
++
i
)
allParticles_
[
i
]
=
i
;
root_
=
new
Node
(
masses_
,
p
article
s_
,
nParticles_
,
0
,
size_
,
center_
,
allParticles_
,
nParticles_
);
root_
=
new
Node
(
masses_
,
p
osition
s_
,
nParticles_
,
0
,
size_
,
center_
,
allParticles_
,
nParticles_
);
}
Tree
::~
Tree
()
{
...
...
This diff is collapsed.
Click to expand it.
lib/tree.hpp
+
2
−
2
View file @
827b23e2
...
...
@@ -9,7 +9,7 @@ class Tree {
public:
// Constructor
Tree
()
=
delete
;
Tree
(
double
*
masses
,
double
*
p
article
s
,
double
*
forces_
,
unsigned
nParticles
,
double
size
,
Vector
center
);
Tree
(
double
*
masses
,
double
*
p
osition
s
,
double
*
forces_
,
unsigned
nParticles
,
double
size
,
Vector
center
);
// Destructor
~
Tree
();
// Calculate force on a particle
...
...
@@ -21,7 +21,7 @@ private:
Node
*
root_
;
double
*
masses_
;
double
*
p
article
s_
;
double
*
p
osition
s_
;
double
*
forces_
;
unsigned
nParticles_
;
...
...
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