Skip to content

Add type first option to correlation fixes#4493

Merged
akohlmey merged 3 commits into
lammps:developfrom
ssande7:correlate_first
Mar 12, 2025
Merged

Add type first option to correlation fixes#4493
akohlmey merged 3 commits into
lammps:developfrom
ssande7:correlate_first

Conversation

@ssande7
Copy link
Copy Markdown
Collaborator

@ssande7 ssande7 commented Mar 11, 2025

Summary

Adds a type first option to fix ave/correlate and fix ave/correlate/long to correlate the first value with all values. This is useful for response theory calculations, where one value may need to be correlated with many values calculated for example by fix ave/chunk, but correlations between chunks are not meaningful. With existing options, many redundant columns are generated, or to avoid that, individual fixes and output files are needed for each correlation. In our use case (calculating the velocity profile across a confined LJ fluid with 100 bins and using 4 different response theory methods with fix ave/correlate/long) this reduces 400 output files into 4, and gives a ~4x speedup.

Related Issue(s)

None

Author(s)

Stephen Sanderson (The University of Queensland) - stephen.sanderson@uq.edu.au

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).

Backward Compatibility

No problems expected.

Implementation Notes

Output with type first tested to exactly match the first N columns when using type full:

# 2-d LJ flow simulation - based on couette flow example

dimension	2
boundary	p s p

atom_style	atomic
neighbor	0.3 bin
neigh_modify	delay 5

# create geometry

lattice		hex 0.7
region		box block 0 20 0 10 -0.25 0.25
create_box	3 box
create_atoms	1 box

mass		1 1.0
mass		2 1.0
mass		3 1.0

# LJ potentials

pair_style	lj/cut 1.12246
pair_coeff	* * 1.0 1.0 1.12246

# define groups

region	     1 block INF INF INF 1.25 INF INF
group	     lower region 1
region	     2 block INF INF 8.75 INF INF INF
group	     upper region 2
group	     boundary union lower upper
group	     flow subtract all boundary

set	     group lower type 2
set	     group upper type 3

# initial velocities

compute	     mobile flow temp
velocity     flow create 1.0 482748 temp mobile
fix	     1 all nve
fix	     2 flow temp/rescale 200 1.0 1.0 0.02 1.0
fix_modify   2 temp mobile

# Couette flow

velocity     lower set 0.0 0.0 0.0
velocity     upper set 3.0 0.0 0.0
fix	     3 boundary setforce 0.0 0.0 0.0
fix	     4 all enforce2d

# Calculate velocity profile

compute cchunk all chunk/atom bin/1d y lower 0.1 units reduced
fix vprof all ave/chunk 1 1 1 cchunk vx

variable prof vector f_vprof[3]

# Correlate temperature with velocity profile - not meaningful, but works as a simple test.
# First 10 columns of "type full" should match output of "type first"

fix full_short all ave/correlate 1 100 500 c_mobile v_prof[*10] type full file full.dat
fix first_short all ave/correlate 1 100 500 c_mobile v_prof[*10] type first file first.dat

fix full all ave/correlate/long 1 500 c_mobile v_prof[*10] type full file full_long.dat
fix first all ave/correlate/long 1 500 c_mobile v_prof[*10] type first file first_long.dat

# Run

timestep	0.003
thermo		500
thermo_modify	temp mobile

run		10000

Post Submission Checklist

  • The feature or features in this pull request is complete
  • Licensing information is complete
  • Corresponding author information is complete
  • The source code follows the LAMMPS formatting guidelines
  • Suitable new documentation files and/or updates to the existing docs are included
  • The added/updated documentation is integrated and tested with the documentation build system
  • The feature has been verified to work with the conventional build system
  • The feature has been verified to work with the CMake based build system
  • Suitable tests have been added to the unittest tree.
  • A package specific README file has been included or updated
  • One or more example input decks are included

Further Information, Files, and Links

@akohlmey akohlmey self-assigned this Mar 11, 2025
@akohlmey akohlmey requested a review from sjplimp March 11, 2025 15:14
@akohlmey akohlmey moved this to In Progress in LAMMPS Pull Requests Mar 11, 2025
Comment thread doc/src/fix_ave_correlate.rst Outdated
:math:`\{i,j\} = \{1,N\}`, so :math:`N_\text{pair} = N^2`).
* If *type* is set to *first* then each input value is correlated with
the first input value (i.e., :math:`C_{ij} = V_1 V_j` for
:math:`\{i,j\} = \{1,N\}`, so :math:`N_\text{pair} = N`).
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should this just be j = (1,N) since i is not varying ?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes - my mistake! Missed it when I copy-pasted from type full. Can fix in an hour or so when I get to the office if you don't beat me to it.

@sjplimp
Copy link
Copy Markdown
Contributor

sjplimp commented Mar 11, 2025

@ssande7 Thanks for the nice addition to the corrrelation options. Makes sense why it is useful.
Just flagged one doc page formula - when that is resolved, we can merge it.

@ssande7
Copy link
Copy Markdown
Collaborator Author

ssande7 commented Mar 11, 2025

Thanks @sjplimp . Should be all good now.

@akohlmey akohlmey merged commit 24ce7be into lammps:develop Mar 12, 2025
@github-project-automation github-project-automation Bot moved this from In Progress to Done in LAMMPS Pull Requests Mar 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Development

Successfully merging this pull request may close these issues.

3 participants