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
Admin message
This server has been upgraded to GitLab release
17.10
.
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
Armin Damon Riess
N Body Simulation
Commits
76bda61d
Commit
76bda61d
authored
2 years ago
by
Armin Damon Riess
Browse files
Options
Downloads
Patches
Plain Diff
nodes can access masses, copy constructor done
parent
338b5a4b
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
lib/nBodySim.cpp
+4
-2
4 additions, 2 deletions
lib/nBodySim.cpp
lib/node.cpp
+43
-1
43 additions, 1 deletion
lib/node.cpp
lib/node.hpp
+11
-1
11 additions, 1 deletion
lib/node.hpp
lib/tree.cpp
+7
-2
7 additions, 2 deletions
lib/tree.cpp
lib/tree.hpp
+4
-1
4 additions, 1 deletion
lib/tree.hpp
with
69 additions
and
7 deletions
lib/nBodySim.cpp
+
4
−
2
View file @
76bda61d
...
...
@@ -49,7 +49,7 @@ nBodySim::nBodySim(std::string datafile) {
file
.
close
();
tree_
=
new
Tree
(
positions_
,
forces_
,
nParticles_
,
4
*
maxCoord
,
new
double
[
3
]{
0
,
0
,
0
});
tree_
=
new
Tree
(
masses_
,
positions_
,
forces_
,
nParticles_
,
4
*
maxCoord
,
new
double
[
3
]{
0
,
0
,
0
});
}
nBodySim
::~
nBodySim
()
{
...
...
@@ -112,7 +112,9 @@ void nBodySim::calculateForces() {
}
void
nBodySim
::
treeCalculateForces
()
{
// TODO
for
(
unsigned
i
=
0
;
i
<
nParticles_
;
++
i
)
{
tree_
->
calculateForce
(
i
);
}
}
double
nBodySim
::
calculateMeanInterparticleDistance
()
{
...
...
This diff is collapsed.
Click to expand it.
lib/node.cpp
+
43
−
1
View file @
76bda61d
#include
"node.hpp"
#include
<cmath>
/*
Node::Node() {
root_ = nullptr;
...
...
@@ -15,15 +17,24 @@ Node::Node() {
}
*/
Node
::
Node
(
Node
*
parent
,
double
*
particles
,
unsigned
nParticles
,
unsigned
depth
,
double
size
,
double
center
[
3
],
unsigned
*
localParticles
,
unsigned
nLocalParticles
)
{
Node
::
Node
(
Node
*
parent
,
double
*
masses
,
double
*
particles
,
unsigned
nParticles
,
unsigned
depth
,
double
size
,
double
center
[
3
],
unsigned
*
localParticles
,
unsigned
nLocalParticles
)
{
parent_
=
parent
;
particles_
=
particles
;
nParticles_
=
nParticles
;
depth_
=
depth
;
size_
=
size
;
for
(
unsigned
i
=
0
;
i
<
3
;
++
i
)
center_
[
i
]
=
center
[
i
];
localParticles_
=
localParticles
;
nLocalParticles_
=
nLocalParticles
;
mass_
=
0
;
for
(
unsigned
i
=
0
;
i
<
nLocalParticles
;
++
i
)
{
mass_
+=
masses_
[
localParticles_
[
i
]];
}
// allocate children
// TODO
}
...
...
@@ -33,4 +44,35 @@ Node::~Node() {
delete
children_
[
i
];
}
delete
[]
localParticles_
;
}
Node
&
Node
::
operator
=
(
const
Node
&
other
)
{
root_
=
other
.
root_
;
parent_
=
other
.
parent_
;
particles_
=
other
.
particles_
;
nParticles_
=
other
.
nParticles_
;
depth_
=
other
.
depth_
;
size_
=
other
.
size_
;
for
(
unsigned
i
=
0
;
i
<
3
;
++
i
)
center_
[
i
]
=
other
.
center_
[
i
];
localParticles_
=
other
.
localParticles_
;
nLocalParticles_
=
other
.
nLocalParticles_
;
mass_
=
other
.
mass_
;
for
(
unsigned
i
=
0
;
i
<
8
;
++
i
)
children_
[
i
]
=
other
.
children_
[
i
];
return
*
this
;
}
double
*
Node
::
calculateForce
(
unsigned
particle
)
{
// calculate theta
double
lambda
=
std
::
sqrt
((
center_
[
0
]
-
particles_
[
3
*
particle
+
0
])
*
(
center_
[
0
]
-
particles_
[
3
*
particle
+
0
])
+
(
center_
[
1
]
-
particles_
[
3
*
particle
+
1
])
*
(
center_
[
1
]
-
particles_
[
3
*
particle
+
1
])
+
(
center_
[
2
]
-
particles_
[
3
*
particle
+
2
])
*
(
center_
[
2
]
-
particles_
[
3
*
particle
+
2
]));
double
theta
=
size_
/
lambda
;
// if angle too large, calculate force on particle from children
// else calculate force on particle from particles in this node
if
(
theta
>
theta0_
)
{
// TODO
}
else
{
// TODO
}
return
nullptr
;
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
lib/node.hpp
+
11
−
1
View file @
76bda61d
...
...
@@ -7,12 +7,20 @@ 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
(
Node
*
parent
,
double
*
particles
,
unsigned
nParticles
,
unsigned
depth
,
double
size
,
double
center
[
3
],
unsigned
*
localParticles
,
unsigned
nLocalParticles
);
Node
(
Node
*
parent
,
double
*
masses
,
double
*
particles
,
unsigned
nParticles
,
unsigned
depth
,
double
size
,
double
center
[
3
],
unsigned
*
localParticles
,
unsigned
nLocalParticles
);
// destuctor
~
Node
();
// copy constructor
Node
(
const
Node
&
)
=
default
;
// copy assignment
Node
&
operator
=
(
const
Node
&
);
// calculate force on a particle recursively
double
*
calculateForce
(
unsigned
particle
);
private:
Node
*
root_
;
Node
*
parent_
;
Node
*
children_
[
8
];
double
*
masses_
;
double
*
particles_
;
unsigned
nParticles_
;
unsigned
depth_
;
...
...
@@ -20,6 +28,8 @@ private:
double
center_
[
3
];
unsigned
*
localParticles_
;
unsigned
nLocalParticles_
;
double
mass_
;
const
double
theta0_
=
0.4
;
};
#endif
/* NODE_HPP */
\ No newline at end of file
This diff is collapsed.
Click to expand it.
lib/tree.cpp
+
7
−
2
View file @
76bda61d
#include
"tree.hpp"
#include
"node.hpp"
Tree
::
Tree
(
double
*
particles
,
double
*
forces
,
unsigned
nParticles
,
double
size
,
double
*
center
)
{
Tree
::
Tree
(
double
*
masses
,
double
*
particles
,
double
*
forces
,
unsigned
nParticles
,
double
size
,
double
*
center
)
{
particles_
=
particles
;
forces_
=
forces
;
nParticles_
=
nParticles
;
...
...
@@ -13,13 +13,18 @@ Tree::Tree(double* particles, double* forces, unsigned nParticles, double size,
for
(
unsigned
i
=
0
;
i
<
nParticles_
;
++
i
)
localParticles_
[
i
]
=
i
;
root_
=
new
Node
();
*
root_
=
Node
(
root_
,
particles_
,
nParticles_
,
0
,
size_
,
center_
,
localParticles_
,
nParticles_
);
*
root_
=
Node
(
root_
,
masses_
,
particles_
,
nParticles_
,
0
,
size_
,
center_
,
localParticles_
,
nParticles_
);
}
Tree
::~
Tree
()
{
delete
root_
;
}
void
Tree
::
calculateForce
(
unsigned
particle
)
{
double
*
force
=
root_
->
calculateForce
(
particle
);
for
(
unsigned
i
=
0
;
i
<
3
;
++
i
)
forces_
[
3
*
particle
+
i
]
=
force
[
i
];
}
void
Tree
::
update
()
{
// TODO
}
...
...
This diff is collapsed.
Click to expand it.
lib/tree.hpp
+
4
−
1
View file @
76bda61d
...
...
@@ -7,9 +7,11 @@ class Tree {
public:
// constructor
Tree
()
=
delete
;
Tree
(
double
*
particles
,
double
*
forces_
,
unsigned
nParticles
,
double
size
,
double
*
center
);
Tree
(
double
*
masses
,
double
*
particles
,
double
*
forces_
,
unsigned
nParticles
,
double
size
,
double
*
center
);
// destructor
~
Tree
();
// calculate force on a particle
void
calculateForce
(
unsigned
particle
);
// update tree: visit each node, check if it needs to be split or merged (for example if a particle has left the region)
void
update
();
// drift tree: visit each node, update positions
...
...
@@ -18,6 +20,7 @@ public:
void
kick
(
double
dt
);
private:
Node
*
root_
;
double
*
masses_
;
double
*
particles_
;
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