/* Molecular dynamics simulation linear code for binary Lennard-Jones liquid under NVE ensemble; Author: You-Liang Zhu, Email: youliangzhu@ciac.ac.cn Copyright: You-Liang Zhu This code is free: you can redistribute it and/or modify it under the terms of the GNU General Public License.*/ #include #include #include #include #include //#include //#include // periodic boundary condition struct float3 { // structure to hold information float3() : x(0.0), y(0.0), z(0.0) {} float3(float x0, float y0, float z0) : x(x0), y(y0), z(z0) {} float x; float y; float z; }; struct float4 { // structure to hold information float4() : x(0.0), y(0.0), z(0.0), w(0.0) {} float4(float x0, float y0, float z0, float w0) : x(x0), y(y0), z(z0), w(w0) {} float x; float y; float z; float w; }; float pbc(float x, float box_len) { // implement periodic bondary condition float box_half = box_len * 0.5; if (x > box_half) x -= box_len; else if (x < -box_half) x += box_len; return x; } // randome number generator [0.0-1.0) float R2S() { int ran = rand(); float fran = (float)ran/(float)RAND_MAX; return fran; } // initially generate the position and mass of particles void init(unsigned int np, float4* r, float4* v, float3 box, float min_dis) { for (unsigned int i=0; i0.5) // randomly generate the type of particle, 1.0 represent type A and 2.0 represent type B ri.w =1.0; else ri.w =2.0; r[i] = ri; v[i].w = 1.0; } } // first step integration of velocity verlet algorithm void first_integration(unsigned int np, float dt, float3 box, float4* r, float4* v, float4* f) { for (unsigned int i=0; i