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
212e8367
"vscode:/vscode.git/clone" did not exist on "ab60c418eb00c0059bc6240dd1ceef9e6d623ca4"
Commit
212e8367
authored
May 18, 2017
by
peastman
Browse files
Serialization of tabulated functions for CustomIntegrator
parent
85c0f767
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
32 additions
and
6 deletions
+32
-6
serialization/src/CustomIntegratorProxy.cpp
serialization/src/CustomIntegratorProxy.cpp
+15
-6
serialization/tests/TestSerializeIntegrator.cpp
serialization/tests/TestSerializeIntegrator.cpp
+17
-0
No files found.
serialization/src/CustomIntegratorProxy.cpp
View file @
212e8367
...
...
@@ -40,22 +40,22 @@ CustomIntegratorProxy::CustomIntegratorProxy() : SerializationProxy("CustomInteg
}
void
CustomIntegratorProxy
::
serialize
(
const
void
*
object
,
SerializationNode
&
node
)
const
{
node
.
setIntProperty
(
"version"
,
1
);
node
.
setIntProperty
(
"version"
,
2
);
const
CustomIntegrator
&
integrator
=
*
reinterpret_cast
<
const
CustomIntegrator
*>
(
object
);
SerializationNode
&
globalVariablesNode
=
node
.
createChildNode
(
"GlobalVariables"
);
for
(
int
i
=
0
;
i
<
integrator
.
getNumGlobalVariables
();
i
++
)
{
for
(
int
i
=
0
;
i
<
integrator
.
getNumGlobalVariables
();
i
++
)
{
globalVariablesNode
.
setDoubleProperty
(
integrator
.
getGlobalVariableName
(
i
),
integrator
.
getGlobalVariable
(
i
));
}
SerializationNode
&
perDofVariablesNode
=
node
.
createChildNode
(
"PerDofVariables"
);
for
(
int
i
=
0
;
i
<
integrator
.
getNumPerDofVariables
();
i
++
)
{
for
(
int
i
=
0
;
i
<
integrator
.
getNumPerDofVariables
();
i
++
)
{
SerializationNode
&
perDofValuesNode
=
perDofVariablesNode
.
createChildNode
(
integrator
.
getPerDofVariableName
(
i
));
vector
<
Vec3
>
perDofValues
;
integrator
.
getPerDofVariable
(
i
,
perDofValues
);
for
(
int
j
=
0
;
j
<
perDofValues
.
size
();
j
++
)
{
for
(
int
j
=
0
;
j
<
perDofValues
.
size
();
j
++
)
{
perDofValuesNode
.
createChildNode
(
"Value"
).
setDoubleProperty
(
"x"
,
perDofValues
[
j
][
0
]).
setDoubleProperty
(
"y"
,
perDofValues
[
j
][
1
]).
setDoubleProperty
(
"z"
,
perDofValues
[
j
][
2
]);
}
}
SerializationNode
&
computationsNode
=
node
.
createChildNode
(
"Computations"
);
for
(
int
i
=
0
;
i
<
integrator
.
getNumComputations
();
i
++
)
{
for
(
int
i
=
0
;
i
<
integrator
.
getNumComputations
();
i
++
)
{
CustomIntegrator
::
ComputationType
computationType
;
string
computationVariable
;
string
computationExpression
;
...
...
@@ -63,6 +63,9 @@ void CustomIntegratorProxy::serialize(const void* object, SerializationNode& nod
computationsNode
.
createChildNode
(
"Computation"
).
setIntProperty
(
"computationType"
,
static_cast
<
int
>
(
computationType
))
.
setStringProperty
(
"computationVariable"
,
computationVariable
).
setStringProperty
(
"computationExpression"
,
computationExpression
);
}
SerializationNode
&
functions
=
node
.
createChildNode
(
"Functions"
);
for
(
int
i
=
0
;
i
<
integrator
.
getNumTabulatedFunctions
();
i
++
)
functions
.
createChildNode
(
"Function"
,
&
integrator
.
getTabulatedFunction
(
i
)).
setStringProperty
(
"name"
,
integrator
.
getTabulatedFunctionName
(
i
));
node
.
setStringProperty
(
"kineticEnergyExpression"
,
integrator
.
getKineticEnergyExpression
());
node
.
setIntProperty
(
"randomSeed"
,
integrator
.
getRandomNumberSeed
());
node
.
setDoubleProperty
(
"stepSize"
,
integrator
.
getStepSize
());
...
...
@@ -70,7 +73,8 @@ void CustomIntegratorProxy::serialize(const void* object, SerializationNode& nod
}
void
*
CustomIntegratorProxy
::
deserialize
(
const
SerializationNode
&
node
)
const
{
if
(
node
.
getIntProperty
(
"version"
)
!=
1
)
int
version
=
node
.
getIntProperty
(
"version"
);
if
(
version
<
1
||
version
>
2
)
throw
OpenMMException
(
"Unsupported version number"
);
CustomIntegrator
*
integrator
=
new
CustomIntegrator
(
node
.
getDoubleProperty
(
"stepSize"
));
const
SerializationNode
&
globalVariablesNode
=
node
.
getChildNode
(
"GlobalVariables"
);
...
...
@@ -112,6 +116,11 @@ void* CustomIntegratorProxy::deserialize(const SerializationNode& node) const {
throw
(
OpenMMException
(
"Custom Integrator Deserialization: Unknown computation type"
));
}
}
if
(
version
>
1
)
{
const
SerializationNode
&
functions
=
node
.
getChildNode
(
"Functions"
);
for
(
auto
&
function
:
functions
.
getChildren
())
integrator
->
addTabulatedFunction
(
function
.
getStringProperty
(
"name"
),
function
.
decodeObject
<
TabulatedFunction
>
());
}
integrator
->
setKineticEnergyExpression
(
node
.
getStringProperty
(
"kineticEnergyExpression"
));
integrator
->
setRandomNumberSeed
(
node
.
getIntProperty
(
"randomSeed"
));
integrator
->
setConstraintTolerance
(
node
.
getDoubleProperty
(
"constraintTolerance"
));
...
...
serialization/tests/TestSerializeIntegrator.cpp
View file @
212e8367
...
...
@@ -156,6 +156,10 @@ void testSerializeCustomIntegrator() {
intg
->
addComputeSum
(
"summand2"
,
"v*v+f*f"
);
intg
->
setConstraintTolerance
(
1e-5
);
intg
->
setKineticEnergyExpression
(
"m*v1*v1/2; v1=v+0.5*dt*f/m"
);
vector
<
double
>
values
(
10
);
for
(
int
i
=
0
;
i
<
10
;
i
++
)
values
[
i
]
=
sin
((
double
)
i
);
intg
->
addTabulatedFunction
(
"f"
,
new
Continuous1DFunction
(
values
,
0.5
,
1.5
));
stringstream
ss
;
XmlSerializer
::
serialize
<
Integrator
>
(
intg
,
"CustomIntegrator"
,
ss
);
CustomIntegrator
*
intg2
=
dynamic_cast
<
CustomIntegrator
*>
(
XmlSerializer
::
deserialize
<
Integrator
>
(
ss
));
...
...
@@ -190,6 +194,19 @@ void testSerializeCustomIntegrator() {
ASSERT_EQUAL
(
intg
->
getRandomNumberSeed
(),
intg2
->
getRandomNumberSeed
());
ASSERT_EQUAL
(
intg
->
getStepSize
(),
intg2
->
getStepSize
());
ASSERT_EQUAL
(
intg
->
getConstraintTolerance
(),
intg2
->
getConstraintTolerance
());
ASSERT_EQUAL
(
intg
->
getNumTabulatedFunctions
(),
intg2
->
getNumTabulatedFunctions
());
for
(
int
i
=
0
;
i
<
intg
->
getNumTabulatedFunctions
();
i
++
)
{
double
min1
,
min2
,
max1
,
max2
;
vector
<
double
>
val1
,
val2
;
dynamic_cast
<
Continuous1DFunction
&>
(
intg
->
getTabulatedFunction
(
i
)).
getFunctionParameters
(
val1
,
min1
,
max1
);
dynamic_cast
<
Continuous1DFunction
&>
(
intg2
->
getTabulatedFunction
(
i
)).
getFunctionParameters
(
val2
,
min2
,
max2
);
ASSERT_EQUAL
(
intg
->
getTabulatedFunctionName
(
i
),
intg2
->
getTabulatedFunctionName
(
i
));
ASSERT_EQUAL
(
min1
,
min2
);
ASSERT_EQUAL
(
max1
,
max2
);
ASSERT_EQUAL
(
val1
.
size
(),
val2
.
size
());
for
(
int
j
=
0
;
j
<
(
int
)
val1
.
size
();
j
++
)
ASSERT_EQUAL
(
val1
[
j
],
val2
[
j
]);
}
delete
intg
;
delete
intg2
;
}
...
...
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