Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
Parabolic
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD 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
Maxence Ferrari
Parabolic
Commits
e6c503b6
Commit
e6c503b6
authored
3 years ago
by
ferrari
Browse files
Options
Downloads
Patches
Plain Diff
version with functor
parent
a8725da9
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
main.cpp
+10
-9
10 additions, 9 deletions
main.cpp
sound_column.cpp
+19
-18
19 additions, 18 deletions
sound_column.cpp
sound_column.h
+4
-1
4 additions, 1 deletion
sound_column.h
with
33 additions
and
28 deletions
main.cpp
+
10
−
9
View file @
e6c503b6
...
...
@@ -3,6 +3,7 @@
#include
<cstring>
#include
"sound_column.h"
#include
<execution>
#include
<algorithm>
#define DEFAULT_DISTANCE 20'000.0f
#define DEFAULT_DEPTH 5'000.0f
...
...
@@ -67,15 +68,15 @@ int run_simulation(float r_max, float z_max, float f_min, float f_max){
auto
nf
=
size_t
(
f_max
/
f_min
);
float
delta_r
=
r_max
/
10'000
;
std
::
vector
<
sound_column
*>
column
(
nf
,
nullptr
);
std
::
vector
<
sound_column
*>
column
;
column
.
reserve
(
nf
);
//std::ranges::iota_view indexes((size_t) 0, nf);
std
::
ranges
::
iota_view
indexes
((
size_t
)
0
,
nf
);
std
::
for_each
(
std
::
execution
::
par_unseq
,
indexes
.
begin
(),
indexes
.
end
(),
[
&
](
size_t
i
)
{
column
[
i
]
=
new
sound_column
(
delta_r
,
(
size_t
)
1.10
*
z_max
*
(
4
*
(
i
+
1
)
*
f_min
)
/
WATER_SPEED
,
7
,
r_max
,
z_max
,
(
i
+
1
)
*
f_min
,
WATER_SPEED
);
c
olumn
[
i
]
->
init_source
(
gaussian_init
);});
std
::
for_each
(
std
::
execution
::
par_unseq
,
indexes
.
begin
(),
indexes
.
end
(),
[
&
](
s
ize_t
i
)
{
while
(
c
olumn
[
i
]
->
step_r
(
media
));});
std
::
for_each
(
std
::
execution
::
par_unseq
,
column
.
begin
(),
column
.
end
(),
[
&
](
sound_column
*&
c
)
{
int
i
=
&
c
-
&
column
[
0
];
c
=
new
sound_column
(
delta_r
,
(
size_t
)
1.10
*
z_max
*
(
4
*
(
i
+
1
)
*
f_min
)
/
WATER_SPEED
,
7
,
r_max
,
z_max
,
(
i
+
1
)
*
f_min
,
WATER_SPEED
);
c
->
init_source
(
gaussian_init
);});
std
::
for_each
(
std
::
execution
::
par_unseq
,
column
.
begin
(),
column
.
end
(),
[
&
](
s
ound_column
*&
c
)
{
while
(
c
->
step_r
(
media
));});
return
0
;
}
This diff is collapsed.
Click to expand it.
sound_column.cpp
+
19
−
18
View file @
e6c503b6
...
...
@@ -14,13 +14,13 @@ sound_column::sound_column(float dr, size_t nz, size_t np, float dm, float zm, f
n_p
=
np
;
freq
=
f
;
c0
=
speed
;
pressures
.
res
erv
e
(
nz
);
_u_
.
res
erv
e
(
nz
-
1
);
_l_
.
res
erv
e
(
nz
-
1
);
_d_
.
res
erv
e
(
nz
);
n_next
.
res
erv
e
(
nz
);
fapbj
.
res
erv
e
(
np
);
fbmaj
.
res
erv
e
(
np
);
pressures
.
res
iz
e
(
nz
);
_u_
.
res
iz
e
(
nz
-
1
);
_l_
.
res
iz
e
(
nz
-
1
);
_d_
.
res
iz
e
(
nz
);
n_next
.
res
iz
e
(
nz
);
fapbj
.
res
iz
e
(
np
);
fbmaj
.
res
iz
e
(
np
);
for
(
int
i
=
0
;
i
<
np
;
i
++
)
{
faj
=
std
::
complex
<
float
>
(
0
,
4
*
M_1_PIf32
*
freq
/
c0
)
/
float
((
2.
f
*
n_p
+
1.
f
)
*
powf
(
sinf
(
float
(
i
+
1
)
*
M_1_PIf32
/
(
2.
f
*
n_p
+
1.
f
)),
2
)
*
delta_r
);
...
...
@@ -36,34 +36,35 @@ sound_column::~sound_column() = default;
bool
sound_column
::
step_r
(
float
(
*
fun
)(
float
,
float
))
{
if
(
r
>=
d_max
)
return
true
;
std
::
ranges
::
iota_view
z_ind
((
size_t
)
0
,
n_z
);
//
std::ranges::iota_view z_ind((size_t) 0, n_z);
r
+=
delta_r
;
std
::
for_each
(
std
::
execution
::
par_unseq
,
z_ind
.
begin
(),
z_ind
.
end
(),
[
&
](
size_t
i
)
{
n_next
[
i
]
=
(
*
fun
)(
r
,
z_max
/
n_z
*
i
);});
std
::
for_each
(
std
::
execution
::
par_unseq
,
n_next
.
begin
(),
n_next
.
end
(),
[
&
](
float
&
n
)
{
int
i
=
&
n
-
&
n_next
[
0
];
n
=
(
*
fun
)(
r
,
z_max
/
n_z
*
i
);});
for
(
int
i
=
0
;
i
<
n_p
;
i
++
){
_step_r_
(
i
);
}
// Hank
std
::
for_each
(
std
::
execution
::
par_unseq
,
z_ind
.
begin
(),
z_ind
.
end
(),
[
&
](
s
ize_t
i
)
{
pressures
[
i
]
*=
2.
f
/
(
M_1_PIf32
*
M_1_PIf32
*
freq
/
c0
*
r
)
*
std
::
for_each
(
std
::
execution
::
par_unseq
,
pressures
.
begin
(),
pressures
.
end
(),
[
&
](
s
td
::
complex
<
float
>&
p
)
{
p
*=
static_cast
<
std
::
complex
<
float
>>
(
2.
f
/
(
M_1_PIf32
*
M_1_PIf32
*
freq
/
c0
*
r
)
)
*
std
::
exp
(
std
::
complex
<
float
>
(
0
,
2.
f
*
M_1_PIf32
*
freq
/
c0
*
r
-
M_1_PIf32
/
4
));});
return
false
;
}
void
sound_column
::
init_source
(
std
::
complex
<
float
>
(
*
fun
)(
float
,
float
))
{
std
::
ranges
::
iota_view
z_ind
((
size_t
)
0
,
n_z
);
std
::
for_each
(
std
::
execution
::
par_unseq
,
z_ind
.
begin
(),
z_ind
.
end
(),
[
&
](
size_t
i
)
{
pressures
[
i
]
=
(
*
fun
)(
z_max
/
n_z
*
i
,
2
*
M_1_PIf32
*
freq
/
c0
);});
// std::ranges::iota_view z_ind((size_t) 0, n_z);
std
::
for_each
(
std
::
execution
::
par_unseq
,
pressures
.
begin
(),
pressures
.
end
(),
[
&
](
std
::
complex
<
float
>&
p
)
{
int
i
=
&
p
-
&
pressures
[
0
];
p
=
(
*
fun
)(
z_max
/
n_z
*
i
,
2
*
M_1_PIf32
*
freq
/
c0
);});
}
void
sound_column
::
_step_r_
(
int
ip
)
{
std
::
ranges
::
iota_view
z_ind
((
size_t
)
0
,
n_z
);
//
std::ranges::iota_view z_ind((size_t) 0, n_z);
//tri diag init
std
::
fill
(
std
::
execution
::
par_unseq
,
_u_
.
begin
(),
_u_
.
end
(),
fbmaj
[
ip
]
/
h2
);
std
::
fill
(
std
::
execution
::
par_unseq
,
_l_
.
begin
(),
_l_
.
end
(),
fbmaj
[
ip
]
/
h2
);
std
::
for_each
(
std
::
execution
::
par_unseq
,
z_ind
.
begin
(),
z_ind
.
end
(),
[
&
](
s
ize_t
i
)
{
_d_
[
i
]
=
4
*
M_1_PIf32
*
freq
/
c0
+
fbmaj
[
ip
]
/
std
::
for_each
(
std
::
execution
::
par_unseq
,
_d_
.
begin
(),
_d_
.
end
(),
[
&
](
s
td
::
complex
<
float
>&
d
)
{
int
i
=
&
d
-
&
_d_
[
0
];
d
=
static_cast
<
std
::
complex
<
float
>>
(
4
*
M_1_PIf32
*
freq
/
c0
)
+
fbmaj
[
ip
]
/
static_cast
<
std
::
complex
<
float
>>
(
-
2.
f
/
h2
+
powf
(
4
*
M_1_PIf32
*
freq
/
c0
,
2
)
*
(
powf
(
n_next
[
i
],
2
)
-
1.
f
));});
// first matmul
...
...
This diff is collapsed.
Click to expand it.
sound_column.h
+
4
−
1
View file @
e6c503b6
...
...
@@ -6,8 +6,9 @@
#define PARABOLIC___SOUND_COLUMN_H
#include
<vector>
#include
<complex>
#include
<ranges>
//
#include <ranges>
#include
<execution>
#include
<algorithm>
# define M_1_PIf32 (0.318309886183790671537767526745028724)
...
...
@@ -30,6 +31,7 @@ private:
std
::
vector
<
std
::
complex
<
float
>>
_l_
;
std
::
vector
<
std
::
complex
<
float
>>
_d_
;
std
::
vector
<
float
>
n_next
;
std
::
complex
<
float
>
(
*
fun
)(
float
,
float
)
source_fun
;
void
_step_r_
(
int
ip
);
...
...
@@ -38,6 +40,7 @@ public:
~
sound_column
();
bool
step_r
(
float
(
*
fun
)(
float
,
float
));
void
init_source
(
std
::
complex
<
float
>
(
*
fun
)(
float
,
float
));
void
init_source
();
};
...
...
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