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
bb2446a8
Commit
bb2446a8
authored
2 years ago
by
Armin Damon Riess
Browse files
Options
Downloads
Patches
Plain Diff
use maxDepth, no segfault but result incorrect
parent
5f34ceb8
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
lib/node.cpp
+16
-4
16 additions, 4 deletions
lib/node.cpp
with
16 additions
and
4 deletions
lib/node.cpp
+
16
−
4
View file @
bb2446a8
...
...
@@ -89,6 +89,7 @@ Node::Node(double* masses, double* positions, unsigned nParticles, unsigned dept
Node
::~
Node
()
{
for
(
unsigned
i
=
0
;
i
<
8
;
++
i
)
{
delete
children_
[
i
];
children_
[
i
]
=
nullptr
;
}
}
...
...
@@ -106,6 +107,9 @@ Node& Node::operator=(const Node& other) {
}
void
Node
::
update
(
List
localParticles
,
unsigned
nLocalParticles
)
{
double
minNParticles
=
8
;
double
maxDepth
=
10
;
localParticles_
=
localParticles
;
nLocalParticles_
=
nLocalParticles
;
updateMassAndCOM
();
...
...
@@ -118,11 +122,19 @@ void Node::update(List localParticles, unsigned nLocalParticles) {
}
isLeaf_
=
true
;
if
(
nLocalParticles_
<=
minNParticles
||
depth_
>=
maxDepth
)
{
// if the node contains less than minNParticles, it is a leaf
for
(
unsigned
i
=
0
;
i
<
8
;
++
i
)
{
delete
children_
[
i
];
children_
[
i
]
=
nullptr
;
}
return
;
}
for
(
unsigned
i
=
0
;
i
<
8
;
++
i
)
{
if
(
children_
[
i
]
!=
nullptr
)
{
// if child is not a nullptr and particleDivision[i] is empty, delete the child
// if child is not a nullptr and particleDivision[i] is empty
or contains a single particle
, delete the child
// otherwise update the child
if
(
particleDivision
[
i
].
size
()
=
=
0
)
{
if
(
particleDivision
[
i
].
size
()
<
=
minNParticles
)
{
delete
children_
[
i
];
children_
[
i
]
=
nullptr
;
}
else
{
...
...
@@ -130,8 +142,8 @@ void Node::update(List localParticles, unsigned nLocalParticles) {
isLeaf_
=
false
;
}
}
else
{
// if child is a nullptr and particleDivision[i]
is not empty
, create a new child
if
(
particleDivision
[
i
].
size
()
!=
0
)
{
// if child is a nullptr and particleDivision[i]
contains more than one particle
, create a new child
if
(
particleDivision
[
i
].
size
()
>
minNParticles
)
{
double
childSize
=
size_
/
2
;
Vector
childCenter
(
3
);
for
(
unsigned
j
=
0
;
j
<
3
;
++
j
)
{
...
...
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