-
Notifications
You must be signed in to change notification settings - Fork 2
/
check_energy_CPU.cpp
146 lines (128 loc) · 4.6 KB
/
check_energy_CPU.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
/********************************************************************************
*
* Copyright (C) 2015 Culham Centre for Fusion Energy,
* United Kingdom Atomic Energy Authority, Oxfordshire OX14 3DB, UK
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
********************************************************************************
*
* Program: SPILADY - A Spin-Lattice Dynamics Simulation Program
* Version: 1.0
* Date: Aug 2015
* Author: Pui-Wai (Leo) MA
* Contact: [email protected]
* Address: Culham Centre for Fusion Energy, OX14 3DB, United Kingdom
*
********************************************************************************/
#ifdef CPU
#include "spilady.h"
void check_energy_CPU(int current_step){
#if defined MD || defined SLDH || defined SLDHL || defined SLDNC
double ave_pe = 0e0;
double ave_ke = 0e0;
#pragma omp parallel for reduction(+:ave_pe,ave_ke)
for (int i = 0; i < natom; ++i){
struct atom_struct *atom_ptr;
atom_ptr = first_atom_ptr + i;
ave_pe += atom_ptr->pe;
ave_ke += atom_ptr->ke;
}
ave_pe /= natom;
ave_ke /= natom;
#endif
#if defined SDH || defined SDHL || defined SLDH || defined SLDHL
double ave_me = 0e0;
double ave_me0 = 0e0;
#pragma omp parallel for reduction(+:ave_me,ave_me0)
for (int i = 0; i < natom; ++i){
struct atom_struct *atom_ptr;
atom_ptr = first_atom_ptr + i;
ave_me += atom_ptr->me;
ave_me0 += atom_ptr->me0;
}
ave_me /= natom;
ave_me0 /= natom;
#endif
#ifdef eltemp
double ave_Ee = 0e0;
#pragma omp parallel for reduction(+:ave_Ee)
for (int i = 0; i < ncells; ++i){
struct cell_struct *cell_ptr;
cell_ptr = first_cell_ptr + i;
cell_ptr->Ee = Te_to_Ee(cell_ptr->Te);
ave_Ee += (double(natom)/double(ncells))*cell_ptr->Ee;
}
ave_Ee /= natom;
#ifdef renormalizeEnergy
double numerical_error_ave_energy = 0e0;
if (current_step == -1){
initial_ave_energy = 0e0;
#if defined MD || defined SLDH || defined SLDHL || defined SLDNC
initial_ave_energy += ave_pe;
initial_ave_energy += ave_ke;
#endif
#if defined SDH || defined SDHL || defined SLDH || defined SLDHL
initial_ave_energy += ave_me;
initial_ave_energy += ave_me0;
#endif
initial_ave_energy += ave_Ee;
} else {
double current_ave_energy = 0e0;
#if defined MD || defined SLDH || defined SLDHL || defined SLDNC
current_ave_energy += ave_pe;
current_ave_energy += ave_ke;
#endif
#if defined SDH || defined SDHL || defined SLDH || defined SLDHL
current_ave_energy += ave_me;
current_ave_energy += ave_me0;
#endif
current_ave_energy += ave_Ee;
numerical_error_ave_energy = current_ave_energy - initial_ave_energy;
}
#pragma omp parallel for
for (int i = 0; i < ncells; ++i){
struct cell_struct *cell_ptr;
cell_ptr = first_cell_ptr + i;
cell_ptr->Ee -= numerical_error_ave_energy;
cell_ptr->Te = Ee_to_Te(cell_ptr->Ee);
}
#endif
#endif /*eltemp*/
char out_enr_front[] = "enr-";
char out_enr[256];
strcpy(out_enr,out_enr_front);
strcat(out_enr,out_body);
strcat(out_enr,".dat");
ofstream out_file(out_enr,ios::app);
out_file << setiosflags(ios::scientific) << setprecision(15);
out_file << current_step //1
<< " " << total_time //2
#if defined MD || defined SLDH || defined SLDHL || defined SLDNC
<< " " << ave_pe //3
<< " " << ave_ke //4
#endif
#if defined SDH || defined SDHL || defined SLDH || defined SLDHL
<< " " << ave_me //5
<< " " << ave_me0 //6
#endif
#ifdef eltemp
<< " " << ave_Ee //7
#endif
<< '\n';
out_file.close();
}
void check_energy(int current_step){
check_energy_CPU(current_step);
}
#endif