Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
openfpm_pdata
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
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
Sbalzarini Lab
Software
Parallel Computing
OpenFPM
openfpm_pdata
Commits
3170267f
Commit
3170267f
authored
8 years ago
by
Pietro Incardona
Browse files
Options
Downloads
Patches
Plain Diff
fixing examples
parent
d2113f22
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
example/Vector/4_reorder/energy_force.hpp
+138
-0
138 additions, 0 deletions
example/Vector/4_reorder/energy_force.hpp
with
138 additions
and
0 deletions
example/Vector/4_reorder/energy_force.hpp
0 → 100644
+
138
−
0
View file @
3170267f
/*
* energy_force.hpp
*
* Created on: Aug 6, 2016
* Author: i-bird
*/
#ifndef EXAMPLE_VECTOR_4_REORDER_ENERGY_FORCE_HPP_
#define EXAMPLE_VECTOR_4_REORDER_ENERGY_FORCE_HPP_
constexpr
int
velocity
=
0
;
constexpr
int
force
=
1
;
void
calc_forces
(
vector_dist
<
3
,
double
,
aggregate
<
double
[
3
],
double
[
3
]
>
>
&
vd
,
CellList
<
3
,
double
,
FAST
,
shift
<
3
,
double
>
>
&
NN
,
double
sigma12
,
double
sigma6
)
{
// update the Cell-list
vd
.
updateCellList
(
NN
);
// Get an iterator over particles
auto
it2
=
vd
.
getDomainIterator
();
// For each particle p ...
while
(
it2
.
isNext
())
{
// ... get the particle p
auto
p
=
it2
.
get
();
// Get the position xp of the particle
Point
<
3
,
double
>
xp
=
vd
.
getPos
(
p
);
// Reset the forice counter
vd
.
template
getProp
<
force
>(
p
)[
0
]
=
0.0
;
vd
.
template
getProp
<
force
>(
p
)[
1
]
=
0.0
;
vd
.
template
getProp
<
force
>(
p
)[
2
]
=
0.0
;
// Get an iterator over the neighborhood particles of p
auto
Np
=
NN
.
template
getNNIterator
<
NO_CHECK
>(
NN
.
getCell
(
vd
.
getPos
(
p
)));
// For each neighborhood particle ...
while
(
Np
.
isNext
())
{
// ... q
auto
q
=
Np
.
get
();
// if (p == q) skip this particle
if
(
q
==
p
.
getKey
())
{
++
Np
;
continue
;};
// Get the position of p
Point
<
3
,
double
>
xq
=
vd
.
getPos
(
q
);
// Get the distance between p and q
Point
<
3
,
double
>
r
=
xp
-
xq
;
// take the norm of this vector
double
rn
=
norm2
(
r
);
// Calculate the force, using pow is slower
Point
<
3
,
double
>
f
=
24.0
*
(
2.0
*
sigma12
/
(
rn
*
rn
*
rn
*
rn
*
rn
*
rn
*
rn
)
-
sigma6
/
(
rn
*
rn
*
rn
*
rn
))
*
r
;
// we sum the force produced by q on p
vd
.
template
getProp
<
force
>(
p
)[
0
]
+=
f
.
get
(
0
);
vd
.
template
getProp
<
force
>(
p
)[
1
]
+=
f
.
get
(
1
);
vd
.
template
getProp
<
force
>(
p
)[
2
]
+=
f
.
get
(
2
);
// Next neighborhood
++
Np
;
}
// Next particle
++
it2
;
}
}
double
calc_energy
(
vector_dist
<
3
,
double
,
aggregate
<
double
[
3
],
double
[
3
]
>
>
&
vd
,
CellList
<
3
,
double
,
FAST
,
shift
<
3
,
double
>
>
&
NN
,
double
sigma12
,
double
sigma6
)
{
double
E
=
0.0
;
// Update the cell-list
vd
.
updateCellList
(
NN
);
// Get the iterator
auto
it2
=
vd
.
getDomainIterator
();
// For each particle ...
while
(
it2
.
isNext
())
{
// ... p
auto
p
=
it2
.
get
();
// Get the position of the particle p
Point
<
3
,
double
>
xp
=
vd
.
getPos
(
p
);
// Reset the force
vd
.
template
getProp
<
force
>(
p
)[
0
]
=
0.0
;
vd
.
template
getProp
<
force
>(
p
)[
1
]
=
0.0
;
vd
.
template
getProp
<
force
>(
p
)[
2
]
=
0.0
;
// Get an iterator over the neighborhood of the particle p
auto
Np
=
NN
.
template
getNNIterator
<
NO_CHECK
>(
NN
.
getCell
(
vd
.
getPos
(
p
)));
// For each neighborhood of the particle p
while
(
Np
.
isNext
())
{
// Neighborhood particle q
auto
q
=
Np
.
get
();
// if p == q skip this particle
if
(
q
==
p
.
getKey
())
{
++
Np
;
continue
;};
// Get position of the particle q
Point
<
3
,
double
>
xq
=
vd
.
getPos
(
q
);
// take the normalized direction
double
rn
=
norm2
(
xp
-
xq
);
// potential energy (using pow is slower)
E
+=
4.0
*
(
sigma12
/
(
rn
*
rn
*
rn
*
rn
*
rn
*
rn
)
-
sigma6
/
(
rn
*
rn
*
rn
)
);
// Next neighborhood
++
Np
;
}
// Kinetic energy of the particle given by its actual speed
E
+=
(
vd
.
template
getProp
<
velocity
>(
p
)[
0
]
*
vd
.
template
getProp
<
velocity
>(
p
)[
0
]
+
vd
.
template
getProp
<
velocity
>(
p
)[
1
]
*
vd
.
template
getProp
<
velocity
>(
p
)[
1
]
+
vd
.
template
getProp
<
velocity
>(
p
)[
2
]
*
vd
.
template
getProp
<
velocity
>(
p
)[
2
])
/
2
;
// Next Particle
++
it2
;
}
return
E
;
}
#endif
/* EXAMPLE_VECTOR_4_REORDER_ENERGY_FORCE_HPP_ */
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