Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
tsoc
openmm
Commits
4bc723ab
Commit
4bc723ab
authored
Jun 06, 2012
by
Peter Eastman
Browse files
Implemented updateParametersInContext() for seven more Force classes
parent
b5e2a951
Changes
51
Show whitespace changes
Inline
Side-by-side
Showing
20 changed files
with
547 additions
and
30 deletions
+547
-30
openmmapi/src/CustomTorsionForceImpl.cpp
openmmapi/src/CustomTorsionForceImpl.cpp
+4
-1
openmmapi/src/HarmonicAngleForce.cpp
openmmapi/src/HarmonicAngleForce.cpp
+4
-0
openmmapi/src/HarmonicAngleForceImpl.cpp
openmmapi/src/HarmonicAngleForceImpl.cpp
+5
-1
openmmapi/src/HarmonicBondForce.cpp
openmmapi/src/HarmonicBondForce.cpp
+5
-1
openmmapi/src/HarmonicBondForceImpl.cpp
openmmapi/src/HarmonicBondForceImpl.cpp
+5
-1
openmmapi/src/PeriodicTorsionForce.cpp
openmmapi/src/PeriodicTorsionForce.cpp
+5
-1
openmmapi/src/PeriodicTorsionForceImpl.cpp
openmmapi/src/PeriodicTorsionForceImpl.cpp
+5
-1
openmmapi/src/RBTorsionForce.cpp
openmmapi/src/RBTorsionForce.cpp
+5
-1
openmmapi/src/RBTorsionForceImpl.cpp
openmmapi/src/RBTorsionForceImpl.cpp
+5
-1
platforms/cuda/src/CudaKernels.cpp
platforms/cuda/src/CudaKernels.cpp
+28
-0
platforms/cuda/src/CudaKernels.h
platforms/cuda/src/CudaKernels.h
+49
-0
platforms/opencl/src/OpenCLKernels.cpp
platforms/opencl/src/OpenCLKernels.cpp
+167
-1
platforms/opencl/src/OpenCLKernels.h
platforms/opencl/src/OpenCLKernels.h
+49
-0
platforms/opencl/src/OpenCLParallelKernels.cpp
platforms/opencl/src/OpenCLParallelKernels.cpp
+35
-0
platforms/opencl/src/OpenCLParallelKernels.h
platforms/opencl/src/OpenCLParallelKernels.h
+49
-0
platforms/opencl/tests/TestOpenCLCustomAngleForce.cpp
platforms/opencl/tests/TestOpenCLCustomAngleForce.cpp
+29
-4
platforms/opencl/tests/TestOpenCLCustomBondForce.cpp
platforms/opencl/tests/TestOpenCLCustomBondForce.cpp
+25
-5
platforms/opencl/tests/TestOpenCLCustomTorsionForce.cpp
platforms/opencl/tests/TestOpenCLCustomTorsionForce.cpp
+25
-0
platforms/opencl/tests/TestOpenCLHarmonicAngleForce.cpp
platforms/opencl/tests/TestOpenCLHarmonicAngleForce.cpp
+27
-7
platforms/opencl/tests/TestOpenCLHarmonicBondForce.cpp
platforms/opencl/tests/TestOpenCLHarmonicBondForce.cpp
+21
-5
No files found.
openmmapi/src/CustomTorsionForceImpl.cpp
View file @
4bc723ab
...
@@ -6,7 +6,7 @@
...
@@ -6,7 +6,7 @@
* Biological Structures at Stanford, funded under the NIH Roadmap for *
* Biological Structures at Stanford, funded under the NIH Roadmap for *
* Medical Research, grant U54 GM072970. See https://simtk.org. *
* Medical Research, grant U54 GM072970. See https://simtk.org. *
* *
* *
* Portions copyright (c) 2010 Stanford University and the Authors.
*
* Portions copyright (c) 2010
-2012
Stanford University and the Authors. *
* Authors: Peter Eastman *
* Authors: Peter Eastman *
* Contributors: *
* Contributors: *
* *
* *
...
@@ -113,3 +113,6 @@ map<string, double> CustomTorsionForceImpl::getDefaultParameters() {
...
@@ -113,3 +113,6 @@ map<string, double> CustomTorsionForceImpl::getDefaultParameters() {
return
parameters
;
return
parameters
;
}
}
void
CustomTorsionForceImpl
::
updateParametersInContext
(
ContextImpl
&
context
)
{
kernel
.
getAs
<
CalcCustomTorsionForceKernel
>
().
copyParametersToContext
(
context
,
owner
);
}
openmmapi/src/HarmonicAngleForce.cpp
View file @
4bc723ab
...
@@ -66,3 +66,7 @@ void HarmonicAngleForce::setAngleParameters(int index, int particle1, int partic
...
@@ -66,3 +66,7 @@ void HarmonicAngleForce::setAngleParameters(int index, int particle1, int partic
ForceImpl
*
HarmonicAngleForce
::
createImpl
()
{
ForceImpl
*
HarmonicAngleForce
::
createImpl
()
{
return
new
HarmonicAngleForceImpl
(
*
this
);
return
new
HarmonicAngleForceImpl
(
*
this
);
}
}
void
HarmonicAngleForce
::
updateParametersInContext
(
Context
&
context
)
{
dynamic_cast
<
HarmonicAngleForceImpl
&>
(
getImplInContext
(
context
)).
updateParametersInContext
(
getContextImpl
(
context
));
}
openmmapi/src/HarmonicAngleForceImpl.cpp
View file @
4bc723ab
...
@@ -6,7 +6,7 @@
...
@@ -6,7 +6,7 @@
* Biological Structures at Stanford, funded under the NIH Roadmap for *
* Biological Structures at Stanford, funded under the NIH Roadmap for *
* Medical Research, grant U54 GM072970. See https://simtk.org. *
* Medical Research, grant U54 GM072970. See https://simtk.org. *
* *
* *
* Portions copyright (c) 2008 Stanford University and the Authors.
*
* Portions copyright (c) 2008
-2012
Stanford University and the Authors. *
* Authors: Peter Eastman *
* Authors: Peter Eastman *
* Contributors: *
* Contributors: *
* *
* *
...
@@ -60,3 +60,7 @@ std::vector<std::string> HarmonicAngleForceImpl::getKernelNames() {
...
@@ -60,3 +60,7 @@ std::vector<std::string> HarmonicAngleForceImpl::getKernelNames() {
names
.
push_back
(
CalcHarmonicAngleForceKernel
::
Name
());
names
.
push_back
(
CalcHarmonicAngleForceKernel
::
Name
());
return
names
;
return
names
;
}
}
void
HarmonicAngleForceImpl
::
updateParametersInContext
(
ContextImpl
&
context
)
{
kernel
.
getAs
<
CalcHarmonicAngleForceKernel
>
().
copyParametersToContext
(
context
,
owner
);
}
openmmapi/src/HarmonicBondForce.cpp
View file @
4bc723ab
...
@@ -6,7 +6,7 @@
...
@@ -6,7 +6,7 @@
* Biological Structures at Stanford, funded under the NIH Roadmap for *
* Biological Structures at Stanford, funded under the NIH Roadmap for *
* Medical Research, grant U54 GM072970. See https://simtk.org. *
* Medical Research, grant U54 GM072970. See https://simtk.org. *
* *
* *
* Portions copyright (c) 2008-20
09
Stanford University and the Authors. *
* Portions copyright (c) 2008-20
12
Stanford University and the Authors. *
* Authors: Peter Eastman *
* Authors: Peter Eastman *
* Contributors: *
* Contributors: *
* *
* *
...
@@ -64,3 +64,7 @@ void HarmonicBondForce::setBondParameters(int index, int particle1, int particle
...
@@ -64,3 +64,7 @@ void HarmonicBondForce::setBondParameters(int index, int particle1, int particle
ForceImpl
*
HarmonicBondForce
::
createImpl
()
{
ForceImpl
*
HarmonicBondForce
::
createImpl
()
{
return
new
HarmonicBondForceImpl
(
*
this
);
return
new
HarmonicBondForceImpl
(
*
this
);
}
}
void
HarmonicBondForce
::
updateParametersInContext
(
Context
&
context
)
{
dynamic_cast
<
HarmonicBondForceImpl
&>
(
getImplInContext
(
context
)).
updateParametersInContext
(
getContextImpl
(
context
));
}
openmmapi/src/HarmonicBondForceImpl.cpp
View file @
4bc723ab
...
@@ -6,7 +6,7 @@
...
@@ -6,7 +6,7 @@
* Biological Structures at Stanford, funded under the NIH Roadmap for *
* Biological Structures at Stanford, funded under the NIH Roadmap for *
* Medical Research, grant U54 GM072970. See https://simtk.org. *
* Medical Research, grant U54 GM072970. See https://simtk.org. *
* *
* *
* Portions copyright (c) 2008 Stanford University and the Authors.
*
* Portions copyright (c) 2008
-2012
Stanford University and the Authors. *
* Authors: Peter Eastman *
* Authors: Peter Eastman *
* Contributors: *
* Contributors: *
* *
* *
...
@@ -70,3 +70,7 @@ vector<pair<int, int> > HarmonicBondForceImpl::getBondedParticles() const {
...
@@ -70,3 +70,7 @@ vector<pair<int, int> > HarmonicBondForceImpl::getBondedParticles() const {
}
}
return
bonds
;
return
bonds
;
}
}
void
HarmonicBondForceImpl
::
updateParametersInContext
(
ContextImpl
&
context
)
{
kernel
.
getAs
<
CalcHarmonicBondForceKernel
>
().
copyParametersToContext
(
context
,
owner
);
}
openmmapi/src/PeriodicTorsionForce.cpp
View file @
4bc723ab
...
@@ -6,7 +6,7 @@
...
@@ -6,7 +6,7 @@
* Biological Structures at Stanford, funded under the NIH Roadmap for *
* Biological Structures at Stanford, funded under the NIH Roadmap for *
* Medical Research, grant U54 GM072970. See https://simtk.org. *
* Medical Research, grant U54 GM072970. See https://simtk.org. *
* *
* *
* Portions copyright (c) 2008-20
09
Stanford University and the Authors. *
* Portions copyright (c) 2008-20
12
Stanford University and the Authors. *
* Authors: Peter Eastman *
* Authors: Peter Eastman *
* Contributors: *
* Contributors: *
* *
* *
...
@@ -70,3 +70,7 @@ void PeriodicTorsionForce::setTorsionParameters(int index, int particle1, int pa
...
@@ -70,3 +70,7 @@ void PeriodicTorsionForce::setTorsionParameters(int index, int particle1, int pa
ForceImpl
*
PeriodicTorsionForce
::
createImpl
()
{
ForceImpl
*
PeriodicTorsionForce
::
createImpl
()
{
return
new
PeriodicTorsionForceImpl
(
*
this
);
return
new
PeriodicTorsionForceImpl
(
*
this
);
}
}
void
PeriodicTorsionForce
::
updateParametersInContext
(
Context
&
context
)
{
dynamic_cast
<
PeriodicTorsionForceImpl
&>
(
getImplInContext
(
context
)).
updateParametersInContext
(
getContextImpl
(
context
));
}
openmmapi/src/PeriodicTorsionForceImpl.cpp
View file @
4bc723ab
...
@@ -6,7 +6,7 @@
...
@@ -6,7 +6,7 @@
* Biological Structures at Stanford, funded under the NIH Roadmap for *
* Biological Structures at Stanford, funded under the NIH Roadmap for *
* Medical Research, grant U54 GM072970. See https://simtk.org. *
* Medical Research, grant U54 GM072970. See https://simtk.org. *
* *
* *
* Portions copyright (c) 2008 Stanford University and the Authors.
*
* Portions copyright (c) 2008
-2012
Stanford University and the Authors. *
* Authors: Peter Eastman *
* Authors: Peter Eastman *
* Contributors: *
* Contributors: *
* *
* *
...
@@ -60,3 +60,7 @@ std::vector<std::string> PeriodicTorsionForceImpl::getKernelNames() {
...
@@ -60,3 +60,7 @@ std::vector<std::string> PeriodicTorsionForceImpl::getKernelNames() {
names
.
push_back
(
CalcPeriodicTorsionForceKernel
::
Name
());
names
.
push_back
(
CalcPeriodicTorsionForceKernel
::
Name
());
return
names
;
return
names
;
}
}
void
PeriodicTorsionForceImpl
::
updateParametersInContext
(
ContextImpl
&
context
)
{
kernel
.
getAs
<
CalcPeriodicTorsionForceKernel
>
().
copyParametersToContext
(
context
,
owner
);
}
openmmapi/src/RBTorsionForce.cpp
View file @
4bc723ab
...
@@ -6,7 +6,7 @@
...
@@ -6,7 +6,7 @@
* Biological Structures at Stanford, funded under the NIH Roadmap for *
* Biological Structures at Stanford, funded under the NIH Roadmap for *
* Medical Research, grant U54 GM072970. See https://simtk.org. *
* Medical Research, grant U54 GM072970. See https://simtk.org. *
* *
* *
* Portions copyright (c) 2008-20
09
Stanford University and the Authors. *
* Portions copyright (c) 2008-20
12
Stanford University and the Authors. *
* Authors: Peter Eastman *
* Authors: Peter Eastman *
* Contributors: *
* Contributors: *
* *
* *
...
@@ -76,3 +76,7 @@ void RBTorsionForce::setTorsionParameters(int index, int particle1, int particle
...
@@ -76,3 +76,7 @@ void RBTorsionForce::setTorsionParameters(int index, int particle1, int particle
ForceImpl
*
RBTorsionForce
::
createImpl
()
{
ForceImpl
*
RBTorsionForce
::
createImpl
()
{
return
new
RBTorsionForceImpl
(
*
this
);
return
new
RBTorsionForceImpl
(
*
this
);
}
}
void
RBTorsionForce
::
updateParametersInContext
(
Context
&
context
)
{
dynamic_cast
<
RBTorsionForceImpl
&>
(
getImplInContext
(
context
)).
updateParametersInContext
(
getContextImpl
(
context
));
}
openmmapi/src/RBTorsionForceImpl.cpp
View file @
4bc723ab
...
@@ -6,7 +6,7 @@
...
@@ -6,7 +6,7 @@
* Biological Structures at Stanford, funded under the NIH Roadmap for *
* Biological Structures at Stanford, funded under the NIH Roadmap for *
* Medical Research, grant U54 GM072970. See https://simtk.org. *
* Medical Research, grant U54 GM072970. See https://simtk.org. *
* *
* *
* Portions copyright (c) 2008 Stanford University and the Authors.
*
* Portions copyright (c) 2008
-2012
Stanford University and the Authors. *
* Authors: Peter Eastman *
* Authors: Peter Eastman *
* Contributors: *
* Contributors: *
* *
* *
...
@@ -60,3 +60,7 @@ std::vector<std::string> RBTorsionForceImpl::getKernelNames() {
...
@@ -60,3 +60,7 @@ std::vector<std::string> RBTorsionForceImpl::getKernelNames() {
names
.
push_back
(
CalcRBTorsionForceKernel
::
Name
());
names
.
push_back
(
CalcRBTorsionForceKernel
::
Name
());
return
names
;
return
names
;
}
}
void
RBTorsionForceImpl
::
updateParametersInContext
(
ContextImpl
&
context
)
{
kernel
.
getAs
<
CalcRBTorsionForceKernel
>
().
copyParametersToContext
(
context
,
owner
);
}
platforms/cuda/src/CudaKernels.cpp
View file @
4bc723ab
...
@@ -255,6 +255,10 @@ double CudaCalcHarmonicBondForceKernel::execute(ContextImpl& context, bool inclu
...
@@ -255,6 +255,10 @@ double CudaCalcHarmonicBondForceKernel::execute(ContextImpl& context, bool inclu
return
0.0
;
return
0.0
;
}
}
void
CudaCalcHarmonicBondForceKernel
::
copyParametersToContext
(
ContextImpl
&
context
,
const
HarmonicBondForce
&
force
)
{
throw
OpenMMException
(
"CudaPlatform does not support copyParametersToContext"
);
}
class
CudaCalcCustomBondForceKernel
::
ForceInfo
:
public
CudaForceInfo
{
class
CudaCalcCustomBondForceKernel
::
ForceInfo
:
public
CudaForceInfo
{
public:
public:
ForceInfo
(
const
CustomBondForce
&
force
)
:
force
(
force
)
{
ForceInfo
(
const
CustomBondForce
&
force
)
:
force
(
force
)
{
...
@@ -327,6 +331,10 @@ void CudaCalcCustomBondForceKernel::updateGlobalParams(ContextImpl& context) {
...
@@ -327,6 +331,10 @@ void CudaCalcCustomBondForceKernel::updateGlobalParams(ContextImpl& context) {
SetCustomBondGlobalParams
(
globalParamValues
);
SetCustomBondGlobalParams
(
globalParamValues
);
}
}
void
CudaCalcCustomBondForceKernel
::
copyParametersToContext
(
ContextImpl
&
context
,
const
CustomBondForce
&
force
)
{
throw
OpenMMException
(
"CudaPlatform does not support copyParametersToContext"
);
}
class
CudaCalcHarmonicAngleForceKernel
::
ForceInfo
:
public
CudaForceInfo
{
class
CudaCalcHarmonicAngleForceKernel
::
ForceInfo
:
public
CudaForceInfo
{
public:
public:
ForceInfo
(
const
HarmonicAngleForce
&
force
)
:
force
(
force
)
{
ForceInfo
(
const
HarmonicAngleForce
&
force
)
:
force
(
force
)
{
...
@@ -380,6 +388,10 @@ double CudaCalcHarmonicAngleForceKernel::execute(ContextImpl& context, bool incl
...
@@ -380,6 +388,10 @@ double CudaCalcHarmonicAngleForceKernel::execute(ContextImpl& context, bool incl
return
0.0
;
return
0.0
;
}
}
void
CudaCalcHarmonicAngleForceKernel
::
copyParametersToContext
(
ContextImpl
&
context
,
const
HarmonicAngleForce
&
force
)
{
throw
OpenMMException
(
"CudaPlatform does not support copyParametersToContext"
);
}
class
CudaCalcCustomAngleForceKernel
::
ForceInfo
:
public
CudaForceInfo
{
class
CudaCalcCustomAngleForceKernel
::
ForceInfo
:
public
CudaForceInfo
{
public:
public:
ForceInfo
(
const
CustomAngleForce
&
force
)
:
force
(
force
)
{
ForceInfo
(
const
CustomAngleForce
&
force
)
:
force
(
force
)
{
...
@@ -454,6 +466,10 @@ void CudaCalcCustomAngleForceKernel::updateGlobalParams(ContextImpl& context) {
...
@@ -454,6 +466,10 @@ void CudaCalcCustomAngleForceKernel::updateGlobalParams(ContextImpl& context) {
SetCustomAngleGlobalParams
(
globalParamValues
);
SetCustomAngleGlobalParams
(
globalParamValues
);
}
}
void
CudaCalcCustomAngleForceKernel
::
copyParametersToContext
(
ContextImpl
&
context
,
const
CustomAngleForce
&
force
)
{
throw
OpenMMException
(
"CudaPlatform does not support copyParametersToContext"
);
}
class
CudaCalcPeriodicTorsionForceKernel
::
ForceInfo
:
public
CudaForceInfo
{
class
CudaCalcPeriodicTorsionForceKernel
::
ForceInfo
:
public
CudaForceInfo
{
public:
public:
ForceInfo
(
const
PeriodicTorsionForce
&
force
)
:
force
(
force
)
{
ForceInfo
(
const
PeriodicTorsionForce
&
force
)
:
force
(
force
)
{
...
@@ -510,6 +526,10 @@ double CudaCalcPeriodicTorsionForceKernel::execute(ContextImpl& context, bool in
...
@@ -510,6 +526,10 @@ double CudaCalcPeriodicTorsionForceKernel::execute(ContextImpl& context, bool in
return
0.0
;
return
0.0
;
}
}
void
CudaCalcPeriodicTorsionForceKernel
::
copyParametersToContext
(
ContextImpl
&
context
,
const
PeriodicTorsionForce
&
force
)
{
throw
OpenMMException
(
"CudaPlatform does not support copyParametersToContext"
);
}
class
CudaCalcRBTorsionForceKernel
::
ForceInfo
:
public
CudaForceInfo
{
class
CudaCalcRBTorsionForceKernel
::
ForceInfo
:
public
CudaForceInfo
{
public:
public:
ForceInfo
(
const
RBTorsionForce
&
force
)
:
force
(
force
)
{
ForceInfo
(
const
RBTorsionForce
&
force
)
:
force
(
force
)
{
...
@@ -572,6 +592,10 @@ double CudaCalcRBTorsionForceKernel::execute(ContextImpl& context, bool includeF
...
@@ -572,6 +592,10 @@ double CudaCalcRBTorsionForceKernel::execute(ContextImpl& context, bool includeF
return
0.0
;
return
0.0
;
}
}
void
CudaCalcRBTorsionForceKernel
::
copyParametersToContext
(
ContextImpl
&
context
,
const
RBTorsionForce
&
force
)
{
throw
OpenMMException
(
"CudaPlatform does not support copyParametersToContext"
);
}
class
CudaCalcCMAPTorsionForceKernel
::
ForceInfo
:
public
CudaForceInfo
{
class
CudaCalcCMAPTorsionForceKernel
::
ForceInfo
:
public
CudaForceInfo
{
public:
public:
ForceInfo
(
const
CMAPTorsionForce
&
force
)
:
force
(
force
)
{
ForceInfo
(
const
CMAPTorsionForce
&
force
)
:
force
(
force
)
{
...
@@ -746,6 +770,10 @@ void CudaCalcCustomTorsionForceKernel::updateGlobalParams(ContextImpl& context)
...
@@ -746,6 +770,10 @@ void CudaCalcCustomTorsionForceKernel::updateGlobalParams(ContextImpl& context)
SetCustomTorsionGlobalParams
(
globalParamValues
);
SetCustomTorsionGlobalParams
(
globalParamValues
);
}
}
void
CudaCalcCustomTorsionForceKernel
::
copyParametersToContext
(
ContextImpl
&
context
,
const
CustomTorsionForce
&
force
)
{
throw
OpenMMException
(
"CudaPlatform does not support copyParametersToContext"
);
}
class
CudaCalcNonbondedForceKernel
::
ForceInfo
:
public
CudaForceInfo
{
class
CudaCalcNonbondedForceKernel
::
ForceInfo
:
public
CudaForceInfo
{
public:
public:
ForceInfo
(
const
NonbondedForce
&
force
)
:
force
(
force
)
{
ForceInfo
(
const
NonbondedForce
&
force
)
:
force
(
force
)
{
...
...
platforms/cuda/src/CudaKernels.h
View file @
4bc723ab
...
@@ -242,6 +242,13 @@ public:
...
@@ -242,6 +242,13 @@ public:
* @return the potential energy due to the force
* @return the potential energy due to the force
*/
*/
double
execute
(
ContextImpl
&
context
,
bool
includeForces
,
bool
includeEnergy
);
double
execute
(
ContextImpl
&
context
,
bool
includeForces
,
bool
includeEnergy
);
/**
* Copy changed parameters over to a context.
*
* @param context the context to copy parameters to
* @param force the HarmonicBondForce to copy the parameters from
*/
void
copyParametersToContext
(
ContextImpl
&
context
,
const
HarmonicBondForce
&
force
);
private:
private:
class
ForceInfo
;
class
ForceInfo
;
int
numBonds
;
int
numBonds
;
...
@@ -274,6 +281,13 @@ public:
...
@@ -274,6 +281,13 @@ public:
* @return the potential energy due to the force
* @return the potential energy due to the force
*/
*/
double
execute
(
ContextImpl
&
context
,
bool
includeForces
,
bool
includeEnergy
);
double
execute
(
ContextImpl
&
context
,
bool
includeForces
,
bool
includeEnergy
);
/**
* Copy changed parameters over to a context.
*
* @param context the context to copy parameters to
* @param force the CustomBondForce to copy the parameters from
*/
void
copyParametersToContext
(
ContextImpl
&
context
,
const
CustomBondForce
&
force
);
private:
private:
class
ForceInfo
;
class
ForceInfo
;
void
updateGlobalParams
(
ContextImpl
&
context
);
void
updateGlobalParams
(
ContextImpl
&
context
);
...
@@ -308,6 +322,13 @@ public:
...
@@ -308,6 +322,13 @@ public:
* @return the potential energy due to the force
* @return the potential energy due to the force
*/
*/
double
execute
(
ContextImpl
&
context
,
bool
includeForces
,
bool
includeEnergy
);
double
execute
(
ContextImpl
&
context
,
bool
includeForces
,
bool
includeEnergy
);
/**
* Copy changed parameters over to a context.
*
* @param context the context to copy parameters to
* @param force the HarmonicAngleForce to copy the parameters from
*/
void
copyParametersToContext
(
ContextImpl
&
context
,
const
HarmonicAngleForce
&
force
);
private:
private:
class
ForceInfo
;
class
ForceInfo
;
int
numAngles
;
int
numAngles
;
...
@@ -340,6 +361,13 @@ public:
...
@@ -340,6 +361,13 @@ public:
* @return the potential energy due to the force
* @return the potential energy due to the force
*/
*/
double
execute
(
ContextImpl
&
context
,
bool
includeForces
,
bool
includeEnergy
);
double
execute
(
ContextImpl
&
context
,
bool
includeForces
,
bool
includeEnergy
);
/**
* Copy changed parameters over to a context.
*
* @param context the context to copy parameters to
* @param force the CustomAngleForce to copy the parameters from
*/
void
copyParametersToContext
(
ContextImpl
&
context
,
const
CustomAngleForce
&
force
);
private:
private:
class
ForceInfo
;
class
ForceInfo
;
void
updateGlobalParams
(
ContextImpl
&
context
);
void
updateGlobalParams
(
ContextImpl
&
context
);
...
@@ -374,6 +402,13 @@ public:
...
@@ -374,6 +402,13 @@ public:
* @return the potential energy due to the force
* @return the potential energy due to the force
*/
*/
double
execute
(
ContextImpl
&
context
,
bool
includeForces
,
bool
includeEnergy
);
double
execute
(
ContextImpl
&
context
,
bool
includeForces
,
bool
includeEnergy
);
/**
* Copy changed parameters over to a context.
*
* @param context the context to copy parameters to
* @param force the PeriodicTorsionForce to copy the parameters from
*/
void
copyParametersToContext
(
ContextImpl
&
context
,
const
PeriodicTorsionForce
&
force
);
private:
private:
class
ForceInfo
;
class
ForceInfo
;
int
numTorsions
;
int
numTorsions
;
...
@@ -405,6 +440,13 @@ public:
...
@@ -405,6 +440,13 @@ public:
* @return the potential energy due to the force
* @return the potential energy due to the force
*/
*/
double
execute
(
ContextImpl
&
context
,
bool
includeForces
,
bool
includeEnergy
);
double
execute
(
ContextImpl
&
context
,
bool
includeForces
,
bool
includeEnergy
);
/**
* Copy changed parameters over to a context.
*
* @param context the context to copy parameters to
* @param force the RBTorsionForce to copy the parameters from
*/
void
copyParametersToContext
(
ContextImpl
&
context
,
const
RBTorsionForce
&
force
);
private:
private:
class
ForceInfo
;
class
ForceInfo
;
int
numTorsions
;
int
numTorsions
;
...
@@ -474,6 +516,13 @@ public:
...
@@ -474,6 +516,13 @@ public:
* @return the potential energy due to the force
* @return the potential energy due to the force
*/
*/
double
execute
(
ContextImpl
&
context
,
bool
includeForces
,
bool
includeEnergy
);
double
execute
(
ContextImpl
&
context
,
bool
includeForces
,
bool
includeEnergy
);
/**
* Copy changed parameters over to a context.
*
* @param context the context to copy parameters to
* @param force the CustomTorsionForce to copy the parameters from
*/
void
copyParametersToContext
(
ContextImpl
&
context
,
const
CustomTorsionForce
&
force
);
private:
private:
class
ForceInfo
;
class
ForceInfo
;
void
updateGlobalParams
(
ContextImpl
&
context
);
void
updateGlobalParams
(
ContextImpl
&
context
);
...
...
platforms/opencl/src/OpenCLKernels.cpp
View file @
4bc723ab
...
@@ -351,6 +351,29 @@ double OpenCLCalcHarmonicBondForceKernel::execute(ContextImpl& context, bool inc
...
@@ -351,6 +351,29 @@ double OpenCLCalcHarmonicBondForceKernel::execute(ContextImpl& context, bool inc
return
0.0
;
return
0.0
;
}
}
void
OpenCLCalcHarmonicBondForceKernel
::
copyParametersToContext
(
ContextImpl
&
context
,
const
HarmonicBondForce
&
force
)
{
int
numContexts
=
cl
.
getPlatformData
().
contexts
.
size
();
int
startIndex
=
cl
.
getContextIndex
()
*
force
.
getNumBonds
()
/
numContexts
;
int
endIndex
=
(
cl
.
getContextIndex
()
+
1
)
*
force
.
getNumBonds
()
/
numContexts
;
if
(
numBonds
!=
endIndex
-
startIndex
)
throw
OpenMMException
(
"updateParametersInContext: The number of bonds has changed"
);
// Record the per-bond parameters.
vector
<
mm_float2
>
paramVector
(
numBonds
);
for
(
int
i
=
0
;
i
<
numBonds
;
i
++
)
{
int
atom1
,
atom2
;
double
length
,
k
;
force
.
getBondParameters
(
startIndex
+
i
,
atom1
,
atom2
,
length
,
k
);
paramVector
[
i
]
=
mm_float2
((
cl_float
)
length
,
(
cl_float
)
k
);
}
params
->
upload
(
paramVector
);
// Mark that the current reordering may be invalid.
cl
.
invalidateMolecules
();
}
class
OpenCLCustomBondForceInfo
:
public
OpenCLForceInfo
{
class
OpenCLCustomBondForceInfo
:
public
OpenCLForceInfo
{
public:
public:
OpenCLCustomBondForceInfo
(
const
CustomBondForce
&
force
)
:
OpenCLForceInfo
(
0
),
force
(
force
)
{
OpenCLCustomBondForceInfo
(
const
CustomBondForce
&
force
)
:
OpenCLForceInfo
(
0
),
force
(
force
)
{
...
@@ -467,6 +490,31 @@ double OpenCLCalcCustomBondForceKernel::execute(ContextImpl& context, bool inclu
...
@@ -467,6 +490,31 @@ double OpenCLCalcCustomBondForceKernel::execute(ContextImpl& context, bool inclu
return
0.0
;
return
0.0
;
}
}
void
OpenCLCalcCustomBondForceKernel
::
copyParametersToContext
(
ContextImpl
&
context
,
const
CustomBondForce
&
force
)
{
int
numContexts
=
cl
.
getPlatformData
().
contexts
.
size
();
int
startIndex
=
cl
.
getContextIndex
()
*
force
.
getNumBonds
()
/
numContexts
;
int
endIndex
=
(
cl
.
getContextIndex
()
+
1
)
*
force
.
getNumBonds
()
/
numContexts
;
if
(
numBonds
!=
endIndex
-
startIndex
)
throw
OpenMMException
(
"updateParametersInContext: The number of bonds has changed"
);
// Record the per-bond parameters.
vector
<
vector
<
cl_float
>
>
paramVector
(
numBonds
);
vector
<
double
>
parameters
;
for
(
int
i
=
0
;
i
<
numBonds
;
i
++
)
{
int
atom1
,
atom2
;
force
.
getBondParameters
(
startIndex
+
i
,
atom1
,
atom2
,
parameters
);
paramVector
[
i
].
resize
(
parameters
.
size
());
for
(
int
j
=
0
;
j
<
(
int
)
parameters
.
size
();
j
++
)
paramVector
[
i
][
j
]
=
(
cl_float
)
parameters
[
j
];
}
params
->
setParameterValues
(
paramVector
);
// Mark that the current reordering may be invalid.
cl
.
invalidateMolecules
();
}
class
OpenCLHarmonicAngleForceInfo
:
public
OpenCLForceInfo
{
class
OpenCLHarmonicAngleForceInfo
:
public
OpenCLForceInfo
{
public:
public:
OpenCLHarmonicAngleForceInfo
(
const
HarmonicAngleForce
&
force
)
:
OpenCLForceInfo
(
0
),
force
(
force
)
{
OpenCLHarmonicAngleForceInfo
(
const
HarmonicAngleForce
&
force
)
:
OpenCLForceInfo
(
0
),
force
(
force
)
{
...
@@ -527,6 +575,29 @@ double OpenCLCalcHarmonicAngleForceKernel::execute(ContextImpl& context, bool in
...
@@ -527,6 +575,29 @@ double OpenCLCalcHarmonicAngleForceKernel::execute(ContextImpl& context, bool in
return
0.0
;
return
0.0
;
}
}
void
OpenCLCalcHarmonicAngleForceKernel
::
copyParametersToContext
(
ContextImpl
&
context
,
const
HarmonicAngleForce
&
force
)
{
int
numContexts
=
cl
.
getPlatformData
().
contexts
.
size
();
int
startIndex
=
cl
.
getContextIndex
()
*
force
.
getNumAngles
()
/
numContexts
;
int
endIndex
=
(
cl
.
getContextIndex
()
+
1
)
*
force
.
getNumAngles
()
/
numContexts
;
if
(
numAngles
!=
endIndex
-
startIndex
)
throw
OpenMMException
(
"updateParametersInContext: The number of angles has changed"
);
// Record the per-angle parameters.
vector
<
mm_float2
>
paramVector
(
numAngles
);
for
(
int
i
=
0
;
i
<
numAngles
;
i
++
)
{
int
atom1
,
atom2
,
atom3
;
double
angle
,
k
;
force
.
getAngleParameters
(
startIndex
+
i
,
atom1
,
atom2
,
atom3
,
angle
,
k
);
paramVector
[
i
]
=
mm_float2
((
cl_float
)
angle
,
(
cl_float
)
k
);
}
params
->
upload
(
paramVector
);
// Mark that the current reordering may be invalid.
cl
.
invalidateMolecules
();
}
class
OpenCLCustomAngleForceInfo
:
public
OpenCLForceInfo
{
class
OpenCLCustomAngleForceInfo
:
public
OpenCLForceInfo
{
public:
public:
OpenCLCustomAngleForceInfo
(
const
CustomAngleForce
&
force
)
:
OpenCLForceInfo
(
0
),
force
(
force
)
{
OpenCLCustomAngleForceInfo
(
const
CustomAngleForce
&
force
)
:
OpenCLForceInfo
(
0
),
force
(
force
)
{
...
@@ -644,6 +715,31 @@ double OpenCLCalcCustomAngleForceKernel::execute(ContextImpl& context, bool incl
...
@@ -644,6 +715,31 @@ double OpenCLCalcCustomAngleForceKernel::execute(ContextImpl& context, bool incl
return
0.0
;
return
0.0
;
}
}
void
OpenCLCalcCustomAngleForceKernel
::
copyParametersToContext
(
ContextImpl
&
context
,
const
CustomAngleForce
&
force
)
{
int
numContexts
=
cl
.
getPlatformData
().
contexts
.
size
();
int
startIndex
=
cl
.
getContextIndex
()
*
force
.
getNumAngles
()
/
numContexts
;
int
endIndex
=
(
cl
.
getContextIndex
()
+
1
)
*
force
.
getNumAngles
()
/
numContexts
;
if
(
numAngles
!=
endIndex
-
startIndex
)
throw
OpenMMException
(
"updateParametersInContext: The number of angles has changed"
);
// Record the per-angle parameters.
vector
<
vector
<
cl_float
>
>
paramVector
(
numAngles
);
vector
<
double
>
parameters
;
for
(
int
i
=
0
;
i
<
numAngles
;
i
++
)
{
int
atom1
,
atom2
,
atom3
;
force
.
getAngleParameters
(
startIndex
+
i
,
atom1
,
atom2
,
atom3
,
parameters
);
paramVector
[
i
].
resize
(
parameters
.
size
());
for
(
int
j
=
0
;
j
<
(
int
)
parameters
.
size
();
j
++
)
paramVector
[
i
][
j
]
=
(
cl_float
)
parameters
[
j
];
}
params
->
setParameterValues
(
paramVector
);
// Mark that the current reordering may be invalid.
cl
.
invalidateMolecules
();
}
class
OpenCLPeriodicTorsionForceInfo
:
public
OpenCLForceInfo
{
class
OpenCLPeriodicTorsionForceInfo
:
public
OpenCLForceInfo
{
public:
public:
OpenCLPeriodicTorsionForceInfo
(
const
PeriodicTorsionForce
&
force
)
:
OpenCLForceInfo
(
0
),
force
(
force
)
{
OpenCLPeriodicTorsionForceInfo
(
const
PeriodicTorsionForce
&
force
)
:
OpenCLForceInfo
(
0
),
force
(
force
)
{
...
@@ -692,7 +788,6 @@ void OpenCLCalcPeriodicTorsionForceKernel::initialize(const System& system, cons
...
@@ -692,7 +788,6 @@ void OpenCLCalcPeriodicTorsionForceKernel::initialize(const System& system, cons
double
phase
,
k
;
double
phase
,
k
;
force
.
getTorsionParameters
(
startIndex
+
i
,
atoms
[
i
][
0
],
atoms
[
i
][
1
],
atoms
[
i
][
2
],
atoms
[
i
][
3
],
periodicity
,
phase
,
k
);
force
.
getTorsionParameters
(
startIndex
+
i
,
atoms
[
i
][
0
],
atoms
[
i
][
1
],
atoms
[
i
][
2
],
atoms
[
i
][
3
],
periodicity
,
phase
,
k
);
paramVector
[
i
]
=
mm_float4
((
cl_float
)
k
,
(
cl_float
)
phase
,
(
cl_float
)
periodicity
,
0.0
f
);
paramVector
[
i
]
=
mm_float4
((
cl_float
)
k
,
(
cl_float
)
phase
,
(
cl_float
)
periodicity
,
0.0
f
);
}
}
params
->
upload
(
paramVector
);
params
->
upload
(
paramVector
);
map
<
string
,
string
>
replacements
;
map
<
string
,
string
>
replacements
;
...
@@ -706,6 +801,29 @@ double OpenCLCalcPeriodicTorsionForceKernel::execute(ContextImpl& context, bool
...
@@ -706,6 +801,29 @@ double OpenCLCalcPeriodicTorsionForceKernel::execute(ContextImpl& context, bool
return
0.0
;
return
0.0
;
}
}
void
OpenCLCalcPeriodicTorsionForceKernel
::
copyParametersToContext
(
ContextImpl
&
context
,
const
PeriodicTorsionForce
&
force
)
{
int
numContexts
=
cl
.
getPlatformData
().
contexts
.
size
();
int
startIndex
=
cl
.
getContextIndex
()
*
force
.
getNumTorsions
()
/
numContexts
;
int
endIndex
=
(
cl
.
getContextIndex
()
+
1
)
*
force
.
getNumTorsions
()
/
numContexts
;
if
(
numTorsions
!=
endIndex
-
startIndex
)
throw
OpenMMException
(
"updateParametersInContext: The number of torsions has changed"
);
// Record the per-torsion parameters.
vector
<
mm_float4
>
paramVector
(
numTorsions
);
for
(
int
i
=
0
;
i
<
numTorsions
;
i
++
)
{
int
atom1
,
atom2
,
atom3
,
atom4
,
periodicity
;
double
phase
,
k
;
force
.
getTorsionParameters
(
startIndex
+
i
,
atom1
,
atom2
,
atom3
,
atom4
,
periodicity
,
phase
,
k
);
paramVector
[
i
]
=
mm_float4
((
cl_float
)
k
,
(
cl_float
)
phase
,
(
cl_float
)
periodicity
,
0.0
f
);
}
params
->
upload
(
paramVector
);
// Mark that the current reordering may be invalid.
cl
.
invalidateMolecules
();
}
class
OpenCLRBTorsionForceInfo
:
public
OpenCLForceInfo
{
class
OpenCLRBTorsionForceInfo
:
public
OpenCLForceInfo
{
public:
public:
OpenCLRBTorsionForceInfo
(
const
RBTorsionForce
&
force
)
:
OpenCLForceInfo
(
0
),
force
(
force
)
{
OpenCLRBTorsionForceInfo
(
const
RBTorsionForce
&
force
)
:
OpenCLForceInfo
(
0
),
force
(
force
)
{
...
@@ -767,6 +885,29 @@ double OpenCLCalcRBTorsionForceKernel::execute(ContextImpl& context, bool includ
...
@@ -767,6 +885,29 @@ double OpenCLCalcRBTorsionForceKernel::execute(ContextImpl& context, bool includ
return
0.0
;
return
0.0
;
}
}
void
OpenCLCalcRBTorsionForceKernel
::
copyParametersToContext
(
ContextImpl
&
context
,
const
RBTorsionForce
&
force
)
{
int
numContexts
=
cl
.
getPlatformData
().
contexts
.
size
();
int
startIndex
=
cl
.
getContextIndex
()
*
force
.
getNumTorsions
()
/
numContexts
;
int
endIndex
=
(
cl
.
getContextIndex
()
+
1
)
*
force
.
getNumTorsions
()
/
numContexts
;
if
(
numTorsions
!=
endIndex
-
startIndex
)
throw
OpenMMException
(
"updateParametersInContext: The number of torsions has changed"
);
// Record the per-torsion parameters.
vector
<
mm_float8
>
paramVector
(
numTorsions
);
for
(
int
i
=
0
;
i
<
numTorsions
;
i
++
)
{
int
atom1
,
atom2
,
atom3
,
atom4
;
double
c0
,
c1
,
c2
,
c3
,
c4
,
c5
;
force
.
getTorsionParameters
(
startIndex
+
i
,
atom1
,
atom2
,
atom3
,
atom4
,
c0
,
c1
,
c2
,
c3
,
c4
,
c5
);
paramVector
[
i
]
=
mm_float8
((
cl_float
)
c0
,
(
cl_float
)
c1
,
(
cl_float
)
c2
,
(
cl_float
)
c3
,
(
cl_float
)
c4
,
(
cl_float
)
c5
,
0.0
f
,
0.0
f
);
}
params
->
upload
(
paramVector
);
// Mark that the current reordering may be invalid.
cl
.
invalidateMolecules
();
}
class
OpenCLCMAPTorsionForceInfo
:
public
OpenCLForceInfo
{
class
OpenCLCMAPTorsionForceInfo
:
public
OpenCLForceInfo
{
public:
public:
OpenCLCMAPTorsionForceInfo
(
const
CMAPTorsionForce
&
force
)
:
OpenCLForceInfo
(
0
),
force
(
force
)
{
OpenCLCMAPTorsionForceInfo
(
const
CMAPTorsionForce
&
force
)
:
OpenCLForceInfo
(
0
),
force
(
force
)
{
...
@@ -972,6 +1113,31 @@ double OpenCLCalcCustomTorsionForceKernel::execute(ContextImpl& context, bool in
...
@@ -972,6 +1113,31 @@ double OpenCLCalcCustomTorsionForceKernel::execute(ContextImpl& context, bool in
return
0.0
;
return
0.0
;
}
}
void
OpenCLCalcCustomTorsionForceKernel
::
copyParametersToContext
(
ContextImpl
&
context
,
const
CustomTorsionForce
&
force
)
{
int
numContexts
=
cl
.
getPlatformData
().
contexts
.
size
();
int
startIndex
=
cl
.
getContextIndex
()
*
force
.
getNumTorsions
()
/
numContexts
;
int
endIndex
=
(
cl
.
getContextIndex
()
+
1
)
*
force
.
getNumTorsions
()
/
numContexts
;
if
(
numTorsions
!=
endIndex
-
startIndex
)
throw
OpenMMException
(
"updateParametersInContext: The number of torsions has changed"
);
// Record the per-torsion parameters.
vector
<
vector
<
cl_float
>
>
paramVector
(
numTorsions
);
vector
<
double
>
parameters
;
for
(
int
i
=
0
;
i
<
numTorsions
;
i
++
)
{
int
atom1
,
atom2
,
atom3
,
atom4
;
force
.
getTorsionParameters
(
startIndex
+
i
,
atom1
,
atom2
,
atom3
,
atom4
,
parameters
);
paramVector
[
i
].
resize
(
parameters
.
size
());
for
(
int
j
=
0
;
j
<
(
int
)
parameters
.
size
();
j
++
)
paramVector
[
i
][
j
]
=
(
cl_float
)
parameters
[
j
];
}
params
->
setParameterValues
(
paramVector
);
// Mark that the current reordering may be invalid.
cl
.
invalidateMolecules
();
}
class
OpenCLNonbondedForceInfo
:
public
OpenCLForceInfo
{
class
OpenCLNonbondedForceInfo
:
public
OpenCLForceInfo
{
public:
public:
OpenCLNonbondedForceInfo
(
int
requiredBuffers
,
const
NonbondedForce
&
force
)
:
OpenCLForceInfo
(
requiredBuffers
),
force
(
force
)
{
OpenCLNonbondedForceInfo
(
int
requiredBuffers
,
const
NonbondedForce
&
force
)
:
OpenCLForceInfo
(
requiredBuffers
),
force
(
force
)
{
...
...
platforms/opencl/src/OpenCLKernels.h
View file @
4bc723ab
...
@@ -243,6 +243,13 @@ public:
...
@@ -243,6 +243,13 @@ public:
* @return the potential energy due to the force
* @return the potential energy due to the force
*/
*/
double
execute
(
ContextImpl
&
context
,
bool
includeForces
,
bool
includeEnergy
);
double
execute
(
ContextImpl
&
context
,
bool
includeForces
,
bool
includeEnergy
);
/**
* Copy changed parameters over to a context.
*
* @param context the context to copy parameters to
* @param force the HarmonicBondForce to copy the parameters from
*/
void
copyParametersToContext
(
ContextImpl
&
context
,
const
HarmonicBondForce
&
force
);
private:
private:
int
numBonds
;
int
numBonds
;
bool
hasInitializedKernel
;
bool
hasInitializedKernel
;
...
@@ -276,6 +283,13 @@ public:
...
@@ -276,6 +283,13 @@ public:
* @return the potential energy due to the force
* @return the potential energy due to the force
*/
*/
double
execute
(
ContextImpl
&
context
,
bool
includeForces
,
bool
includeEnergy
);
double
execute
(
ContextImpl
&
context
,
bool
includeForces
,
bool
includeEnergy
);
/**
* Copy changed parameters over to a context.
*
* @param context the context to copy parameters to
* @param force the CustomBondForce to copy the parameters from
*/
void
copyParametersToContext
(
ContextImpl
&
context
,
const
CustomBondForce
&
force
);
private:
private:
int
numBonds
;
int
numBonds
;
bool
hasInitializedKernel
;
bool
hasInitializedKernel
;
...
@@ -312,6 +326,13 @@ public:
...
@@ -312,6 +326,13 @@ public:
* @return the potential energy due to the force
* @return the potential energy due to the force
*/
*/
double
execute
(
ContextImpl
&
context
,
bool
includeForces
,
bool
includeEnergy
);
double
execute
(
ContextImpl
&
context
,
bool
includeForces
,
bool
includeEnergy
);
/**
* Copy changed parameters over to a context.
*
* @param context the context to copy parameters to
* @param force the HarmonicAngleForce to copy the parameters from
*/
void
copyParametersToContext
(
ContextImpl
&
context
,
const
HarmonicAngleForce
&
force
);
private:
private:
int
numAngles
;
int
numAngles
;
bool
hasInitializedKernel
;
bool
hasInitializedKernel
;
...
@@ -345,6 +366,13 @@ public:
...
@@ -345,6 +366,13 @@ public:
* @return the potential energy due to the force
* @return the potential energy due to the force
*/
*/
double
execute
(
ContextImpl
&
context
,
bool
includeForces
,
bool
includeEnergy
);
double
execute
(
ContextImpl
&
context
,
bool
includeForces
,
bool
includeEnergy
);
/**
* Copy changed parameters over to a context.
*
* @param context the context to copy parameters to
* @param force the CustomAngleForce to copy the parameters from
*/
void
copyParametersToContext
(
ContextImpl
&
context
,
const
CustomAngleForce
&
force
);
private:
private:
int
numAngles
;
int
numAngles
;
bool
hasInitializedKernel
;
bool
hasInitializedKernel
;
...
@@ -381,6 +409,13 @@ public:
...
@@ -381,6 +409,13 @@ public:
* @return the potential energy due to the force
* @return the potential energy due to the force
*/
*/
double
execute
(
ContextImpl
&
context
,
bool
includeForces
,
bool
includeEnergy
);
double
execute
(
ContextImpl
&
context
,
bool
includeForces
,
bool
includeEnergy
);
/**
* Copy changed parameters over to a context.
*
* @param context the context to copy parameters to
* @param force the PeriodicTorsionForce to copy the parameters from
*/
void
copyParametersToContext
(
ContextImpl
&
context
,
const
PeriodicTorsionForce
&
force
);
private:
private:
int
numTorsions
;
int
numTorsions
;
bool
hasInitializedKernel
;
bool
hasInitializedKernel
;
...
@@ -414,6 +449,13 @@ public:
...
@@ -414,6 +449,13 @@ public:
* @return the potential energy due to the force
* @return the potential energy due to the force
*/
*/
double
execute
(
ContextImpl
&
context
,
bool
includeForces
,
bool
includeEnergy
);
double
execute
(
ContextImpl
&
context
,
bool
includeForces
,
bool
includeEnergy
);
/**
* Copy changed parameters over to a context.
*
* @param context the context to copy parameters to
* @param force the RBTorsionForce to copy the parameters from
*/
void
copyParametersToContext
(
ContextImpl
&
context
,
const
RBTorsionForce
&
force
);
private:
private:
int
numTorsions
;
int
numTorsions
;
bool
hasInitializedKernel
;
bool
hasInitializedKernel
;
...
@@ -482,6 +524,13 @@ public:
...
@@ -482,6 +524,13 @@ public:
* @return the potential energy due to the force
* @return the potential energy due to the force
*/
*/
double
execute
(
ContextImpl
&
context
,
bool
includeForces
,
bool
includeEnergy
);
double
execute
(
ContextImpl
&
context
,
bool
includeForces
,
bool
includeEnergy
);
/**
* Copy changed parameters over to a context.
*
* @param context the context to copy parameters to
* @param force the CustomTorsionForce to copy the parameters from
*/
void
copyParametersToContext
(
ContextImpl
&
context
,
const
CustomTorsionForce
&
force
);
private:
private:
int
numTorsions
;
int
numTorsions
;
bool
hasInitializedKernel
;
bool
hasInitializedKernel
;
...
...
platforms/opencl/src/OpenCLParallelKernels.cpp
View file @
4bc723ab
...
@@ -234,6 +234,11 @@ double OpenCLParallelCalcHarmonicBondForceKernel::execute(ContextImpl& context,
...
@@ -234,6 +234,11 @@ double OpenCLParallelCalcHarmonicBondForceKernel::execute(ContextImpl& context,
return
0.0
;
return
0.0
;
}
}
void
OpenCLParallelCalcHarmonicBondForceKernel
::
copyParametersToContext
(
ContextImpl
&
context
,
const
HarmonicBondForce
&
force
)
{
for
(
int
i
=
0
;
i
<
(
int
)
kernels
.
size
();
i
++
)
getKernel
(
i
).
copyParametersToContext
(
context
,
force
);
}
class
OpenCLParallelCalcCustomBondForceKernel
::
Task
:
public
OpenCLContext
::
WorkTask
{
class
OpenCLParallelCalcCustomBondForceKernel
::
Task
:
public
OpenCLContext
::
WorkTask
{
public:
public:
Task
(
ContextImpl
&
context
,
OpenCLCalcCustomBondForceKernel
&
kernel
,
bool
includeForce
,
Task
(
ContextImpl
&
context
,
OpenCLCalcCustomBondForceKernel
&
kernel
,
bool
includeForce
,
...
@@ -270,6 +275,11 @@ double OpenCLParallelCalcCustomBondForceKernel::execute(ContextImpl& context, bo
...
@@ -270,6 +275,11 @@ double OpenCLParallelCalcCustomBondForceKernel::execute(ContextImpl& context, bo
return
0.0
;
return
0.0
;
}
}
void
OpenCLParallelCalcCustomBondForceKernel
::
copyParametersToContext
(
ContextImpl
&
context
,
const
CustomBondForce
&
force
)
{
for
(
int
i
=
0
;
i
<
(
int
)
kernels
.
size
();
i
++
)
getKernel
(
i
).
copyParametersToContext
(
context
,
force
);
}
class
OpenCLParallelCalcHarmonicAngleForceKernel
::
Task
:
public
OpenCLContext
::
WorkTask
{
class
OpenCLParallelCalcHarmonicAngleForceKernel
::
Task
:
public
OpenCLContext
::
WorkTask
{
public:
public:
Task
(
ContextImpl
&
context
,
OpenCLCalcHarmonicAngleForceKernel
&
kernel
,
bool
includeForce
,
Task
(
ContextImpl
&
context
,
OpenCLCalcHarmonicAngleForceKernel
&
kernel
,
bool
includeForce
,
...
@@ -306,6 +316,11 @@ double OpenCLParallelCalcHarmonicAngleForceKernel::execute(ContextImpl& context,
...
@@ -306,6 +316,11 @@ double OpenCLParallelCalcHarmonicAngleForceKernel::execute(ContextImpl& context,
return
0.0
;
return
0.0
;
}
}
void
OpenCLParallelCalcHarmonicAngleForceKernel
::
copyParametersToContext
(
ContextImpl
&
context
,
const
HarmonicAngleForce
&
force
)
{
for
(
int
i
=
0
;
i
<
(
int
)
kernels
.
size
();
i
++
)
getKernel
(
i
).
copyParametersToContext
(
context
,
force
);
}
class
OpenCLParallelCalcCustomAngleForceKernel
::
Task
:
public
OpenCLContext
::
WorkTask
{
class
OpenCLParallelCalcCustomAngleForceKernel
::
Task
:
public
OpenCLContext
::
WorkTask
{
public:
public:
Task
(
ContextImpl
&
context
,
OpenCLCalcCustomAngleForceKernel
&
kernel
,
bool
includeForce
,
Task
(
ContextImpl
&
context
,
OpenCLCalcCustomAngleForceKernel
&
kernel
,
bool
includeForce
,
...
@@ -342,6 +357,11 @@ double OpenCLParallelCalcCustomAngleForceKernel::execute(ContextImpl& context, b
...
@@ -342,6 +357,11 @@ double OpenCLParallelCalcCustomAngleForceKernel::execute(ContextImpl& context, b
return
0.0
;
return
0.0
;
}
}
void
OpenCLParallelCalcCustomAngleForceKernel
::
copyParametersToContext
(
ContextImpl
&
context
,
const
CustomAngleForce
&
force
)
{
for
(
int
i
=
0
;
i
<
(
int
)
kernels
.
size
();
i
++
)
getKernel
(
i
).
copyParametersToContext
(
context
,
force
);
}
class
OpenCLParallelCalcPeriodicTorsionForceKernel
::
Task
:
public
OpenCLContext
::
WorkTask
{
class
OpenCLParallelCalcPeriodicTorsionForceKernel
::
Task
:
public
OpenCLContext
::
WorkTask
{
public:
public:
Task
(
ContextImpl
&
context
,
OpenCLCalcPeriodicTorsionForceKernel
&
kernel
,
bool
includeForce
,
Task
(
ContextImpl
&
context
,
OpenCLCalcPeriodicTorsionForceKernel
&
kernel
,
bool
includeForce
,
...
@@ -378,6 +398,11 @@ double OpenCLParallelCalcPeriodicTorsionForceKernel::execute(ContextImpl& contex
...
@@ -378,6 +398,11 @@ double OpenCLParallelCalcPeriodicTorsionForceKernel::execute(ContextImpl& contex
return
0.0
;
return
0.0
;
}
}
void
OpenCLParallelCalcPeriodicTorsionForceKernel
::
copyParametersToContext
(
ContextImpl
&
context
,
const
PeriodicTorsionForce
&
force
)
{
for
(
int
i
=
0
;
i
<
(
int
)
kernels
.
size
();
i
++
)
getKernel
(
i
).
copyParametersToContext
(
context
,
force
);
}
class
OpenCLParallelCalcRBTorsionForceKernel
::
Task
:
public
OpenCLContext
::
WorkTask
{
class
OpenCLParallelCalcRBTorsionForceKernel
::
Task
:
public
OpenCLContext
::
WorkTask
{
public:
public:
Task
(
ContextImpl
&
context
,
OpenCLCalcRBTorsionForceKernel
&
kernel
,
bool
includeForce
,
Task
(
ContextImpl
&
context
,
OpenCLCalcRBTorsionForceKernel
&
kernel
,
bool
includeForce
,
...
@@ -414,6 +439,11 @@ double OpenCLParallelCalcRBTorsionForceKernel::execute(ContextImpl& context, boo
...
@@ -414,6 +439,11 @@ double OpenCLParallelCalcRBTorsionForceKernel::execute(ContextImpl& context, boo
return
0.0
;
return
0.0
;
}
}
void
OpenCLParallelCalcRBTorsionForceKernel
::
copyParametersToContext
(
ContextImpl
&
context
,
const
RBTorsionForce
&
force
)
{
for
(
int
i
=
0
;
i
<
(
int
)
kernels
.
size
();
i
++
)
getKernel
(
i
).
copyParametersToContext
(
context
,
force
);
}
class
OpenCLParallelCalcCMAPTorsionForceKernel
::
Task
:
public
OpenCLContext
::
WorkTask
{
class
OpenCLParallelCalcCMAPTorsionForceKernel
::
Task
:
public
OpenCLContext
::
WorkTask
{
public:
public:
Task
(
ContextImpl
&
context
,
OpenCLCalcCMAPTorsionForceKernel
&
kernel
,
bool
includeForce
,
Task
(
ContextImpl
&
context
,
OpenCLCalcCMAPTorsionForceKernel
&
kernel
,
bool
includeForce
,
...
@@ -486,6 +516,11 @@ double OpenCLParallelCalcCustomTorsionForceKernel::execute(ContextImpl& context,
...
@@ -486,6 +516,11 @@ double OpenCLParallelCalcCustomTorsionForceKernel::execute(ContextImpl& context,
return
0.0
;
return
0.0
;
}
}
void
OpenCLParallelCalcCustomTorsionForceKernel
::
copyParametersToContext
(
ContextImpl
&
context
,
const
CustomTorsionForce
&
force
)
{
for
(
int
i
=
0
;
i
<
(
int
)
kernels
.
size
();
i
++
)
getKernel
(
i
).
copyParametersToContext
(
context
,
force
);
}
class
OpenCLParallelCalcNonbondedForceKernel
::
Task
:
public
OpenCLContext
::
WorkTask
{
class
OpenCLParallelCalcNonbondedForceKernel
::
Task
:
public
OpenCLContext
::
WorkTask
{
public:
public:
Task
(
ContextImpl
&
context
,
OpenCLCalcNonbondedForceKernel
&
kernel
,
bool
includeForce
,
Task
(
ContextImpl
&
context
,
OpenCLCalcNonbondedForceKernel
&
kernel
,
bool
includeForce
,
...
...
platforms/opencl/src/OpenCLParallelKernels.h
View file @
4bc723ab
...
@@ -113,6 +113,13 @@ public:
...
@@ -113,6 +113,13 @@ public:
* @return the potential energy due to the force
* @return the potential energy due to the force
*/
*/
double
execute
(
ContextImpl
&
context
,
bool
includeForces
,
bool
includeEnergy
);
double
execute
(
ContextImpl
&
context
,
bool
includeForces
,
bool
includeEnergy
);
/**
* Copy changed parameters over to a context.
*
* @param context the context to copy parameters to
* @param force the HarmonicBondForce to copy the parameters from
*/
void
copyParametersToContext
(
ContextImpl
&
context
,
const
HarmonicBondForce
&
force
);
private:
private:
class
Task
;
class
Task
;
OpenCLPlatform
::
PlatformData
&
data
;
OpenCLPlatform
::
PlatformData
&
data
;
...
@@ -144,6 +151,13 @@ public:
...
@@ -144,6 +151,13 @@ public:
* @return the potential energy due to the force
* @return the potential energy due to the force
*/
*/
double
execute
(
ContextImpl
&
context
,
bool
includeForces
,
bool
includeEnergy
);
double
execute
(
ContextImpl
&
context
,
bool
includeForces
,
bool
includeEnergy
);
/**
* Copy changed parameters over to a context.
*
* @param context the context to copy parameters to
* @param force the CustomBondForce to copy the parameters from
*/
void
copyParametersToContext
(
ContextImpl
&
context
,
const
CustomBondForce
&
force
);
private:
private:
class
Task
;
class
Task
;
OpenCLPlatform
::
PlatformData
&
data
;
OpenCLPlatform
::
PlatformData
&
data
;
...
@@ -175,6 +189,13 @@ public:
...
@@ -175,6 +189,13 @@ public:
* @return the potential energy due to the force
* @return the potential energy due to the force
*/
*/
double
execute
(
ContextImpl
&
context
,
bool
includeForces
,
bool
includeEnergy
);
double
execute
(
ContextImpl
&
context
,
bool
includeForces
,
bool
includeEnergy
);
/**
* Copy changed parameters over to a context.
*
* @param context the context to copy parameters to
* @param force the HarmonicAngleForce to copy the parameters from
*/
void
copyParametersToContext
(
ContextImpl
&
context
,
const
HarmonicAngleForce
&
force
);
private:
private:
class
Task
;
class
Task
;
OpenCLPlatform
::
PlatformData
&
data
;
OpenCLPlatform
::
PlatformData
&
data
;
...
@@ -206,6 +227,13 @@ public:
...
@@ -206,6 +227,13 @@ public:
* @return the potential energy due to the force
* @return the potential energy due to the force
*/
*/
double
execute
(
ContextImpl
&
context
,
bool
includeForces
,
bool
includeEnergy
);
double
execute
(
ContextImpl
&
context
,
bool
includeForces
,
bool
includeEnergy
);
/**
* Copy changed parameters over to a context.
*
* @param context the context to copy parameters to
* @param force the CustomAngleForce to copy the parameters from
*/
void
copyParametersToContext
(
ContextImpl
&
context
,
const
CustomAngleForce
&
force
);
private:
private:
class
Task
;
class
Task
;
OpenCLPlatform
::
PlatformData
&
data
;
OpenCLPlatform
::
PlatformData
&
data
;
...
@@ -238,6 +266,13 @@ public:
...
@@ -238,6 +266,13 @@ public:
*/
*/
double
execute
(
ContextImpl
&
context
,
bool
includeForces
,
bool
includeEnergy
);
double
execute
(
ContextImpl
&
context
,
bool
includeForces
,
bool
includeEnergy
);
class
Task
;
class
Task
;
/**
* Copy changed parameters over to a context.
*
* @param context the context to copy parameters to
* @param force the PeriodicTorsionForce to copy the parameters from
*/
void
copyParametersToContext
(
ContextImpl
&
context
,
const
PeriodicTorsionForce
&
force
);
private:
private:
OpenCLPlatform
::
PlatformData
&
data
;
OpenCLPlatform
::
PlatformData
&
data
;
std
::
vector
<
Kernel
>
kernels
;
std
::
vector
<
Kernel
>
kernels
;
...
@@ -268,6 +303,13 @@ public:
...
@@ -268,6 +303,13 @@ public:
* @return the potential energy due to the force
* @return the potential energy due to the force
*/
*/
double
execute
(
ContextImpl
&
context
,
bool
includeForces
,
bool
includeEnergy
);
double
execute
(
ContextImpl
&
context
,
bool
includeForces
,
bool
includeEnergy
);
/**
* Copy changed parameters over to a context.
*
* @param context the context to copy parameters to
* @param force the RBTorsionForce to copy the parameters from
*/
void
copyParametersToContext
(
ContextImpl
&
context
,
const
RBTorsionForce
&
force
);
private:
private:
class
Task
;
class
Task
;
OpenCLPlatform
::
PlatformData
&
data
;
OpenCLPlatform
::
PlatformData
&
data
;
...
@@ -330,6 +372,13 @@ public:
...
@@ -330,6 +372,13 @@ public:
* @return the potential energy due to the force
* @return the potential energy due to the force
*/
*/
double
execute
(
ContextImpl
&
context
,
bool
includeForces
,
bool
includeEnergy
);
double
execute
(
ContextImpl
&
context
,
bool
includeForces
,
bool
includeEnergy
);
/**
* Copy changed parameters over to a context.
*
* @param context the context to copy parameters to
* @param force the CustomTorsionForce to copy the parameters from
*/
void
copyParametersToContext
(
ContextImpl
&
context
,
const
CustomTorsionForce
&
force
);
private:
private:
class
Task
;
class
Task
;
OpenCLPlatform
::
PlatformData
&
data
;
OpenCLPlatform
::
PlatformData
&
data
;
...
...
platforms/opencl/tests/TestOpenCLCustomAngleForce.cpp
View file @
4bc723ab
...
@@ -90,11 +90,36 @@ void testAngles() {
...
@@ -90,11 +90,36 @@ void testAngles() {
init_gen_rand
(
0
,
sfmt
);
init_gen_rand
(
0
,
sfmt
);
vector
<
Vec3
>
positions
(
4
);
vector
<
Vec3
>
positions
(
4
);
for
(
int
i
=
0
;
i
<
10
;
i
++
)
{
VerletIntegrator
integrator1
(
0.01
);
VerletIntegrator
integrator1
(
0.01
);
VerletIntegrator
integrator2
(
0.01
);
VerletIntegrator
integrator2
(
0.01
);
Context
c1
(
customSystem
,
integrator1
,
platform
);
Context
c1
(
customSystem
,
integrator1
,
platform
);
Context
c2
(
harmonicSystem
,
integrator2
,
platform
);
Context
c2
(
harmonicSystem
,
integrator2
,
platform
);
for
(
int
i
=
0
;
i
<
10
;
i
++
)
{
for
(
int
j
=
0
;
j
<
(
int
)
positions
.
size
();
j
++
)
positions
[
j
]
=
Vec3
(
5.0
*
genrand_real2
(
sfmt
),
5.0
*
genrand_real2
(
sfmt
),
5.0
*
genrand_real2
(
sfmt
));
c1
.
setPositions
(
positions
);
c2
.
setPositions
(
positions
);
State
s1
=
c1
.
getState
(
State
::
Forces
|
State
::
Energy
);
State
s2
=
c2
.
getState
(
State
::
Forces
|
State
::
Energy
);
const
vector
<
Vec3
>&
forces
=
s1
.
getForces
();
for
(
int
i
=
0
;
i
<
customSystem
.
getNumParticles
();
i
++
)
ASSERT_EQUAL_VEC
(
s1
.
getForces
()[
i
],
s2
.
getForces
()[
i
],
TOL
);
ASSERT_EQUAL_TOL
(
s1
.
getPotentialEnergy
(),
s2
.
getPotentialEnergy
(),
TOL
);
}
// Try changing the angle parameters and make sure it's still correct.
parameters
[
0
]
=
1.6
;
parameters
[
1
]
=
0.9
;
custom
->
setAngleParameters
(
0
,
0
,
1
,
2
,
parameters
);
parameters
[
0
]
=
2.1
;
parameters
[
1
]
=
0.6
;
custom
->
setAngleParameters
(
1
,
1
,
2
,
3
,
parameters
);
custom
->
updateParametersInContext
(
c1
);
harmonic
->
setAngleParameters
(
0
,
0
,
1
,
2
,
1.6
,
0.9
);
harmonic
->
setAngleParameters
(
1
,
1
,
2
,
3
,
2.1
,
0.6
);
harmonic
->
updateParametersInContext
(
c2
);
{
for
(
int
j
=
0
;
j
<
(
int
)
positions
.
size
();
j
++
)
for
(
int
j
=
0
;
j
<
(
int
)
positions
.
size
();
j
++
)
positions
[
j
]
=
Vec3
(
5.0
*
genrand_real2
(
sfmt
),
5.0
*
genrand_real2
(
sfmt
),
5.0
*
genrand_real2
(
sfmt
));
positions
[
j
]
=
Vec3
(
5.0
*
genrand_real2
(
sfmt
),
5.0
*
genrand_real2
(
sfmt
),
5.0
*
genrand_real2
(
sfmt
));
c1
.
setPositions
(
positions
);
c1
.
setPositions
(
positions
);
...
...
platforms/opencl/tests/TestOpenCLCustomBondForce.cpp
View file @
4bc723ab
...
@@ -74,11 +74,31 @@ void testBonds() {
...
@@ -74,11 +74,31 @@ void testBonds() {
positions
[
2
]
=
Vec3
(
1
,
0
,
0
);
positions
[
2
]
=
Vec3
(
1
,
0
,
0
);
context
.
setPositions
(
positions
);
context
.
setPositions
(
positions
);
State
state
=
context
.
getState
(
State
::
Forces
|
State
::
Energy
);
State
state
=
context
.
getState
(
State
::
Forces
|
State
::
Energy
);
{
const
vector
<
Vec3
>&
forces
=
state
.
getForces
();
const
vector
<
Vec3
>&
forces
=
state
.
getForces
();
ASSERT_EQUAL_VEC
(
Vec3
(
0
,
-
0.8
*
0.5
,
0
),
forces
[
0
],
TOL
);
ASSERT_EQUAL_VEC
(
Vec3
(
0
,
-
0.8
*
0.5
,
0
),
forces
[
0
],
TOL
);
ASSERT_EQUAL_VEC
(
Vec3
(
0.7
*
0.2
,
0
,
0
),
forces
[
2
],
TOL
);
ASSERT_EQUAL_VEC
(
Vec3
(
0.7
*
0.2
,
0
,
0
),
forces
[
2
],
TOL
);
ASSERT_EQUAL_VEC
(
Vec3
(
-
forces
[
0
][
0
]
-
forces
[
2
][
0
],
-
forces
[
0
][
1
]
-
forces
[
2
][
1
],
-
forces
[
0
][
2
]
-
forces
[
2
][
2
]),
forces
[
1
],
TOL
);
ASSERT_EQUAL_VEC
(
Vec3
(
-
forces
[
0
][
0
]
-
forces
[
2
][
0
],
-
forces
[
0
][
1
]
-
forces
[
2
][
1
],
-
forces
[
0
][
2
]
-
forces
[
2
][
2
]),
forces
[
1
],
TOL
);
ASSERT_EQUAL_TOL
(
0.5
*
0.8
*
0.5
*
0.5
+
0.5
*
0.7
*
0.2
*
0.2
,
state
.
getPotentialEnergy
(),
TOL
);
ASSERT_EQUAL_TOL
(
0.5
*
0.8
*
0.5
*
0.5
+
0.5
*
0.7
*
0.2
*
0.2
,
state
.
getPotentialEnergy
(),
TOL
);
}
// Try changing the bond parameters and make sure it's still correct.
parameters
[
0
]
=
1.6
;
parameters
[
1
]
=
0.9
;
forceField
->
setBondParameters
(
0
,
0
,
1
,
parameters
);
parameters
[
0
]
=
1.3
;
parameters
[
1
]
=
0.8
;
forceField
->
setBondParameters
(
1
,
1
,
2
,
parameters
);
forceField
->
updateParametersInContext
(
context
);
state
=
context
.
getState
(
State
::
Forces
|
State
::
Energy
);
{
const
vector
<
Vec3
>&
forces
=
state
.
getForces
();
ASSERT_EQUAL_VEC
(
Vec3
(
0
,
-
0.9
*
0.4
,
0
),
forces
[
0
],
TOL
);
ASSERT_EQUAL_VEC
(
Vec3
(
0.8
*
0.3
,
0
,
0
),
forces
[
2
],
TOL
);
ASSERT_EQUAL_VEC
(
Vec3
(
-
forces
[
0
][
0
]
-
forces
[
2
][
0
],
-
forces
[
0
][
1
]
-
forces
[
2
][
1
],
-
forces
[
0
][
2
]
-
forces
[
2
][
2
]),
forces
[
1
],
TOL
);
ASSERT_EQUAL_TOL
(
0.5
*
0.9
*
0.4
*
0.4
+
0.5
*
0.8
*
0.3
*
0.3
,
state
.
getPotentialEnergy
(),
TOL
);
}
}
}
void
testManyParameters
()
{
void
testManyParameters
()
{
...
...
platforms/opencl/tests/TestOpenCLCustomTorsionForce.cpp
View file @
4bc723ab
...
@@ -111,6 +111,31 @@ void testTorsions() {
...
@@ -111,6 +111,31 @@ void testTorsions() {
ASSERT_EQUAL_VEC
(
s1
.
getForces
()[
i
],
s2
.
getForces
()[
i
],
TOL
);
ASSERT_EQUAL_VEC
(
s1
.
getForces
()[
i
],
s2
.
getForces
()[
i
],
TOL
);
ASSERT_EQUAL_TOL
(
s1
.
getPotentialEnergy
(),
s2
.
getPotentialEnergy
(),
TOL
);
ASSERT_EQUAL_TOL
(
s1
.
getPotentialEnergy
(),
s2
.
getPotentialEnergy
(),
TOL
);
}
}
// Try changing the torsion parameters and make sure it's still correct.
parameters
[
0
]
=
1.6
;
parameters
[
1
]
=
2
;
custom
->
setTorsionParameters
(
0
,
0
,
1
,
2
,
3
,
parameters
);
parameters
[
0
]
=
2.1
;
parameters
[
1
]
=
3
;
custom
->
setTorsionParameters
(
1
,
1
,
2
,
3
,
4
,
parameters
);
custom
->
updateParametersInContext
(
c1
);
periodic
->
setTorsionParameters
(
0
,
0
,
1
,
2
,
3
,
2
,
1.6
,
0.5
);
periodic
->
setTorsionParameters
(
1
,
1
,
2
,
3
,
4
,
3
,
2.1
,
0.5
);
periodic
->
updateParametersInContext
(
c2
);
{
for
(
int
j
=
0
;
j
<
(
int
)
positions
.
size
();
j
++
)
positions
[
j
]
=
Vec3
(
5.0
*
genrand_real2
(
sfmt
),
5.0
*
genrand_real2
(
sfmt
),
5.0
*
genrand_real2
(
sfmt
));
c1
.
setPositions
(
positions
);
c2
.
setPositions
(
positions
);
State
s1
=
c1
.
getState
(
State
::
Forces
|
State
::
Energy
);
State
s2
=
c2
.
getState
(
State
::
Forces
|
State
::
Energy
);
const
vector
<
Vec3
>&
forces
=
s1
.
getForces
();
for
(
int
i
=
0
;
i
<
customSystem
.
getNumParticles
();
i
++
)
ASSERT_EQUAL_VEC
(
s1
.
getForces
()[
i
],
s2
.
getForces
()[
i
],
TOL
);
ASSERT_EQUAL_TOL
(
s1
.
getPotentialEnergy
(),
s2
.
getPotentialEnergy
(),
TOL
);
}
}
}
void
testRange
()
{
void
testRange
()
{
...
...
platforms/opencl/tests/TestOpenCLHarmonicAngleForce.cpp
View file @
4bc723ab
...
@@ -69,6 +69,7 @@ void testAngles() {
...
@@ -69,6 +69,7 @@ void testAngles() {
positions
[
3
]
=
Vec3
(
2
,
1
,
0
);
positions
[
3
]
=
Vec3
(
2
,
1
,
0
);
context
.
setPositions
(
positions
);
context
.
setPositions
(
positions
);
State
state
=
context
.
getState
(
State
::
Forces
|
State
::
Energy
);
State
state
=
context
.
getState
(
State
::
Forces
|
State
::
Energy
);
{
const
vector
<
Vec3
>&
forces
=
state
.
getForces
();
const
vector
<
Vec3
>&
forces
=
state
.
getForces
();
double
torque1
=
1.1
*
PI_M
/
6
;
double
torque1
=
1.1
*
PI_M
/
6
;
double
torque2
=
1.2
*
PI_M
/
4
;
double
torque2
=
1.2
*
PI_M
/
4
;
...
@@ -76,6 +77,25 @@ void testAngles() {
...
@@ -76,6 +77,25 @@ void testAngles() {
ASSERT_EQUAL_VEC
(
Vec3
(
-
0.5
*
torque2
,
0.5
*
torque2
,
0
),
forces
[
3
],
TOL
);
// reduced by sqrt(2) due to the bond length, another sqrt(2) due to the angle
ASSERT_EQUAL_VEC
(
Vec3
(
-
0.5
*
torque2
,
0.5
*
torque2
,
0
),
forces
[
3
],
TOL
);
// reduced by sqrt(2) due to the bond length, another sqrt(2) due to the angle
ASSERT_EQUAL_VEC
(
Vec3
(
forces
[
0
][
0
]
+
forces
[
1
][
0
]
+
forces
[
2
][
0
]
+
forces
[
3
][
0
],
forces
[
0
][
1
]
+
forces
[
1
][
1
]
+
forces
[
2
][
1
]
+
forces
[
3
][
1
],
forces
[
0
][
2
]
+
forces
[
1
][
2
]
+
forces
[
2
][
2
]
+
forces
[
3
][
2
]),
Vec3
(
0
,
0
,
0
),
TOL
);
ASSERT_EQUAL_VEC
(
Vec3
(
forces
[
0
][
0
]
+
forces
[
1
][
0
]
+
forces
[
2
][
0
]
+
forces
[
3
][
0
],
forces
[
0
][
1
]
+
forces
[
1
][
1
]
+
forces
[
2
][
1
]
+
forces
[
3
][
1
],
forces
[
0
][
2
]
+
forces
[
1
][
2
]
+
forces
[
2
][
2
]
+
forces
[
3
][
2
]),
Vec3
(
0
,
0
,
0
),
TOL
);
ASSERT_EQUAL_TOL
(
0.5
*
1.1
*
(
PI_M
/
6
)
*
(
PI_M
/
6
)
+
0.5
*
1.2
*
(
PI_M
/
4
)
*
(
PI_M
/
4
),
state
.
getPotentialEnergy
(),
TOL
);
ASSERT_EQUAL_TOL
(
0.5
*
1.1
*
(
PI_M
/
6
)
*
(
PI_M
/
6
)
+
0.5
*
1.2
*
(
PI_M
/
4
)
*
(
PI_M
/
4
),
state
.
getPotentialEnergy
(),
TOL
);
}
// Try changing the angle parameters and make sure it's still correct.
forceField
->
setAngleParameters
(
0
,
0
,
1
,
2
,
PI_M
/
3.1
,
1.3
);
forceField
->
setAngleParameters
(
1
,
1
,
2
,
3
,
PI_M
/
2.1
,
1.4
);
forceField
->
updateParametersInContext
(
context
);
state
=
context
.
getState
(
State
::
Forces
|
State
::
Energy
);
{
const
vector
<
Vec3
>&
forces
=
state
.
getForces
();
double
dtheta1
=
(
PI_M
/
2
)
-
(
PI_M
/
3.1
);
double
dtheta2
=
(
3
*
PI_M
/
4
)
-
(
PI_M
/
2.1
);
double
torque1
=
1.3
*
dtheta1
;
double
torque2
=
1.4
*
dtheta2
;
ASSERT_EQUAL_VEC
(
Vec3
(
torque1
,
0
,
0
),
forces
[
0
],
TOL
);
ASSERT_EQUAL_VEC
(
Vec3
(
-
0.5
*
torque2
,
0.5
*
torque2
,
0
),
forces
[
3
],
TOL
);
// reduced by sqrt(2) due to the bond length, another sqrt(2) due to the angle
ASSERT_EQUAL_VEC
(
Vec3
(
forces
[
0
][
0
]
+
forces
[
1
][
0
]
+
forces
[
2
][
0
]
+
forces
[
3
][
0
],
forces
[
0
][
1
]
+
forces
[
1
][
1
]
+
forces
[
2
][
1
]
+
forces
[
3
][
1
],
forces
[
0
][
2
]
+
forces
[
1
][
2
]
+
forces
[
2
][
2
]
+
forces
[
3
][
2
]),
Vec3
(
0
,
0
,
0
),
TOL
);
ASSERT_EQUAL_TOL
(
0.5
*
1.3
*
dtheta1
*
dtheta1
+
0.5
*
1.4
*
dtheta2
*
dtheta2
,
state
.
getPotentialEnergy
(),
TOL
);
}
}
}
void
testParallelComputation
()
{
void
testParallelComputation
()
{
...
...
platforms/opencl/tests/TestOpenCLHarmonicBondForce.cpp
View file @
4bc723ab
...
@@ -66,11 +66,27 @@ void testBonds() {
...
@@ -66,11 +66,27 @@ void testBonds() {
positions
[
2
]
=
Vec3
(
1
,
0
,
0
);
positions
[
2
]
=
Vec3
(
1
,
0
,
0
);
context
.
setPositions
(
positions
);
context
.
setPositions
(
positions
);
State
state
=
context
.
getState
(
State
::
Forces
|
State
::
Energy
);
State
state
=
context
.
getState
(
State
::
Forces
|
State
::
Energy
);
{
const
vector
<
Vec3
>&
forces
=
state
.
getForces
();
const
vector
<
Vec3
>&
forces
=
state
.
getForces
();
ASSERT_EQUAL_VEC
(
Vec3
(
0
,
-
0.8
*
0.5
,
0
),
forces
[
0
],
TOL
);
ASSERT_EQUAL_VEC
(
Vec3
(
0
,
-
0.8
*
0.5
,
0
),
forces
[
0
],
TOL
);
ASSERT_EQUAL_VEC
(
Vec3
(
0.7
*
0.2
,
0
,
0
),
forces
[
2
],
TOL
);
ASSERT_EQUAL_VEC
(
Vec3
(
0.7
*
0.2
,
0
,
0
),
forces
[
2
],
TOL
);
ASSERT_EQUAL_VEC
(
Vec3
(
-
forces
[
0
][
0
]
-
forces
[
2
][
0
],
-
forces
[
0
][
1
]
-
forces
[
2
][
1
],
-
forces
[
0
][
2
]
-
forces
[
2
][
2
]),
forces
[
1
],
TOL
);
ASSERT_EQUAL_VEC
(
Vec3
(
-
forces
[
0
][
0
]
-
forces
[
2
][
0
],
-
forces
[
0
][
1
]
-
forces
[
2
][
1
],
-
forces
[
0
][
2
]
-
forces
[
2
][
2
]),
forces
[
1
],
TOL
);
ASSERT_EQUAL_TOL
(
0.5
*
0.8
*
0.5
*
0.5
+
0.5
*
0.7
*
0.2
*
0.2
,
state
.
getPotentialEnergy
(),
TOL
);
ASSERT_EQUAL_TOL
(
0.5
*
0.8
*
0.5
*
0.5
+
0.5
*
0.7
*
0.2
*
0.2
,
state
.
getPotentialEnergy
(),
TOL
);
}
// Try changing the bond parameters and make sure it's still correct.
forceField
->
setBondParameters
(
0
,
0
,
1
,
1.6
,
0.9
);
forceField
->
setBondParameters
(
1
,
1
,
2
,
1.3
,
0.8
);
forceField
->
updateParametersInContext
(
context
);
state
=
context
.
getState
(
State
::
Forces
|
State
::
Energy
);
{
const
vector
<
Vec3
>&
forces
=
state
.
getForces
();
ASSERT_EQUAL_VEC
(
Vec3
(
0
,
-
0.9
*
0.4
,
0
),
forces
[
0
],
TOL
);
ASSERT_EQUAL_VEC
(
Vec3
(
0.8
*
0.3
,
0
,
0
),
forces
[
2
],
TOL
);
ASSERT_EQUAL_VEC
(
Vec3
(
-
forces
[
0
][
0
]
-
forces
[
2
][
0
],
-
forces
[
0
][
1
]
-
forces
[
2
][
1
],
-
forces
[
0
][
2
]
-
forces
[
2
][
2
]),
forces
[
1
],
TOL
);
ASSERT_EQUAL_TOL
(
0.5
*
0.9
*
0.4
*
0.4
+
0.5
*
0.8
*
0.3
*
0.3
,
state
.
getPotentialEnergy
(),
TOL
);
}
}
}
void
testParallelComputation
()
{
void
testParallelComputation
()
{
...
...
Prev
1
2
3
Next
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment