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
6aebd7d7
Commit
6aebd7d7
authored
2 years ago
by
Armin Damon Riess
Browse files
Options
Downloads
Patches
Plain Diff
minor changes to update function
parent
f19bbcfa
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
+23
-8
23 additions, 8 deletions
lib/node.cpp
lib/node.hpp
+3
-2
3 additions, 2 deletions
lib/node.hpp
lib/tree.cpp
+4
-1
4 additions, 1 deletion
lib/tree.cpp
lib/tree.hpp
+3
-0
3 additions, 0 deletions
lib/tree.hpp
with
33 additions
and
11 deletions
lib/node.cpp
+
23
−
8
View file @
6aebd7d7
...
@@ -19,7 +19,7 @@ Node::Node() {
...
@@ -19,7 +19,7 @@ Node::Node() {
*/
*/
Node
::
Node
(
Node
*
root
,
Node
*
parent
,
double
*
masses
,
double
*
particles
,
unsigned
nParticles
,
unsigned
depth
,
Node
::
Node
(
Node
*
root
,
Node
*
parent
,
double
*
masses
,
double
*
particles
,
unsigned
nParticles
,
unsigned
depth
,
double
size
,
double
center
[
3
],
std
::
vector
<
unsigned
>
localParticles
,
unsigned
nLocalParticles
)
{
double
size
,
double
center
[
3
],
std
::
vector
<
unsigned
>
&
localParticles
,
unsigned
nLocalParticles
)
{
parent_
=
parent
;
parent_
=
parent
;
particles_
=
particles
;
particles_
=
particles
;
nParticles_
=
nParticles
;
nParticles_
=
nParticles
;
...
@@ -37,9 +37,10 @@ Node::Node(Node* root, Node* parent, double* masses, double* particles, unsigned
...
@@ -37,9 +37,10 @@ Node::Node(Node* root, Node* parent, double* masses, double* particles, unsigned
mass_
+=
masses_
[
localParticles_
[
i
]];
mass_
+=
masses_
[
localParticles_
[
i
]];
}
}
// TODO
// allocate children
// allocate children
// check if child contains no particles, in that case set child to nullptr
// check if child contains no particles, in that case set child to nullptr
//
TODO
//
check if node is leaf
}
}
Node
::~
Node
()
{
Node
::~
Node
()
{
...
@@ -63,12 +64,18 @@ Node& Node::operator=(const Node& other) {
...
@@ -63,12 +64,18 @@ Node& Node::operator=(const Node& other) {
return
*
this
;
return
*
this
;
}
}
void
Node
::
update
()
{
void
Node
::
update
(
std
::
vector
<
unsigned
>&
localParticles
)
{
// update this node
// TODO
// TODO
// update center of mass
// maybe subdivide?
// update this node
// update children
// update children
isLeaf_
=
true
;
for
(
unsigned
i
=
0
;
i
<
8
;
++
i
)
{
for
(
unsigned
i
=
0
;
i
<
8
;
++
i
)
{
if
(
children_
[
i
]
!=
nullptr
)
children_
[
i
]
->
update
();
if
(
children_
[
i
]
!=
nullptr
)
{
// children_[i]->update();
isLeaf_
=
false
;
}
}
}
}
}
...
@@ -81,10 +88,18 @@ double* Node::calculateForce(unsigned particle) {
...
@@ -81,10 +88,18 @@ double* Node::calculateForce(unsigned particle) {
+
(
center_
[
1
]
-
py
)
*
(
center_
[
1
]
-
py
)
+
(
center_
[
1
]
-
py
)
*
(
center_
[
1
]
-
py
)
+
(
center_
[
2
]
-
pz
)
*
(
center_
[
2
]
-
pz
));
+
(
center_
[
2
]
-
pz
)
*
(
center_
[
2
]
-
pz
));
double
theta
=
size_
/
lambda
;
double
theta
=
size_
/
lambda
;
// if angle too large, call this function for every child. If a child is a nullptr, calculate force on particle from particles in this node
// else calculate force on particle from particles in this node
// TODO
// If angle too large, call this function for every child which is not a nullptr.
// If the node is a leaf, calculate force on particle from particles in this node.
// If the node is not a leaf, call this function for every child which is not a nullptr.
// If angle small enough, calculate force on particle from this node.
if
(
theta
>
theta0_
)
{
if
(
theta
>
theta0_
)
{
// TODO
if
(
isLeaf_
)
{
// TODO
}
else
{
// TODO
}
}
else
{
}
else
{
// TODO
// TODO
}
}
...
...
This diff is collapsed.
Click to expand it.
lib/node.hpp
+
3
−
2
View file @
6aebd7d7
...
@@ -10,7 +10,7 @@ public:
...
@@ -10,7 +10,7 @@ public:
// whoever creates the node is responsible for deciding which particles are in which octant and for allocating the localParticles array
// 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 will write to localParticles array
Node
(
Node
*
root
,
Node
*
parent
,
double
*
masses
,
double
*
particles
,
unsigned
nParticles
,
unsigned
depth
,
Node
(
Node
*
root
,
Node
*
parent
,
double
*
masses
,
double
*
particles
,
unsigned
nParticles
,
unsigned
depth
,
double
size
,
double
center
[
3
],
std
::
vector
<
unsigned
>
localParticles
,
unsigned
nLocalParticles
);
double
size
,
double
center
[
3
],
std
::
vector
<
unsigned
>
&
localParticles
,
unsigned
nLocalParticles
);
// destuctor
// destuctor
~
Node
();
~
Node
();
// copy constructor
// copy constructor
...
@@ -18,7 +18,7 @@ public:
...
@@ -18,7 +18,7 @@ public:
// copy assignment
// copy assignment
Node
&
operator
=
(
const
Node
&
);
Node
&
operator
=
(
const
Node
&
);
// update tree: visit each node, check if it needs to be split or merged (for example if a particle has left the region)
// 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
();
void
update
(
std
::
vector
<
unsigned
>&
allParticles
);
// calculate force on a particle recursively
// calculate force on a particle recursively
double
*
calculateForce
(
unsigned
particle
);
double
*
calculateForce
(
unsigned
particle
);
private:
private:
...
@@ -35,6 +35,7 @@ private:
...
@@ -35,6 +35,7 @@ private:
unsigned
nLocalParticles_
;
unsigned
nLocalParticles_
;
double
mass_
;
double
mass_
;
const
double
theta0_
=
0.4
;
const
double
theta0_
=
0.4
;
bool
isLeaf_
;
};
};
#endif
/* NODE_HPP */
#endif
/* NODE_HPP */
\ No newline at end of file
This diff is collapsed.
Click to expand it.
lib/tree.cpp
+
4
−
1
View file @
6aebd7d7
...
@@ -17,6 +17,9 @@ Tree::Tree(double* masses, double* particles, double* forces, unsigned nParticle
...
@@ -17,6 +17,9 @@ Tree::Tree(double* masses, double* particles, double* forces, unsigned nParticle
root_
=
new
Node
();
root_
=
new
Node
();
*
root_
=
Node
(
root_
,
root_
,
masses_
,
particles_
,
nParticles_
,
0
,
*
root_
=
Node
(
root_
,
root_
,
masses_
,
particles_
,
nParticles_
,
0
,
size_
,
center_
,
localParticles_
,
nParticles_
);
size_
,
center_
,
localParticles_
,
nParticles_
);
allParticles_
=
std
::
vector
<
unsigned
>
(
nParticles_
);
for
(
unsigned
i
=
0
;
i
<
nParticles_
;
++
i
)
allParticles_
[
i
]
=
i
;
}
}
Tree
::~
Tree
()
{
Tree
::~
Tree
()
{
...
@@ -29,5 +32,5 @@ void Tree::calculateForce(unsigned particle) {
...
@@ -29,5 +32,5 @@ void Tree::calculateForce(unsigned particle) {
}
}
void
Tree
::
update
()
{
void
Tree
::
update
()
{
root_
->
update
();
root_
->
update
(
allParticles_
);
}
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
lib/tree.hpp
+
3
−
0
View file @
6aebd7d7
...
@@ -3,6 +3,8 @@
...
@@ -3,6 +3,8 @@
#include
"node.hpp"
#include
"node.hpp"
#include
<vector>
class
Tree
{
class
Tree
{
public:
public:
// constructor
// constructor
...
@@ -22,6 +24,7 @@ private:
...
@@ -22,6 +24,7 @@ private:
unsigned
nParticles_
;
unsigned
nParticles_
;
double
size_
;
double
size_
;
double
center_
[
3
];
double
center_
[
3
];
std
::
vector
<
unsigned
>
allParticles_
;
};
};
#endif
/* TREE_HPP */
#endif
/* TREE_HPP */
\ 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