APBS 3.0.0
Loading...
Searching...
No Matches
femparm.c
Go to the documentation of this file.
1
57#include "femparm.h"
58
59VEMBED(rcsid="$Id$")
60
61#if !defined(VINLINE_MGPARM)
62
63#endif /* if !defined(VINLINE_MGPARM) */
64
66
67 /* Set up the structure */
68 FEMparm *thee = VNULL;
69 thee = (FEMparm*)Vmem_malloc(VNULL, 1, sizeof(FEMparm));
70 VASSERT( thee != VNULL);
71 VASSERT( FEMparm_ctor2(thee, type) );
72
73 return thee;
74}
75
76VPUBLIC int FEMparm_ctor2(FEMparm *thee,
78 ) {
79
80 if (thee == VNULL) return 0;
81
82 thee->parsed = 0;
83 thee->type = type;
84 thee->settype = 1;
85
86 thee->setglen = 0;
87 thee->setetol = 0;
88 thee->setekey = 0;
89 thee->setakeyPRE = 0;
90 thee->setakeySOLVE = 0;
91 thee->settargetNum = 0;
92 thee->settargetRes = 0;
93 thee->setmaxsolve = 0;
94 thee->setmaxvert = 0;
95 thee->useMesh = 0;
96
97 return 1;
98}
99
100VPUBLIC void FEMparm_copy(
101 FEMparm *thee,
102 FEMparm *source
103 ) {
104
105 int i;
106
107 thee->parsed = source->parsed;
108 thee->type = source->type;
109 thee->settype = source->settype;
110 for (i=0; i<3; i++) thee->glen[i] = source->glen[i];
111 thee->setglen = source->setglen;
112 thee->etol = source->etol;
113 thee->setetol = source->setetol;
114 thee->ekey = source->ekey;
115 thee->setekey = source->setekey;
116 thee->akeyPRE = source->akeyPRE;
117 thee->setakeyPRE = source->setakeyPRE;
118 thee->akeySOLVE = source->akeySOLVE;
119 thee->setakeySOLVE = source->setakeySOLVE;
120 thee->targetNum = source->targetNum;
121 thee->settargetNum = source->settargetNum;
122 thee->targetRes = source->targetRes;
123 thee->settargetRes = source->settargetRes;
124 thee->maxsolve = source->maxsolve;
125 thee->setmaxsolve = source->setmaxsolve;
126 thee->maxvert = source->maxvert;
127 thee->setmaxvert = source->setmaxvert;
128 thee->pkey = source->pkey;
129 thee->useMesh = source->useMesh;
130 thee->meshID = source->meshID;
131}
132
133VPUBLIC void FEMparm_dtor(FEMparm **thee) {
134 if ((*thee) != VNULL) {
135 FEMparm_dtor2(*thee);
136 Vmem_free(VNULL, 1, sizeof(FEMparm), (void **)thee);
137 (*thee) = VNULL;
138 }
139}
140
141VPUBLIC void FEMparm_dtor2(FEMparm *thee) { ; }
142
143VPUBLIC int FEMparm_check(FEMparm *thee) {
144
145 int rc;
146 rc = 1;
147
148 if (!thee->parsed) {
149 Vnm_print(2, "FEMparm_check: not filled!\n");
150 return 0;
151 }
152 if (!thee->settype) {
153 Vnm_print(2, "FEMparm_check: type not set!\n");
154 rc = 0;
155 }
156 if (!thee->setglen) {
157 Vnm_print(2, "FEMparm_check: glen not set!\n");
158 rc = 0;
159 }
160 if (!thee->setetol) {
161 Vnm_print(2, "FEMparm_check: etol not set!\n");
162 rc = 0;
163 }
164 if (!thee->setekey) {
165 Vnm_print(2, "FEMparm_check: ekey not set!\n");
166 rc = 0;
167 }
168 if (!thee->setakeyPRE) {
169 Vnm_print(2, "FEMparm_check: akeyPRE not set!\n");
170 rc = 0;
171 }
172 if (!thee->setakeySOLVE) {
173 Vnm_print(2, "FEMparm_check: akeySOLVE not set!\n");
174 rc = 0;
175 }
176 if (!thee->settargetNum) {
177 Vnm_print(2, "FEMparm_check: targetNum not set!\n");
178 rc = 0;
179 }
180 if (!thee->settargetRes) {
181 Vnm_print(2, "FEMparm_check: targetRes not set!\n");
182 rc = 0;
183 }
184 if (!thee->setmaxsolve) {
185 Vnm_print(2, "FEMparm_check: maxsolve not set!\n");
186 rc = 0;
187 }
188 if (!thee->setmaxvert) {
189 Vnm_print(2, "FEMparm_check: maxvert not set!\n");
190 rc = 0;
191 }
192
193 return rc;
194}
195
196VPRIVATE Vrc_Codes FEMparm_parseDOMAINLENGTH(FEMparm *thee,
197 Vio *sock
198 ) {
199
200 int i;
201 double tf;
202 char tok[VMAX_BUFSIZE];
203
204 for (i=0; i<3; i++) {
205 VJMPERR1(Vio_scanf(sock, "%s", tok) == 1);
206 if (sscanf(tok, "%lf", &tf) == 0) {
207 Vnm_print(2, "parseFE: Read non-double (%s) while parsing \
208DOMAINLENGTH keyword!\n", tok);
209 return VRC_FAILURE;
210 }
211 thee->glen[i] = tf;
212 }
213 thee->setglen = 1;
214 return VRC_SUCCESS;
215VERROR1:
216 Vnm_print(2, "parseFE: ran out of tokens!\n");
217 return VRC_FAILURE;
218
219}
220
221VPRIVATE Vrc_Codes FEMparm_parseETOL(FEMparm *thee,
222 Vio *sock
223 ) {
224
225 double tf;
226 char tok[VMAX_BUFSIZE];
227
228 VJMPERR1(Vio_scanf(sock, "%s", tok) == 1);
229 if (sscanf(tok, "%lf", &tf) == 0) {
230 Vnm_print(2, "parseFE: Read non-double (%s) while parsing \
231ETOL keyword!\n", tok);
232 return VRC_FAILURE;
233 }
234 thee->etol = tf;
235 thee->setetol = 1;
236 return VRC_SUCCESS;
237VERROR1:
238 Vnm_print(2, "parseFE: ran out of tokens!\n");
239 return VRC_FAILURE;
240
241
242}
243
244VPRIVATE Vrc_Codes FEMparm_parseEKEY(FEMparm *thee,
245 Vio *sock
246 ) {
247
248 char tok[VMAX_BUFSIZE];
249 Vrc_Codes vrc = VRC_FAILURE;
250
251 VJMPERR1(Vio_scanf(sock, "%s", tok) == 1);
252 if (Vstring_strcasecmp(tok, "simp") == 0) {
253 thee->ekey = FET_SIMP;
254 thee->setekey = 1;
255 vrc = VRC_SUCCESS;
256 } else if (Vstring_strcasecmp(tok, "glob") == 0) {
257 thee->ekey = FET_GLOB;
258 thee->setekey = 1;
259 vrc = VRC_SUCCESS;
260 } else if (Vstring_strcasecmp(tok, "frac") == 0) {
261 thee->ekey = FET_FRAC;
262 thee->setekey = 1;
263 vrc = VRC_SUCCESS;
264 } else {
265 Vnm_print(2, "parseFE: undefined value (%s) for ekey!\n", tok);
266 vrc = VRC_FAILURE;
267 }
268
269 return vrc;
270VERROR1:
271 Vnm_print(2, "parseFE: ran out of tokens!\n");
272 return VRC_FAILURE;
273
274}
275
276VPRIVATE Vrc_Codes FEMparm_parseAKEYPRE(FEMparm *thee, Vio *sock) {
277
278 char tok[VMAX_BUFSIZE];
279 Vrc_Codes vrc = VRC_FAILURE;
280
281 VJMPERR1(Vio_scanf(sock, "%s", tok) == 1);
282 if (Vstring_strcasecmp(tok, "unif") == 0) {
283 thee->akeyPRE = FRT_UNIF;
284 thee->setakeyPRE = 1;
285 vrc = VRC_SUCCESS;
286 } else if (Vstring_strcasecmp(tok, "geom") == 0) {
287 thee->akeyPRE = FRT_GEOM;
288 thee->setakeyPRE = 1;
289 vrc = VRC_SUCCESS;
290 } else {
291 Vnm_print(2, "parseFE: undefined value (%s) for akeyPRE!\n", tok);
292 vrc = VRC_FAILURE;
293 }
294
295 return vrc;
296
297VERROR1:
298 Vnm_print(2, "parseFE: ran out of tokens!\n");
299 return VRC_FAILURE;
300
301}
302
303VPRIVATE Vrc_Codes FEMparm_parseAKEYSOLVE(FEMparm *thee, Vio *sock) {
304
305 char tok[VMAX_BUFSIZE];
306 Vrc_Codes vrc = VRC_FAILURE;
307
308 VJMPERR1(Vio_scanf(sock, "%s", tok) == 1);
309 if (Vstring_strcasecmp(tok, "resi") == 0) {
310 thee->akeySOLVE = FRT_RESI;
311 thee->setakeySOLVE = 1;
312 vrc = VRC_SUCCESS;
313 } else if (Vstring_strcasecmp(tok, "dual") == 0) {
314 thee->akeySOLVE = FRT_DUAL;
315 thee->setakeySOLVE = 1;
316 vrc = VRC_SUCCESS;
317 } else if (Vstring_strcasecmp(tok, "loca") == 0) {
318 thee->akeySOLVE = FRT_LOCA;
319 thee->setakeySOLVE = 1;
320 vrc = VRC_SUCCESS;
321 } else {
322 Vnm_print(2, "parseFE: undefined value (%s) for akeyPRE!\n", tok);
323 vrc = VRC_FAILURE;
324 }
325
326 return vrc;
327VERROR1:
328 Vnm_print(2, "parseFE: ran out of tokens!\n");
329 return VRC_SUCCESS;
330
331}
332
333VPRIVATE Vrc_Codes FEMparm_parseTARGETNUM(FEMparm *thee, Vio *sock) {
334
335 char tok[VMAX_BUFSIZE];
336 int ti;
337
338 VJMPERR1(Vio_scanf(sock, "%s", tok) == 1);
339 if (sscanf(tok, "%d", &ti) == 0) {
340 Vnm_print(2, "parseFE: read non-int (%s) for targetNum!\n", tok);
341 return VRC_FAILURE;
342 }
343 thee->targetNum = ti;
344 thee->settargetNum = 1;
345 return VRC_SUCCESS;
346VERROR1:
347 Vnm_print(2, "parseFE: ran out of tokens!\n");
348 return VRC_FAILURE;
349
350}
351
352VPRIVATE Vrc_Codes FEMparm_parseTARGETRES(FEMparm *thee, Vio *sock) {
353
354 char tok[VMAX_BUFSIZE];
355 double tf;
356
357 VJMPERR1(Vio_scanf(sock, "%s", tok) == 1);
358 if (sscanf(tok, "%lf", &tf) == 0) {
359 Vnm_print(2, "parseFE: read non-double (%s) for targetNum!\n",
360 tok);
361 return VRC_FAILURE;
362 }
363 thee->targetRes = tf;
364 thee->settargetRes = 1;
365 return VRC_SUCCESS;
366VERROR1:
367 Vnm_print(2, "parseFE: ran out of tokens!\n");
368 return VRC_FAILURE;
369
370}
371
372VPRIVATE Vrc_Codes FEMparm_parseMAXSOLVE(FEMparm *thee, Vio *sock) {
373
374 char tok[VMAX_BUFSIZE];
375 int ti;
376
377 VJMPERR1(Vio_scanf(sock, "%s", tok) == 1);
378 if (sscanf(tok, "%d", &ti) == 0) {
379 Vnm_print(2, "parseFE: read non-int (%s) for maxsolve!\n", tok);
380 return VRC_FAILURE;
381 }
382 thee->maxsolve = ti;
383 thee->setmaxsolve = 1;
384 return VRC_SUCCESS;
385VERROR1:
386 Vnm_print(2, "parseFE: ran out of tokens!\n");
387 return VRC_FAILURE;
388
389}
390
391VPRIVATE Vrc_Codes FEMparm_parseMAXVERT(FEMparm *thee, Vio *sock) {
392
393 char tok[VMAX_BUFSIZE];
394 int ti;
395
396 VJMPERR1(Vio_scanf(sock, "%s", tok) == 1);
397 if (sscanf(tok, "%d", &ti) == 0) {
398 Vnm_print(2, "parseFE: read non-int (%s) for maxvert!\n", tok);
399 return VRC_FAILURE;
400 }
401 thee->maxvert = ti;
402 thee->setmaxvert = 1;
403 return VRC_SUCCESS;
404
405VERROR1:
406 Vnm_print(2, "parseFE: ran out of tokens!\n");
407 return VRC_FAILURE;
408
409}
410
411VPRIVATE Vrc_Codes FEMparm_parseUSEMESH(FEMparm *thee, Vio *sock) {
412 char tok[VMAX_BUFSIZE];
413 int ti;
414
415 VJMPERR1(Vio_scanf(sock, "%s", tok) == 1);
416 if (sscanf(tok, "%d", &ti) == 0) {
417 Vnm_print(2, "parseFE: read non-int (%s) for usemesh!\n", tok);
418 return VRC_FAILURE;
419 }
420 thee->useMesh = 1;
421 thee->meshID = ti;
422
423 return VRC_SUCCESS;
424
425VERROR1:
426 Vnm_print(2, "parsePBE: ran out of tokens!\n");
427 return VRC_FAILURE;
428}
429
430
431VPUBLIC Vrc_Codes FEMparm_parseToken(FEMparm *thee, char tok[VMAX_BUFSIZE],
432 Vio *sock) {
433
434 //int i, ti; // gcc says unused
435 //double tf; // gcc says unused
436
437 if (thee == VNULL) {
438 Vnm_print(2, "parseFE: got NULL thee!\n");
439 return VRC_FAILURE;
440 }
441
442 if (sock == VNULL) {
443 Vnm_print(2, "parseFE: got NULL socket!\n");
444 return VRC_FAILURE;
445 }
446
447 if (Vstring_strcasecmp(tok, "domainLength") == 0) {
448 return FEMparm_parseDOMAINLENGTH(thee, sock);
449 } else if (Vstring_strcasecmp(tok, "etol") == 0) {
450 return FEMparm_parseETOL(thee, sock);
451 } else if (Vstring_strcasecmp(tok, "ekey") == 0) {
452 return FEMparm_parseEKEY(thee, sock);
453 } else if (Vstring_strcasecmp(tok, "akeyPRE") == 0) {
454 return FEMparm_parseAKEYPRE(thee, sock);
455 } else if (Vstring_strcasecmp(tok, "akeySOLVE") == 0) {
456 return FEMparm_parseAKEYSOLVE(thee, sock);
457 } else if (Vstring_strcasecmp(tok, "targetNum") == 0) {
458 return FEMparm_parseTARGETNUM(thee, sock);
459 } else if (Vstring_strcasecmp(tok, "targetRes") == 0) {
460 return FEMparm_parseTARGETRES(thee, sock);
461 } else if (Vstring_strcasecmp(tok, "maxsolve") == 0) {
462 return FEMparm_parseMAXSOLVE(thee, sock);
463 } else if (Vstring_strcasecmp(tok, "maxvert") == 0) {
464 return FEMparm_parseMAXVERT(thee, sock);
465 } else if (Vstring_strcasecmp(tok, "usemesh") == 0) {
466 return FEMparm_parseUSEMESH(thee, sock);
467 }
468
469 return VRC_WARNING;
470
471}
Contains declarations for class APOLparm.
VPUBLIC void FEMparm_copy(FEMparm *thee, FEMparm *source)
Copy target object into thee.
Definition femparm.c:100
VPUBLIC FEMparm * FEMparm_ctor(FEMparm_CalcType type)
Construct FEMparm.
Definition femparm.c:65
VPUBLIC int FEMparm_check(FEMparm *thee)
Consistency check for parameter values stored in object.
Definition femparm.c:143
enum eFEMparm_CalcType FEMparm_CalcType
Declare FEMparm_CalcType type.
Definition femparm.h:126
VPUBLIC void FEMparm_dtor(FEMparm **thee)
Object destructor.
Definition femparm.c:133
VPUBLIC void FEMparm_dtor2(FEMparm *thee)
FORTRAN stub for object destructor.
Definition femparm.c:141
VPUBLIC int FEMparm_ctor2(FEMparm *thee, FEMparm_CalcType type)
FORTRAN stub to construct FEMparm.
Definition femparm.c:76
@ FET_SIMP
Definition femparm.h:80
@ FET_GLOB
Definition femparm.h:81
@ FET_FRAC
Definition femparm.h:82
@ FRT_GEOM
Definition femparm.h:100
@ FRT_LOCA
Definition femparm.h:104
@ FRT_RESI
Definition femparm.h:101
@ FRT_DUAL
Definition femparm.h:102
@ FRT_UNIF
Definition femparm.h:99
VPUBLIC Vrc_Codes FEMparm_parseToken(FEMparm *thee, char tok[VMAX_BUFSIZE], Vio *sock)
Parse an MG keyword from an input file.
Definition femparm.c:431
#define VEMBED(rctag)
Allows embedding of RCS ID tags in object files.
Definition vhal.h:556
@ VRC_FAILURE
Definition vhal.h:69
@ VRC_SUCCESS
Definition vhal.h:70
VPUBLIC int Vstring_strcasecmp(const char *s1, const char *s2)
Case-insensitive string comparison (BSD standard)
Definition vstring.c:66
Parameter structure for FEM-specific variables from input files.
Definition femparm.h:133
int useMesh
Definition femparm.h:173
int setmaxvert
Definition femparm.h:169
int setakeyPRE
Definition femparm.h:151
FEMparm_EstType akeySOLVE
Definition femparm.h:152
double glen[3]
Definition femparm.h:140
int parsed
Definition femparm.h:135
int settype
Definition femparm.h:139
int setmaxsolve
Definition femparm.h:166
int meshID
Definition femparm.h:174
FEMparm_CalcType type
Definition femparm.h:138
int maxsolve
Definition femparm.h:165
int settargetRes
Definition femparm.h:164
FEMparm_EstType akeyPRE
Definition femparm.h:148
FEMparm_EtolType ekey
Definition femparm.h:145
double etol
Definition femparm.h:142
int settargetNum
Definition femparm.h:159
int setekey
Definition femparm.h:147
int setakeySOLVE
Definition femparm.h:154
int pkey
Definition femparm.h:170
int targetNum
Definition femparm.h:155
int maxvert
Definition femparm.h:167
int setglen
Definition femparm.h:141
double targetRes
Definition femparm.h:160
int setetol
Definition femparm.h:144