I want to compute the rate of change (derivative) of a global scalar, i.e., the number of atoms in a group. LAMMPS has fix store/state to store the per-atom attributes, so that one can easily compute the derivatives of those per-atom quantities. However, I have not found such a command for global scalars. So I wonder if there is a convenient way to obtain this derivative on the fly without modifying the source code. Thanks in advance!
You can use fix vector and then the slope() variable function on that vector. Fix vector has an ânmaxâ keyword that can limit over how many values you will compute the slope. To reduce noise, it is often better to not use only the direct delta, but to compute the slope over a larger number of values.
Thanks for your advice. But what I want to obtain is the instantaneous rates. The slope function assumes that the value changes linearly, which is not the case in my simulation. Now I output it to a yaml file via fix print, and compute the derivatives during post-processing.
But as I already mentioned, such data is generally very noisy and computing the derivative is enhancing this, thus some averaging is usually beneficial and that you get from increasing the vector length.
I use fix evaporate to implement the outflow boundary condition, and want to compute the outflow rate. Becuase fix evaporate computes a global scalar, I try to add it to fix vector:
ERROR: Must set âextvectorâ or âextlistâ when setting âvector_flagâ for fix vector. Contact the developer. (src/fix.cpp:138)
I donât understand what I should do according to the error message. But when I store f_outflow in a variable and add the latter to fix vector, the error is fixed:
When reporting unexpected errors, please always report which LAMMPS version you are using and what platform you are on. Also, please see the forum guidelines post
Please try making the following change, recompile, and try again:
diff --git a/src/fix_vector.cpp b/src/fix_vector.cpp
index 7c75f93a3a..de8fa83dbe 100644
--- a/src/fix_vector.cpp
+++ b/src/fix_vector.cpp
@@ -114,9 +114,9 @@ FixVector::FixVector(LAMMPS *lmp, int narg, char **arg) :
error->all(FLERR, "Fix for fix {} vector not computed at compatible time", val.id);
if (val.argindex == 0)
- value = ifix->extvector;
+ value = ifix->extscalar;
else
- value = ifix->extarray;
+ value = ifix->extvector;
val.val.f = ifix;
} else if (val.which == ArgInfo::VARIABLE) {
P.S.: If you need an updated Windows installer package for Windows, I can probably produce one as well, but we are planning to release update2 for the stable version next week, and that will include this bugfix and new packages will be provided for that anyway.
Itâs also worth noting that fix controller (documentation) tracks the time derivative of its process variable as an output scalar. Thus, for example, the following combination:
should track the difference between f_outflowâs current value and its 5-steps-ago value, every five steps, in f_ns_out[3], and the fix ns_ave will further collect 20 values of ns_out and average over them (albeit somewhat superfluous in this example â sampling a difference every 5 steps, and averaging over 20 samples, is exactly the same as sampling a difference every 100 steps).
You should be able to use this without patching the source code and recompiling.