Lemina
A molecular dynamics package for network, granular material and point particles with a range of interaction potential.
Loading...
Searching...
No Matches
ApplyBoundaryCond.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<stdio.h>
22
#include<stdlib.h>
23
#include<string.h>
24
#include<math.h>
25
#include"
global.h
"
26
27
void
ApplyBoundaryCond
(){
28
int
n;
29
for
(n = 1 ; n <=
nAtom
; n ++){
30
if
(strcmp(
xBoundary
,
"p"
) == 0 && strcmp(
yBoundary
,
"p"
) == 0){
// P.B.C along x and y axis
31
rx
[n] -=
region
[1]*rint(
rx
[n]/
region
[1]);
32
ry
[n] -=
region
[2]*rint(
ry
[n]/
region
[2]);
33
}
else
if
(strcmp(
xBoundary
,
"r"
) == 0 && strcmp(
yBoundary
,
"r"
) == 0){
//R.B.C. along x and y axis
34
if
((
rx
[n] +
atomRadius
[n]) >=
regionH
[1]){
35
rx
[n] = 0.999999*
regionH
[1] -
atomRadius
[n];
vx
[n] = -
vx
[n] ;
36
}
if
((
rx
[n]-
atomRadius
[n]) < -
regionH
[1]){
37
rx
[n] = -0.999999*
regionH
[1] +
atomRadius
[n];
vx
[n] = -
vx
[n] ;
38
}
39
if
((
ry
[n] +
atomRadius
[n])>=
regionH
[2]){
40
ry
[n] = 0.999999*
regionH
[2] -
atomRadius
[n];
vy
[n] = -
vy
[n] ;
41
}
if
((
ry
[n]-
atomRadius
[n]) < -
regionH
[2]){
42
ry
[n] = -0.999999*
regionH
[2] +
atomRadius
[n];
vy
[n] = -
vy
[n] ;
43
}}
44
else
if
(strcmp(
xBoundary
,
"p"
) == 0 && strcmp(
yBoundary
,
"r"
) == 0){
//P.B.C. along x and R.B.C along y axis
45
rx
[n] -=
region
[1]*rint(
rx
[n]/
region
[1]);
46
if
((
ry
[n] +
atomRadius
[n]) >=
regionH
[2]){
47
ry
[n] = 0.999999*
regionH
[2] -
atomRadius
[n];
vy
[n] = -
vy
[n] ;
48
}
if
((
ry
[n] -
atomRadius
[n]) < -
regionH
[2]){
49
ry
[n] = -0.999999*
regionH
[2] +
atomRadius
[n];
vy
[n] = -
vy
[n] ;
50
}}
51
else
if
(strcmp(
xBoundary
,
"r"
) == 0 && strcmp(
yBoundary
,
"p"
) == 0){
//R.B.C. along x and P.B.C along y axis
52
if
((
rx
[n] +
atomRadius
[n]) >=
regionH
[1]){
53
rx
[n] = 0.999999*
regionH
[1] -
atomRadius
[n];
vx
[n] = -
vx
[n] ;
54
}
if
((
rx
[n] -
atomRadius
[n]) < -
regionH
[1]){
55
rx
[n] = -0.999999*
regionH
[1] +
atomRadius
[n];
vx
[n] = -
vx
[n] ;
56
}
57
ry
[n] -=
region
[2]*rint(
ry
[n]/
region
[2]);
58
}
else
{
59
// Print error message and exit the program
60
fprintf(
fpresult
,
"Error: Invalid boundary configuration: '%s %s'\n"
,
xBoundary
,
yBoundary
);
61
exit(EXIT_FAILURE);
// Exit with failure status
62
}
63
}
64
}
ApplyBoundaryCond
void ApplyBoundaryCond()
Definition
ApplyBoundaryCond.c:27
global.h
nAtom
int nAtom
Definition
global.h:24
region
double region[2+1]
yBoundary
char yBoundary[10]
Definition
global.h:68
vx
double * vx
Definition
global.h:17
fpresult
FILE * fpresult
rx
double * rx
atomRadius
double * atomRadius
xBoundary
char xBoundary[10]
vy
double * vy
Definition
global.h:17
regionH
double regionH[2+1]
Definition
global.h:20
ry
double * ry
Definition
global.h:17
source
ApplyBoundaryCond.c
Generated by
1.13.2