Lemina
A molecular dynamics package for network, granular material and point particles with a range of interaction potential.
 
Loading...
Searching...
No Matches
LeapfrogStep.c
Go to the documentation of this file.
1/*
2 * This file is part of Lamina.
3 *
4 * Lamina is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
8 *
9 * Lamina is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with Lamina. If not, see <https://www.gnu.org/licenses/>.
16
17 Copyright (C) 2025 Harish Charan, University of Durham, UK
18
19 */
20#include<stdio.h>
21#include<math.h>
22#include<stdlib.h>
23#include <gsl/gsl_rng.h>
24#include <gsl/gsl_randist.h>
25#include"global.h"
26
27
28void LeapfrogStep(char thermo, gsl_rng * rnd){
29double temperature, GAMMA;
30GAMMA = 100;
31
32double *TValSum;
33TValSum = (double*)malloc((nAtom + 1) * sizeof(double));
34
35
36 if(stepCount <= stepEquil){
37 double gSum, varS, massS;
38 temperature = 1./GAMMA;
39
40 if(stepCount == 1) varS = 0.;
41 double A, S1, S2, T;
42 int n;
43 S1 = 0.; S2 = 0.; gSum = 0.; massS = 0.1;
44
45 vvSum = 0.;
46 double halfdt = 0.5*deltaT;
47 for (n = 1; n <= nAtom; n++){
48 T = vx[n] + halfdt * ax[n];
49 S1 += T * ax[n];
50 S2 += Sqr(T);
51
52 T = vy[n] + halfdt * ay[n];
53 S1 += T * ay[n];
54 S2 += Sqr(T);
55 vvSum += (Sqr(vx[n]) + Sqr(vy[n]));
56 }
57
58 A = -S1 / S2;
59 S2 = vvSum;
60
61 double C = 1 + A*deltaT ;
62 double D = deltaT * (1 + 0.5 * A * deltaT);
63
64 int i,j;
65 real dr[NDIM+1], r, rr, ri, rrCut;
66 double vv;
67
68 double uVal, AA, AASum;
69 double TVal;
70
71 double deno, VVSum;
72 deno = 0.;
73 VVSum = 0.;
74 AASum = 0.;
75
76 for(n=1;n<=nAtom; n++)
77 TValSum[n] = 0.;
78
79 rrCut = Sqr(rCut);
80
81/*****Calculating Configarational temperature*****/
82//Solving the equation of motion here
83if(thermo == 'C'){
84for(i = 1 ; i <= nAtom; i ++){
85 for(j = i+1 ; j <= nAtom ; j ++){
86 dr[1] = rx[i] - rx[j];
87 if(fabs(dr[1]) > regionH[1])
88 dr[1] -= SignR(region[1], dr[1]);
89
90 dr[2] = ry[i] - ry[j];
91 if(fabs(dr[2]) > regionH[2])
92 dr[2] -= SignR(region[2], dr[2]);
93
94 rr = Sqr(dr[1]) + Sqr(dr[2]);
95 if(rr < rrCut ){
96 r = sqrt(rr);
97 ri = 1/r;
98 uVal = ri*exp(-kappa*r);
99
100 TVal = (1./rr + Sqr(kappa) + kappa/r)*uVal;
101 TValSum[i] += TVal;
102 TValSum[j] += TVal;
103 } }
104 AA = Sqr(ax[i]) + Sqr(ay[i]);
105 AASum += AA;
106 vv = Sqr(vx[i]) + Sqr(vy[i]);
107 VVSum += vv;
108 deno += TValSum[i];
109}
110
111 double gSumconfig, varSconfig, massSconfig;
112 if(stepCount == 1) varSconfig = 0.;
113 gSumconfig = 0.; massSconfig = 2.0;
114
115 gSumconfig = (AASum/temperature - deno)/massSconfig;
116 varSconfig += deltaT*gSumconfig;
117
118 /*****Configarational Nose-Hoover thermostat*****/
119 for (n = 1; n <= nAtom; n++){
120 vx[n] += deltaT * ax[n];
121 rx[n] += deltaT * (vx[n] + varSconfig * ax[n]);
122 vy[n] += deltaT * ay[n];
123 ry[n] += deltaT * (vy[n] + varSconfig * ay[n]);
124 }
125 /*****Kinetic Nose-Hoover thermostat*****/
126 }else if(thermo == 'N'){
127 gSum = (0.5*S2 - (nAtom + 1)*temperature)/massS;
128 varS += deltaT*gSum;
129 for (n = 1; n <= nAtom; n++){
130 vx[n] += deltaT * (ax[n] - varS *vx[n]);
131 rx[n] += deltaT * vx[n];
132 vy[n] += deltaT * (ay[n] - varS *vy[n]);
133 ry[n] += deltaT * vy[n];
134 }
135 /*****for Gaussian thermostat*****/
136 }else if(thermo == 'G'){
137 for (n = 1; n <= nAtom; n++){
138 vx[n] = C * vx[n] + D * ax[n];
139 rx[n] += deltaT * vx[n];
140 vy[n] = C * vy[n] + D * ay[n];
141 ry[n] += deltaT * vy[n];
142 }
143 }else if (thermo == 'L'){
144 double nu = 0.03066;
145 double var = sqrt(2*nu/(GAMMA*deltaT));
146 double scale = 1. + nu*deltaT/2.;
147 double scale_v = 2./scale - 1.;
148 double scale_f = deltaT/scale;
149 for(n = 1 ; n <= nAtom ; n ++){
150 vx[n] = scale_v*vx[n] + scale_f*(ax[n] + var*gsl_ran_gaussian(rnd,1));
151 rx[n] += deltaT * vx[n];
152 vy[n] = scale_v*vy[n] + scale_f*(ay[n] + var*gsl_ran_gaussian(rnd,1));
153 ry[n] += deltaT * vy[n];
154 }
155 }
156 }else{
157 int n;
158 for(n = 1 ; n <= nAtom ; n ++){
159 vx[n] += deltaT * ax[n];
160 rx[n] += deltaT * vx[n];
161 vy[n] += deltaT * ay[n];
162 ry[n] += deltaT * vy[n];
163 }
164 }
165}
166
void LeapfrogStep(char thermo, gsl_rng *rnd)
double kappa
Definition global.h:21
int nAtom
Definition global.h:24
double real
Definition global.h:11
double rCut
Definition global.h:21
#define NDIM
Definition global.h:13
double region[2+1]
double vvSum
Definition global.h:21
double * ay
Definition global.h:17
double * vx
Definition global.h:17
double deltaT
Definition global.h:20
double * rx
double * ax
Definition global.h:17
#define Sqr(x)
Definition global.h:14
int stepEquil
Definition global.h:24
int stepCount
Definition global.h:24
double * vy
Definition global.h:17
double regionH[2+1]
Definition global.h:20
#define SignR(x, y)
Definition global.h:15
double * ry
Definition global.h:17