00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169
00170
00171
00172
00173
00174
00175
00176
00177
00178
00179
00180
00181
00182
00183
00184
00185
00186
00187
00188
00189
00190
00191
00192
00193
00194
00195
00196
00197
00198
00199
00200
00201
00202
00203
00204
00205
00206
00207
00208
00209
00210
00211
00212
00213
00214
00215
00216
00217
00218
00219
00220
00221
00222
00223
00224
00225
00226
00227
00228
00229
00230
00231
00232
00233
00234
00235
00236
00237
00238
00239
00240
00241
00242
00243
00244
00245
00246
00247
00248
00249
00250
00251
00252
00253
00254
00255
00256
00257
00258
00259
00260
00261
00262
00263
00264
00265
00266
00267
00268
00269
00270
00271
00272
00273
00274
00275
00276
00277
00278
00279
00280
00281
00282
00283
00284
00285
00286
00287
00288
00289
00290
00291
00292
00293
00294
00295
00296
00297 #include <stdlib.h>
00298 #include <string.h>
00299 #include "anamod.h"
00300 #include "anamodsalsamodules.h"
00301 #include "petscmat.h"
00302
00303 #define MXC 30
00304 #define INC 7
00305 static int ncategories=0,maxcategories=MXC,
00306 *ncomponents=NULL,*maxcomponents=NULL;
00307 static PetscErrorCode (***modules)(AnaModNumericalProblem,AnalysisItem*,int*,PetscTruth*)=NULL;
00308 static PetscErrorCode (**optionfunctions)(char*)=NULL;
00309 static PetscTruth **hasval=NULL; static int **ids=NULL;
00310 static char **categories=NULL,***components=NULL;
00311 #define TYPEii(icat,icmp) types[icat][icmp]
00312 static AnalysisDataType **types=NULL;
00313 static struct{int id; const char *name,*mysqlname;} anamodtypenames[5];
00314 static int nAnaModTypeNames;
00315 static int AnaModIsInitialized = 0;
00316
00317 #undef __FUNCT__
00318 #define __FUNCT__ "AnaModInitialize"
00319 PetscErrorCode AnaModInitialize()
00320 {
00321 PetscFunctionBegin;
00322 anamodtypenames[0].id = NMDString;
00323 anamodtypenames[0].name="string";
00324 anamodtypenames[0].mysqlname="VARCHAR(256)";
00325
00326 anamodtypenames[1].id = NMDInt;
00327 anamodtypenames[1].name="int";
00328 anamodtypenames[1].mysqlname="INTEGER";
00329
00330 anamodtypenames[2].id = NMDReal;
00331 anamodtypenames[2].name="real";
00332 anamodtypenames[2].mysqlname="DOUBLE";
00333
00334 anamodtypenames[3].id = NMDIntarray;
00335 anamodtypenames[3].name="intarray";
00336 anamodtypenames[3].mysqlname="VARCHAR(1024)";
00337
00338 anamodtypenames[4].id = NMDRealarray;
00339 anamodtypenames[4].name="realarray";
00340 anamodtypenames[4].mysqlname="VARCHAR(1024)";
00341
00342 AnaModIsInitialized = 1; nAnaModTypeNames = 5;
00343 PetscFunctionReturn(0);
00344 }
00345
00346 #undef __FUNCT__
00347 #define __FUNCT__ "AnaModFinalize"
00348 PetscErrorCode AnaModFinalize()
00349 {
00350 PetscFunctionBegin;
00351 PetscFunctionReturn(0);
00352 }
00353
00354 #undef __FUNCT__
00355 #define __FUNCT__ "AnaModGetTypeName"
00356 PetscErrorCode AnaModGetTypeName(int id,char **name)
00357 {
00358 int i;
00359 PetscFunctionBegin;
00360 for (i=0; i<nAnaModTypeNames; i++) {
00361 if (id==anamodtypenames[i].id) {
00362 *name = (char*)anamodtypenames[i].name; goto exit;
00363 }
00364 }
00365 SETERRQ1(1,"Unknown AnaMod datatype %d",id);
00366 exit:
00367 PetscFunctionReturn(0);
00368 }
00369
00370 #undef __FUNCT__
00371 #define __FUNCT__ "AnaModGetTypeMySQLName"
00372 PetscErrorCode AnaModGetTypeMySQLName(int id,char **name)
00373 {
00374 int i;
00375 PetscFunctionBegin;
00376 if (AnaModIsInitialized<1)
00377 SETERRQ(1,"AnaMod has not been not formally initialized.\nInsert a call to AnaModInitialize() in your code");
00378 for (i=0; i<nAnaModTypeNames; i++) {
00379 if (id==anamodtypenames[i].id) {
00380 *name = (char*)anamodtypenames[i].mysqlname; goto exit;
00381 }
00382 }
00383 SETERRQ1(1,"Unknown AnaMod datatype %d",id);
00384 exit:
00385 PetscFunctionReturn(0);
00386 }
00387
00388 #undef __FUNCT__
00389 #define __FUNCT__ "RegisterModule"
00390
00391
00392
00393
00394
00395
00396
00397
00398
00399
00400
00401
00402
00403
00404
00405
00406
00407
00408
00409 PetscErrorCode RegisterModule
00410 (const char *cat,const char *cmp,AnalysisDataType type,
00411 PetscErrorCode(*f)(AnaModNumericalProblem,AnalysisItem*,int*,PetscTruth*))
00412 {
00413 PetscTruth flg; int i,icmp,icat,id; PetscErrorCode ierr;
00414 PetscFunctionBegin;
00415
00416
00417
00418
00419 if (strchr(cat,':'))
00420 SETERRQ(1,"Illegal colon in category name");
00421 if (strchr(cmp,':'))
00422 SETERRQ(1,"Illegal colon in component name");
00423
00424
00425 if (ncategories==0) {
00426 ierr = PetscMalloc
00427 (maxcategories*sizeof(char*),&categories); CHKERRQ(ierr);
00428 ierr = PetscMalloc
00429 (maxcategories*sizeof(int),&maxcomponents); CHKERRQ(ierr);
00430 ierr = PetscMalloc
00431 (maxcategories*sizeof(int),&ncomponents); CHKERRQ(ierr);
00432 ierr = PetscMalloc
00433 (maxcategories*sizeof(char**),&components); CHKERRQ(ierr);
00434 ierr = PetscMalloc
00435 (maxcategories*sizeof(AnalysisDataType*),&types); CHKERRQ(ierr);
00436 ierr = PetscMalloc
00437 (maxcategories*sizeof(PetscErrorCode(**)(Mat,AnalysisItem*,int*,PetscTruth*)),
00438 &modules); CHKERRQ(ierr);
00439 ierr = PetscMalloc
00440 (maxcategories*sizeof(PetscErrorCode(*)(char*)),
00441 &optionfunctions); CHKERRQ(ierr);
00442 ierr = PetscMalloc
00443 (maxcategories*sizeof(PetscTruth*),&hasval); CHKERRQ(ierr);
00444 ierr = PetscMalloc
00445 (maxcategories*sizeof(int*),&ids); CHKERRQ(ierr);
00446 }
00447
00448
00449 flg = PETSC_FALSE;
00450 for (i=0; i<ncategories; i++) {
00451 ierr = PetscStrcmp(cat,categories[i],&flg); CHKERRQ(ierr);
00452 if (flg) {
00453 icat = i; goto old_cat;
00454 }
00455 }
00456 icat=ncategories;
00457
00458
00459
00460
00461 if (icat>=maxcategories) {
00462 int m = maxcategories;
00463 char **newcategories,***newcomponents; AnalysisDataType **newtypes;
00464 int *newmaxcomponents,*newncomponents;
00465 PetscErrorCode(***newmodules)(AnaModNumericalProblem,AnalysisItem*,int*,PetscTruth*);
00466 PetscErrorCode(**newoptionfunctions)(char*);
00467 PetscTruth **newhasval; int **newids;
00468 maxcategories += INC;
00469
00470
00471 ierr = PetscMalloc
00472 (maxcategories*sizeof(char*),&newcategories); CHKERRQ(ierr);
00473 ierr = PetscMalloc
00474 (maxcategories*sizeof(int),&newmaxcomponents); CHKERRQ(ierr);
00475 ierr = PetscMalloc
00476 (maxcategories*sizeof(int),&newncomponents); CHKERRQ(ierr);
00477 ierr = PetscMalloc
00478 (maxcategories*sizeof(char**),&newcomponents); CHKERRQ(ierr);
00479 ierr = PetscMalloc
00480 (maxcategories*sizeof(AnalysisDataType*),&newtypes); CHKERRQ(ierr);
00481 ierr = PetscMalloc
00482 (maxcategories*sizeof(PetscErrorCode(**)(Mat,AnalysisItem*,int*,PetscTruth*)),
00483 &newmodules); CHKERRQ(ierr);
00484 ierr = PetscMalloc
00485 (maxcategories*sizeof(PetscErrorCode(**)(char*)),
00486 &newoptionfunctions); CHKERRQ(ierr);
00487 ierr = PetscMalloc
00488 (maxcategories*sizeof(PetscTruth*),&newhasval); CHKERRQ(ierr);
00489 ierr = PetscMalloc
00490 (maxcategories*sizeof(int*),&newids); CHKERRQ(ierr);
00491
00492 for (i=0; i<m; i++) {
00493 newcategories[i] = categories[i];
00494 newmaxcomponents[i] = maxcomponents[i];
00495 newncomponents[i] = ncomponents[i];
00496 newcomponents[i] = components[i];
00497 newtypes[i] = types[i];
00498 newmodules[i] = modules[i];
00499 newoptionfunctions[i] = optionfunctions[i];
00500 newhasval[i] = hasval[i];
00501 newids[i] = ids[i];
00502 }
00503
00504 ierr = PetscFree(categories); CHKERRQ(ierr);
00505 ierr = PetscFree(maxcomponents); CHKERRQ(ierr);
00506 ierr = PetscFree(ncomponents); CHKERRQ(ierr);
00507 ierr = PetscFree(components); CHKERRQ(ierr);
00508 ierr = PetscFree(types); CHKERRQ(ierr);
00509 ierr = PetscFree(modules); CHKERRQ(ierr);
00510 ierr = PetscFree(optionfunctions); CHKERRQ(ierr);
00511 ierr = PetscFree(hasval); CHKERRQ(ierr);
00512 ierr = PetscFree(ids); CHKERRQ(ierr);
00513
00514 categories = newcategories;
00515 maxcomponents = newmaxcomponents;
00516 ncomponents = newncomponents;
00517 components = newcomponents;
00518 types = newtypes;
00519 modules = newmodules;
00520 optionfunctions = newoptionfunctions;
00521 hasval = newhasval;
00522 ids = newids;
00523
00524 }
00525
00526
00527
00528
00529 ierr = PetscStrallocpy(cat,categories+icat); CHKERRQ(ierr);
00530 maxcomponents[icat] = MXC; ncomponents[icat] = 0;
00531 ierr = PetscMalloc
00532 (maxcomponents[icat]*sizeof(char*),&(components[icat])); CHKERRQ(ierr);
00533 ierr = PetscMalloc
00534 (maxcomponents[icat]*sizeof(AnalysisDataType),&(types[icat])); CHKERRQ(ierr);
00535 ierr = PetscMalloc
00536 (maxcomponents[icat]*sizeof(int(*)(Mat,AnalysisItem*,int*,PetscTruth*)),
00537 &(modules[icat])); CHKERRQ(ierr);
00538 ierr = PetscMalloc
00539 (maxcomponents[icat]*sizeof(PetscTruth),&(hasval[icat])); CHKERRQ(ierr);
00540 ierr = PetscMalloc
00541 (maxcomponents[icat]*sizeof(int),&(ids[icat])); CHKERRQ(ierr);
00542 ncategories++;
00543
00544
00545
00546
00547 old_cat:
00548
00549
00550 flg = PETSC_FALSE;
00551 for (i=0; i<ncomponents[icat]; i++) {
00552 ierr = PetscStrcmp(cmp,components[icat][i],&flg); CHKERRQ(ierr);
00553 if (flg) {
00554 icmp = i; goto old_cmp;
00555 }
00556 }
00557 icmp=ncomponents[icat];
00558
00559 if (icmp>=maxcomponents[icat]) {
00560 int m = maxcomponents[icat];
00561 char **newcomponents; AnalysisDataType *newtypes;
00562 int(**newmodules)(AnaModNumericalProblem,AnalysisItem*,int*,PetscTruth*);
00563 PetscTruth *newhasval; int *newids;
00564 maxcomponents[icat] += INC;
00565
00566
00567 ierr = PetscMalloc
00568 (maxcomponents[icat]*sizeof(char*),&newcomponents); CHKERRQ(ierr);
00569 ierr = PetscMalloc
00570 (maxcomponents[icat]*sizeof(AnalysisDataType),&newtypes); CHKERRQ(ierr);
00571 ierr = PetscMalloc
00572 (maxcomponents[icat]*sizeof(int(*)(Mat,AnalysisItem*,int*,PetscTruth*)),&newmodules); CHKERRQ(ierr);
00573 ierr = PetscMalloc
00574 (maxcomponents[icat]*sizeof(PetscTruth),&newhasval); CHKERRQ(ierr);
00575 ierr = PetscMalloc
00576 (maxcomponents[icat]*sizeof(int),&newids); CHKERRQ(ierr);
00577
00578 for (i=0; i<m; i++) {
00579 newcomponents[i] = components[icat][i];
00580 newtypes[i] = types[icat][i];
00581 newmodules[i] = modules[icat][i];
00582 newhasval[i] = hasval[icat][i];
00583 newids[i] = ids[icat][i];
00584 }
00585 ierr = PetscFree(components[icat]); CHKERRQ(ierr);
00586 ierr = PetscFree(types[icat]); CHKERRQ(ierr);
00587 ierr = PetscFree(modules[icat]); CHKERRQ(ierr);
00588 ierr = PetscFree(hasval[icat]); CHKERRQ(ierr);
00589 ierr = PetscFree(ids[icat]); CHKERRQ(ierr);
00590 components[icat] = newcomponents;
00591 types[icat] = newtypes;
00592 modules[icat] = newmodules;
00593 hasval[icat] = newhasval;
00594 ids[icat] = newids;
00595 }
00596 ierr = PetscStrallocpy(cmp,components[icat]+icmp); CHKERRQ(ierr);
00597 types[icat][icmp] = type;
00598 ncomponents[icat]++;
00599 old_cmp:
00600
00601
00602 modules[icat][icmp] = f;
00603 ierr = PetscObjectComposedDataRegister(&id); CHKERRQ(ierr);
00604 ids[icat][icmp] = id;
00605
00606 PetscFunctionReturn(0);
00607 }
00608
00609 #undef __FUNCT__
00610 #define __FUNCT__ "DeRegisterCategory"
00611
00612 PetscErrorCode DeRegisterCategory(char *cat)
00613 {
00614 PetscTruth flg; int icat,i; PetscErrorCode ierr;
00615 PetscFunctionBegin;
00616
00617 flg = PETSC_FALSE;
00618 for (i=0; i<ncategories && !flg; i++) {
00619 ierr = PetscStrcmp(cat,categories[i],&flg); CHKERRQ(ierr);
00620 if (flg) {
00621 icat = i; goto found;
00622 }
00623 }
00624 SETERRQ(1,"Trying to deregister unknown category");
00625 found:
00626
00627 for (i=0; i<ncomponents[icat]; i++) {
00628 ierr = PetscFree(components[icat][i]); CHKERRQ(ierr);
00629 }
00630 ierr = PetscFree(categories[icat]); CHKERRQ(ierr);
00631 ierr = PetscFree(components[icat]); CHKERRQ(ierr);
00632 ierr = PetscFree(modules[icat]); CHKERRQ(ierr);
00633 ierr = PetscFree(types[icat]); CHKERRQ(ierr);
00634 ierr = PetscFree(hasval[icat]); CHKERRQ(ierr);
00635 ierr = PetscFree(ids[icat]); CHKERRQ(ierr);
00636
00637 PetscFunctionReturn(0);
00638 }
00639
00640 #undef __FUNCT__
00641 #define __FUNCT__ "DeregisterModules"
00642 PetscErrorCode DeregisterModules()
00643 {
00644 int icat,ncat; char **cat;
00645 PetscErrorCode ierr;
00646 PetscFunctionBegin;
00647
00648
00649
00650 ierr = GetCategories(&cat,&ncat); CHKERRQ(ierr);
00651 for (icat=0; icat<ncat; icat++) {
00652 ierr = DeRegisterCategory(cat[icat]); CHKERRQ(ierr);
00653 }
00654 ierr = PetscFree(categories); CHKERRQ(ierr);
00655 ncategories = 0;
00656 ierr = PetscFree(maxcomponents); CHKERRQ(ierr);
00657 ierr = PetscFree(ncomponents); CHKERRQ(ierr);
00658 ierr = PetscFree(components); CHKERRQ(ierr);
00659 ierr = PetscFree(types); CHKERRQ(ierr);
00660 ierr = PetscFree(modules); CHKERRQ(ierr);
00661 ierr = PetscFree(optionfunctions); CHKERRQ(ierr);
00662 ierr = PetscFree(hasval); CHKERRQ(ierr);
00663 ierr = PetscFree(ids); CHKERRQ(ierr);
00664 PetscFunctionReturn(0);
00665 }
00666
00667
00668
00669
00670
00671
00672
00673
00674
00675
00676
00677 #undef __FUNCT__
00678 #define __FUNCT__ "GetCategories"
00679
00680
00681
00682
00683
00684
00685
00686
00687 PetscErrorCode GetCategories(char ***cats,int *n)
00688 {
00689 PetscFunctionBegin;
00690 *n = ncategories; if (cats) *cats = categories;
00691 PetscFunctionReturn(0);
00692 }
00693
00694 #undef __FUNCT__
00695 #define __FUNCT__ "CategoryGetModules"
00696
00697
00698
00699
00700
00701
00702
00703
00704
00705
00706
00707
00708
00709
00710 PetscErrorCode CategoryGetModules
00711 (char *cat,char ***ms,AnalysisDataType **t,int **id,int *n)
00712 {
00713 int i; PetscErrorCode ierr;
00714 PetscFunctionBegin;
00715 *ms = NULL; *n = 0;
00716 for (i=0; i<ncategories; i++) {
00717 PetscTruth flg;
00718 ierr = PetscStrcmp(cat,categories[i],&flg); CHKERRQ(ierr);
00719 if (flg) {
00720 if (ms) *ms = components[i];
00721 if (t) *t = types[i];
00722 if (id) *id = ids[i];
00723 if (n) *n = ncomponents[i];
00724 PetscFunctionReturn(0);
00725 }
00726 }
00727 SETERRQ1(1,"Unknown category <%s>\n",cat);
00728 }
00729
00730 #undef __FUNCT__
00731 #define __FUNCT__ "GetCategoryIndex"
00732
00733 static PetscErrorCode GetCategoryIndex(char *cat,int *idx,PetscTruth *f)
00734 {
00735 PetscTruth flg; int i; PetscErrorCode ierr;
00736 PetscFunctionBegin;
00737
00738 flg = PETSC_FALSE;
00739 for (i=0; i<ncategories; i++) {
00740 ierr = PetscStrcmp(cat,categories[i],&flg); CHKERRQ(ierr);
00741 if (flg) {
00742 *idx = i; break;
00743 }
00744 }
00745 *f = flg;
00746
00747 PetscFunctionReturn(0);
00748 }
00749
00750 #undef __FUNCT__
00751 #define __FUNCT__ "GetModuleIndex"
00752
00753 static PetscErrorCode GetModuleIndex(int icat,char *cmp,int *idx,PetscTruth *f)
00754 {
00755 PetscTruth flg; int i; PetscErrorCode ierr;
00756 PetscFunctionBegin;
00757
00758 flg = PETSC_FALSE;
00759 for (i=0; i<ncomponents[icat]; i++) {
00760 ierr = PetscStrcmp(cmp,components[icat][i],&flg); CHKERRQ(ierr);
00761 if (flg) {
00762 *idx = i; break;
00763 }
00764 }
00765 *f = flg;
00766
00767 PetscFunctionReturn(0);
00768 }
00769
00770 #undef __FUNCT__
00771 #define __FUNCT__ "HasComputeCategory"
00772
00773 PetscErrorCode HasComputeCategory(char *cat,PetscTruth *f)
00774 {
00775 int icat; PetscErrorCode ierr;
00776 PetscFunctionBegin;
00777 ierr = GetCategoryIndex(cat,&icat,f); CHKERRQ(ierr);
00778 PetscFunctionReturn(0);
00779 }
00780
00781 #undef __FUNCT__
00782 #define __FUNCT__ "HasComputeModule"
00783
00784
00785
00786
00787 PetscErrorCode HasComputeModule(char *cat,char *cmp,PetscTruth *f)
00788 {
00789 int icat,icmp; PetscErrorCode ierr;
00790 PetscFunctionBegin;
00791 ierr = GetCategoryIndex(cat,&icat,f); CHKERRQ(ierr);
00792 if (*f) {
00793 ierr = GetModuleIndex(icat,cmp,&icmp,f); CHKERRQ(ierr);
00794 }
00795 PetscFunctionReturn(0);
00796 }
00797
00798 #undef __FUNCT__
00799 #define __FUNCT__ "DeclareCategoryOptionFunction"
00800
00801
00802
00803
00804
00805
00806 PetscErrorCode DeclareCategoryOptionFunction
00807 (char *cat,PetscErrorCode(*f)(char*))
00808 {
00809 PetscTruth flg; int icat; PetscErrorCode ierr;
00810 PetscFunctionBegin;
00811 ierr = GetCategoryIndex(cat,&icat,&flg); CHKERRQ(ierr);
00812 if (flg) {
00813 optionfunctions[icat] = f;
00814 }
00815 PetscFunctionReturn(0);
00816 }
00817
00818 #undef __FUNCT__
00819 #define __FUNCT__ "GetCategoryOptionFunction"
00820
00821
00822
00823
00824
00825
00826 PetscErrorCode GetCategoryOptionFunction
00827 (char *cat,PetscErrorCode(**f)(char*))
00828 {
00829 PetscTruth flg; int icat; PetscErrorCode ierr;
00830 PetscFunctionBegin;
00831 ierr = GetCategoryIndex(cat,&icat,&flg); CHKERRQ(ierr);
00832 if (flg) {
00833 *f = optionfunctions[icat];
00834 } else *f = NULL;
00835 PetscFunctionReturn(0);
00836 }
00837
00838 #undef __FUNCT__
00839 #define __FUNCT__ "ComputeQuantity"
00840
00841
00842
00843
00844
00845
00846
00847
00848
00849
00850
00851
00852
00853
00854
00855
00856
00857
00858
00859
00860
00861
00862
00863
00864
00865 PetscErrorCode ComputeQuantity
00866 (AnaModNumericalProblem prob,const char *cat,const char *cmp,
00867 AnalysisItem *res,int *rreslen,PetscTruth *success)
00868 {
00869 PetscTruth flg,trace;
00870 int icat,icmp,reslen; PetscErrorCode ierr;
00871
00872 PetscFunctionBegin;
00873
00874
00875
00876
00877 ierr = GetCategoryIndex((char*)cat,&icat,&flg); CHKERRQ(ierr);
00878 if (!flg)
00879 SETERRQ1(1,"Could not find category <%s>",cat);
00880 ierr = GetModuleIndex(icat,(char*)cmp,&icmp,&flg); CHKERRQ(ierr);
00881 if (!flg)
00882 SETERRQ2(1,"Could not find module <%s:%s>",cat,cmp);
00883
00884
00885
00886
00887 if (modules[icat][icmp]) {
00888 ierr = (modules[icat][icmp])(prob,res,&reslen,&flg); CHKERRQ(ierr);
00889 } else flg = PETSC_FALSE;
00890
00891 hasval[icat][icmp] = flg;
00892
00893 if (!flg) goto nosuccess;
00894
00895
00896
00897 ierr = AnaModHasTrace(&trace); CHKERRQ(ierr);
00898 if (trace) {
00899 if (flg) {
00900 char *string; PetscTruth trace_arrays;
00901 AnalysisDataType t = TYPEii(icat,icmp);
00902
00903 ierr = AnaModTraceArrays(&trace_arrays); CHKERRQ(ierr);
00904 if (t<ANALYSISINTARRAY || trace_arrays) {
00905 ierr = QuantityAsString
00906 (res,types[icat][icmp],&string); CHKERRQ(ierr);
00907 ierr = AnaModTraceMessage
00908 ("Anamod computed <%s:%s> = <%s>\n",cat,cmp,string); CHKERRQ(ierr);
00909 ierr = PetscFree(string); CHKERRQ(ierr);
00910 }
00911 } else {
00912 ierr = AnaModTraceMessage
00913 ("Anamod failed to compute <%s:%s>\n",cat,cmp); CHKERRQ(ierr);
00914 }
00915 }
00916
00917 if (rreslen) *rreslen = reslen;
00918 nosuccess:
00919 if (success) *success = flg;
00920
00921 PetscFunctionReturn(0);
00922 }
00923
00924 #undef __FUNCT__
00925 #define __FUNCT__ "RetrieveQuantity"
00926
00927
00928
00929
00930 PetscErrorCode RetrieveQuantity
00931 (AnaModNumericalProblem prob,char *cat,char *cmp,
00932 AnalysisItem *res,PetscTruth *success)
00933 {
00934 PetscTruth flg,trace;
00935 int icat,icmp; PetscErrorCode ierr;
00936
00937 PetscFunctionBegin;
00938
00939
00940
00941
00942 ierr = GetCategoryIndex(cat,&icat,&flg); CHKERRQ(ierr);
00943 if (!flg)
00944 SETERRQ1(1,"Could not find category <%s>",cat);
00945 ierr = GetModuleIndex(icat,cmp,&icmp,&flg); CHKERRQ(ierr);
00946 if (!flg)
00947 SETERRQ2(1,"Could not find module <%s:%s>",cat,cmp);
00948
00949
00950
00951
00952 ierr = RetrieveQuantityByID(prob,icat,icmp,res,&flg); CHKERRQ(ierr);
00953
00954 hasval[icat][icmp] = flg;
00955
00956 if (!flg) goto nosuccess;
00957
00958
00959
00960 ierr = AnaModHasTrace(&trace); CHKERRQ(ierr);
00961 if (trace) {
00962 if (flg) {
00963 char *string; PetscTruth trace_arrays;
00964 AnalysisDataType t = TYPEii(icat,icmp);
00965
00966 ierr = AnaModTraceArrays(&trace_arrays); CHKERRQ(ierr);
00967 if (t<ANALYSISINTARRAY || trace_arrays) {
00968 ierr = QuantityAsString
00969 (res,types[icat][icmp],&string); CHKERRQ(ierr);
00970 ierr = AnaModTraceMessage
00971 ("Anamod retrieved <%s:%s> = <%s>\n",cat,cmp,string); CHKERRQ(ierr);
00972 ierr = PetscFree(string); CHKERRQ(ierr);
00973 }
00974 } else {
00975 ierr = AnaModTraceMessage
00976 ("Anamod failed to compute <%s:%s>\n",cat,cmp); CHKERRQ(ierr);
00977 }
00978 }
00979
00980 nosuccess:
00981 if (success) *success = flg;
00982
00983 PetscFunctionReturn(0);
00984 }
00985
00986 #if 0
00987 #undef __FUNCT__
00988 #define __FUNCT__ "ComputeQuantityByID"
00989 PetscErrorCode ComputeQuantityByID
00990 (AnaModNumericalProblem prob,int icat,int icmp,
00991 AnalysisItem *res,int *reslen,PetscTruth *flg)
00992 {
00993 PetscErrorCode ierr;
00994 PetscFunctionBegin;
00995 if (modules[icat][icmp]) {
00996 ierr = (modules[icat][icmp])(prob,res,reslen,flg); CHKERRQ(ierr);
00997 } else *flg = PETSC_FALSE;
00998 PetscFunctionReturn(0);
00999 }
01000 #endif
01001
01002 #undef __FUNCT__
01003 #define __FUNCT__ "HasQuantity"
01004
01005
01006
01007
01008
01009
01010
01011
01012
01013
01014
01015
01016 PetscErrorCode HasQuantity
01017 (AnaModNumericalProblem prob,char *cat,char *cmp,PetscTruth *f)
01018 {
01019 AnalysisDataType t; int id; PetscErrorCode ierr;
01020 PetscFunctionBegin;
01021 ierr = GetDataID(cat,cmp,&id,f); CHKERRQ(ierr);
01022 if (!*f)
01023 SETERRQ2(1,">>>> Warning: undeclared module <%s:%s>\n",cat,cmp);
01024 ierr = GetDataType(cat,cmp,&t); CHKERRQ(ierr);
01025 ierr = HasQuantityByID(prob,id,t,f); CHKERRQ(ierr);
01026 PetscFunctionReturn(0);
01027 }
01028
01029 #undef __FUNCT__
01030 #define __FUNCT__ "HasQuantityByID"
01031
01032
01033
01034 PetscErrorCode HasQuantityByID
01035 (AnaModNumericalProblem prob,int id,AnalysisDataType type,PetscTruth *f)
01036 {
01037 Mat A = (Mat)prob; PetscReal rv,*rsv; int iv,*isv;
01038 PetscErrorCode ierr;
01039 PetscFunctionBegin;
01040 switch (type) {
01041 case ANALYSISINTEGER :
01042 ierr = PetscObjectComposedDataGetInt
01043 ((PetscObject)A,id,iv,*f); CHKERRQ(ierr);
01044 break;
01045 case ANALYSISDOUBLE :
01046 ierr = PetscObjectComposedDataGetReal
01047 ((PetscObject)A,id,rv,*f); CHKERRQ(ierr);
01048 break;
01049 case ANALYSISINTARRAY :
01050 ierr = PetscObjectComposedDataGetIntstar
01051 ((PetscObject)A,id,isv,*f); CHKERRQ(ierr);
01052 break;
01053 case ANALYSISDBLARRAY :
01054 ierr = PetscObjectComposedDataGetRealstar
01055 ((PetscObject)A,id,rsv,*f); CHKERRQ(ierr);
01056 break;
01057 default : SETERRQ1(1,"Unknown data type %d",type);
01058 }
01059 PetscFunctionReturn(0);
01060 }
01061
01062 #undef __FUNCT__
01063 #define __FUNCT__ "RetrieveQuantityByID"
01064
01065 PetscErrorCode RetrieveQuantityByID
01066 (AnaModNumericalProblem prob,int icat,int icmp,
01067 AnalysisItem *result,PetscTruth *f)
01068 {
01069 Mat A = (Mat)prob; AnalysisDataType type; int id = ids[icat][icmp];
01070 PetscErrorCode ierr;
01071 PetscFunctionBegin;
01072
01073 type = TYPEii(icat,icmp);
01074 switch (type) {
01075 case ANALYSISINTEGER :
01076 ierr = PetscObjectComposedDataGetInt
01077 ((PetscObject)A,id,result->i,*f); CHKERRQ(ierr);
01078 break;
01079 case ANALYSISDOUBLE :
01080 ierr = PetscObjectComposedDataGetReal
01081 ((PetscObject)A,id,result->r,*f); CHKERRQ(ierr);
01082 break;
01083 case ANALYSISINTARRAY :
01084 ierr = PetscObjectComposedDataGetIntstar
01085 ((PetscObject)A,id,result->ii,*f); CHKERRQ(ierr);
01086 break;
01087 case ANALYSISDBLARRAY :
01088 ierr = PetscObjectComposedDataGetRealstar
01089 ((PetscObject)A,id,result->rr,*f); CHKERRQ(ierr);
01090 break;
01091 default : SETERRQ1(1,"Unknown data type %d",type);
01092 }
01093 PetscFunctionReturn(0);
01094 }
01095
01096 #undef __FUNCT__
01097 #define __FUNCT__ "QuantityAsString"
01098
01099
01100
01101 PetscErrorCode QuantityAsString(AnalysisItem *q,AnalysisDataType t,char **s)
01102 {
01103 PetscErrorCode ierr; size_t l;
01104
01105 PetscFunctionBegin;
01106 switch (t) {
01107 case ANALYSISINTEGER :
01108 ierr = PetscMalloc(12*sizeof(char),s); CHKERRQ(ierr);
01109 ierr = PetscMemzero(*s,12*sizeof(char)); CHKERRQ(ierr);
01110 sprintf(*s,"%d",q->i);
01111 break;
01112 case ANALYSISDOUBLE :
01113 ierr = PetscMalloc(22*sizeof(char),s); CHKERRQ(ierr);
01114 ierr = PetscMemzero(*s,22*sizeof(char)); CHKERRQ(ierr);
01115 sprintf(*s,"%e",q->r);
01116 break;
01117 case ANALYSISSTRING :
01118 ierr = PetscMalloc((strlen(q->c)+1)*sizeof(char),s); CHKERRQ(ierr);
01119 ierr = PetscMemzero(*s,(strlen(q->c)+1)*sizeof(char)); CHKERRQ(ierr);
01120 sprintf(*s,"%s",q->c);
01121 break;
01122 case ANALYSISINTARRAY :
01123 {
01124 int i,n,*iar;
01125 iar = q->ii;
01126 n = q->len;
01127 ierr = PetscMalloc((10*n+1)*sizeof(char),s); CHKERRQ(ierr);
01128 ierr = PetscMemzero(*s,(10*n+1)*sizeof(char)); CHKERRQ(ierr);
01129 for (i=0; i<=n; i++) {
01130 ierr = PetscStrlen(*s,&l); CHKERRQ(ierr);
01131 sprintf(*s+l,"%d,",iar[i]);
01132 }
01133 }
01134 break;
01135 case ANALYSISDBLARRAY :
01136 {
01137 int i,n; PetscReal *rar;
01138 rar = q->rr;
01139 n = q->len;
01140 ierr = PetscMalloc((15*n+1)*sizeof(char),s); CHKERRQ(ierr);
01141 ierr = PetscMemzero(*s,(15*n+1)*sizeof(char)); CHKERRQ(ierr);
01142 for (i=0; i<=n; i++) {
01143 ierr = PetscStrlen(*s,&l); CHKERRQ(ierr);
01144 sprintf(*s+l,"%e,",rar[i]);
01145 }
01146 }
01147 break;
01148 default : SETERRQ1(1,"Cannot string quantity type %d",t);
01149 }
01150 PetscFunctionReturn(0);
01151 }
01152
01153 #undef __FUNCT__
01154 #define __FUNCT__ "GetDataID"
01155
01156
01157
01158
01159
01160
01161
01162
01163
01164 PetscErrorCode GetDataID(const char *cat,const char *cmp,int *id,PetscTruth *flg)
01165 {
01166 PetscTruth f; int icat,icmp; PetscErrorCode ierr;
01167 PetscFunctionBegin;
01168 ierr = GetCategoryIndex((char*)cat,&icat,&f); CHKERRQ(ierr);
01169 if (!f) {
01170 goto out;
01171 }
01172 ierr = GetModuleIndex(icat,(char*)cmp,&icmp,&f); CHKERRQ(ierr);
01173 if (!f) {
01174 goto out;
01175 }
01176 *id = ids[icat][icmp];
01177 out:
01178 if (flg)
01179 *flg = f;
01180 else if (!f)
01181 SETERRQ2(1,"cat/cmp <%s;%s> not found, but no flag give to report this",
01182 cat,cmp);
01183 PetscFunctionReturn(0);
01184 }
01185
01186 #undef __FUNCT__
01187 #define __FUNCT__ "GetDataType"
01188
01189
01190
01191 PetscErrorCode GetDataType(const char *cat,const char *cmp,AnalysisDataType *t)
01192 {
01193 PetscTruth flg; int icat,icmp; PetscErrorCode ierr;
01194 PetscFunctionBegin;
01195 ierr = GetCategoryIndex((char*)cat,&icat,&flg); CHKERRQ(ierr);
01196 if (!flg)
01197 SETERRQ(1,"Could not find category");
01198 ierr = GetModuleIndex(icat,(char*)cmp,&icmp,&flg); CHKERRQ(ierr);
01199 if (!flg)
01200 SETERRQ(1,"Could not find module");
01201 *t = TYPEii(icat,icmp);
01202 PetscFunctionReturn(0);
01203 }
01204