-
Notifications
You must be signed in to change notification settings - Fork 1
/
comfixed.h
176 lines (146 loc) · 4.26 KB
/
comfixed.h
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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
/*
Copyright (C) 2010 The ESPResSo project
Copyright (C) 2002,2003,2004,2005,2006,2007,2008,2009,2010 Max-Planck-Institute for Polymer Research, Theory Group, PO Box 3148, 55021 Mainz, Germany
This file is part of ESPResSo.
ESPResSo is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
ESPResSo is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef COMFIXED_H
#define COMFIXED_H
#include "utils.h"
/** \file comfixed.h
* Routines to enable comfixed
*/
#ifdef COMFIXED
MDINLINE int comfixed_set_params(int part_type_a, int part_type_b, int flag)
{
Particle *p;
int i, j, np, c;
Cell *cell;
IA_parameters *data, *data_sym;
make_particle_type_exist(part_type_a);
make_particle_type_exist(part_type_b);
data = get_ia_param(part_type_a, part_type_b);
data_sym = get_ia_param(part_type_b, part_type_a);
if (!data || !data_sym)
return 1;
if (n_nodes > 1)
return 2;
if (PERIODIC(0) || PERIODIC(1) || PERIODIC(2)) {
return 3;
}
/* COMFIXED should be symmetrically */
data_sym->COMFIXED_flag = data->COMFIXED_flag = flag;
/* broadcast interaction parameters */
mpi_bcast_ia_params(part_type_a, part_type_b);
mpi_bcast_ia_params(part_type_b, part_type_a);
for (c = 0; c < local_cells.n; c++) {
cell = local_cells.cell[c];
p = cell->part;
np = cell->n;
for(i = 0; i < np; i++) {
if(p[i].p.type==part_type_a) {
for(j = 0; j < 3; j++) {
p[i].m.v[j] = 0.;
p[i].f.f[j] = 0.;
}
}
}
}
return 0;
}
MDINLINE int printcomfixedIAToResult(Tcl_Interp *interp, int i, int j)
{
char buffer[TCL_DOUBLE_SPACE];
IA_parameters *data = get_ia_param(i, j);
sprintf(buffer,"%d",data->COMFIXED_flag);
Tcl_AppendResult(interp, "comfixed ", buffer, " ", (char *) NULL);
return TCL_OK;
}
MDINLINE int comfixed_parser(Tcl_Interp * interp,
int part_type_a, int part_type_b,
int argc, char ** argv)
{
int flagc;
if (argc != 2) {
Tcl_AppendResult(interp, "comfixed needs 1 parameters: "
"<comfixed_flag> ", (char *) NULL);
return 0;
}
if (part_type_a != part_type_b) {
Tcl_AppendResult(interp, "comfixed must be among same type interactions", (char *) NULL);
return 0;
}
/* copy comfixed parameters */
if ((! ARG_IS_I(1, flagc)) ) {
Tcl_AppendResult(interp, "comfixed needs 1 INTEGER parameter: "
"<comfixed_flag>", (char *) NULL);
return 0;
}
switch (comfixed_set_params(part_type_a, part_type_b, flagc)) {
case 1:
Tcl_AppendResult(interp, "particle types must be non-negative", (char *) NULL);
return 0;
case 2:
Tcl_AppendResult(interp, "works only with a single CPU", (char *) NULL);
return 0;
case 3:
Tcl_AppendResult(interp, "works only with non periodic BC", (char *) NULL);
return 0;
}
return 2;
}
MDINLINE void calc_comfixed()
{
Particle *p;
int i, np, c;
Cell *cell;
IA_parameters *ia_params;
int t0;
int j;
double fsum0[3], type_mass;
for (t0=0; t0<n_particle_types; t0++) {
ia_params = get_ia_param(t0,t0);
if(ia_params->COMFIXED_flag == 1) {
type_mass=0.0;
for(j = 0; j < 3; j++) {
fsum0[j]= 0.;
}
for (c = 0; c < local_cells.n; c++) {
cell = local_cells.cell[c];
p = cell->part;
np = cell->n;
for(i = 0; i < np; i++) {
if(p[i].p.type==t0) {
type_mass += PMASS(p[i]);
for(j = 0; j < 3; j++) {
fsum0[j] += p[i].f.f[j];
}
}
}
}
for (c = 0; c < local_cells.n; c++) {
cell = local_cells.cell[c];
p = cell->part;
np = cell->n;
for(i = 0; i < np; i++) {
if(p[i].p.type==t0) {
for(j = 0; j < 3; j++) {
p[i].f.f[j] -= fsum0[j]/type_mass*PMASS(p[i]);
}
}
}
}
}
}
}
#endif
#endif