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
50bb275a
Commit
50bb275a
authored
Apr 05, 2020
by
Charlles Abreu
Browse files
Continuous1DFunction evaluation with periodic=true
parent
1d5ee1a3
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
39 additions
and
11 deletions
+39
-11
platforms/common/src/ExpressionUtilities.cpp
platforms/common/src/ExpressionUtilities.cpp
+21
-7
platforms/reference/src/ReferenceTabulatedFunction.cpp
platforms/reference/src/ReferenceTabulatedFunction.cpp
+18
-4
No files found.
platforms/common/src/ExpressionUtilities.cpp
View file @
50bb275a
...
@@ -238,11 +238,20 @@ void ExpressionUtilities::processExpression(stringstream& out, const ExpressionT
...
@@ -238,11 +238,20 @@ void ExpressionUtilities::processExpression(stringstream& out, const ExpressionT
for
(
auto
&
suffix
:
suffixes
)
{
for
(
auto
&
suffix
:
suffixes
)
{
out
<<
"{
\n
"
;
out
<<
"{
\n
"
;
if
(
dynamic_cast
<
const
Continuous1DFunction
*>
(
functions
[
i
])
!=
NULL
)
{
if
(
dynamic_cast
<
const
Continuous1DFunction
*>
(
functions
[
i
])
!=
NULL
)
{
out
<<
"real x = "
<<
getTempName
(
node
.
getChildren
()[
0
],
temps
)
<<
suffix
<<
";
\n
"
;
int
periodic
=
functionParams
[
i
][
4
];
out
<<
"if (x >= "
<<
paramsFloat
[
0
]
<<
" && x <= "
<<
paramsFloat
[
1
]
<<
") {
\n
"
;
if
(
periodic
)
{
out
<<
"x = (x - "
<<
paramsFloat
[
0
]
<<
")*"
<<
paramsFloat
[
2
]
<<
";
\n
"
;
out
<<
"real x = "
<<
getTempName
(
node
.
getChildren
()[
0
],
temps
)
<<
suffix
<<
";
\n
"
;
out
<<
"int index = (int) (floor(x));
\n
"
;
out
<<
"x = (x - "
<<
paramsFloat
[
0
]
<<
")*"
<<
paramsFloat
[
5
]
<<
";
\n
"
;
out
<<
"index = min(index, (int) "
<<
paramsInt
[
3
]
<<
");
\n
"
;
out
<<
"x = (x - floor(x))*"
<<
paramsFloat
[
6
]
<<
";
\n
"
;
out
<<
"int index = (int) (floor(x));
\n
"
;
}
else
{
out
<<
"real x = "
<<
getTempName
(
node
.
getChildren
()[
0
],
temps
)
<<
suffix
<<
";
\n
"
;
out
<<
"if (x >= "
<<
paramsFloat
[
0
]
<<
" && x <= "
<<
paramsFloat
[
1
]
<<
") {
\n
"
;
out
<<
"x = (x - "
<<
paramsFloat
[
0
]
<<
")*"
<<
paramsFloat
[
2
]
<<
";
\n
"
;
out
<<
"int index = (int) (floor(x));
\n
"
;
out
<<
"index = min(index, (int) "
<<
paramsInt
[
3
]
<<
");
\n
"
;
}
out
<<
"float4 coeff = "
<<
functionNames
[
i
].
second
<<
"[index];
\n
"
;
out
<<
"float4 coeff = "
<<
functionNames
[
i
].
second
<<
"[index];
\n
"
;
out
<<
"real b = x-index;
\n
"
;
out
<<
"real b = x-index;
\n
"
;
out
<<
"real a = 1.0f-b;
\n
"
;
out
<<
"real a = 1.0f-b;
\n
"
;
...
@@ -253,8 +262,9 @@ void ExpressionUtilities::processExpression(stringstream& out, const ExpressionT
...
@@ -253,8 +262,9 @@ void ExpressionUtilities::processExpression(stringstream& out, const ExpressionT
else
else
out
<<
nodeNames
[
j
]
<<
suffix
<<
" = (coeff.y-coeff.x)*"
<<
paramsFloat
[
2
]
<<
"+((1.0f-3.0f*a*a)*coeff.z+(3.0f*b*b-1.0f)*coeff.w)/"
<<
paramsFloat
[
2
]
<<
";
\n
"
;
out
<<
nodeNames
[
j
]
<<
suffix
<<
" = (coeff.y-coeff.x)*"
<<
paramsFloat
[
2
]
<<
"+((1.0f-3.0f*a*a)*coeff.z+(3.0f*b*b-1.0f)*coeff.w)/"
<<
paramsFloat
[
2
]
<<
";
\n
"
;
}
}
out
<<
"}
\n
"
;
if
(
!
periodic
)
}
out
<<
"}
\n
"
;
}
else
if
(
dynamic_cast
<
const
Continuous2DFunction
*>
(
functions
[
i
])
!=
NULL
)
{
else
if
(
dynamic_cast
<
const
Continuous2DFunction
*>
(
functions
[
i
])
!=
NULL
)
{
out
<<
"real x = "
<<
getTempName
(
node
.
getChildren
()[
0
],
temps
)
<<
suffix
<<
";
\n
"
;
out
<<
"real x = "
<<
getTempName
(
node
.
getChildren
()[
0
],
temps
)
<<
suffix
<<
";
\n
"
;
out
<<
"real y = "
<<
getTempName
(
node
.
getChildren
()[
1
],
temps
)
<<
suffix
<<
";
\n
"
;
out
<<
"real y = "
<<
getTempName
(
node
.
getChildren
()[
1
],
temps
)
<<
suffix
<<
";
\n
"
;
...
@@ -844,6 +854,10 @@ vector<vector<double> > ExpressionUtilities::computeFunctionParameters(const vec
...
@@ -844,6 +854,10 @@ vector<vector<double> > ExpressionUtilities::computeFunctionParameters(const vec
params
[
i
].
push_back
(
max
);
params
[
i
].
push_back
(
max
);
params
[
i
].
push_back
((
values
.
size
()
-
1
)
/
(
max
-
min
));
params
[
i
].
push_back
((
values
.
size
()
-
1
)
/
(
max
-
min
));
params
[
i
].
push_back
(
values
.
size
()
-
2
);
params
[
i
].
push_back
(
values
.
size
()
-
2
);
int
periodic
=
(
int
)
fn
.
getPeriodic
();
params
[
i
].
push_back
(
periodic
);
params
[
i
].
push_back
(
1.0
/
(
max
-
min
));
params
[
i
].
push_back
(
values
.
size
()
-
1
);
}
}
else
if
(
dynamic_cast
<
const
Continuous2DFunction
*>
(
functions
[
i
])
!=
NULL
)
{
else
if
(
dynamic_cast
<
const
Continuous2DFunction
*>
(
functions
[
i
])
!=
NULL
)
{
const
Continuous2DFunction
&
fn
=
dynamic_cast
<
const
Continuous2DFunction
&>
(
*
functions
[
i
]);
const
Continuous2DFunction
&
fn
=
dynamic_cast
<
const
Continuous2DFunction
&>
(
*
functions
[
i
]);
...
...
platforms/reference/src/ReferenceTabulatedFunction.cpp
View file @
50bb275a
...
@@ -101,15 +101,29 @@ int ReferenceContinuous1DFunction::getNumArguments() const {
...
@@ -101,15 +101,29 @@ int ReferenceContinuous1DFunction::getNumArguments() const {
double
ReferenceContinuous1DFunction
::
evaluate
(
const
double
*
arguments
)
const
{
double
ReferenceContinuous1DFunction
::
evaluate
(
const
double
*
arguments
)
const
{
double
t
=
arguments
[
0
];
double
t
=
arguments
[
0
];
if
(
t
<
min
||
t
>
max
)
if
(
t
<
min
||
t
>
max
)
{
return
0.0
;
if
(
periodic
)
{
double
L
=
max
-
min
;
double
s
=
(
t
-
min
)
/
L
;
t
=
min
+
L
*
(
s
-
floor
(
s
));
}
else
return
0.0
;
}
return
SplineFitter
::
evaluateSpline
(
x
,
values
,
derivs
,
t
);
return
SplineFitter
::
evaluateSpline
(
x
,
values
,
derivs
,
t
);
}
}
double
ReferenceContinuous1DFunction
::
evaluateDerivative
(
const
double
*
arguments
,
const
int
*
derivOrder
)
const
{
double
ReferenceContinuous1DFunction
::
evaluateDerivative
(
const
double
*
arguments
,
const
int
*
derivOrder
)
const
{
double
t
=
arguments
[
0
];
double
t
=
arguments
[
0
];
if
(
t
<
min
||
t
>
max
)
if
(
t
<
min
||
t
>
max
)
{
return
0.0
;
if
(
periodic
)
{
double
L
=
max
-
min
;
double
s
=
(
t
-
min
)
/
L
;
t
=
min
+
L
*
(
s
-
floor
(
s
));
}
else
return
0.0
;
}
return
SplineFitter
::
evaluateSplineDerivative
(
x
,
values
,
derivs
,
t
);
return
SplineFitter
::
evaluateSplineDerivative
(
x
,
values
,
derivs
,
t
);
}
}
...
...
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