Lemina
A molecular dynamics package for network, granular material and point particles with a range of interaction potential.
Loading...
Searching...
No Matches
WriteRestartBinary.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
22
#include <stdio.h>
23
#include <stdlib.h>
24
#include <string.h>
25
#include "
global.h
"
26
27
// Header struct must match that of WriteRestartBinary
28
typedef
struct
{
29
char
magic[8];
// "LAMINA\0"
30
double
version;
31
double
timeNow
;
32
int
nAtom
;
33
int
nBond
;
34
int
nAtomType
;
35
int
nBondType
;
36
double
regionX;
// = region[1]
37
double
regionY;
// = region[2]
38
int
nAtomInterface
;
39
int
nAtomBlock
;
40
int
nDiscInterface
;
41
double
bigDiameter
;
42
double
InterfaceWidth
;
43
int
nPairActive
;
44
int
nPairTotal
;
45
double
uSumPair
;
46
double
virSumPair
;
47
double
virSumPairxx
;
48
double
virSumPairyy
;
49
double
virSumPairxy
;
50
double
TotalBondEnergy
;
51
double
virSumBond
;
52
double
virSumBondxx
;
53
double
virSumBondyy
;
54
double
virSumBondxy
;
55
int
stepCount
;
56
double
forceSumxExtern
;
57
double
forceSumyExtern
;
58
}
RestartHeader
;
59
60
void
WriteBinaryRestart
() {
61
RestartHeader
hdr = {
62
.magic =
"LAMINA"
,
63
.version = 1.0,
64
.timeNow =
timeNow
,
65
.nAtom =
nAtom
,
66
.nBond =
nBond
,
67
.nAtomType =
nAtomType
,
68
.nBondType =
nBondType
,
69
.regionX =
region
[1],
70
.regionY =
region
[2],
71
.nAtomInterface =
nAtomInterface
,
72
.nAtomBlock =
nAtomBlock
,
73
.nDiscInterface =
nDiscInterface
,
74
.bigDiameter =
bigDiameter
,
75
.InterfaceWidth =
InterfaceWidth
,
76
.nPairActive =
nPairActive
,
77
.nPairTotal =
nPairTotal
,
78
.uSumPair =
uSumPair
,
79
.virSumPair =
virSumPair
,
80
.virSumPairxx =
virSumPairxx
,
81
.virSumPairyy =
virSumPairyy
,
82
.virSumPairxy =
virSumPairxy
,
83
.TotalBondEnergy =
TotalBondEnergy
,
84
.virSumBond =
virSumBond
,
85
.virSumBondxx =
virSumBondxx
,
86
.virSumBondyy =
virSumBondyy
,
87
.virSumBondxy =
virSumBondxy
,
88
.stepCount =
stepCount
,
89
.forceSumxExtern =
forceSumxExtern
,
90
.forceSumyExtern =
forceSumyExtern
91
};
92
93
char
DUMP[256];
94
FILE *fp;
95
sprintf(DUMP,
"%s.bin"
,
prefix
);
// Produces e.g. "../output/test.bin"
96
fp = fopen(DUMP,
"wb"
);
97
if
(!fp) {
98
fprintf(stderr,
"Error opening binary restart file %s for writing\n"
, DUMP);
99
exit(EXIT_FAILURE);
100
}
101
102
//Here we are writing the data to binary file
103
fwrite(&hdr,
sizeof
(
RestartHeader
), 1, fp);
104
fwrite(&
atomID
[1],
sizeof
(
int
),
nAtom
, fp);
105
fwrite(&
molID
[1],
sizeof
(
int
),
nAtom
, fp);
106
fwrite(&
atomType
[1],
sizeof
(
int
),
nAtom
, fp);
107
fwrite(&
atomRadius
[1],
sizeof
(
double
),
nAtom
, fp);
108
fwrite(&
rx
[1],
sizeof
(
double
),
nAtom
, fp);
109
fwrite(&
ry
[1],
sizeof
(
double
),
nAtom
, fp);
110
fwrite(&
vx
[1],
sizeof
(
double
),
nAtom
, fp);
111
fwrite(&
vy
[1],
sizeof
(
double
),
nAtom
, fp);
112
fwrite(&
ax
[1],
sizeof
(
double
),
nAtom
, fp);
113
fwrite(&
ay
[1],
sizeof
(
double
),
nAtom
, fp);
114
fwrite(&
fx
[1],
sizeof
(
double
),
nAtom
, fp);
115
fwrite(&
fy
[1],
sizeof
(
double
),
nAtom
, fp);
116
fwrite(&
atomMass
[1],
sizeof
(
double
),
nAtom
, fp);
117
fwrite(&
discDragx
[1],
sizeof
(
double
),
nAtom
, fp);
118
fwrite(&
discDragy
[1],
sizeof
(
double
),
nAtom
, fp);
119
fwrite(&
atomIDInterface
[1],
sizeof
(
int
),
nAtomInterface
, fp);
120
121
fwrite(&
BondID
[1],
sizeof
(
int
),
nBond
, fp);
122
fwrite(&
BondType
[1],
sizeof
(
int
),
nBond
, fp);
123
fwrite(&
atom1
[1],
sizeof
(
int
),
nBond
, fp);
124
fwrite(&
atom2
[1],
sizeof
(
int
),
nBond
, fp);
125
fwrite(&
kb
[1],
sizeof
(
double
),
nBond
, fp);
126
fwrite(&
ro
[1],
sizeof
(
double
),
nBond
, fp);
127
fwrite(&
BondEnergy
[1],
sizeof
(
double
),
nBond
, fp);
128
fwrite(&
BondLength
[1],
sizeof
(
double
),
nBond
, fp);
129
fwrite(&
nodeDragx
[1],
sizeof
(
double
),
nAtom
, fp);
130
fwrite(&
nodeDragy
[1],
sizeof
(
double
),
nAtom
, fp);
131
fwrite(&
rxUnwrap
[1],
sizeof
(
double
),
nAtom
, fp);
132
fwrite(&
ryUnwrap
[1],
sizeof
(
double
),
nAtom
, fp);
133
fwrite(&
ImageX
[1],
sizeof
(
int
),
nAtom
, fp);
134
fwrite(&
ImageY
[1],
sizeof
(
int
),
nAtom
, fp);
135
136
fwrite(&
PairID
[1],
sizeof
(
int
),
nPairActive
, fp);
137
fwrite(&
Pairatom1
[1],
sizeof
(
int
),
nPairActive
, fp);
138
fwrite(&
Pairatom2
[1],
sizeof
(
int
),
nPairActive
, fp);
139
fwrite(&
PairXij
[1],
sizeof
(
double
),
nPairActive
, fp);
140
fwrite(&
PairYij
[1],
sizeof
(
double
),
nPairActive
, fp);
141
142
fclose(fp);
143
}
144
WriteBinaryRestart
void WriteBinaryRestart()
Definition
WriteRestartBinary.c:60
global.h
virSumBond
double virSumBond
nAtom
int nAtom
Definition
global.h:24
BondID
int * BondID
discDragy
double * discDragy
Definition
global.h:42
nDiscInterface
int nDiscInterface
Definition
global.h:76
atomMass
double * atomMass
virSumPairyy
double virSumPairyy
Definition
global.h:88
nAtomBlock
int nAtomBlock
Definition
global.h:76
virSumPair
double virSumPair
Definition
global.h:88
nPairTotal
int nPairTotal
atom2
int * atom2
Definition
global.h:36
BondType
int * BondType
Definition
global.h:37
nBondType
int nBondType
Definition
global.h:35
nAtomType
int nAtomType
InterfaceWidth
double InterfaceWidth
region
double region[2+1]
virSumPairxx
double virSumPairxx
Definition
global.h:88
nPairActive
int nPairActive
Definition
global.h:62
molID
int * molID
virSumBondxy
double virSumBondxy
Definition
global.h:89
ay
double * ay
Definition
global.h:17
vx
double * vx
Definition
global.h:17
ImageX
int * ImageX
ImageY
int * ImageY
Definition
global.h:50
nAtomInterface
int nAtomInterface
ro
double * ro
Definition
global.h:38
BondLength
double * BondLength
Definition
global.h:39
atomIDInterface
int * atomIDInterface
atom1
int * atom1
rx
double * rx
ax
double * ax
Definition
global.h:17
fy
double * fy
Definition
global.h:17
nBond
int nBond
BondEnergy
double * BondEnergy
bigDiameter
double bigDiameter
Definition
global.h:75
kb
double * kb
uSumPair
double uSumPair
PairID
int * PairID
PairXij
double * PairXij
ryUnwrap
double * ryUnwrap
Definition
global.h:51
nodeDragy
double * nodeDragy
Definition
global.h:42
atomRadius
double * atomRadius
virSumBondxx
double virSumBondxx
Definition
global.h:89
timeNow
double timeNow
Definition
global.h:20
Pairatom2
int * Pairatom2
Definition
global.h:63
stepCount
int stepCount
Definition
global.h:24
forceSumyExtern
double forceSumyExtern
Definition
global.h:53
TotalBondEnergy
double TotalBondEnergy
PairYij
double * PairYij
Definition
global.h:64
discDragx
double * discDragx
prefix
char * prefix
Definition
main.c:13
atomType
int * atomType
vy
double * vy
Definition
global.h:17
rxUnwrap
double * rxUnwrap
nodeDragx
double * nodeDragx
Definition
global.h:42
virSumBondyy
double virSumBondyy
Definition
global.h:89
atomID
int * atomID
forceSumxExtern
double forceSumxExtern
Definition
global.h:53
virSumPairxy
double virSumPairxy
Definition
global.h:88
fx
double * fx
Definition
global.h:17
Pairatom1
int * Pairatom1
Definition
global.h:63
ry
double * ry
Definition
global.h:17
RestartHeader
Definition
ReadRestartBinary.c:27
source
WriteRestartBinary.c
Generated by
1.13.2