add library interface to Variable::internal_set()
This commit is contained in:
@ -2451,19 +2451,59 @@ int lammps_extract_variable_datatype(void *handle, const char *name)
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
// for printing obsolete function call warning only once
|
||||
static int set_variable_deprecated_flag = 1;
|
||||
|
||||
/** Set the value of a string-style variable.
|
||||
*
|
||||
* This function assigns a new value from the string str to the
|
||||
* string-style variable name. Returns -1 if a variable of that
|
||||
* name does not exist or is not a string-style variable, otherwise 0.
|
||||
*
|
||||
\verbatim embed:rst
|
||||
|
||||
.. deprecated:: TBD
|
||||
|
||||
This function assigns a new value from the string str to the
|
||||
string-style variable *name*. Returns -1 if a variable of that
|
||||
name does not exist or is not a string-style variable, otherwise 0.
|
||||
|
||||
.. warning::
|
||||
|
||||
This function is deprecated and :cpp:func:`lammps_set_string_variable`
|
||||
should be used instead.
|
||||
|
||||
\endverbatim
|
||||
|
||||
* \param handle pointer to a previously created LAMMPS instance
|
||||
* \param name name of the variable
|
||||
* \param str new value of the variable
|
||||
* \return 0 on success or -1 on failure */
|
||||
|
||||
int lammps_set_variable(void *handle, const char *name, const char *str)
|
||||
{
|
||||
if (set_variable_deprecated_flag) {
|
||||
fprintf(stderr,"Using the 'lammps_set_variable()' function is deprecated. "
|
||||
"Please use 'lammps_set_string_variable()' instead.\n");
|
||||
set_variable_deprecated_flag = 0;
|
||||
}
|
||||
return lammps_set_string_variable(handle, name, str);
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
|
||||
/** Set the value of a string-style variable.
|
||||
\verbatim embed:rst
|
||||
|
||||
.. versionadded:: TBD
|
||||
|
||||
This function assigns a new value from the string str to the
|
||||
string-style variable *name*. Returns -1 if a variable of that
|
||||
name does not exist or is not a string-style variable, otherwise 0.
|
||||
|
||||
\endverbatim
|
||||
|
||||
* \param handle pointer to a previously created LAMMPS instance
|
||||
* \param name name of the variable
|
||||
* \param str new value of the variable
|
||||
* \return 0 on success or -1 on failure
|
||||
*/
|
||||
int lammps_set_variable(void *handle, char *name, char *str)
|
||||
int lammps_set_string_variable(void *handle, const char *name, const char *str)
|
||||
{
|
||||
auto lmp = (LAMMPS *) handle;
|
||||
int err = -1;
|
||||
@ -2477,6 +2517,35 @@ int lammps_set_variable(void *handle, char *name, char *str)
|
||||
return err;
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
|
||||
/** Set the value of an internal-style variable.
|
||||
*
|
||||
* This function assigns a new value value to an internal-style variable.
|
||||
* Returns -1 if a variable of that name does not exist or is not an
|
||||
* internal-style variable, otherwise 0.
|
||||
*
|
||||
* \param handle pointer to a previously created LAMMPS instance
|
||||
* \param name name of the variable
|
||||
* \param value new value of the variable
|
||||
* \return 0 on success or -1 on failure
|
||||
*/
|
||||
int lammps_set_internal_variable(void *handle, const char *name, double value)
|
||||
{
|
||||
auto lmp = (LAMMPS *) handle;
|
||||
|
||||
BEGIN_CAPTURE
|
||||
{
|
||||
int ivar = lmp->input->variable->find(name);
|
||||
if (ivar < 0) return -1;
|
||||
if (lmp->input->variable->internalstyle(ivar)) {
|
||||
lmp->input->variable->internal_set(ivar, value);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
END_CAPTURE
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
|
||||
|
||||
Reference in New Issue
Block a user