/
comfixed.h
164 lines (139 loc) · 4.17 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
// This file is part of the ESPResSo distribution (http://www.espresso.mpg.de).
// It is therefore subject to the ESPResSo license agreement which you accepted upon receiving the distribution
// and by which you are legally bound while utilizing this file in any form or way.
// There is NO WARRANTY, not even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
// You should have received a copy of that license along with this program;
// if not, refer to http://www.espresso.mpg.de/license.html where its current version can be found, or
// write to Max-Planck-Institute for Polymer Research, Theory Group, PO Box 3148, 55021 Mainz, Germany.
// Copyright (c) 2002-2006; all rights reserved unless otherwise stated.
#include "utils.h"
/** \file comfixed.h
* Routines to enable comfixed
*
* <b>Responsible:</b>
* <a href="mailto:sayar@mpip-mainz.mpg.de">Mehmet</a>
*/
#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