Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
R
RBComb simulation
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
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
Pascal Engeler
RBComb simulation
Commits
401fd455
Commit
401fd455
authored
5 years ago
by
Pascal Engeler
Browse files
Options
Downloads
Patches
Plain Diff
Added rk4 stepper
parent
58d28d1c
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
include/rk4_stepper.hpp
+95
-0
95 additions, 0 deletions
include/rk4_stepper.hpp
with
95 additions
and
0 deletions
include/rk4_stepper.hpp
0 → 100644
+
95
−
0
View file @
401fd455
#ifndef RK4_STEPPER_HPP_INCLUDED
#define RK4_STEPPER_HPP_INCLUDED
template
<
typename
value_t
,
template
<
typename
T
>
class
params_t
,
template
<
typename
R
>
class
vars_t
,
template
<
typename
Q
>
class
buffer_t
,
template
<
value_t
,
params_t
,
vars_t
,
buffer_t
>
force_t
>
class
Rk4Stepper
{
public:
Rk4Stepper
()
=
default
;
~
Rk4Stepper
()
=
default
;
//time signifies the state of the system, i.e. the time when the complete step was started.
//operations performed at t
void
step_1
(
const
force_t
&
force
,
std
::
vector
<
Drum
<
value_t
,
params_t
,
vars_t
,
buffer_t
>
>&
drums
,
const
std
::
vector
<
std
::
vector
<
int
>
>&
adj_vec
,
const
value_t
dt
,
const
value_t
time
)
const
noexcept
{
//step 1: calculate k1 and l1 for all drums
for
(
size_t
i
=
0
;
i
<
drums
.
size
()
-
1
;
++
i
){
//TODO: Empty neighbours are now signified by adj_vec[i][j] == -1. We could also push a 0-drum to the end and point to that.
drums
[
i
].
get_sbuffer
().
k1
=
dt
*
(
force
(
drums
[
i
],
drums
[
adj_vec
[
i
][
0
]],
drums
[
adj_vec
[
i
][
1
]],
drums
[
adj_vec
[
i
][
2
]],
time
));
drums
[
i
].
get_sbuffer
().
l1
=
dt
*
xdot
;
}
//update x_temp, xdot_temp
for
(
size_t
i
=
0
;
i
<
drums
.
size
()
-
1
;
++
i
){
drums
[
i
].
get_variables
().
xdot_temp
=
drums
[
i
].
get_variables
().
xdot
+
drums
[
i
].
get_sbuffer
().
k1
/
2.
;
drums
[
i
].
get_variables
().
x_temp
=
drums
[
i
].
get_variables
().
x
+
drums
[
i
].
get_sbuffer
().
l1
/
2.
;
}
//now it's time for the owner to update the coupler and driver to t+dt/2.
}
//operations performed at t+dt/2
void
step_2
(
const
force_t
<
value_t
,
params_t
,
vars_t
,
buffer_t
>&
force
,
std
::
vector
<
Drum
<
value_t
,
params_t
,
vars_t
,
buffer_t
>
>&
drums
,
const
std
::
vector
<
std
::
vector
<
int
>
>&
adj_vec
,
const
value_t
dt
,
const
value_t
time
)
const
noexcept
{
//step 2: calculate k2 and l2 for all drums
for
(
size_t
i
=
0
;
i
<
drums
.
size
()
-
1
;
++
i
){
//TODO: Empty neighbours are now signified by adj_vec[i][j] == -1. We could also push a 0-drum to the end and point to that.
drums
[
i
].
get_sbuffer
().
k2
=
dt
*
(
force
(
drums
[
i
],
drums
[
adj_vec
[
i
][
0
]],
drums
[
adj_vec
[
i
][
1
]],
drums
[
adj_vec
[
i
][
2
]],
time
));
drums
[
i
].
get_sbuffer
().
l2
=
dt
*
xdot_temp
;
}
//update x_temp, xdot_temp
for
(
size_t
i
=
0
;
i
<
drums
.
size
()
-
1
;
++
i
){
drums
[
i
].
get_variables
().
xdot_temp
=
drums
[
i
].
get_variables
().
xdot
+
drums
[
i
].
get_sbuffer
().
k2
/
2.
;
drums
[
i
].
get_variables
().
x_temp
=
drums
[
i
].
get_variables
().
x
+
drums
[
i
].
get_sbuffer
().
l2
/
2.
;
}
//step 3: calculate k3 and l3 for all drums
for
(
size_t
i
=
0
;
i
<
drums
.
size
()
-
1
;
++
i
){
//TODO: Empty neighbours are now signified by adj_vec[i][j] == -1. We could also push a 0-drum to the end and point to that.
drums
[
i
].
get_sbuffer
().
k3
=
dt
*
(
force
(
drums
[
i
],
drums
[
adj_vec
[
i
][
0
]],
drums
[
adj_vec
[
i
][
1
]],
drums
[
adj_vec
[
i
][
2
]],
time
));
drums
[
i
].
get_sbuffer
().
l3
=
dt
*
xdot_temp
;
}
//update x_temp, xdot_temp
for
(
size_t
i
=
0
;
i
<
drums
.
size
()
-
1
;
++
i
){
drums
[
i
].
get_variables
().
xdot_temp
=
drums
[
i
].
get_variables
().
xdot
+
drums
[
i
].
get_sbuffer
().
k3
;
drums
[
i
].
get_variables
().
x_temp
=
drums
[
i
].
get_variables
().
x
+
drums
[
i
].
get_sbuffer
().
l3
;
}
//now it's time for the owner to update the coupler and driver to t+dt/2.
}
//operations performed at t+dt
void
step_3
(
const
force_t
<
value_t
,
params_t
,
vars_t
,
buffer_t
>&
force
,
std
::
vector
<
Drum
<
value_t
,
params_t
,
vars_t
,
buffer_t
>
>&
drums
,
const
std
::
vector
<
std
::
vector
<
int
>
>&
adj_vec
,
const
value_t
dt
,
const
value_t
time
)
const
noexcept
{
//step 4: calculate k4 and l4 for all drums
for
(
size_t
i
=
0
;
i
<
drums
.
size
()
-
1
;
++
i
){
//TODO: Empty neighbours are now signified by adj_vec[i][j] == -1. We could also push a 0-drum to the end and point to that.
drums
[
i
].
get_sbuffer
().
k4
=
dt
*
(
force
(
drums
[
i
],
drums
[
adj_vec
[
i
][
0
]],
drums
[
adj_vec
[
i
][
1
]],
drums
[
adj_vec
[
i
][
2
]],
time
));
drums
[
i
].
get_sbuffer
().
l4
=
dt
*
xdot_temp
;
}
//update x, xdot, x_temp, xdot_temp to t+dt
for
(
size_t
i
=
0
;
i
<
drums
.
size
()
-
1
;
++
i
){
drums
[
i
].
get_variables
().
xdot_temp
=
drums
[
i
].
get_variables
().
xdot
+
drums
[
i
].
get_sbuffer
().
k4
;
drums
[
i
].
get_variables
().
x_temp
=
drums
[
i
].
get_variables
().
x
+
drums
[
i
].
get_sbuffer
().
l4
;
drums
[
i
].
get_variables
().
xdot
=
drums
[
i
].
get_variables
().
xdot
+
drums
[
i
].
get_sbuffer
().
k4
;
drums
[
i
].
get_variables
().
x
=
drums
[
i
].
get_variables
().
x
+
drums
[
i
].
get_sbuffer
().
l4
;
}
}
};
#endif
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