Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Q
QuickSched
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor 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
SWIFT
QuickSched
Commits
29f893de
Commit
29f893de
authored
10 years ago
by
Matthieu Schaller
Browse files
Options
Downloads
Patches
Plain Diff
Implemented 0-th order correction that just kills all inexact forces.
parent
2780ab8d
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
examples/plot_sorted.py
+7
-7
7 additions, 7 deletions
examples/plot_sorted.py
examples/test_bh_sorted.c
+105
-7
105 additions, 7 deletions
examples/test_bh_sorted.c
with
112 additions
and
14 deletions
examples/plot_sorted.py
+
7
−
7
View file @
29f893de
...
...
@@ -36,7 +36,7 @@ import os
from
scipy
import
stats
from
scipy
import
optimize
dist_cutoff_ratio
=
1.
2
dist_cutoff_ratio
=
1.
5
ortho_max_fit
=
0.2
ortho_min_fit
=
0.
ortho_max
=
2.5
...
...
@@ -137,7 +137,7 @@ for orientation in range( 26 ):
print
this_axis
print
"
actual:
"
,
orientation
,
min
(
dist
),
max
(
dist
),
min_dist
[
0
],
max_dist
[
0
]
print
"
---
"
continue
#
continue
if
cell_edge
>
1.5
:
cubic_param1
=
[
0.04730586
,
-
0.37960746
,
0.99371996
,
0.15444646
]
...
...
@@ -219,11 +219,11 @@ for orientation in range( 26 ):
# Apply the correction ---------------------------------------
for
i
in
range
(
size
(
x
)):
if
cell_edge
-
dist
[
i
]
>
limit_exact
:
accx_s
[
i
]
/=
cubic
(
dist
[
i
],
cubic_param2
[
0
],
cubic_param2
[
1
],
cubic_param2
[
2
],
cubic_param2
[
3
])
if
dist
[
i
]
-
cell_edge
>
limit_exact
:
accx_s
[
i
]
/=
cubic
(
dist
[
i
],
cubic_param1
[
0
],
cubic_param1
[
1
],
cubic_param1
[
2
],
cubic_param1
[
3
])
#
for i in range(size(x)):
#
if cell_edge-dist[i] > limit_exact:
#
accx_s[i] /= cubic(dist[i], cubic_param2[0], cubic_param2[1], cubic_param2[2], cubic_param2[3])
#
if dist[i]-cell_edge > limit_exact:
#
accx_s[i] /= cubic(dist[i], cubic_param1[0], cubic_param1[1], cubic_param1[2], cubic_param1[3])
# Build error ------------------------------------------------
...
...
This diff is collapsed.
Click to expand it.
examples/test_bh_sorted.c
+
105
−
7
View file @
29f893de
...
...
@@ -42,7 +42,7 @@
#define task_limit 1e8
#define const_G 1 // 6.6738e-8
#define dist_min 0.5
/* Used for legacy walk only */
#define dist_cutoff_ratio 1.
2
#define dist_cutoff_ratio 1.
5
#define iact_pair_direct iact_pair_direct_sorted_multipole
#define ICHECK -1
#define NO_SANITY_CHECKS
...
...
@@ -495,9 +495,8 @@ void cell_sort(struct cell *c, const float *axis, int aid) {
* @param ind_j Sorted indices of the cell @c cj.
*/
void
get_axis
(
struct
cell
**
ci
,
struct
cell
**
cj
,
struct
index
**
ind_i
,
struct
index
**
ind_j
,
float
*
min_dist
,
float
*
max_dist
)
{
struct
index
**
ind_j
,
float
*
min_dist
,
float
*
max_dist
,
float
axis
[
3
]
)
{
float
axis
[
3
];
float
dx
[
3
];
int
aid
=
0
;
...
...
@@ -1176,6 +1175,78 @@ float correction_coefs[6*4] =
};
/**
* @brief Compute the best-fitting bias correction factor for the acceleration of a particle
*
* @param d The normalized position of the particle along the axis
* @param axis The axis along which the two cells are interacting
* @param The correction to apply in each direction
*/
static
inline
void
gravity_bias_correction
(
float
d
,
float
axis
[
3
],
float
corr
[
3
]
)
{
int
k
,
orientation
;
int
is_zero
[
3
];
float
limit_exact
=
(
dist_cutoff_ratio
-
1
.
);
/* Start with no applied correction */
corr
[
0
]
=
corr
[
1
]
=
corr
[
2
]
=
1
.
f
;
/* Find which case we are dealing with */
orientation
=
0
;
for
(
k
=
0
;
k
<
3
;
++
k
)
{
is_zero
[
k
]
=
(
fabs
(
axis
[
k
])
>
0
?
1
:
0
);
orientation
+=
is_zero
[
k
];
}
//message("%f %f", d, limit_exact);
/* Apply the correction corresponding to this axis */
switch
(
orientation
)
{
case
1
:
/* side */
{
if
(
d
>
limit_exact
||
d
<
-
limit_exact
)
for
(
k
=
0
;
k
<
3
;
k
++
)
corr
[
k
]
=
0
.;
}
break
;
case
2
:
/* edge */
{
if
(
d
>
limit_exact
||
d
<
-
limit_exact
)
for
(
k
=
0
;
k
<
3
;
k
++
)
corr
[
k
]
=
0
.;
}
break
;
case
3
:
/* corner */
{
if
(
d
>
limit_exact
||
d
<
-
limit_exact
)
for
(
k
=
0
;
k
<
3
;
k
++
)
corr
[
k
]
=
0
.;
}
break
;
default:
error
(
"Invalid orientation axis=(%f %f %f) orientation= %d"
,
axis
[
0
],
axis
[
1
],
axis
[
2
],
orientation
);
}
/* Correction only applies in the direction along the axis. Rest is untouched */
for
(
k
=
0
;
k
<
3
;
++
k
)
corr
[
k
]
=
(
is_zero
[
k
]
?
corr
[
k
]
:
1
);
}
static
inline
void
iact_pair_direct_sorted_multipole
(
struct
cell
*
ci
,
struct
cell
*
cj
)
{
...
...
@@ -1184,7 +1255,7 @@ static inline void iact_pair_direct_sorted_multipole(struct cell *ci,
struct
part_local
*
parts_i
,
*
parts_j
;
float
xi
[
3
];
float
dx
[
3
],
ai
[
3
],
mi
,
mj
,
r2
,
w
,
ir
;
float
min_dist
,
max_dist
,
length_dist
,
mid_dist
;
float
min_dist
,
max_dist
,
length_dist
,
mid_dist
,
d_norm
,
axis
[
3
],
corr
[
3
]
;
#ifdef SANITY_CHECKS
...
...
@@ -1196,7 +1267,7 @@ static inline void iact_pair_direct_sorted_multipole(struct cell *ci,
/* Get the sorted indices and geometry. */
struct
index
*
ind_i
,
*
ind_j
;
get_axis
(
&
ci
,
&
cj
,
&
ind_i
,
&
ind_j
,
&
min_dist
,
&
max_dist
);
get_axis
(
&
ci
,
&
cj
,
&
ind_i
,
&
ind_j
,
&
min_dist
,
&
max_dist
,
axis
);
length_dist
=
max_dist
-
min_dist
;
mid_dist
=
min_dist
+
0
.
5
f
*
length_dist
;
...
...
@@ -1373,9 +1444,36 @@ static inline void iact_pair_direct_sorted_multipole(struct cell *ci,
}
/* Apply the correction to cancel the bias */
for
(
i
=
0
;
i
<
count_i
;
i
++
)
{
message
(
"Length = %f Mid = %f dist = %f"
,
length_dist
,
mid_dist
,
parts_i
[
i
].
d
);
/* Get the normalized position along the axis */
d_norm
=
parts_i
[
i
].
d
-
mid_dist
;
d_norm
/=
ci
->
h
;
/* Get the correction */
gravity_bias_correction
(
d_norm
,
axis
,
corr
);
/* And apply it */
parts_i
[
i
].
a
[
0
]
*=
corr
[
0
];
parts_i
[
i
].
a
[
1
]
*=
corr
[
1
];
parts_i
[
i
].
a
[
2
]
*=
corr
[
2
];
}
/* Do the same on the other particles */
for
(
j
=
0
;
j
<
count_i
;
j
++
)
{
/* Get the normalized position along the axis */
d_norm
=
parts_j
[
j
].
d
-
mid_dist
;
d_norm
/=
cj
->
h
;
/* Get the correction */
gravity_bias_correction
(
d_norm
,
axis
,
corr
);
/* And apply it */
parts_j
[
j
].
a
[
0
]
*=
corr
[
0
];
parts_j
[
j
].
a
[
1
]
*=
corr
[
1
];
parts_j
[
j
].
a
[
2
]
*=
corr
[
2
];
}
/* Copy the accelerations back to the original particles. */
...
...
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