1 /*
2  * ***************************************************************************
3  * MC = < Manifold Code >
4  * Copyright (C) 1994-- Michael Holst
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19  *
20  * rcsid="$Id: mcsh-old.c,v 1.3 2010/08/12 05:19:09 fetk Exp $"
21  * ***************************************************************************
22  */
23 
24 /*
25  * ***************************************************************************
26  * File:     mcsh.c
27  *
28  * Purpose:  Class MCsh: methods.
29  *
30  * Author:   Michael Holst
31  * ***************************************************************************
32  */
33 
34 #include "mcsh_p.h"
35 
36 VEMBED(rcsid="$Id: mcsh-old.c,v 1.3 2010/08/12 05:19:09 fetk Exp $")
37 
38 /* builtin MCsh commands */
39 typedef enum MCsh_command {
40     mccom_none,
41     mccom_mark,
42     mccom_lsolve,
43     mccom_dsolve,
44     mccom_nsolve,
45     mccom_estimate,
46     mccom_refine,
47     mccom_deform,
48     mccom_part,
49     mccom_partsmooth,
50     mccom_partset,
51     mccom_evall2,
52     mccom_evall8,
53     mccom_evalh1,
54     mccom_makebnd,
55     mccom_makebndd,
56     mccom_makebndn,
57     mccom_makebndx,
58     mccom_gen,
59     mccom_reordersv,
60     mccom_smooth,
61     mccom_smoothb,
62     mccom_smootho,
63     mccom_tangent,
64     mccom_formfix,
65     mccom_evalj,
66     mccom_eval,
67     mccom_evalbint,
68     mccom_buildcharts,
69     mccom_clearcharts,
70     mccom_read,
71     mccom_write,
72     mccom_writebrep,
73     mccom_writeoff,
74     mccom_writeoffdef,
75     mccom_writeoffdis,
76     mccom_writemath,
77     mccom_writemathdef,
78     mccom_writemathdis,
79     mccom_writegmv,
80     mccom_writeucd,
81     mccom_writedx,
82     mccom_writetec,
83     mccom_printj,
84     mccom_printa,
85     mccom_printasp,
86     mccom_printanod,
87     mccom_printaspnod,
88     mccom_printc,
89     mccom_printcsp,
90     mccom_printcnod,
91     mccom_printcspnod,
92     mccom_printp,
93     mccom_printpsp,
94     mccom_printv,
95     mccom_printvsp,
96     mccom_typechk,
97     mccom_memchk,
98     mccom_shapechk,
99     mccom_formchk,
100     mccom_formchkf,
101     mccom_contentchk,
102     mccom_speedchk,
103     mccom_free,
104     mccom_help
105 } MCsh_command;
106 
107 /*
108  * ***************************************************************************
109  * Class MCsh: Inlineable methods
110  * ***************************************************************************
111  */
112 #if !defined(VINLINE_MCSH)
113 
114 #endif /* if !defined(VINLINE_MCSH) */
115 /*
116  * ***************************************************************************
117  * Class MCsh: Non-inlineable methods
118  * ***************************************************************************
119  */
120 
121 /*
122  * ***************************************************************************
123  * Routine:  MCsh_ctor
124  *
125  * Purpose:  The MCsh constructor.
126  *
127  * Author:   Michael Holst
128  * ***************************************************************************
129  */
MCsh_ctor(PDE * tpde,int argc,char ** argv)130 VPUBLIC MCsh* MCsh_ctor(PDE *tpde, int argc, char **argv)
131 {
132     MCsh *thee = VNULL;
133 
134     VDEBUGIO("MCsh_ctor: CREATING object..");
135 
136     thee = Vmem_malloc( VNULL, 1, sizeof(MCsh) );
137     thee->vmem = Vmem_ctor( "MCsh" );
138 
139     VDEBUGIO("..done.\n");
140 
141     /* the environment and shell object */
142     thee->PR[0] = '\0';
143     thee->USER_shell = VNULL;
144     thee->vsh = Vsh_ctor(VNULL, argc, argv);
145 
146     /* the differential equation object */
147     thee->pde = tpde;
148 
149     /* the geometry manager object */
150     thee->gm = Gem_ctor( VNULL, thee->pde );
151 
152     /* the approximation object */
153     thee->aprx = Aprx_ctor( VNULL, thee->gm, thee->pde );
154 
155     /* the algebra manager object */
156     thee->am = AM_ctor( VNULL, thee->aprx );
157 
158     return thee;
159 }
160 
161 /*
162  * ***************************************************************************
163  * Routine:  MCsh_dtor
164  *
165  * Purpose:  The MCsh destructor.
166  *
167  * Author:   Michael Holst
168  * ***************************************************************************
169  */
MCsh_dtor(MCsh ** thee)170 VPUBLIC void MCsh_dtor(MCsh **thee)
171 {
172     VASSERT( (*thee) != VNULL );
173     if ((*thee) != VNULL) {
174 
175         AM_dtor(   &((*thee)->am) );
176         Aprx_dtor( &((*thee)->aprx) );
177         Gem_dtor(  &((*thee)->gm) );
178         Vsh_dtor(  &((*thee)->vsh) );
179 
180         VDEBUGIO("MCsh_dtor: DESTROYING object..");
181         Vmem_dtor( &((*thee)->vmem) );
182         Vmem_free( VNULL, 1, sizeof(MCsh), (void**)thee );
183         VDEBUGIO("..done.\n");
184 
185         (*thee) = VNULL;
186     }
187 }
188 
189 /*
190  * ***************************************************************************
191  * Routine:  MCsh_publishVars
192  *
193  * Purpose:  Publish a set of environment variables with Vsh.
194  *
195  * Author:   Michael Holst
196  * ***************************************************************************
197  */
MCsh_publishVars(MCsh * thee)198 VPRIVATE void MCsh_publishVars(MCsh *thee)
199 {
200     int i, numVars = 25;
201     typedef struct mcVars {
202         char envi[80];
203         char valu[80];
204         char info[80];
205     } mcVars;
206     mcVars envVars[] = {
207 
208         /* --------   -----       ----------- */
209         /* VARIABLE   VALUE       EXPLANATION */
210         /* --------   -----       ----------- */
211 
212         /* ===[ MESH=10]=== */
213         { "ETOL",     "1.0e-2",
214             "error estimator tolerance (error per simplex)" },
215         { "EKEY",     "1",
216             "error barrier choice (0=ETOL, 1=ETOL/#simplices)" },
217         { "AKEY",     "1",
218             "estimator (-1=clear,0=all,1=user,2=nresid,3=dual,4=loc,5=rgrad)" },
219         { "RKEY",     "0",
220             "simplex refinement method (0=b-b, 1=q-b, 2=q-q)" },
221         { "BKEY",     "0",
222             "bisection type (0=longest edge, 1=newest vertex, 2=newest pair)" },
223         { "RCOL",     "-1",
224             "refine restriction (-1=none,k>=0=>restrict to subd k)" },
225         { "PKEY",     "0",
226             "partition method (0=inert,1=spect,2=gspect,3=i-then-s)" },
227         { "PWHT",     "0",
228             "partitioning weighting (0=none, 1=by error)" },
229         { "PPOW",     "1",
230             "partitioning steps (0=none,1=one,etc) [part=2^ppow]" },
231         { "PROK",     "0",
232             "prolongation operator (0=[I,P], 1=[P])" },
233 
234         /* ===[ SOLV=10 ]=== */
235         { "LKEY",     "0",
236             "linear solver (0=slu,1=mg,2=cg,3=bcg)" },
237         { "NKEY",     "0",
238             "nonlinear solver (0=newton,1=incremental,2=pseudo-arclength)" },
239         { "PREC",     "0",
240             "preconditioner (0=identity,1=diag-scale,2=mg)" },
241         { "LTOL",     "1.0e-7",
242             "linear solve tolerance (2-norm of rel resid)" },
243         { "NTOL",     "1.0e-7",
244             "nonlinear solve tolerance (2-norm of nonlinear resid)" },
245         { "LMAX",     "100",
246             "linear solve itmax (standalone or inside Newton)" },
247         { "NMAX",     "100",
248             "nonlinear solve itmax (e.g. Newton iteration max)" },
249         { "GUES",     "2",
250             "initial guess (0=0,1=ud,2=I_h[u])" },
251         { "PJAC",     "-1",
252             "print jacs (-1=no,-2=all,k>=0=>kth jac as jac_k.m)" },
253         { "PVEC",     "-1",
254             "which vec (...,-1=u+ud,0=f,1=u,2=ud,3=ui,4=ut,5=r,...)" },
255 
256         /* ===[ GRAPHICS=5 ]=== */
257         { "TKEY",     "0",
258             "mesh i/o format (0=simplex,1=edge,2=simplex-nabor)" },
259         { "FKEY",     "0",
260             "volume/face plot/write (0=volume,1=face)  [3D only]" },
261         { "CKEY",     "1",
262             "color (0=none,1=simplex chart#,2=by bndry face type)" },
263         { "DKEY",     "-1",
264             "subd write (-1=entire mesh,0<=k chart# simps only)" },
265         { "GVAL",     "1.0e-0",
266             "glue value (separation of simplices in graphics)" },
267     };
268 
269     for (i=0; i<numVars; i++) {
270         Vsh_putenv(     thee->vsh, envVars[i].envi, envVars[i].valu );
271         Vsh_putenvInfo( thee->vsh, envVars[i].envi, envVars[i].info );
272     }
273 }
274 
275 /*
276  * ***************************************************************************
277  * Routine:  MCsh_getCmd
278  *
279  * Purpose:  Get (decode) the command.
280  *
281  * Author:   Michael Holst
282  * ***************************************************************************
283  */
MCsh_getCmd(MCsh * thee,int argc,char ** argv)284 VPRIVATE MCsh_command MCsh_getCmd(MCsh *thee, int argc, char **argv)
285 {
286     MCsh_command theCmd = mccom_none;
287     if (!strcmp(argv[0],"")) {
288         theCmd = mccom_none;
289     } else if (!strcmp(argv[0],"help")) {
290         theCmd = mccom_help;
291     } else if (!strcmp(argv[0],"mark")) {
292         theCmd = mccom_mark;
293     } else if (!strcmp(argv[0],"lsolve")) {
294         theCmd = mccom_lsolve;
295     } else if (!strcmp(argv[0],"dsolve")) {
296         theCmd = mccom_dsolve;
297     } else if (!strcmp(argv[0],"nsolve")) {
298         theCmd = mccom_nsolve;
299     } else if (!strcmp(argv[0],"estimate")) {
300         theCmd = mccom_estimate;
301     } else if (!strcmp(argv[0],"refine")) {
302         theCmd = mccom_refine;
303     } else if (!strcmp(argv[0],"deform")) {
304         theCmd = mccom_deform;
305     } else if (!strcmp(argv[0],"part")) {
306         theCmd = mccom_part;
307     } else if (!strcmp(argv[0],"partsmooth")) {
308         theCmd = mccom_partsmooth;
309     } else if (!strcmp(argv[0],"partset")) {
310         theCmd = mccom_partset;
311     } else if (!strcmp(argv[0],"evall2")) {
312         theCmd = mccom_evall2;
313     } else if (!strcmp(argv[0],"evall8")) {
314         theCmd = mccom_evall8;
315     } else if (!strcmp(argv[0],"evalh1")) {
316         theCmd = mccom_evalh1;
317     } else if (!strcmp(argv[0],"makebnd")) {
318         theCmd = mccom_makebnd;
319     } else if (!strcmp(argv[0],"makebndd")) {
320         theCmd = mccom_makebndd;
321     } else if (!strcmp(argv[0],"makebndn")) {
322         theCmd = mccom_makebndn;
323     } else if (!strcmp(argv[0],"makebndx")) {
324         theCmd = mccom_makebndx;
325     } else if (!strcmp(argv[0],"gen")) {
326         theCmd = mccom_gen;
327     } else if (!strcmp(argv[0],"reordersv")) {
328         theCmd = mccom_reordersv;
329     } else if (!strcmp(argv[0],"smooth")) {
330         theCmd = mccom_smooth;
331     } else if (!strcmp(argv[0],"smoothb")) {
332         theCmd = mccom_smoothb;
333     } else if (!strcmp(argv[0],"smootho")) {
334         theCmd = mccom_smootho;
335     } else if (!strcmp(argv[0],"tangent")) {
336         theCmd = mccom_tangent;
337     } else if (!strcmp(argv[0],"formfix")) {
338         theCmd = mccom_formfix;
339     } else if (!strcmp(argv[0],"evalj")) {
340         theCmd = mccom_evalj;
341     } else if (!strcmp(argv[0],"eval")) {
342         theCmd = mccom_eval;
343     } else if (!strcmp(argv[0],"evalbint")) {
344         theCmd = mccom_evalbint;
345     } else if (!strcmp(argv[0],"buildcharts")) {
346         theCmd = mccom_buildcharts;
347     } else if (!strcmp(argv[0],"clearcharts")) {
348         theCmd = mccom_clearcharts;
349     } else if (!strcmp(argv[0],"read")) {
350         theCmd = mccom_read;
351     } else if (!strcmp(argv[0],"write")) {
352         theCmd = mccom_write;
353     } else if (!strcmp(argv[0],"writebrep")) {
354         theCmd = mccom_writebrep;
355     } else if (!strcmp(argv[0],"writeoff")) {
356         theCmd = mccom_writeoff;
357     } else if (!strcmp(argv[0],"writeoffdef")) {
358         theCmd = mccom_writeoffdef;
359     } else if (!strcmp(argv[0],"writeoffdis")) {
360         theCmd = mccom_writeoffdis;
361     } else if (!strcmp(argv[0],"writemath")) {
362         theCmd = mccom_writemath;
363     } else if (!strcmp(argv[0],"writemathdef")) {
364         theCmd = mccom_writemathdef;
365     } else if (!strcmp(argv[0],"writemathdis")) {
366         theCmd = mccom_writemathdis;
367     } else if (!strcmp(argv[0],"writegmv")) {
368         theCmd = mccom_writegmv;
369     } else if (!strcmp(argv[0],"writeucd")) {
370         theCmd = mccom_writeucd;
371     } else if (!strcmp(argv[0],"writedx")) {
372         theCmd = mccom_writedx;
373     } else if (!strcmp(argv[0],"writetec")) {
374         theCmd = mccom_writetec;
375     } else if (!strcmp(argv[0],"printj")) {
376         theCmd = mccom_printj;
377     } else if (!strcmp(argv[0],"printa")) {
378         theCmd = mccom_printa;
379     } else if (!strcmp(argv[0],"printasp")) {
380         theCmd = mccom_printasp;
381     } else if (!strcmp(argv[0],"printanod")) {
382         theCmd = mccom_printanod;
383     } else if (!strcmp(argv[0],"printaspnod")) {
384         theCmd = mccom_printaspnod;
385     } else if (!strcmp(argv[0],"printc")) {
386         theCmd = mccom_printc;
387     } else if (!strcmp(argv[0],"printcsp")) {
388         theCmd = mccom_printcsp;
389     } else if (!strcmp(argv[0],"printcnod")) {
390         theCmd = mccom_printcnod;
391     } else if (!strcmp(argv[0],"printcspnod")) {
392         theCmd = mccom_printcspnod;
393     } else if (!strcmp(argv[0],"printp")) {
394         theCmd = mccom_printp;
395     } else if (!strcmp(argv[0],"printpsp")) {
396         theCmd = mccom_printpsp;
397     } else if (!strcmp(argv[0],"printv")) {
398         theCmd = mccom_printv;
399     } else if (!strcmp(argv[0],"printvsp")) {
400         theCmd = mccom_printvsp;
401     } else if (!strcmp(argv[0],"typechk")) {
402         theCmd = mccom_typechk;
403     } else if (!strcmp(argv[0],"memchk")) {
404         theCmd = mccom_memchk;
405     } else if (!strcmp(argv[0],"shapechk")) {
406         theCmd = mccom_shapechk;
407     } else if (!strcmp(argv[0],"formchk")) {
408         theCmd = mccom_formchk;
409     } else if (!strcmp(argv[0],"formchkf")) {
410         theCmd = mccom_formchkf;
411     } else if (!strcmp(argv[0],"contentchk")) {
412         theCmd = mccom_contentchk;
413     } else if (!strcmp(argv[0],"speedchk")) {
414         theCmd = mccom_speedchk;
415     } else if (!strcmp(argv[0],"free")) {
416         theCmd = mccom_free;
417     } else {
418         theCmd = mccom_none;
419     }
420     return theCmd;
421 }
422 
423 /*
424  * ***************************************************************************
425  * Routine:  MCsh_builtIn
426  *
427  * Purpose:  Deal with a builtin command.
428  *
429  * Author:   Michael Holst
430  * ***************************************************************************
431  */
MCsh_builtIn(void * pthee,int argc,char ** argv)432 VPRIVATE int MCsh_builtIn(void *pthee, int argc, char **argv)
433 {
434     MCsh *thee = (MCsh*)pthee;
435 
436     int i,rc,defKey,ncolor,marked;
437     int block, numPts, marks[6];
438     double *defX[3] = { VNULL, VNULL, VNULL };
439     double pts[6*3], vals[6];
440     MCsh_command theCmd;
441     Vio *sock;
442 
443     static int  init=0;
444     static char num[VMAX_BUFSIZE], mesh[VMAX_BUFSIZE], solv[VMAX_BUFSIZE];
445     const char *stmp;
446 
447     /* one-time intialization */
448     if (!init) {
449         init=1;
450 
451         /* no simplices have been marked */
452         Vsh_putenvInt(thee->vsh,"MARKED",0);
453 
454         /* make the num message (%s slots = 1) */
455         stmp = "%s: General numerical commands: \n"
456                "    speedchk --> run a speed check\n"
457                "    free     --> free any extra mallocs\n";
458         sprintf(num,stmp,thee->PR);
459 
460         /* make the mesh message (%s slots = 1) */
461         /* (NOTE: Only 509 char-length constant strings supported in ISO C) */
462         stmp = "%s: Mesh manipulation commands: \n"
463                "    mark        --> mark a mesh\n"
464                "    estimate    --> a posteriori error estim\n"
465                "    refine      --> refine the mesh\n"
466                "    deform      --> deform the mesh using existing solution\n"
467                "    makebnd     --> clear all bndry faces in mesh\n";
468         sprintf(mesh,stmp,thee->PR);
469         stmp = "    makebndd    --> rebuild dirichlet bndry faces in mesh\n"
470                "    makebndn    --> rebuild neumann bndry faces in mesh\n"
471                "    makebndx    --> rebuild special bndry faces in mesh\n"
472                "    gen         --> generate delaunay mesh\n"
473                "    reordersv   --> reorder the vertices in every simplex\n";
474         strcat(mesh,stmp);
475         stmp = "    smooth      --> interior mesh smoothing\n"
476                "    smoothb     --> boundary mesh smoothing\n"
477                "    smootho     --> optimization mesh smoothing\n"
478                "    tangent     --> build tangent plane at each vertex\n"
479                "    formfix     --> make a specific fix to a mesh\n";
480         strcat(mesh,stmp);
481         stmp = "    buildcharts --> build the manifold charts\n"
482                "    clearcharts --> clear the manifold charts\n"
483                "    typechk     --> run a datatype size check\n"
484                "    memchk      --> run a memory check\n"
485                "    shapechk    --> run element shape check\n"
486                "    formchk     --> run ringed-vertex datastructure check\n";
487         strcat(mesh,stmp);
488         stmp = "    formchkf    --> run formcheck and also conformity check\n"
489                "    contentchk  --> run geometry content check\n"
490                "    part        --> mesh partition (recursive bisection)\n"
491                "    partsmooth  --> smooth the partition\n"
492                "    partset     --> reset the partition\n";
493         strcat(mesh,stmp);
494         stmp = "    read        --> read mesh in MC-Simplex-Format (MCSF)\n"
495                "    write       --> write mesh in MC-Simplex-Format (MCSF)\n"
496                "    writebrep   --> write bdry mesh in GeomPak BREP-Format\n"
497                "    writeoff    --> write mesh in Geomview OFF-Format\n"
498                "    writemath   --> write mesh in Mathematica MATH-Format\n";
499         strcat(mesh,stmp);
500 
501         /* make the solv message (%s slots = 1) */
502         stmp = "%s: Solver related commands: \n"
503                "    lsolve      --> solve linear problem\n"
504                "    dsolve      --> solve linear dual problem\n"
505                "    nsolve      --> solve nonlinear problem\n"
506                "    evalj       --> energy functional of global FE solution\n"
507                "    eval        --> evaluate FE function at a point\n";
508         sprintf(solv,stmp,thee->PR);
509         stmp = "    evalbint    --> evaluate FE function boundary integral\n"
510                "    evall2      --> L2-norm of error in subdomain <rcol>\n"
511                "    evall8      --> L8-norm of error in subdomain <rcol>\n"
512                "    evalh1      --> H1-norm of error in subdomain <rcol>\n"
513                "    printa      --> print fine jac matrix\n";
514         strcat(solv,stmp);
515         stmp = "    printasp    --> print fine jac matrix (sparse .m)\n"
516                "    printc      --> print coarse jac matrix\n"
517                "    printcsp    --> print coarse jac matrix (sparse .m)\n"
518                "    printp      --> print prolongation matrix\n"
519                "    printpsp    --> print prolongation matrix (sparse .m)\n";
520         strcat(solv,stmp);
521         stmp = "    printv      --> print a vector\n"
522                "    printvsp    --> print a vector (sparse .m)\n"
523                "    printanod   --> printa with dirichlet equations zeroed\n"
524                "    printaspnod --> printasp with dirichlet equations zeroed\n"
525                "    printcnod   --> printc with dirichlet equations zeroed\n";
526         strcat(solv,stmp);
527         stmp = "    printcspnod --> printcsp with dirichlet equations zeroed\n"
528                "    writeoffdef --> write deformation in OFF-Format\n"
529                "    writeoffdis --> write displacement in OFF-Format\n"
530                "    writemathdef--> write deformation in MATH-Format\n"
531                "    writemathdis--> write displacement in MATH-Format\n"
532                "    writegmv    --> write solution in GMV-Format\n"
533                "    writeucd    --> write solution in UCD-Format\n"
534                "    writedx     --> write solution in DX-Format\n"
535                "    writetec    --> write solution in TECPLOT-Format\n";
536         strcat(solv,stmp);
537     }
538 
539     /* the user-defined shell gets first shot at the command */
540     if (thee->USER_shell != VNULL) {
541         rc = (*(thee->USER_shell))(thee,argc,argv);
542         if (rc != 0) return rc;
543     }
544 
545     /* default return code (success) */
546     rc = 1;
547 
548     /* get the command */
549     theCmd = MCsh_getCmd(thee, argc, argv);
550 
551     /* decode and execute the command */
552     switch (theCmd) {
553 
554       case mccom_mark:
555         marked = Gem_markRefine(thee->gm,
556             Vsh_getenvInt(thee->vsh,"AKEY"),
557             Vsh_getenvInt(thee->vsh,"RCOL"));
558         Vsh_putenvInt(thee->vsh,"MARKED",marked);
559         break;
560 
561       case mccom_lsolve:
562         AM_lSolve(thee->am,
563             0,
564             Vsh_getenvInt(thee->vsh,"LKEY"),
565             Vsh_getenvInt(thee->vsh,"LMAX"),
566             Vsh_getenvReal(thee->vsh,"LTOL"),
567             Vsh_getenvInt(thee->vsh,"PREC"),
568             Vsh_getenvInt(thee->vsh,"GUES"),
569             Vsh_getenvInt(thee->vsh,"PJAC"));
570         break;
571 
572       case mccom_dsolve:
573         AM_lSolve(thee->am,
574             1,
575             Vsh_getenvInt(thee->vsh,"LKEY"),
576             Vsh_getenvInt(thee->vsh,"LMAX"),
577             Vsh_getenvReal(thee->vsh,"LTOL"),
578             Vsh_getenvInt(thee->vsh,"PREC"),
579             Vsh_getenvInt(thee->vsh,"GUES"),
580             Vsh_getenvInt(thee->vsh,"PJAC"));
581         break;
582 
583       case mccom_nsolve:
584         AM_nSolve(thee->am,
585             Vsh_getenvInt(thee->vsh,"NKEY"),
586             Vsh_getenvInt(thee->vsh,"NMAX"),
587             Vsh_getenvReal(thee->vsh,"NTOL"),
588             Vsh_getenvInt(thee->vsh,"LKEY"),
589             Vsh_getenvInt(thee->vsh,"LMAX"),
590             Vsh_getenvReal(thee->vsh,"LTOL"),
591             Vsh_getenvInt(thee->vsh,"PREC"),
592             Vsh_getenvInt(thee->vsh,"GUES"),
593             Vsh_getenvInt(thee->vsh,"PJAC"));
594         break;
595 
596       case mccom_estimate:
597         marked = AM_markRefine(thee->am,
598             Vsh_getenvInt(thee->vsh,"AKEY"),
599             Vsh_getenvInt(thee->vsh,"RCOL"),
600             Vsh_getenvInt(thee->vsh,"EKEY"),
601             Vsh_getenvReal(thee->vsh,"ETOL"));
602         Vsh_putenvInt(thee->vsh,"MARKED",marked);
603         break;
604 
605       case mccom_refine:
606         marked = Vsh_getenvInt(thee->vsh,"MARKED");
607         if (marked) {
608             (void)AM_refine(thee->am,
609                 Vsh_getenvInt(thee->vsh,"RKEY"),
610                 Vsh_getenvInt(thee->vsh,"BKEY"),
611                 Vsh_getenvInt(thee->vsh,"PROK"));
612             Vsh_putenvInt(thee->vsh,"MARKED",0);
613         }
614         break;
615 
616       case mccom_deform:
617         (void)AM_deform(thee->am);
618         break;
619 
620       case mccom_part:
621         (void)AM_part(thee->am,
622             Vsh_getenvInt(thee->vsh,"PKEY"),
623             Vsh_getenvInt(thee->vsh,"PWHT"),
624             Vsh_getenvInt(thee->vsh,"PPOW"));
625         break;
626 
627       case mccom_partsmooth:
628         ncolor = AM_partSmooth(thee->am);
629         break;
630 
631       case mccom_partset:
632         ncolor = 0;
633         ncolor = AM_partSet(thee->am,ncolor);
634         break;
635 
636       case mccom_evall2:
637         (void)AM_evalError(thee->am,
638             Vsh_getenvInt(thee->vsh,"RCOL"),
639             0);
640         break;
641 
642       case mccom_evall8:
643         (void)AM_evalError(thee->am,
644             Vsh_getenvInt(thee->vsh,"RCOL"),
645             1);
646         break;
647 
648       case mccom_evalh1:
649         (void)AM_evalError(thee->am,
650             Vsh_getenvInt(thee->vsh,"RCOL"),
651             2);
652         break;
653 
654       case mccom_makebnd:
655         Gem_makeBnd(thee->gm,0);
656         break;
657 
658       case mccom_makebndd:
659         Gem_makeBnd(thee->gm,1);
660         break;
661 
662       case mccom_makebndn:
663         Gem_makeBnd(thee->gm,2);
664         break;
665 
666       case mccom_makebndx:
667         Gem_makeBndExt(thee->gm,0);
668         break;
669 
670       case mccom_gen:
671         Gem_delaunay(thee->gm);
672         break;
673 
674       case mccom_reordersv:
675         Gem_reorderSV(thee->gm);
676         break;
677 
678       case mccom_smooth:
679         Gem_smoothMesh(thee->gm);
680         break;
681 
682       case mccom_smoothb:
683         Gem_smoothMeshBnd(thee->gm);
684         break;
685 
686       case mccom_smootho:
687         Gem_smoothMeshOpt(thee->gm);
688         break;
689 
690       case mccom_formfix:
691         Gem_formFix(thee->gm,0);
692         break;
693 
694       case mccom_evalj:
695         (void)AM_evalJ(thee->am);
696         break;
697 
698       case mccom_eval:
699 #if 0
700         pts[0]  =  1.; pts[1]  =  0.; pts[2]  =  0.;
701         pts[3]  =  0.; pts[4]  =  1.; pts[5]  =  0.;
702         pts[6]  =  0.; pts[7]  =  0.; pts[8]  =  1.;
703         pts[9]  = -1.; pts[10] =  0.; pts[11] =  0.;
704         pts[12] =  0.; pts[13] = -1.; pts[14] =  0.;
705         pts[15] =  0.; pts[16] =  0.; pts[17] = -1.;
706 #else
707         pts[0]  =  0.0; pts[1]  =  0.0; pts[2]  =  2.1;
708         pts[3]  =  0.0; pts[4]  =  2.1; pts[5]  =  0.0;
709         pts[6]  =  2.1; pts[7]  =  0.0; pts[8]  =  0.0;
710         pts[9]  =  0.0; pts[10] =  0.0; pts[11] = -2.1;
711         pts[12] =  0.0; pts[13] = -2.1; pts[14] =  0.0;
712         pts[15] = -2.1; pts[16] =  0.0; pts[17] =  0.0;
713 #endif
714         block  = 0;
715         numPts = 6;
716         AM_evalFunc(thee->am,
717             Vsh_getenvInt(thee->vsh,"PVEC"),
718             block, numPts, pts, vals, marks);
719         for (i=0; i<numPts; i++) {
720             Vnm_print(0,"MCsh_builtIn: W_{%d}(%g,%g,%g)=<%g>\n",
721                 Vsh_getenvInt(thee->vsh,"PVEC"),
722                 pts[i*3+0],pts[i*3+1],pts[i*3+2],vals[i]);
723         }
724         break;
725 
726       case mccom_evalbint:
727         AM_bndIntegral(thee->am);
728         break;
729 
730       case mccom_buildcharts:
731         Gem_buildCharts(thee->gm);
732         break;
733 
734       case mccom_clearcharts:
735         Gem_clearCharts(thee->gm);
736         break;
737 
738       case mccom_read:
739         sock = Vsh_ioSetup(thee->vsh,"r");
740         (void)AM_read(thee->am,
741             Vsh_getenvInt(thee->vsh,"TKEY"),
742             sock);
743         Vsh_ioCleanup(thee->vsh,&sock);
744         Vsh_putenvInt(thee->vsh,"MARKED",0);
745         break;
746 
747       case mccom_write:
748         sock = Vsh_ioSetup(thee->vsh,"w");
749         Gem_write(thee->gm,
750             Vsh_getenvInt(thee->vsh,"TKEY"),
751             sock,
752             Vsh_getenvInt(thee->vsh,"FKEY"));
753         Vsh_ioCleanup(thee->vsh,&sock);
754         break;
755 
756       case mccom_writebrep:
757         sock = Vsh_ioSetup(thee->vsh,"w");
758         Gem_writeBrep(thee->gm,sock);
759         Vsh_ioCleanup(thee->vsh,&sock);
760         break;
761 
762       case mccom_writeoff:
763         defKey = 0;
764         sock = Vsh_ioSetup(thee->vsh,"w");
765         Gem_writeGEOM(thee->gm,
766             sock,
767             defKey,
768             Vsh_getenvInt(thee->vsh,"CKEY"),
769             Vsh_getenvInt(thee->vsh,"DKEY"),
770             Vsh_getenvReal(thee->vsh,"GVAL"),
771             Vsh_getenvInt(thee->vsh,"FKEY"),
772             defX,
773             "GV");
774         Vsh_ioCleanup(thee->vsh,&sock);
775         break;
776 
777       case mccom_writeoffdef:
778         defKey = 1;
779         sock = Vsh_ioSetup(thee->vsh,"w");
780         AM_writeGEOM(thee->am,
781             sock,
782             defKey,
783             Vsh_getenvInt(thee->vsh,"CKEY"),
784             Vsh_getenvInt(thee->vsh,"DKEY"),
785             Vsh_getenvReal(thee->vsh,"GVAL"),
786             Vsh_getenvInt(thee->vsh,"FKEY"),
787             Vsh_getenvInt(thee->vsh,"PVEC"),
788             "GV");
789         Vsh_ioCleanup(thee->vsh,&sock);
790         break;
791 
792       case mccom_writeoffdis:
793         defKey = 2;
794         sock = Vsh_ioSetup(thee->vsh,"w");
795         AM_writeGEOM(thee->am,
796             sock,
797             defKey,
798             Vsh_getenvInt(thee->vsh,"CKEY"),
799             Vsh_getenvInt(thee->vsh,"DKEY"),
800             Vsh_getenvReal(thee->vsh,"GVAL"),
801             Vsh_getenvInt(thee->vsh,"FKEY"),
802             Vsh_getenvInt(thee->vsh,"PVEC"),
803             "GV");
804         Vsh_ioCleanup(thee->vsh,&sock);
805         break;
806 
807       case mccom_writemath:
808         defKey = 0;
809         sock = Vsh_ioSetup(thee->vsh,"w");
810         Gem_writeGEOM(thee->gm,
811             sock,
812             defKey,
813             Vsh_getenvInt(thee->vsh,"CKEY"),
814             Vsh_getenvInt(thee->vsh,"DKEY"),
815             Vsh_getenvReal(thee->vsh,"GVAL"),
816             Vsh_getenvInt(thee->vsh,"FKEY"),
817             defX,
818             "MATH");
819         Vsh_ioCleanup(thee->vsh,&sock);
820         break;
821 
822       case mccom_writemathdef:
823         defKey = 1;
824         sock = Vsh_ioSetup(thee->vsh,"w");
825         AM_writeGEOM(thee->am,
826             sock,
827             defKey,
828             Vsh_getenvInt(thee->vsh,"CKEY"),
829             Vsh_getenvInt(thee->vsh,"DKEY"),
830             Vsh_getenvReal(thee->vsh,"GVAL"),
831             Vsh_getenvInt(thee->vsh,"FKEY"),
832             Vsh_getenvInt(thee->vsh,"PVEC"),
833             "MATH");
834         Vsh_ioCleanup(thee->vsh,&sock);
835         break;
836 
837       case mccom_writemathdis:
838         defKey = 2;
839         sock = Vsh_ioSetup(thee->vsh,"w");
840         AM_writeGEOM(thee->am,
841             sock,
842             defKey,
843             Vsh_getenvInt(thee->vsh,"CKEY"),
844             Vsh_getenvInt(thee->vsh,"DKEY"),
845             Vsh_getenvReal(thee->vsh,"GVAL"),
846             Vsh_getenvInt(thee->vsh,"FKEY"),
847             Vsh_getenvInt(thee->vsh,"PVEC"),
848             "MATH");
849         Vsh_ioCleanup(thee->vsh,&sock);
850         break;
851 
852       case mccom_writegmv:
853         sock = Vsh_ioSetup(thee->vsh,"w");
854         AM_writeSOL(thee->am,
855             sock,
856             Vsh_getenvInt(thee->vsh,"PVEC"),
857             "GMV");
858         Vsh_ioCleanup(thee->vsh,&sock);
859         break;
860 
861       case mccom_writeucd:
862         sock = Vsh_ioSetup(thee->vsh,"w");
863         AM_writeSOL(thee->am,
864             sock,
865             Vsh_getenvInt(thee->vsh,"PVEC"),
866             "UCD");
867         Vsh_ioCleanup(thee->vsh,&sock);
868         break;
869 
870       case mccom_writedx:
871         sock = Vsh_ioSetup(thee->vsh,"w");
872         AM_writeSOL(thee->am,
873             sock,
874             Vsh_getenvInt(thee->vsh,"PVEC"),
875             "DX");
876         Vsh_ioCleanup(thee->vsh,&sock);
877         break;
878 
879       case mccom_writetec:
880         sock = Vsh_ioSetup(thee->vsh,"w");
881         AM_writeSOL(thee->am,
882             sock,
883             Vsh_getenvInt(thee->vsh,"PVEC"),
884             "TEC");
885         Vsh_ioCleanup(thee->vsh,&sock);
886         break;
887 
888       case mccom_printj:
889         AM_printJ(thee->am);
890         break;
891 
892       case mccom_printa:
893         AM_printA(thee->am);
894         break;
895 
896       case mccom_printasp:
897         AM_printAsp(thee->am, "jac.m");
898         break;
899 
900       case mccom_printanod:
901         AM_printAnoD(thee->am);
902         break;
903 
904       case mccom_printaspnod:
905         AM_printAspNoD(thee->am, "jac.m");
906         break;
907 
908       case mccom_printc:
909         AM_printA(thee->am);
910         break;
911 
912       case mccom_printcsp:
913         AM_printAsp(thee->am, "jacc.m");
914         break;
915 
916       case mccom_printcnod:
917         AM_printAnoD(thee->am);
918         break;
919 
920       case mccom_printcspnod:
921         AM_printAspNoD(thee->am, "jacc.m");
922         break;
923 
924       case mccom_printp:
925         AM_printP(thee->am);
926         break;
927 
928       case mccom_printpsp:
929         AM_printPsp(thee->am, "pro.m");
930         break;
931 
932       case mccom_printv:
933         AM_printV(thee->am,
934             Vsh_getenvInt(thee->vsh,"PVEC"));
935         break;
936 
937       case mccom_printvsp:
938         AM_printVsp(thee->am,
939             Vsh_getenvInt(thee->vsh,"PVEC"),
940             "sol.m");
941         break;
942 
943       case mccom_typechk:
944         Vnm_typeChk();
945         break;
946 
947       case mccom_memchk:
948         MCsh_memChk(thee);
949         break;
950 
951       case mccom_formchk:
952         /* check ringed vertex: 0=[v+s],1=[.+sRing],2=[.+eRing],3=[.+conform] */
953         Gem_formChk(thee->gm,2);
954         break;
955 
956       case mccom_formchkf:
957         /* check ringed vertex: 0=[v+s],1=[.+sRing],2=[.+eRing],3=[.+conform] */
958         Gem_formChk(thee->gm,3);
959         break;
960 
961       case mccom_shapechk:
962         Gem_shapeChk(thee->gm);
963         break;
964 
965       case mccom_contentchk:
966         Gem_contentChk(thee->gm);
967         break;
968 
969       case mccom_speedchk:
970         Gem_speedChk(thee->gm);
971         break;
972 
973       case mccom_free:
974         Gem_ramClear(thee->gm,2);
975         Gem_ramClear(thee->gm,1);
976         Gem_ramClear(thee->gm,0);
977         break;
978 
979       case mccom_help:
980         if (argc==1) {
981             Vnm_print(1,"MCsh: MCsh-layer Help Menu:\n");
982             Vnm_print(1,
983                 "    help num  --> Help on %s general numerical commands\n",
984                 thee->PR);
985             Vnm_print(1,
986                 "    help mesh --> Help on %s mesh manipulation commands\n",
987                 thee->PR);
988             Vnm_print(1,
989                 "    help solv --> Help on %s solver control commands\n",
990                 thee->PR);
991             rc = 0;  /* pretend we didn't see it so subshell can help too */
992         } else {
993             if (!strcmp(argv[1],"num")) {
994                 Vnm_print(1, "%s", num);
995             } else if (!strcmp(argv[1],"mesh")) {
996                 Vnm_print(1, "%s", mesh);
997             } else if (!strcmp(argv[1],"solv")) {
998                 Vnm_print(1, "%s", solv);
999             } else {
1000                 rc = 0;  /* pretend we didn't it so subshell can help too */
1001             }
1002         }
1003         break;
1004 
1005       default:
1006         rc = 0;
1007         break;
1008     }
1009     return rc;
1010 }
1011 
1012 /*
1013  * ***************************************************************************
1014  * Routine:  MCsh_shell
1015  *
1016  * Purpose:  The actual shell.
1017  *
1018  * Author:   Michael Holst
1019  * ***************************************************************************
1020  */
MCsh_shell(MCsh * thee,int (* USER_shell)(void * thee,int argc,char ** argv))1021 VPUBLIC int MCsh_shell(MCsh *thee,
1022     int (*USER_shell)(void *thee, int argc, char **argv))
1023 {
1024     thee->USER_shell = USER_shell;
1025     strcpy(thee->PR,"MCsh");
1026     MCsh_publishVars(thee);
1027     return Vsh_shell(thee->vsh, thee->PR, (void*)thee, &MCsh_builtIn);
1028 }
1029 
1030 /*
1031  * ***************************************************************************
1032  * Routine:  MCsh_pshell
1033  *
1034  * Purpose:  The actual shell (version with parallel extensions).
1035  *
1036  * Author:   Michael Holst
1037  * ***************************************************************************
1038  */
MCsh_pshell(MCsh * thee,int (* USER_shell)(void * thee,int argc,char ** argv))1039 VPUBLIC int MCsh_pshell(MCsh *thee,
1040     int (*USER_shell)(void *thee, int argc, char **argv))
1041 {
1042     thee->USER_shell = USER_shell;
1043     strcpy(thee->PR,"MCsh");
1044     MCsh_publishVars(thee);
1045     return Vsh_pshell(thee->vsh, thee->PR, (void*)thee, &MCsh_builtIn);
1046 }
1047 
1048 /*
1049  * ***************************************************************************
1050  * Routine:  MCsh_memChk
1051  *
1052  * Purpose:  Print the exact current malloc usage.
1053  *
1054  * Author:   Michael Holst
1055  * ***************************************************************************
1056  */
MCsh_memChk(MCsh * thee)1057 VPUBLIC void MCsh_memChk(MCsh *thee)
1058 {
1059     Vnm_print(0,"mc_vertex  = %d;\n", Gem_numVV(thee->gm));
1060     Vnm_print(0,"mc_simplex = %d;\n", Gem_numSS(thee->gm));
1061     Vnm_print(0,"mc_memory  = [\n");
1062     Vnm_print(0,"%% --------------------------------------"
1063                 "--------------------------------------\n");
1064     Vnm_print(0,"%%  Footprint        Areas       Malloc         Free"
1065                 "    Highwater   Class\n"),
1066     Vnm_print(0,"%% --------------------------------------"
1067                 "--------------------------------------\n");
1068     if (thee->gm != VNULL) Gem_memChk(thee->gm);
1069     if (thee->am != VNULL) AM_memChk(thee->am);
1070     Vmem_print(VNULL);
1071     Vnm_print(0,"%% --------------------------------------"
1072                 "--------------------------------------\n");
1073     Vmem_printTotal();
1074     Vnm_print(0,"%% --------------------------------------"
1075                 "--------------------------------------\n");
1076     Vnm_print(0,"];\n");
1077     if (thee->gm != VNULL) Gem_memChkMore(thee->gm);
1078 }
1079 
1080