Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F79193819
fix_spring_self.cpp
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Sun, Aug 25, 05:24
Size
7 KB
Mime Type
text/x-c
Expires
Tue, Aug 27, 05:24 (2 d)
Engine
blob
Format
Raw Data
Handle
20159416
Attached To
rLAMMPS lammps
fix_spring_self.cpp
View Options
/* ----------------------------------------------------------------------
LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator
www.cs.sandia.gov/~sjplimp/lammps.html
Steve Plimpton, sjplimp@sandia.gov, Sandia National Laboratories
Copyright (2003) Sandia Corporation. Under the terms of Contract
DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains
certain rights in this software. This software is distributed under
the GNU General Public License.
See the README file in the top-level LAMMPS directory.
------------------------------------------------------------------------- */
/* ----------------------------------------------------------------------
Contributing author: Naveen Michaud-Agrawal (Johns Hopkins University)
------------------------------------------------------------------------- */
#include "stdlib.h"
#include "string.h"
#include "fix_spring_self.h"
#include "atom.h"
#include "update.h"
#include "domain.h"
#include "respa.h"
#include "memory.h"
#include "error.h"
/* ---------------------------------------------------------------------- */
FixSpringSelf
::
FixSpringSelf
(
int
narg
,
char
**
arg
)
:
Fix
(
narg
,
arg
)
{
if
(
narg
!=
4
)
error
->
all
(
"Illegal fix spring/self command"
);
restart_peratom
=
1
;
k
=
atof
(
arg
[
3
]);
if
(
k
<=
0.0
)
error
->
all
(
"Illegal fix spring/self command"
);
// perform initial allocation of atom-based array
// register with atom class
xoriginal
=
NULL
;
grow_arrays
(
atom
->
nmax
);
atom
->
add_callback
(
0
);
atom
->
add_callback
(
1
);
// xoriginal = initial unwrapped positions of atoms
double
**
x
=
atom
->
x
;
int
*
mask
=
atom
->
mask
;
int
*
image
=
atom
->
image
;
int
nlocal
=
atom
->
nlocal
;
double
xprd
=
domain
->
xprd
;
double
yprd
=
domain
->
yprd
;
double
zprd
=
domain
->
zprd
;
int
xbox
,
ybox
,
zbox
;
for
(
int
i
=
0
;
i
<
nlocal
;
i
++
)
{
if
(
mask
[
i
]
&
groupbit
)
{
xbox
=
(
image
[
i
]
&
1023
)
-
512
;
ybox
=
(
image
[
i
]
>>
10
&
1023
)
-
512
;
zbox
=
(
image
[
i
]
>>
20
)
-
512
;
xoriginal
[
i
][
0
]
=
x
[
i
][
0
]
+
xbox
*
xprd
;
xoriginal
[
i
][
1
]
=
x
[
i
][
1
]
+
ybox
*
yprd
;
xoriginal
[
i
][
2
]
=
x
[
i
][
2
]
+
zbox
*
zprd
;
}
else
xoriginal
[
i
][
0
]
=
xoriginal
[
i
][
1
]
=
xoriginal
[
i
][
2
]
=
0.0
;
}
}
/* ---------------------------------------------------------------------- */
FixSpringSelf
::~
FixSpringSelf
()
{
// if atom class still exists:
// unregister this fix so atom class doesn't invoke it any more
if
(
atom
)
atom
->
delete_callback
(
id
,
0
);
if
(
atom
)
atom
->
delete_callback
(
id
,
1
);
// delete locally stored array
memory
->
destroy_2d_double_array
(
xoriginal
);
}
/* ---------------------------------------------------------------------- */
int
FixSpringSelf
::
setmask
()
{
int
mask
=
0
;
mask
|=
POST_FORCE
;
mask
|=
POST_FORCE_RESPA
;
return
mask
;
}
/* ---------------------------------------------------------------------- */
void
FixSpringSelf
::
init
()
{
if
(
strcmp
(
update
->
integrate_style
,
"respa"
)
==
0
)
nlevels_respa
=
((
Respa
*
)
update
->
integrate
)
->
nlevels
;
}
/* ---------------------------------------------------------------------- */
void
FixSpringSelf
::
setup
()
{
if
(
strcmp
(
update
->
integrate_style
,
"verlet"
)
==
0
)
post_force
(
1
);
else
{
((
Respa
*
)
update
->
integrate
)
->
copy_flevel_f
(
nlevels_respa
-
1
);
post_force_respa
(
1
,
nlevels_respa
-
1
,
0
);
((
Respa
*
)
update
->
integrate
)
->
copy_f_flevel
(
nlevels_respa
-
1
);
}
}
/* ---------------------------------------------------------------------- */
void
FixSpringSelf
::
post_force
(
int
vflag
)
{
double
**
x
=
atom
->
x
;
double
**
f
=
atom
->
f
;
int
*
mask
=
atom
->
mask
;
int
*
image
=
atom
->
image
;
int
nlocal
=
atom
->
nlocal
;
double
xprd
=
domain
->
xprd
;
double
yprd
=
domain
->
yprd
;
double
zprd
=
domain
->
zprd
;
int
xbox
,
ybox
,
zbox
;
double
dx
,
dy
,
dz
;
for
(
int
i
=
0
;
i
<
nlocal
;
i
++
)
if
(
mask
[
i
]
&
groupbit
)
{
xbox
=
(
image
[
i
]
&
1023
)
-
512
;
ybox
=
(
image
[
i
]
>>
10
&
1023
)
-
512
;
zbox
=
(
image
[
i
]
>>
20
)
-
512
;
dx
=
x
[
i
][
0
]
+
xbox
*
xprd
-
xoriginal
[
i
][
0
];
dy
=
x
[
i
][
1
]
+
ybox
*
yprd
-
xoriginal
[
i
][
1
];
dz
=
x
[
i
][
2
]
+
zbox
*
zprd
-
xoriginal
[
i
][
2
];
f
[
i
][
0
]
-=
k
*
dx
;
f
[
i
][
1
]
-=
k
*
dy
;
f
[
i
][
2
]
-=
k
*
dz
;
}
}
/* ---------------------------------------------------------------------- */
void
FixSpringSelf
::
post_force_respa
(
int
vflag
,
int
ilevel
,
int
iloop
)
{
if
(
ilevel
==
nlevels_respa
-
1
)
post_force
(
vflag
);
}
/* ----------------------------------------------------------------------
memory usage of local atom-based array
------------------------------------------------------------------------- */
int
FixSpringSelf
::
memory_usage
()
{
int
bytes
=
atom
->
nmax
*
3
*
sizeof
(
double
);
return
bytes
;
}
/* ----------------------------------------------------------------------
allocate atom-based array
------------------------------------------------------------------------- */
void
FixSpringSelf
::
grow_arrays
(
int
nmax
)
{
xoriginal
=
memory
->
grow_2d_double_array
(
xoriginal
,
nmax
,
3
,
"fix_spring/self:xoriginal"
);
}
/* ----------------------------------------------------------------------
copy values within local atom-based array
------------------------------------------------------------------------- */
void
FixSpringSelf
::
copy_arrays
(
int
i
,
int
j
)
{
xoriginal
[
j
][
0
]
=
xoriginal
[
i
][
0
];
xoriginal
[
j
][
1
]
=
xoriginal
[
i
][
1
];
xoriginal
[
j
][
2
]
=
xoriginal
[
i
][
2
];
}
/* ----------------------------------------------------------------------
pack values in local atom-based array for exchange with another proc
------------------------------------------------------------------------- */
int
FixSpringSelf
::
pack_exchange
(
int
i
,
double
*
buf
)
{
buf
[
0
]
=
xoriginal
[
i
][
0
];
buf
[
1
]
=
xoriginal
[
i
][
1
];
buf
[
2
]
=
xoriginal
[
i
][
2
];
return
3
;
}
/* ----------------------------------------------------------------------
unpack values in local atom-based array from exchange with another proc
------------------------------------------------------------------------- */
int
FixSpringSelf
::
unpack_exchange
(
int
nlocal
,
double
*
buf
)
{
xoriginal
[
nlocal
][
0
]
=
buf
[
0
];
xoriginal
[
nlocal
][
1
]
=
buf
[
1
];
xoriginal
[
nlocal
][
2
]
=
buf
[
2
];
return
3
;
}
/* ----------------------------------------------------------------------
pack values in local atom-based arrays for restart file
------------------------------------------------------------------------- */
int
FixSpringSelf
::
pack_restart
(
int
i
,
double
*
buf
)
{
buf
[
0
]
=
4
;
buf
[
1
]
=
xoriginal
[
i
][
0
];
buf
[
2
]
=
xoriginal
[
i
][
1
];
buf
[
3
]
=
xoriginal
[
i
][
2
];
return
4
;
}
/* ----------------------------------------------------------------------
unpack values from atom->extra array to restart the fix
------------------------------------------------------------------------- */
void
FixSpringSelf
::
unpack_restart
(
int
nlocal
,
int
nth
)
{
double
**
extra
=
atom
->
extra
;
// skip to Nth set of extra values
int
m
=
0
;
for
(
int
i
=
0
;
i
<
nth
;
i
++
)
m
+=
static_cast
<
int
>
(
extra
[
nlocal
][
m
]);
m
++
;
xoriginal
[
nlocal
][
0
]
=
extra
[
nlocal
][
m
++
];
xoriginal
[
nlocal
][
1
]
=
extra
[
nlocal
][
m
++
];
xoriginal
[
nlocal
][
2
]
=
extra
[
nlocal
][
m
++
];
}
/* ----------------------------------------------------------------------
maxsize of any atom's restart data
------------------------------------------------------------------------- */
int
FixSpringSelf
::
maxsize_restart
()
{
return
4
;
}
/* ----------------------------------------------------------------------
size of atom nlocal's restart data
------------------------------------------------------------------------- */
int
FixSpringSelf
::
size_restart
(
int
nlocal
)
{
return
4
;
}
Event Timeline
Log In to Comment