Lemina
A molecular dynamics package for network, granular material and point particles with a range of interaction potential.
 
Loading...
Searching...
No Matches
ComputeBondForce.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
21#include "ComputeBondForce.h"
22
23#include<stdio.h>
24#include<math.h>
25#include<stdlib.h>
26#include"global.h"
27
29 int n;
30 double dr[NDIM+1], r, rr, ri, roi;
31 double uVal, fcVal;
32
33 uVal = 0.0; TotalBondEnergy = 0.0;
34 virSumBond = 0.0; virSumBondxx = 0.0; virSumBondyy = 0.0; virSumBondxy = 0.0;
35
36 double vr[NDIM+1], fdVal, rri;
37
38 for(n = 1 ; n <= nAtom ; n ++){
39 nodeDragx[n] = 0.0;
40 nodeDragy[n] = 0.0;
41 } //Important change made on 03Apr2025. Mention it in GitHub
42
43 int atom1ID, atom2ID;
44
45 for(n=1; n<=nBond; n++){
46 rr = 0.0; rri = 0.0; fcVal = 0.0; fdVal = 0.0; strech = 0.0;
47 atom1ID = atom1[n];
48 atom2ID = atom2[n];
49
50 dr[1] = rx[atom1ID] - rx[atom2ID];
51 if(dr[1] >= regionH[1])
52 dr[1] -= region[1];
53 else if(dr[1] < -regionH[1])
54 dr[1] += region[1];
55
56 dr[2] = ry[atom1ID] - ry[atom2ID];
57 if(dr[2] >= regionH[2]){
58 dr[1] -= shearDisplacement;
59 if(dr[1] < -regionH[1]) dr[1] += region[1];
60 dr[2] -= region[2];
61 }else if(dr[2] < -regionH[2]){
62 dr[1] += shearDisplacement;
63 if(dr[1] >= regionH[1]) dr[1] -= region[1];
64 dr[2] += region[2];
65 }
66
67 rr = Sqr(dr[1]) + Sqr(dr[2]);
68 r = sqrt(rr);
69 rri = 1.0/rr;
70 ri = 1.0/r;
71 roi = 1.0/ro[n];
72 strech = (r * roi - 1.0);
73 uVal = 0.5 * kb[n] * ro[n] * Sqr(strech);
74 fcVal = -kb[n] * strech * ri; //F = -Grad U
75
76 vr[1] = vx[atom1ID] - vx[atom2ID];
77 vr[2] = vy[atom1ID] - vy[atom2ID];
78 fdVal = -gamman * (vr[1]*dr[1] + vr[2]*dr[2]) * rri; //node-node drag
79
80 //DampFlag = 1. LAMMPS version
81 if(DampFlag == 1){
82 nodeDragx[atom1ID] = fdVal * dr[1]; //node-node drag //Important change made on 03Apr2025. Mention it in GitHub
83 nodeDragy[atom1ID] = fdVal * dr[2]; //node-node drag //Adding the drag forces is wrong. Only add the
84 nodeDragx[atom2ID] = -fdVal * dr[1]; //node-node drag //total force
85 nodeDragy[atom2ID] = -fdVal * dr[2]; //node-node drag
86
87 fx[atom1ID] += (fcVal + fdVal) * dr[1];
88 fy[atom1ID] += (fcVal + fdVal) * dr[2];
89 fx[atom2ID] += -(fcVal + fdVal) * dr[1];
90 fy[atom2ID] += -(fcVal + fdVal) * dr[2];
91 }
92
93 //DampFlag = 2. Suzanne notes version
94 else if(DampFlag == 2){
95 nodeDragx[atom1ID] = -gamman * vr[1]; //node-node drag
96 nodeDragy[atom1ID] = -gamman * vr[2]; //node-node drag
97 nodeDragx[atom2ID] = -(-gamman * vr[1]); //node-node drag
98 nodeDragy[atom2ID] = -(-gamman * vr[2]); //node-node drag
99
100 fx[atom1ID] += (fcVal * dr[1] - gamman * vr[1]);
101 fy[atom1ID] += (fcVal * dr[2] - gamman * vr[2]);
102 fx[atom2ID] += -(fcVal * dr[1] - gamman * vr[1]);
103 fy[atom2ID] += -(fcVal * dr[2] - gamman * vr[2]);
104 }
105
106 BondLength[n] = r;
107 BondEnergy[n] = uVal; //No 0.5 factor since it is the energy of the bond
109
110 //Virial and pressure are defnined as per dampFlag = 1
111 virSumBond += 0.5 * (fcVal + fdVal) * rr;
112 virSumBondxx += (fcVal + fdVal) * dr[1] * dr[1]; //Virial term is just r * f
113 virSumBondyy += (fcVal + fdVal) * dr[2] * dr[2];
114 virSumBondxy += (fcVal + fdVal) * dr[1] * dr[2];
115} }
void ComputeBondForce()
double virSumBond
int nAtom
Definition global.h:24
int * atom2
Definition global.h:36
#define NDIM
Definition global.h:13
double region[2+1]
double gamman
double virSumBondxy
Definition global.h:89
double * vx
Definition global.h:17
double * ro
Definition global.h:38
double * BondLength
Definition global.h:39
int * atom1
double * rx
double * fy
Definition global.h:17
#define Sqr(x)
Definition global.h:14
int nBond
double * BondEnergy
double * kb
double shearDisplacement
int DampFlag
double * nodeDragy
Definition global.h:42
double strech
double virSumBondxx
Definition global.h:89
double TotalBondEnergy
double * vy
Definition global.h:17
double regionH[2+1]
Definition global.h:20
double * nodeDragx
Definition global.h:42
double virSumBondyy
Definition global.h:89
double * fx
Definition global.h:17
double * ry
Definition global.h:17