Reversible integration of SLLOD#4781
Conversation
I am sorry, but we cannot merge this pull request because it is not based on the develop branch but on the stable release branch. Those branches have diverged since we backport changes and make update releases with bugfixes. Thus you will have to either rebase your changes to the develop branch or rather create a new feature branch from develop, create the diff for your changes only and then apply it to the feature branch, commit, and resubmit as a new pull request (assuming there were no conflicting changes to develop since). |
|
@akohlmey no worries, I suspected that might be the case - I'll sort that out shortly. |
564c366 to
37d1e0e
Compare
|
Should be fixed now. |
Thanks. Please let us know when you want people to take a closer look. |
|
I think it's ready now for someone to take a look. I've convinced myself of correctness, so it would be good to get feedback on any code structure/user interface/etc changes before I duplicate into accelerator styles and update the documentation. |
|
@ssande7 This sounds like a significant improvement in the consistency of SLLOD in LAMMPS, particularly recovering the correct work production rate and also time reversibility. For people who want to be able to reproduce previous results, can you provide an option for that (including both psslod yes/no cases)? Will this change affect regression testing for examples/nemd/in.nemd and examples/VISCOSITY/in.nemd.2d? I would be interested in seeing the pre-arXiv manuscript. |
|
Thanks @athomps , I think that should be possible. It wouldn't account for the bug fixes in domain, angmom, etc relating to velocity remapping, so it wouldn't give exactly the same results, but probably very close in large systems. I'll take a look and see what I can get working. For fix deform, I think a flag to turn on/off handling of coupled directions makes sense. Fix nvt/sllod could also just use a flag, but it might get a little messy, so perhaps it would be simpler to copy the old version as a new fix and call it nvt/sllod/legacy or something like that. Would that fit ok with the LAMMPS way of doing things? |
|
@ssande7 We prefer not to keep legacy versions hanging around. If there is a clean way to provide old functionality, then good, if not, let's not do it. |
|
@athomps that makes sense - I'll see what I can do with just flags. I think at least the flag for fix deform makes sense to preserve the ability to mix x/y/z TRATE with xy/xz/yz ERATE without them coupling. |
|
@athomps I've added some flags which I think should achieve close enough to the previous behaviour - I'll leave it up to you whether it's worth the added complication (which isn't that much) and added risk of people using it incorrectly. For For Probably some bike shedding to do on the flag names if we go ahead with them, but let me know what you think. I've checked that I've also edited the example input scripts in my earlier comment to use |
…de extra/dof and dynamic/dof options if required.
…r to fix deform to avoid friend classes
| if ((mask[i] & groupbit) && abs(spin[i])==1) | ||
| tspin += mefactor*mass[type[i]]*ervel[i]*ervel[i]; | ||
|
|
||
| MPI_Allreduce(&tspin_all,&tspin,1,MPI_DOUBLE,MPI_SUM,world); |
There was a problem hiding this comment.
The arguments to MPI_Allreduce are swapped. The source and destination buffers should be &tspin (send) and &tspin_all (receive), not the other way around. The current code tries to reduce from uninitialized tspin_all and place the result in tspin, which is incorrect.
| MPI_Allreduce(&tspin_all,&tspin,1,MPI_DOUBLE,MPI_SUM,world); | |
| MPI_Allreduce(&tspin,&tspin_all,1,MPI_DOUBLE,MPI_SUM,world); |
|
|
||
| MPI_Allreduce(t,vector,6,MPI_DOUBLE,MPI_SUM,world); | ||
| for (int i = 0; i < 6; i++) vector[i] *= force->mvv2e; | ||
| MPI_Allreduce(tspin_all,tspin,3,MPI_DOUBLE,MPI_SUM,world); |
There was a problem hiding this comment.
The arguments to MPI_Allreduce are swapped. The source and destination buffers should be tspin (send) and tspin_all (receive), not the other way around. The current code tries to reduce from uninitialized tspin_all and place the result in tspin, which is incorrect.
| MPI_Allreduce(tspin_all,tspin,3,MPI_DOUBLE,MPI_SUM,world); | |
| MPI_Allreduce(tspin,tspin_all,3,MPI_DOUBLE,MPI_SUM,world); |
| <fix_evaporate>`), then this option should be used to ensure the | ||
| temperature is correctly normalized. | ||
|
|
||
| .. versionadded::TBD |
There was a problem hiding this comment.
Missing space between directive and version. The reStructuredText directive should be .. versionadded:: TBD (with double colon and space before TBD), not .. versionadded::TBD (no space).
| .. versionadded::TBD | |
| .. versionadded:: TBD |
|
@athomps all tests are passing now, including some extra ones I've added for the new integration method and peculiar frame option. I've also updated the docs to hopefully make everything clear, and updated the relevant nemd examples and HowTo guide. Note, using N = 0 as the flag for For moving erate/rescale, the simplest solution I found was to just move For now, when the tilt factors are mapped back to the closest unit cell, I've made it so that the correction to xz due to xy tilt only applies if we have erate/rescale for xz to keep status quo behavior in other cases, but if similar handling were extended to other cases then (combined with the updated flip code) it might allow the restriction on flips that would induce a continuous xz change to be dropped in cases where I haven't had a chance to test the Kokkos version on GPU yet, but I will try to do that soon, and it's working fine with the OpenMP backend. It would be worth someone double checking what I've done though in case anything is suboptimal. On that note - is the sync at fix_nvt_sllod.cpp:247 needed? I included it copying from line 385 to be safe, but I think it could be skipped unless I'm missing something. It also might be worth having a fused kernel version of For the /eff variants, I think the integration scheme is correct/equivalent to the previous version, and I didn't notice any problems in the comparison tests I ran, but it might be worth one of the original authors double checking since I'm not too familiar with that package. I don't think |
|
Thanks @athomps , it's been good to see this all come together finally. |
That was an oversight, so good catch!
I just finished reading through all the code and it looks good to me. I'm going to run a few tests early next week to check a few combinations of deform commands, but if I don't remember to reply that means all the tests passed. Overall, really impressive to get all this in and working! Certainly not a trivial improvement. |
|
Thanks @jtclemm ! |
Summary
This PR updates$-V\mathbf{P}^T:\nabla\mathbf{u}$ ), and it is now possible to do this:

fix nvt/sllod,fix deform, andcompute temp/deform(and some other associated code) for stable integration of the equations of motion in a way which is reversible and energy-conserving (once work done to drive the flow is accounted for). With these changes, energy dissipation is now in good agreement with the expected analytical value (Logo input script
The initial motivation for these changes was some discrepancies/issues we noticed when looking at the transient response and trying to do response theory calculations, but in the end we have found that even viscosity calculations at steady state were slightly affected by the issues fixed in this PR (viscosity was slightly overestimated, becoming significant at high shear rates or under mixed flows). I'm currently in the final stages of preparing a paper with the details, which I'm happy to share privately if you want to see it before we put it on arXiv. I've already sent it to Pieter in 't Veld for his comments, and he hasn't flagged any concerns.
The main changes are:
fix deformduringpost_integraterather thanend_of_stepto avoid an off-by-one error on the first step (SLLOD technically requires that the box be updated at the same time as particle positions to avoid an additional force calculation).fix nvt/sllod) not staying constant.h_ratefrom the start for TRATE deform style so that the correct flow rate tensor is used byfix nvt/sllodin the first time step.See the implementation details section below for additional notes on some of these changes (numbers match up).
Still to-do:
Updates to documentation - I've left this for now until the user interface is finalised, but see below for an example input script.Accelerator styles - I've focused on the bare styles for now, but it should be easy enough to propagate the changes to the accelerator variants once any issues have been sorted out.Fix merge conflicts withdevelop- I based this on the29Aug2024_update4release to be able to reference it in the paper.Example Input Script
Related Issue(s)
Author(s)
Stephen Sanderson - The University of Queensland
Licensing
By submitting this pull request, I agree, that my contribution will be included in LAMMPS and redistributed under either the GNU General Public License version 2 (GPL v2) or the GNU Lesser General Public License version 2.1 (LGPL v2.1).
Artificial Intelligence (AI) Tools Usage
By submitting this pull request, I confirm that I did NOT use any AI tools to generate
all or parts of the code and modifications in this pull request.
Backward Compatibility
Since the new
kickflag offix nvt/slloddefaults toyeswhen using lab-frame velocity, scripts which previously applied the velocity profile manually would need to either stop doing that or setkick no.Previous scripts will also generate a warning about
fix deformbeing applied at the end of the step, and suggest settingnevery = 0infix deformto correct the issue.With
fix nvt/sllodnow havingcompute temp/deformas a hard requirement, scripts which used some other velocity bias will need to adapt by setting that bias via the newtempargument ofcompute temp/deform.Implementation Notes
compute temp/deformto have an additional method for applying the velocity bias based on current particle positions, rather than just restoring it from whatever was previously calculated. This meant that use oftemp/deformbysllodbecame a hard requirement, so to preserve the ability to use other biases (and reduce duplicate code),temp/deformnow uses an internal temperature compute (tempby default), which is only called at times when the bias due tofix deformhas been removed. This also enables new possibilities like turning off the thermostat in some/all directions withcompute temp/partial, and I think will work nicely with our plans for a molecular thermostat. The other benefit here is that we can add akick yes/noflag for applying the streaming velocity profile at the start of the first run, rather than having the user do so manually (which has some pitfalls to the uninitiated due to shear using the lower box corner as the origin, but elongation using the center of the box, calculated as if tilt factors were zero).post_integrateto be settingnevery = 0infix deform, since using it only really makes sense (at least to me) if deformation is being applied every time step. I realise that's not particularly intuitive as a user interface though, so I'm happy to switch to a flag plus some error checking or some other solution if that's preferred. I've also made sure this is compatible with respa.peculiar = yes/noflag tofix nvt/sllodto toggle on use of peculiar frame velocities. Using peculiar velocities would be problematic for some calculations like angular momentum which assume velocities are in the lab frame, but when those aren't needed I think it's worth having the option for the performance it gives (and it was withpeculiar yesthat I first got reversibility working properly - lab frame was more sensitive).fix deform/pressurestyle to determine how/whether these changes should interact with it (perhaps @jtclemm could weigh in on this?). For handling long-running xy + yz deformation with a box flip, I've required xz to also be set to ERATE (even if it's ERATE 0) so that we can be given explicit control over it. The solution to the ODE for dealing with this is a bit annoying with (many) different cases depending on the structure of the flow tensor; for now I've used some simple equality checks to choose the correct solution since the rates being checked are user inputs and therefore unlikely to be "very close but not exactly the same", but a proper floating pointnearly_equalfunction would be a more robust solution. I've flagged places where I think those should be used, and if that's the way forward then my suggestion is to movenearly_equalfrom the UEF package (possibly with minor modifications for robustness) intomath_extraor similar.Possible future expansion:
Beyond the scope of this PR (I think), and perhaps this should be a separate issue, but it would be nice to be able to support things like
fix npt/sllodand long-running mixed flows. I think this is difficult to do with the currentfix */sllod+fix deformsetup since both fixes would want to be changing the unit cell, so to that end, I think it would be useful if sllod were to be separated fromfix deformand instead control the unit cell itself and integrate it directly instead of trying to solve analytically for its shape (similar to how the UEF package does it). This certainly isn't the only solution though, and I'm suggesting this mainly as a starting point for conversation.Post Submission Checklist
Further Information, Files, and Links
After submitting, I see that this is also showing a bunch of changes from the diff between 29Aug2024_update4 and develop, so here is a compare link to see just my changes:stable_29Aug2024_update4...ssande7:lammps:sllod-integration
Please let me know if you want me to try and rebase before going further.