59 ITG i,j,index,id,idof,nterm,idepend,*nodempc=NULL,
60 ispooles,iexpand,ichange,indexold,ifluidmpc,
61 mpc,indexnew,index1,index2,index1old,index2old,*jmpc=NULL,nl;
63 double coef,*coefmpc=NULL;
67 ITG irow,icolumn,node,idir,irownl,icolnl,*ipointer=NULL,*icoef=NULL,
68 ifree,*indepdof=NULL,nindep;
72 DenseMtx *mtxB, *mtxX ;
74 ChvManager *chvmanager ;
75 SubMtxManager *mtxmanager ;
83 ITG jrhs, msglvl=0, nedges,error,
84 nent, neqns, nrhs, pivotingflag=1, seed=389,
85 symmetryflag=2, type=1,maxdomainsize,maxzeros,maxsize;
88 IV *newToOldIV, *oldToNewIV ;
89 IVL *adjIVL, *symbfacIVL ;
106 for(i=0;i<*nmpc;i++){
111 if(ikboun[
id-1]==ikmpc[i]){
112 if(
strcmp1(&labmpc[20*i],
"FLUID")!=0){
113 printf(
"*ERROR in cascade: the DOF corresponding to \n node %" ITGFORMAT " in direction %" ITGFORMAT " is detected on the \n dependent side of a MPC and a SPC\n",
114 (ikmpc[i])/8+1,ikmpc[i]-8*((ikmpc[i])/8));
116 printf(
"*ERROR in cascade: the DOF corresponding to \n face %" ITGFORMAT
" in direction %" ITGFORMAT
" is detected on the \n dependent side of a MPC and a SPC\n",
117 (-ikmpc[i])/8+1,-ikmpc[i]-8*((-ikmpc[i])/8));
128 for(i=0;i<*nmpc;i++){
136 if((
strcmp1(&labmpc[20*i],
" ")==0) ||
137 (
strcmp1(&labmpc[20*i],
"CYCLIC")==0) ||
138 (
strcmp1(&labmpc[20*i],
"SUBCYCLIC")==0)||
139 (
strcmp1(&labmpc[20*i],
"PRETENSION")==0)||
140 (
strcmp1(&labmpc[20*i],
"THERMALPRET")==0)||
142 (
strcmp1(&labmpc[20*i],
"FLUID")==0)||
143 (*iperturb<2)) jmpc[i]=0;
147 else if((
strcmp1(&labmpc[20*i],
"RIGID")==0) ||
148 (
strcmp1(&labmpc[20*i],
"KNOT")==0) ||
149 (
strcmp1(&labmpc[20*i],
"PLANE")==0) ||
150 (
strcmp1(&labmpc[20*i],
"BEAM")==0) ||
151 (
strcmp1(&labmpc[20*i],
"STRAIGHT")==0)) jmpc[i]=1;
157 if(*icascade==0) *icascade=1;
169 for(i=0;i<*nmpc;i++){
171 if(
strcmp1(&labmpc[20*i],
"FLUID")!=0){
180 index=nodempc[3*ipompc[i]-1];
181 if(index==0)
continue;
185 idof=(nodempc[3*index-3]-1)*8+nodempc[3*index-2];
187 if(nodempc[3*index-3]>0){
189 idof=-((nodempc[3*index-3]-1)*8+nodempc[3*index-2]);
195 idof=(nodeboun[-nodempc[3*index-3]-1]-1)*8+nodempc[3*index-2];
200 if((
id>0)&&(ikmpc[
id-1]==idof)){
205 indexold=nodempc[3*index-1];
206 coef=coefmpc[index-1];
213 if((jmpc[mpc-1]==1)||(nl==1)){
216 printf(
"*INFO in cascade: linear MPCs and\n");
217 printf(
" nonlinear MPCs depend on each other\n");
218 printf(
" common node: %" ITGFORMAT
" in direction %" ITGFORMAT
"\n\n",nodempc[3*index-3],nodempc[3*index-2]);
220 if(*callfrommain==1){
221 index=nodempc[3*index-1];
222 if(index!=0)
continue;
234 index2=nodempc[3*index1-1];
237 if((nodempc[3*index1-3]==nodempc[3*index2-3])&&
238 (nodempc[3*index1-2]==nodempc[3*index2-2])){
239 coefmpc[index1-1]+=coefmpc[index2-1];
240 nodempc[3*index2old-1]=nodempc[3*index2-1];
241 nodempc[3*index2-1]=*mpcfree;
243 index2=nodempc[3*index2old-1];
248 index2=nodempc[3*index2-1];
252 index1=nodempc[3*index1-1];
259 if(fabs(coefmpc[index1-1])<1.e-10){
260 printf(
"*ERROR in cascade: zero coefficient on the\n");
261 printf(
" dependent side of an equation\n");
262 printf(
" dependent node: %" ITGFORMAT
"",nodempc[3*index1-3]);
263 printf(
" direction: %" ITGFORMAT
"",nodempc[3*index1-2]);
268 if((
strcmp1(&labmpc[20*i],
" ")==0)&&
269 (
strcmp1(&labmpc[20*(mpc-1)],
"CYCLIC")==0))
270 strcpy1(&labmpc[20*i],
"SUBCYCLIC",9);
271 indexnew=ipompc[mpc-1];
272 coef=-coef/coefmpc[indexnew-1];
273 indexnew=nodempc[3*indexnew-1];
276 coefmpc[index-1]=coef*coefmpc[indexnew-1];
277 nodempc[3*index-3]=nodempc[3*indexnew-3];
278 nodempc[3*index-2]=nodempc[3*indexnew-2];
279 indexnew=nodempc[3*indexnew-1];
281 nodempc[3*index-1]=*mpcfree;
283 *mpcfree=nodempc[3**mpcfree-1];
286 nodempc[3*index-1]=*mpcfree;
287 *memmpc_=(
ITG)(1.1**memmpc_);
288 printf(
"*INFO in cascade: reallocating nodempc; new size = %" ITGFORMAT
"\n\n",*memmpc_);
290 RENEW(coefmpc,
double,*memmpc_);
291 for(j=*mpcfree;j<*memmpc_;j++){
294 nodempc[3**memmpc_-1]=0;
299 nodempc[3*index-1]=indexold;
309 index=nodempc[3*index-1];
310 if(index!=0)
continue;
314 if(iexpand==0)
continue;
322 index2=nodempc[3*index1-1];
325 if((nodempc[3*index1-3]==nodempc[3*index2-3])&&
326 (nodempc[3*index1-2]==nodempc[3*index2-2])){
327 coefmpc[index1-1]+=coefmpc[index2-1];
328 nodempc[3*index2old-1]=nodempc[3*index2-1];
329 nodempc[3*index2-1]=*mpcfree;
331 index2=nodempc[3*index2old-1];
336 index2=nodempc[3*index2-1];
340 index1=nodempc[3*index1-1];
350 if(fabs(coefmpc[index1-1])<1.e-10){
352 printf(
"*ERROR in cascade: zero coefficient on the\n");
353 printf(
" dependent side of an equation\n");
354 printf(
" dependent node: %" ITGFORMAT
"",nodempc[3*index1-3]);
355 printf(
" direction: %" ITGFORMAT
"",nodempc[3*index1-2]);
359 nodempc[3*index1old-1]=nodempc[3*index1-1];
360 nodempc[3*index1-1]=*mpcfree;
362 index1=nodempc[3*index1old-1];
367 index1=nodempc[3*index1-1];
372 if(ichange==0)
break;
378 if((*icascade==1)&&(ispooles==1)){
379 if ( (msgFile = fopen(
"spooles.out",
"a")) == NULL ) {
380 fprintf(stderr,
"\n fatal error in spooles.c" 381 "\n unable to open file spooles.out\n") ;
386 NNEW(xcoef,
double,*memmpc_);
390 for(i=*nmpc-1;i>-1;i--){
393 idof=8*(nodempc[3*index-3]-1)+nodempc[3*index-2]-1;
399 if((
id==0)||(ikmpc[
id-1]!=idof)){
401 if((
id==0)||(indepdof[
id-1]!=idof)){
402 for(j=nindep;j>id;j--){
403 indepdof[j]=indepdof[j-1];
411 icoef[2*ifree+1]=ipointer[idof];
412 xcoef[ifree]=coefmpc[index-1];
413 ipointer[idof]=++ifree;
414 index=nodempc[3*index-1];
423 mtxA = InpMtx_new() ;
424 InpMtx_init(mtxA, INPMTX_BY_ROWS, type, nent, neqns) ;
426 for(i=0;i<*nmpc;i++){
429 if(
strcmp1(&labmpc[20*icolumn],
"RIGID")==0) icolnl=1;
431 index=ipointer[idof-1];
433 irow=icoef[2*index-2]-1;
435 if(
strcmp1(&labmpc[20*irow],
"RIGID")==0)irownl=1;
437 if((irownl==1)||(icolnl==1)){
440 printf(
"*ERROR in cascade: linear and nonlinear MPCs depend on each other");
444 if((
strcmp1(&labmpc[20*irow],
" ")==0)&&
445 (
strcmp1(&labmpc[20*icolumn],
"CYCLIC")==0)){
446 strcpy1(&labmpc[20*irow],
"SUBCYCLIC",9);}
448 InpMtx_inputRealEntry(mtxA,irow,icolumn,coef);
449 index=icoef[2*index-1];
455 InpMtx_changeStorageMode(mtxA, INPMTX_BY_VECTORS) ;
457 fprintf(msgFile,
"\n\n input matrix") ;
458 InpMtx_writeForHumanEye(mtxA, msgFile) ;
469 graph = Graph_new() ;
470 adjIVL = InpMtx_fullAdjacency(mtxA) ;
471 nedges = IVL_tsize(adjIVL) ;
472 Graph_init2(graph, 0, neqns, 0, nedges, neqns, nedges, adjIVL,
475 fprintf(msgFile,
"\n\n graph of the input matrix") ;
476 Graph_writeForHumanEye(graph, msgFile) ;
479 maxdomainsize=800;maxzeros=1000;maxsize=64;
484 frontETree=orderViaBestOfNDandMS(graph,maxdomainsize,maxzeros,
485 maxsize,seed,msglvl,msgFile);
487 fprintf(msgFile,
"\n\n front tree from ordering") ;
488 ETree_writeForHumanEye(frontETree, msgFile) ;
498 oldToNewIV = ETree_oldToNewVtxPerm(frontETree) ;
499 oldToNew = IV_entries(oldToNewIV) ;
500 newToOldIV = ETree_newToOldVtxPerm(frontETree) ;
501 ETree_permuteVertices(frontETree, oldToNewIV) ;
502 InpMtx_permute(mtxA, oldToNew, oldToNew) ;
504 InpMtx_changeCoordType(mtxA,INPMTX_BY_CHEVRONS);
505 InpMtx_changeStorageMode(mtxA,INPMTX_BY_VECTORS);
506 symbfacIVL = SymbFac_initFromInpMtx(frontETree, mtxA) ;
508 fprintf(msgFile,
"\n\n old-to-new permutation vector") ;
509 IV_writeForHumanEye(oldToNewIV, msgFile) ;
510 fprintf(msgFile,
"\n\n new-to-old permutation vector") ;
511 IV_writeForHumanEye(newToOldIV, msgFile) ;
512 fprintf(msgFile,
"\n\n front tree after permutation") ;
513 ETree_writeForHumanEye(frontETree, msgFile) ;
514 fprintf(msgFile,
"\n\n input matrix after permutation") ;
515 InpMtx_writeForHumanEye(mtxA, msgFile) ;
516 fprintf(msgFile,
"\n\n symbolic factorization") ;
517 IVL_writeForHumanEye(symbfacIVL, msgFile) ;
526 frontmtx = FrontMtx_new() ;
527 mtxmanager = SubMtxManager_new() ;
528 SubMtxManager_init(mtxmanager, NO_LOCK, 0) ;
529 FrontMtx_init(frontmtx, frontETree, symbfacIVL, type, symmetryflag,
530 FRONTMTX_DENSE_FRONTS, pivotingflag, NO_LOCK, 0, NULL,
531 mtxmanager, msglvl, msgFile) ;
538 chvmanager = ChvManager_new() ;
539 ChvManager_init(chvmanager, NO_LOCK, 1) ;
540 DVfill(10, cpus, 0.0) ;
541 IVfill(20, stats, 0) ;
542 rootchv = FrontMtx_factorInpMtx(frontmtx, mtxA, tau, 0.0, chvmanager,
543 &error,cpus, stats, msglvl, msgFile) ;
544 ChvManager_free(chvmanager) ;
546 fprintf(msgFile,
"\n\n factor matrix") ;
547 FrontMtx_writeForHumanEye(frontmtx, msgFile) ;
550 if ( rootchv != NULL ) {
551 fprintf(msgFile,
"\n\n matrix found to be singular\n") ;
555 fprintf(msgFile,
"\n\nerror encountered at front %" ITGFORMAT
"",error);
564 FrontMtx_postProcess(frontmtx, msglvl, msgFile) ;
566 fprintf(msgFile,
"\n\n factor matrix after post-processing") ;
567 FrontMtx_writeForHumanEye(frontmtx, msgFile) ;
574 for(j=0;j<*nmpc;j++){
584 for(i=nindep;i>0;i--){
586 if(ipointer[idof]>0){
590 DenseMtx_init(mtxB, type, 0, 0, neqns, nrhs, 1, neqns) ;
591 DenseMtx_zero(mtxB) ;
593 index=ipointer[idof];
595 irow=icoef[2*index-2]-1;
597 DenseMtx_setRealEntry(mtxB,irow,jrhs,coef);
598 index=icoef[2*index-1];
603 fprintf(msgFile,
"\n\n rhs matrix in original ordering") ;
604 DenseMtx_writeForHumanEye(mtxB, msgFile) ;
614 DenseMtx_permuteRows(mtxB, oldToNewIV) ;
616 fprintf(msgFile,
"\n\n right hand side matrix in new ordering") ;
617 DenseMtx_writeForHumanEye(mtxB, msgFile) ;
626 DenseMtx_init(mtxX, type, 0, 0, neqns, nrhs, 1, neqns) ;
627 DenseMtx_zero(mtxX) ;
628 FrontMtx_solve(frontmtx, mtxX, mtxB, mtxmanager,cpus, msglvl, msgFile) ;
630 fprintf(msgFile,
"\n\n solution matrix in new ordering") ;
631 DenseMtx_writeForHumanEye(mtxX, msgFile) ;
640 DenseMtx_permuteRows(mtxX, newToOldIV) ;
642 fprintf(msgFile,
"\n\n solution matrix in original ordering") ;
643 DenseMtx_writeForHumanEye(mtxX, msgFile) ;
648 for(j=0;j<*nmpc;j++){
649 b=DenseMtx_entries(mtxX)[j];
651 nodempc[3**mpcfree-1]=ipompc[j];
652 node=(
ITG)((idof+8)/8);
653 idir=idof+1-8*(node-1);
654 nodempc[3**mpcfree-3]=node;
655 nodempc[3**mpcfree-2]=idir;
656 coefmpc[*mpcfree-1]=b;
657 ipompc[j]=(*mpcfree)++;
658 if(*mpcfree>*memmpc_){
659 *memmpc_=(
ITG)(1.1**memmpc_);
661 RENEW(coefmpc,
double,*memmpc_);
673 FrontMtx_free(frontmtx) ;
674 DenseMtx_free(mtxB) ;
675 DenseMtx_free(mtxX) ;
676 IV_free(newToOldIV) ;
677 IV_free(oldToNewIV) ;
679 ETree_free(frontETree) ;
680 IVL_free(symbfacIVL) ;
681 SubMtxManager_free(mtxmanager) ;
686 for(i=0;i<*nmpc;i++){
689 node=(
ITG)((idof+7)/8);
690 idir=idof-8*(node-1);
691 nodempc[3**mpcfree-1]=ipompc[j];
692 nodempc[3**mpcfree-3]=node;
693 nodempc[3**mpcfree-2]=idir;
694 coefmpc[*mpcfree-1]=1.;
695 ipompc[j]=(*mpcfree)++;
696 if(*mpcfree>*memmpc_){
697 *memmpc_=(
ITG)(1.1**memmpc_);
699 RENEW(coefmpc,
double,*memmpc_);
715 for(i=0;i<*nmpc;i++){
717 *mpcend=
max(*mpcend,index);
720 index=nodempc[3*index-1];
722 *maxlenmpc=
max(*maxlenmpc,nterm);
725 *mpcend=
max(*mpcend,index);
#define ITGFORMAT
Definition: CalculiX.h:52
#define max(a, b)
Definition: cascade.c:32
ITG strcpy1(char *s1, const char *s2, ITG length)
Definition: strcpy1.c:24
void FORTRAN(actideacti,(char *set, ITG *nset, ITG *istartset, ITG *iendset, ITG *ialset, char *objectset, ITG *ipkon, ITG *ibject, ITG *ne))
ITG strcmp1(const char *s1, const char *s2)
Definition: strcmp1.c:24
subroutine stop()
Definition: stop.f:20
void tau(double *ad, double **aup, double *adb, double *aubp, double *sigma, double *b, ITG *icol, ITG **irowp, ITG *neq, ITG *nzs)
#define RENEW(a, b, c)
Definition: CalculiX.h:40
#define SFREE(a)
Definition: CalculiX.h:41
subroutine nident(x, px, n, id)
Definition: nident.f:26
#define ITG
Definition: CalculiX.h:51
#define NNEW(a, b, c)
Definition: CalculiX.h:39