APBS  1.5
bemparm.c
Go to the documentation of this file.
1 
57 #include "bemparm.h"
58 
59 VEMBED(rcsid="$Id$")
60 
61 #if !defined(VINLINE_MGPARM)
62 
63 #endif /* if !defined(VINLINE_MGPARM) */
64 
65 
67 
68  /* Set up the structure */
69  BEMparm *thee = VNULL;
70  thee = (BEMparm*)Vmem_malloc(VNULL, 1, sizeof(BEMparm));
71  VASSERT( thee != VNULL);
72  VASSERT( BEMparm_ctor2(thee, type) == VRC_SUCCESS );
73 
74  return thee;
75 }
76 
77 VPUBLIC Vrc_Codes BEMparm_ctor2(BEMparm *thee, BEMparm_CalcType type) {
78 
79  int i;
80 
81  if (thee == VNULL) return VRC_FAILURE;
82 
83  thee->parsed = 0;
84  thee->type = type;
85 
86  /* *** GENERIC PARAMETERS *** */
87 
88  /* *** TYPE 0 PARAMETERS *** */
89  thee->tree_order = 1;
90  thee->settree_order = 0;
91  thee->tree_n0 = 500;
92  thee->settree_n0 = 0;
93  thee->mac = 0.8;
94  thee->setmac = 0;
95 
96  thee->mesh = 0;
97  thee->setmesh = 0;
98 
99  thee->outdata = 0;
100  thee->setoutdata = 0;
101 
102  /* *** TYPE 1 & 2 PARAMETERS *** */
103 
104  /* *** TYPE 2 PARAMETERS *** */
105  thee->nonlintype = 0;
106  thee->setnonlintype = 0;
107 
108  /* *** Default parameters for TINKER *** */
109  thee->chgs = VCM_CHARGE;
110 
111  return VRC_SUCCESS;
112 }
113 
114 VPUBLIC void BEMparm_dtor(BEMparm **thee) {
115  if ((*thee) != VNULL) {
116  BEMparm_dtor2(*thee);
117  Vmem_free(VNULL, 1, sizeof(BEMparm), (void **)thee);
118  (*thee) = VNULL;
119  }
120 }
121 
122 VPUBLIC void BEMparm_dtor2(BEMparm *thee) { ; }
123 
124 VPUBLIC Vrc_Codes BEMparm_check(BEMparm *thee) {
125 
126  Vrc_Codes rc;
127  int i, tdime[3], ti, tnlev[3], nlev;
128 
129  rc = VRC_SUCCESS;
130 
131  Vnm_print(0, "BEMparm_check: checking BEMparm object of type %d.\n",
132  thee->type);
133 
134  /* Check to see if we were even filled... */
135  if (!thee->parsed) {
136  Vnm_print(2, "BEMparm_check: not filled!\n");
137  return VRC_FAILURE;
138  }
139 
140 
141  /* Check type settings */
142  if ((thee->type != BCT_MANUAL) && (thee->type != BCT_NONE)) {
143  Vnm_print(2,"BEMparm_check: type not set");
144  rc = VRC_FAILURE;
145  }
146 
147  /* Check treecode setting*/
148  if (thee->tree_order < 1) {
149  Vnm_print(2, "BEMparm_check: treecode order is less than 1");
150  rc = VRC_FAILURE;
151  }
152  if (thee->tree_n0 < 1) {
153  Vnm_print(2, "BEMparm_check: treecode leaf size is less than 1");
154  rc = VRC_FAILURE;
155  }
156  if (thee->mac > 1 || thee->mac <= 0) {
157  Vnm_print(2, "BEMparm_check: MAC criterion fails");
158  rc = VRC_FAILURE;
159  }
160 
161  if (thee->mesh > 2 || thee->mesh < 0) {
162  Vnm_print(2, "BEMparm_check: mesh must be 0 (msms) or 1 and 2 (NanoShaper)");
163  rc = VRC_FAILURE;
164  }
165 
166  if (thee->outdata > 2 || thee->outdata < 0) {
167  Vnm_print(2, "BEMparm_check: outdata must be 0, 1 (vtk), or 2 (not specified)");
168  rc = VRC_FAILURE;
169  }
170 
171  return rc;
172 }
173 
174 VPUBLIC void BEMparm_copy(BEMparm *thee, BEMparm *parm) {
175 
176  int i;
177 
178  VASSERT(thee != VNULL);
179  VASSERT(parm != VNULL);
180 
181 
182  thee->type = parm->type;
183  thee->parsed = parm->parsed;
184 
185  /* *** GENERIC PARAMETERS *** */
186 
187  /* *** TYPE 0 PARMS *** */
188 
189  thee->tree_order = parm->tree_order;
190  thee->settree_order = parm->settree_order;
191  thee->tree_n0 = parm->tree_n0;
192  thee->settree_n0 = parm->settree_n0;
193  thee->mac = parm->mac;
194  thee->setmac = parm->setmac;
195 
196  thee->mesh = parm->mesh;
197  thee->setmesh = parm->setmesh;
198 
199  thee->outdata = parm->outdata;
200  thee->setoutdata = parm->setoutdata;
201 
202  /* *** TYPE 1 & 2 PARMS *** */
203 
204  /* *** TYPE 2 PARMS *** */
205  thee->nonlintype = parm->nonlintype;
206  thee->setnonlintype = parm->setnonlintype;
207 }
208 
209 
210 VPRIVATE Vrc_Codes BEMparm_parseTREE_ORDER(BEMparm *thee, Vio *sock) {
211 
212  char tok[VMAX_BUFSIZE];
213  int ti;
214 
215  VJMPERR1(Vio_scanf(sock, "%s", tok) == 1);
216  if (sscanf(tok, "%d", &ti) == 0) {
217  Vnm_print(2, "NOsh: Read non-integer (%s) while parsing TREE_ORDER \
218 keyword!\n", tok);
219  return VRC_WARNING;
220  } else if (ti <= 0) {
221  Vnm_print(2, "parseBEM: tree_order must be greater than 0!\n");
222  return VRC_WARNING;
223  } else thee->tree_order = ti;
224  thee->settree_order = 1;
225  return VRC_SUCCESS;
226 
227  VERROR1:
228  Vnm_print(2, "parseBEM: ran out of tokens!\n");
229  return VRC_WARNING;
230 }
231 
232 
233 VPRIVATE Vrc_Codes BEMparm_parseTREE_N0(BEMparm *thee, Vio *sock) {
234 
235  char tok[VMAX_BUFSIZE];
236  int ti;
237 
238  VJMPERR1(Vio_scanf(sock, "%s", tok) == 1);
239  if (sscanf(tok, "%d", &ti) == 0) {
240  Vnm_print(2, "NOsh: Read non-integer (%s) while parsing TREE_N0 \
241 keyword!\n", tok);
242  return VRC_WARNING;
243  } else if (ti <= 0) {
244  Vnm_print(2, "parseBEM: tree_n0 must be greater than 0!\n");
245  return VRC_WARNING;
246  } else thee->tree_n0 = ti;
247  thee->settree_n0 = 1;
248  return VRC_SUCCESS;
249 
250  VERROR1:
251  Vnm_print(2, "parseBEM: ran out of tokens!\n");
252  return VRC_WARNING;
253 }
254 
255 
256 VPRIVATE Vrc_Codes BEMparm_parseMAC(BEMparm *thee, Vio *sock) {
257 
258  char tok[VMAX_BUFSIZE];
259  double tf;
260 
261  VJMPERR1(Vio_scanf(sock, "%s", tok) == 1);
262  if (sscanf(tok, "%lf", &tf) == 0) {
263  Vnm_print(2, "NOsh: Read non-float (%s) while parsing mac \
264 keyword!\n", tok);
265  return VRC_WARNING;
266  } else if (tf <= 0.0 || tf > 1.0) {
267  Vnm_print(2, "parseBEM: mac must be between 0 and 1!\n");
268  return VRC_WARNING;
269  } else thee->mac = tf;
270  thee->setmac = 1;
271  return VRC_SUCCESS;
272 
273  VERROR1:
274  Vnm_print(2, "parseBEM: ran out of tokens!\n");
275  return VRC_WARNING;
276 }
277 
278 
279 VPRIVATE Vrc_Codes BEMparm_parseMESH(BEMparm *thee, Vio *sock) {
280 
281  char tok[VMAX_BUFSIZE];
282  int ti;
283 
284  VJMPERR1(Vio_scanf(sock, "%s", tok) == 1);
285  if (sscanf(tok, "%d", &ti) == 0) {
286  Vnm_print(2, "NOsh: Read non-integer (%s) while parsing MESH \
287  keyword!\n", tok);
288  return VRC_WARNING;
289  } else if (ti < 0 || ti > 2) {
290  Vnm_print(2, "parseBEM: mesh must be 0 (msms), 1 (NanoShaper_ses), \
291  or 2 (NanoShaper_Skin)!\n");
292  return VRC_WARNING;
293  } else thee->mesh = ti;
294  thee->setmesh = 1;
295  return VRC_SUCCESS;
296 
297  VERROR1:
298  Vnm_print(2, "parseBEM: ran out of tokens!\n");
299  return VRC_WARNING;
300 }
301 
302 
303 VPRIVATE Vrc_Codes BEMparm_parseOUTDATA(BEMparm *thee, Vio *sock) {
304 
305  char tok[VMAX_BUFSIZE];
306  int ti;
307 
308  VJMPERR1(Vio_scanf(sock, "%s", tok) == 1);
309  if (sscanf(tok, "%d", &ti) == 0) {
310  Vnm_print(2, "NOsh: Read non-integer (%s) while parsing OUTDATA \
311  keyword!\n", tok);
312  return VRC_WARNING;
313  } else if (ti < 0 || ti > 2) {
314  Vnm_print(2, "parseBEM: outdata must be 0, 1 (vtk), \
315  or 2 (unspecified)!\n");
316  return VRC_WARNING;
317  } else thee->outdata = ti;
318  thee->setoutdata = 1;
319  return VRC_SUCCESS;
320 
321  VERROR1:
322  Vnm_print(2, "parseBEM: ran out of tokens!\n");
323  return VRC_WARNING;
324 }
325 
326 
327 VPUBLIC Vrc_Codes BEMparm_parseToken(BEMparm *thee, char tok[VMAX_BUFSIZE],
328  Vio *sock) {
329 
330  if (thee == VNULL) {
331  Vnm_print(2, "parseBEM: got NULL thee!\n");
332  return VRC_WARNING;
333  }
334  if (sock == VNULL) {
335  Vnm_print(2, "parseBEM: got NULL socket!\n");
336  return VRC_WARNING;
337  }
338 
339  Vnm_print(0, "BEMparm_parseToken: trying %s...\n", tok);
340 
341 
342  if (Vstring_strcasecmp(tok, "tree_order") == 0) {
343  return BEMparm_parseTREE_ORDER(thee, sock);
344  } else if (Vstring_strcasecmp(tok, "tree_n0") == 0) {
345  return BEMparm_parseTREE_N0(thee, sock);
346  } else if (Vstring_strcasecmp(tok, "mac") == 0) {
347  return BEMparm_parseMAC(thee, sock);
348  } else if (Vstring_strcasecmp(tok, "mesh") == 0) {
349  return BEMparm_parseMESH(thee, sock);
350  } else if (Vstring_strcasecmp(tok, "outdata") == 0) {
351  return BEMparm_parseOUTDATA(thee, sock);
352  } else {
353  Vnm_print(2, "parseBEM: Unrecognized keyword (%s)!\n", tok);
354  return VRC_WARNING;
355  }
356 
357  return VRC_FAILURE;
358 
359 }
int settree_n0
Definition: bemparm.h:107
int tree_n0
Definition: bemparm.h:106
int parsed
Definition: bemparm.h:99
enum eBEMparm_CalcType BEMparm_CalcType
Declare BEMparm_CalcType type.
Definition: bemparm.h:86
int setmesh
Definition: bemparm.h:114
VPUBLIC void BEMparm_copy(BEMparm *thee, BEMparm *parm)
Copy object info into thee.
Definition: bemparm.c:174
int setmac
Definition: bemparm.h:109
int settree_order
Definition: bemparm.h:105
VPUBLIC BEMparm * BEMparm_ctor(BEMparm_CalcType type)
Construct BEMparm object.
Definition: bemparm.c:66
int nonlintype
Definition: bemparm.h:110
VPUBLIC void BEMparm_dtor(BEMparm **thee)
Object destructor.
Definition: bemparm.c:114
int mesh
Definition: bemparm.h:113
Vchrg_Src chgs
Definition: bemparm.h:102
double mac
Definition: bemparm.h:108
#define VEMBED(rctag)
Allows embedding of RCS ID tags in object files.
Definition: vhal.h:556
BEMparm_CalcType type
Definition: bemparm.h:98
VPUBLIC int Vstring_strcasecmp(const char *s1, const char *s2)
Case-insensitive string comparison (BSD standard)
Definition: vstring.c:66
VPUBLIC void BEMparm_dtor2(BEMparm *thee)
FORTRAN stub for object destructor.
Definition: bemparm.c:122
VPUBLIC Vrc_Codes BEMparm_ctor2(BEMparm *thee, BEMparm_CalcType type)
FORTRAN stub to construct BEMparm object.
Definition: bemparm.c:77
int setnonlintype
Definition: bemparm.h:111
Parameter structure for BEM-specific variables from input files.
Definition: bemparm.h:96
int outdata
Definition: bemparm.h:116
int tree_order
Definition: bemparm.h:104
int setoutdata
Definition: bemparm.h:117
VPUBLIC Vrc_Codes BEMparm_parseToken(BEMparm *thee, char tok[VMAX_BUFSIZE], Vio *sock)
Parse an MG keyword from an input file.
Definition: bemparm.c:327
VPUBLIC Vrc_Codes BEMparm_check(BEMparm *thee)
Consistency check for parameter values stored in object.
Definition: bemparm.c:124