1 |
/* |
2 |
* Copyright (c) 2005 The University of Notre Dame. All Rights Reserved. |
3 |
* |
4 |
* The University of Notre Dame grants you ("Licensee") a |
5 |
* non-exclusive, royalty free, license to use, modify and |
6 |
* redistribute this software in source and binary code form, provided |
7 |
* that the following conditions are met: |
8 |
* |
9 |
* 1. Acknowledgement of the program authors must be made in any |
10 |
* publication of scientific results based in part on use of the |
11 |
* program. An acceptable form of acknowledgement is citation of |
12 |
* the article in which the program was described (Matthew |
13 |
* A. Meineke, Charles F. Vardeman II, Teng Lin, Christopher |
14 |
* J. Fennell and J. Daniel Gezelter, "OOPSE: An Object-Oriented |
15 |
* Parallel Simulation Engine for Molecular Dynamics," |
16 |
* J. Comput. Chem. 26, pp. 252-271 (2005)) |
17 |
* |
18 |
* 2. Redistributions of source code must retain the above copyright |
19 |
* notice, this list of conditions and the following disclaimer. |
20 |
* |
21 |
* 3. Redistributions in binary form must reproduce the above copyright |
22 |
* notice, this list of conditions and the following disclaimer in the |
23 |
* documentation and/or other materials provided with the |
24 |
* distribution. |
25 |
* |
26 |
* This software is provided "AS IS," without a warranty of any |
27 |
* kind. All express or implied conditions, representations and |
28 |
* warranties, including any implied warranty of merchantability, |
29 |
* fitness for a particular purpose or non-infringement, are hereby |
30 |
* excluded. The University of Notre Dame and its licensors shall not |
31 |
* be liable for any damages suffered by licensee as a result of |
32 |
* using, modifying or distributing the software or its |
33 |
* derivatives. In no event will the University of Notre Dame or its |
34 |
* licensors be liable for any lost revenue, profit or data, or for |
35 |
* direct, indirect, special, consequential, incidental or punitive |
36 |
* damages, however caused and regardless of the theory of liability, |
37 |
* arising out of the use of or inability to use software, even if the |
38 |
* University of Notre Dame has been advised of the possibility of |
39 |
* such damages. |
40 |
*/ |
41 |
|
42 |
#include <stdio.h> |
43 |
#include <stdlib.h> |
44 |
#include <string.h> |
45 |
|
46 |
#include "io/parse_interface.h" |
47 |
#include "io/BASS_interface.h" |
48 |
#include "utils/simError.h" |
49 |
#ifdef IS_MPI |
50 |
#include "io/mpiBASS.h" |
51 |
#endif |
52 |
|
53 |
void interface_error( event* the_event ); |
54 |
|
55 |
void init_component( int comp_index ){ |
56 |
event* the_event; |
57 |
|
58 |
the_event = (event* )malloc( sizeof( event ) ); |
59 |
|
60 |
the_event->event_type = COMPONENT; |
61 |
the_event->err_msg = NULL; |
62 |
the_event->evt.blk_index = comp_index; |
63 |
|
64 |
if( !event_handler( the_event ) ) interface_error( the_event ); |
65 |
#ifdef IS_MPI |
66 |
throwMPIEvent(the_event); |
67 |
#endif |
68 |
|
69 |
free( the_event ); |
70 |
} |
71 |
|
72 |
void init_molecule( int mol_index ){ |
73 |
event* the_event; |
74 |
|
75 |
the_event = (event* )malloc( sizeof( event ) ); |
76 |
|
77 |
the_event->event_type = MOLECULE; |
78 |
the_event->err_msg = NULL; |
79 |
the_event->evt.blk_index = mol_index; |
80 |
|
81 |
if( !event_handler( the_event ) ) interface_error( the_event ); |
82 |
#ifdef IS_MPI |
83 |
throwMPIEvent(the_event); |
84 |
#endif |
85 |
|
86 |
free( the_event ); |
87 |
} |
88 |
|
89 |
void init_rigidbody( int rigidbody_index ){ |
90 |
event* the_event; |
91 |
|
92 |
the_event = (event* )malloc( sizeof( event ) ); |
93 |
|
94 |
the_event->event_type = RIGIDBODY; |
95 |
the_event->err_msg = NULL; |
96 |
the_event->evt.blk_index = rigidbody_index; |
97 |
|
98 |
if( !event_handler( the_event ) ) interface_error( the_event ); |
99 |
#ifdef IS_MPI |
100 |
throwMPIEvent(the_event); |
101 |
#endif |
102 |
|
103 |
free( the_event ); |
104 |
} |
105 |
|
106 |
void init_cutoffgroup( int cutoffgroup_index ){ |
107 |
event* the_event; |
108 |
|
109 |
the_event = (event* )malloc( sizeof( event ) ); |
110 |
|
111 |
the_event->event_type = CUTOFFGROUP; |
112 |
the_event->err_msg = NULL; |
113 |
the_event->evt.blk_index = cutoffgroup_index; |
114 |
|
115 |
if( !event_handler( the_event ) ) interface_error( the_event ); |
116 |
#ifdef IS_MPI |
117 |
throwMPIEvent(the_event); |
118 |
#endif |
119 |
|
120 |
free( the_event ); |
121 |
} |
122 |
|
123 |
void init_atom( int atom_index ){ |
124 |
event* the_event; |
125 |
|
126 |
the_event = (event* )malloc( sizeof( event ) ); |
127 |
|
128 |
the_event->event_type = ATOM; |
129 |
the_event->err_msg = NULL; |
130 |
the_event->evt.blk_index = atom_index; |
131 |
|
132 |
if( !event_handler( the_event ) ) interface_error( the_event ); |
133 |
#ifdef IS_MPI |
134 |
throwMPIEvent(the_event); |
135 |
#endif |
136 |
|
137 |
free( the_event ); |
138 |
} |
139 |
|
140 |
void init_bond( int bond_index ){ |
141 |
event* the_event; |
142 |
|
143 |
the_event = (event* )malloc( sizeof( event ) ); |
144 |
|
145 |
the_event->event_type = BOND; |
146 |
the_event->err_msg = NULL; |
147 |
the_event->evt.blk_index = bond_index; |
148 |
|
149 |
if( !event_handler( the_event ) ) interface_error( the_event ); |
150 |
#ifdef IS_MPI |
151 |
throwMPIEvent(the_event); |
152 |
#endif |
153 |
|
154 |
free( the_event ); |
155 |
} |
156 |
|
157 |
void init_bend( int bend_index ){ |
158 |
event* the_event; |
159 |
|
160 |
the_event = (event* )malloc( sizeof( event ) ); |
161 |
|
162 |
the_event->event_type = BEND; |
163 |
the_event->err_msg = NULL; |
164 |
the_event->evt.blk_index = bend_index; |
165 |
|
166 |
if( !event_handler( the_event ) ) interface_error( the_event ); |
167 |
#ifdef IS_MPI |
168 |
throwMPIEvent(the_event); |
169 |
#endif |
170 |
|
171 |
free( the_event ); |
172 |
} |
173 |
|
174 |
void init_torsion( int torsion_index ){ |
175 |
event* the_event; |
176 |
|
177 |
the_event = (event* )malloc( sizeof( event ) ); |
178 |
|
179 |
the_event->event_type = TORSION; |
180 |
the_event->err_msg = NULL; |
181 |
the_event->evt.blk_index = torsion_index; |
182 |
|
183 |
if( !event_handler( the_event ) ) interface_error( the_event ); |
184 |
#ifdef IS_MPI |
185 |
throwMPIEvent(the_event); |
186 |
#endif |
187 |
|
188 |
free( the_event ); |
189 |
} |
190 |
|
191 |
void init_zconstraint( int zconstraint_index ){ |
192 |
event* the_event; |
193 |
|
194 |
the_event = (event* )malloc( sizeof( event ) ); |
195 |
|
196 |
the_event->event_type = ZCONSTRAINT; |
197 |
the_event->err_msg = NULL; |
198 |
the_event->evt.blk_index = zconstraint_index; |
199 |
|
200 |
if( !event_handler( the_event ) ) interface_error( the_event ); |
201 |
#ifdef IS_MPI |
202 |
throwMPIEvent(the_event); |
203 |
#endif |
204 |
|
205 |
free( the_event ); |
206 |
} |
207 |
|
208 |
|
209 |
/* |
210 |
* the next few deal with the statement initializations |
211 |
*/ |
212 |
|
213 |
void init_members( struct node_tag* the_node, |
214 |
struct namespc the_namespc ){ |
215 |
event* the_event; |
216 |
int i; |
217 |
|
218 |
the_event = (event* )malloc( sizeof( event ) ); |
219 |
|
220 |
the_event->event_type = MEMBERS; |
221 |
the_event->err_msg = NULL; |
222 |
|
223 |
the_event->evt.mbrs.nMembers = the_node->the_data.mbrs.nMembers; |
224 |
|
225 |
the_event->evt.mbrs.memberList = (int *) calloc(the_node->the_data.mbrs.nMembers, |
226 |
sizeof(int)); |
227 |
|
228 |
for (i = 0; i < the_node->the_data.mbrs.nMembers; i++) { |
229 |
the_event->evt.mbrs.memberList[i] = the_node->the_data.mbrs.memberList[i]; |
230 |
} |
231 |
|
232 |
if( !event_handler( the_event ) ) interface_error( the_event ); |
233 |
#ifdef IS_MPI |
234 |
throwMPIEvent(the_event); |
235 |
#endif |
236 |
|
237 |
free( the_event->evt.mbrs.memberList ); |
238 |
free( the_event ); |
239 |
} |
240 |
|
241 |
void init_constraint( struct node_tag* the_node, |
242 |
struct namespc the_namespc ){ |
243 |
event* the_event; |
244 |
|
245 |
the_event = (event* )malloc( sizeof( event ) ); |
246 |
|
247 |
the_event->event_type = CONSTRAINT; |
248 |
the_event->err_msg = NULL; |
249 |
the_event->evt.cnstr = the_node->the_data.cnstr.constraint_val; |
250 |
|
251 |
if( !event_handler( the_event ) ) interface_error( the_event ); |
252 |
#ifdef IS_MPI |
253 |
throwMPIEvent(the_event); |
254 |
#endif |
255 |
|
256 |
free( the_event ); |
257 |
} |
258 |
|
259 |
void init_assignment( struct node_tag* the_node, |
260 |
struct namespc the_namespc ){ |
261 |
event* the_event; |
262 |
|
263 |
the_event = (event* )malloc( sizeof( event ) ); |
264 |
|
265 |
the_event->event_type = ASSIGNMENT; |
266 |
the_event->err_msg = NULL; |
267 |
|
268 |
strcpy( the_event->evt.asmt.lhs, the_node->the_data.asmt.identifier ); |
269 |
switch( the_node->the_data.asmt.type ){ |
270 |
|
271 |
case STR_ASSN: |
272 |
the_event->evt.asmt.asmt_type = STRING; |
273 |
strcpy( the_event->evt.asmt.rhs.sval, |
274 |
the_node->the_data.asmt.rhs.str_ptr ); |
275 |
break; |
276 |
|
277 |
case INT_ASSN: |
278 |
the_event->evt.asmt.asmt_type = INT; |
279 |
the_event->evt.asmt.rhs.ival = the_node->the_data.asmt.rhs.i_val; |
280 |
break; |
281 |
|
282 |
case DOUBLE_ASSN: |
283 |
the_event->evt.asmt.asmt_type = DOUBLE; |
284 |
the_event->evt.asmt.rhs.dval = the_node->the_data.asmt.rhs.d_val; |
285 |
break; |
286 |
} |
287 |
|
288 |
if( !event_handler( the_event ) ) interface_error( the_event ); |
289 |
#ifdef IS_MPI |
290 |
throwMPIEvent(the_event); |
291 |
#endif |
292 |
|
293 |
free( the_event ); |
294 |
} |
295 |
|
296 |
void init_position( struct node_tag* the_node, |
297 |
struct namespc the_namespc ){ |
298 |
event* the_event; |
299 |
|
300 |
the_event = (event* )malloc( sizeof( event ) ); |
301 |
|
302 |
the_event->event_type = POSITION; |
303 |
the_event->err_msg = NULL; |
304 |
the_event->evt.pos.x = the_node->the_data.pos.x; |
305 |
the_event->evt.pos.y = the_node->the_data.pos.y; |
306 |
the_event->evt.pos.z = the_node->the_data.pos.z; |
307 |
|
308 |
if( !event_handler( the_event ) ) interface_error( the_event ); |
309 |
#ifdef IS_MPI |
310 |
throwMPIEvent(the_event); |
311 |
#endif |
312 |
|
313 |
free( the_event ); |
314 |
} |
315 |
|
316 |
void init_orientation( struct node_tag* the_node, |
317 |
struct namespc the_namespc ){ |
318 |
event* the_event; |
319 |
|
320 |
the_event = (event* )malloc( sizeof( event ) ); |
321 |
|
322 |
the_event->event_type = ORIENTATION; |
323 |
the_event->err_msg = NULL; |
324 |
the_event->evt.ornt.phi = the_node->the_data.ort.phi; |
325 |
the_event->evt.ornt.theta = the_node->the_data.ort.theta; |
326 |
the_event->evt.ornt.psi = the_node->the_data.ort.psi; |
327 |
|
328 |
if( !event_handler( the_event ) ) interface_error( the_event ); |
329 |
#ifdef IS_MPI |
330 |
throwMPIEvent(the_event); |
331 |
#endif |
332 |
|
333 |
free( the_event ); |
334 |
} |
335 |
|
336 |
|
337 |
void end_of_block( void ){ |
338 |
event* the_event; |
339 |
|
340 |
the_event = (event* )malloc( sizeof( event ) ); |
341 |
|
342 |
the_event->event_type = BLOCK_END; |
343 |
the_event->err_msg = NULL; |
344 |
|
345 |
if( !event_handler( the_event ) ) interface_error( the_event ); |
346 |
#ifdef IS_MPI |
347 |
throwMPIEvent(the_event); |
348 |
#endif |
349 |
|
350 |
free( the_event ); |
351 |
} |
352 |
|
353 |
void interface_error( event* the_event ){ |
354 |
|
355 |
sprintf( painCave.errMsg, |
356 |
"Error in parsing meta-data file!\n" |
357 |
"\t%s\n", |
358 |
the_event->err_msg ); |
359 |
painCave.severity = OOPSE_ERROR; |
360 |
painCave.isFatal = 1; |
361 |
simError(); |
362 |
#ifdef IS_MPI |
363 |
mpiInterfaceExit(); |
364 |
#endif //IS_MPI |
365 |
} |