Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
L
lammps
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
Container Registry
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
multiscale
lammps
Commits
1ad7d856
Commit
1ad7d856
authored
7 years ago
by
Stefan Paquay
Browse files
Options
Downloads
Patches
Plain Diff
Added forgotten #include string to bond_harmonic.cpp
parent
874944f2
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
src/bond_harmonic.cpp
+215
-0
215 additions, 0 deletions
src/bond_harmonic.cpp
with
215 additions
and
0 deletions
src/bond_harmonic.cpp
0 → 100644
+
215
−
0
View file @
1ad7d856
/* ----------------------------------------------------------------------
LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator
http://lammps.sandia.gov, Sandia National Laboratories
Steve Plimpton, sjplimp@sandia.gov
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.
------------------------------------------------------------------------- */
#include
<math.h>
#include
<stdlib.h>
#include
<string.h>
#include
"bond_harmonic.h"
#include
"atom.h"
#include
"neighbor.h"
#include
"domain.h"
#include
"comm.h"
#include
"force.h"
#include
"memory.h"
#include
"error.h"
using
namespace
LAMMPS_NS
;
/* ---------------------------------------------------------------------- */
BondHarmonic
::
BondHarmonic
(
LAMMPS
*
lmp
)
:
Bond
(
lmp
)
{
reinitflag
=
1
;
}
/* ---------------------------------------------------------------------- */
BondHarmonic
::~
BondHarmonic
()
{
if
(
allocated
&&
!
copymode
)
{
memory
->
destroy
(
setflag
);
memory
->
destroy
(
k
);
memory
->
destroy
(
r0
);
}
}
/* ---------------------------------------------------------------------- */
void
BondHarmonic
::
compute
(
int
eflag
,
int
vflag
)
{
int
i1
,
i2
,
n
,
type
;
double
delx
,
dely
,
delz
,
ebond
,
fbond
;
double
rsq
,
r
,
dr
,
rk
;
ebond
=
0.0
;
if
(
eflag
||
vflag
)
ev_setup
(
eflag
,
vflag
);
else
evflag
=
0
;
double
**
x
=
atom
->
x
;
double
**
f
=
atom
->
f
;
int
**
bondlist
=
neighbor
->
bondlist
;
int
nbondlist
=
neighbor
->
nbondlist
;
int
nlocal
=
atom
->
nlocal
;
int
newton_bond
=
force
->
newton_bond
;
for
(
n
=
0
;
n
<
nbondlist
;
n
++
)
{
i1
=
bondlist
[
n
][
0
];
i2
=
bondlist
[
n
][
1
];
type
=
bondlist
[
n
][
2
];
delx
=
x
[
i1
][
0
]
-
x
[
i2
][
0
];
dely
=
x
[
i1
][
1
]
-
x
[
i2
][
1
];
delz
=
x
[
i1
][
2
]
-
x
[
i2
][
2
];
rsq
=
delx
*
delx
+
dely
*
dely
+
delz
*
delz
;
r
=
sqrt
(
rsq
);
dr
=
r
-
r0
[
type
];
rk
=
k
[
type
]
*
dr
;
// force & energy
if
(
r
>
0.0
)
fbond
=
-
2.0
*
rk
/
r
;
else
fbond
=
0.0
;
if
(
eflag
)
ebond
=
rk
*
dr
;
// apply force to each of 2 atoms
if
(
newton_bond
||
i1
<
nlocal
)
{
f
[
i1
][
0
]
+=
delx
*
fbond
;
f
[
i1
][
1
]
+=
dely
*
fbond
;
f
[
i1
][
2
]
+=
delz
*
fbond
;
}
if
(
newton_bond
||
i2
<
nlocal
)
{
f
[
i2
][
0
]
-=
delx
*
fbond
;
f
[
i2
][
1
]
-=
dely
*
fbond
;
f
[
i2
][
2
]
-=
delz
*
fbond
;
}
if
(
evflag
)
ev_tally
(
i1
,
i2
,
nlocal
,
newton_bond
,
ebond
,
fbond
,
delx
,
dely
,
delz
);
}
}
/* ---------------------------------------------------------------------- */
void
BondHarmonic
::
allocate
()
{
allocated
=
1
;
int
n
=
atom
->
nbondtypes
;
memory
->
create
(
k
,
n
+
1
,
"bond:k"
);
memory
->
create
(
r0
,
n
+
1
,
"bond:r0"
);
memory
->
create
(
setflag
,
n
+
1
,
"bond:setflag"
);
for
(
int
i
=
1
;
i
<=
n
;
i
++
)
setflag
[
i
]
=
0
;
}
/* ----------------------------------------------------------------------
set coeffs for one or more types
------------------------------------------------------------------------- */
void
BondHarmonic
::
coeff
(
int
narg
,
char
**
arg
)
{
if
(
narg
!=
3
)
error
->
all
(
FLERR
,
"Incorrect args for bond coefficients"
);
if
(
!
allocated
)
allocate
();
int
ilo
,
ihi
;
force
->
bounds
(
FLERR
,
arg
[
0
],
atom
->
nbondtypes
,
ilo
,
ihi
);
double
k_one
=
force
->
numeric
(
FLERR
,
arg
[
1
]);
double
r0_one
=
force
->
numeric
(
FLERR
,
arg
[
2
]);
int
count
=
0
;
for
(
int
i
=
ilo
;
i
<=
ihi
;
i
++
)
{
k
[
i
]
=
k_one
;
r0
[
i
]
=
r0_one
;
setflag
[
i
]
=
1
;
count
++
;
}
if
(
count
==
0
)
error
->
all
(
FLERR
,
"Incorrect args for bond coefficients"
);
}
/* ----------------------------------------------------------------------
return an equilbrium bond length
------------------------------------------------------------------------- */
double
BondHarmonic
::
equilibrium_distance
(
int
i
)
{
return
r0
[
i
];
}
/* ----------------------------------------------------------------------
proc 0 writes out coeffs to restart file
------------------------------------------------------------------------- */
void
BondHarmonic
::
write_restart
(
FILE
*
fp
)
{
fwrite
(
&
k
[
1
],
sizeof
(
double
),
atom
->
nbondtypes
,
fp
);
fwrite
(
&
r0
[
1
],
sizeof
(
double
),
atom
->
nbondtypes
,
fp
);
}
/* ----------------------------------------------------------------------
proc 0 reads coeffs from restart file, bcasts them
------------------------------------------------------------------------- */
void
BondHarmonic
::
read_restart
(
FILE
*
fp
)
{
allocate
();
if
(
comm
->
me
==
0
)
{
fread
(
&
k
[
1
],
sizeof
(
double
),
atom
->
nbondtypes
,
fp
);
fread
(
&
r0
[
1
],
sizeof
(
double
),
atom
->
nbondtypes
,
fp
);
}
MPI_Bcast
(
&
k
[
1
],
atom
->
nbondtypes
,
MPI_DOUBLE
,
0
,
world
);
MPI_Bcast
(
&
r0
[
1
],
atom
->
nbondtypes
,
MPI_DOUBLE
,
0
,
world
);
for
(
int
i
=
1
;
i
<=
atom
->
nbondtypes
;
i
++
)
setflag
[
i
]
=
1
;
}
/* ----------------------------------------------------------------------
proc 0 writes to data file
------------------------------------------------------------------------- */
void
BondHarmonic
::
write_data
(
FILE
*
fp
)
{
for
(
int
i
=
1
;
i
<=
atom
->
nbondtypes
;
i
++
)
fprintf
(
fp
,
"%d %g %g
\n
"
,
i
,
k
[
i
],
r0
[
i
]);
}
/* ---------------------------------------------------------------------- */
double
BondHarmonic
::
single
(
int
type
,
double
rsq
,
int
i
,
int
j
,
double
&
fforce
)
{
double
r
=
sqrt
(
rsq
);
double
dr
=
r
-
r0
[
type
];
double
rk
=
k
[
type
]
*
dr
;
fforce
=
0
;
if
(
r
>
0.0
)
fforce
=
-
2.0
*
rk
/
r
;
return
rk
*
dr
;
}
/* ----------------------------------------------------------------------
Return ptr to internal members upon request.
------------------------------------------------------------------------ */
void
*
BondHarmonic
::
extract
(
char
*
str
,
int
&
dim
)
{
dim
=
1
;
if
(
strcmp
(
str
,
"kappa"
)
==
0
)
return
(
void
*
)
k
;
if
(
strcmp
(
str
,
"r0"
)
==
0
)
return
(
void
*
)
r0
;
return
NULL
;
}
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