1 /*     CalculiX - A 3-dimensional finite element program                 */
2 /*              Copyright (C) 1998-2021 Guido Dhondt                          */
3 
4 /*     This program is free software; you can redistribute it and/or     */
5 /*     modify it under the terms of the GNU General Public License as    */
6 /*     published by the Free Software Foundation(version 2);    */
7 /*                                                                       */
8 
9 /*     This program is distributed in the hope that it will be useful,   */
10 /*     but WITHOUT ANY WARRANTY; without even the implied warranty of    */
11 /*     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the      */
12 /*     GNU General Public License for more details.                      */
13 
14 /*     You should have received a copy of the GNU General Public License */
15 /*     along with this program; if not, write to the Free Software       */
16 /*     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.         */
17 
18 #include <stdlib.h>
19 #include <math.h>
20 #include <stdio.h>
21 #include <string.h>
22 #include "CalculiX.h"
23 
24 #define min(a,b) ((a) <= (b) ? (a) : (b))
25 #define max(a,b) ((a) >= (b) ? (a) : (b))
26 
crackfrd(ITG * nk,ITG * ngraph,ITG * noddiam,double * cs,ITG * kode,ITG * inum,ITG * nmethod,double * time,ITG * istep,ITG * iinc,ITG * mode,char * description,char * set,ITG * nset,ITG * istartset,ITG * iendset,ITG * ialset,char * jobnamec,char * output,double * dkeqglob,double * wk1glob,double * wk2glob,double * wk3glob,double * phiglob,double * dadnglob,double * dnglob,double * acrackglob,double * xkeqminglob,double * xkeqmaxglob,ITG * iincglob,double * domstepglob)27 void crackfrd(ITG *nk,ITG *ngraph,ITG *noddiam,double *cs,ITG *kode,ITG *inum,
28 	      ITG *nmethod,double *time,ITG *istep,ITG *iinc,ITG *mode,
29 	      char *description,char *set,ITG *nset,ITG *istartset,
30 	      ITG *iendset,ITG *ialset,char *jobnamec,char *output,
31 	      double *dkeqglob,double *wk1glob,double *wk2glob,double *wk3glob,
32 	      double *phiglob,double *dadnglob,double *dnglob,
33 	      double *acrackglob,double *xkeqminglob,double *xkeqmaxglob,
34 	      ITG *iincglob,double *domstepglob){
35 
36   /* stores the results in frd format
37 
38      iselect selects which nodes are to be stored:
39      iselect=-1 means only those nodes for which inum negative
40      ist, i.e. network nodes
41      iselect=+1 means only those nodes for which inum positive
42      ist, i.e. structural nodes
43      iselect=0  means both of the above */
44 
45   FILE *f1;
46 
47   char m1[4]=" -1",m2[4]=" -2",m3[4]=" -3",fneig[132]="",filab[87]="";
48 
49   ITG icounter=0,nkcoords;
50 
51   ITG null,i,j,noutloc,iset,iselect,nfield[2],ifieldstate[15],icompstate[15],
52     ioutall=0,nout,noutplus,noutmin,nstate_;
53 
54   double pi,oner,nullr,*xstaten=NULL;
55 
56   strcpy(fneig,jobnamec);
57   strcat(fneig,".frd");
58 
59   if((f1=fopen(fneig,"ab"))==NULL){
60     printf("*EOR in frd: cannot open frd file for writing...");
61     exit(0);
62   }
63 
64   /* check whether all results have to be stored (also those
65      corresponding to inactive nodes or elements) */
66 
67   if(strcmp1(&output[3],"a")==0) ioutall=1;
68 
69   pi=4.*atan(1.);
70   null=0;
71   nullr=0;
72   oner=1.;
73 
74   /* nkcoords is the number of nodes at the time when
75      the nodal coordinates are stored in the frd file */
76 
77   nkcoords=*nk;
78 
79   /* determining nout, noutplus and noutmin
80      nout: number of structural and network nodes
81      noutplus: number of structural nodes
82      noutmin: number of network nodes */
83 
84   if(*nmethod!=0){
85     nout=0;
86     noutplus=0;
87     noutmin=0;
88     if(ioutall==0){
89       for(i=0;i<*nk;i++){
90 	if(inum[i]==0) continue;
91 	nout++;
92 	if(inum[i]>0) noutplus++;
93 	if(inum[i]<0) noutmin++;
94       }
95     }else{
96       for(i=0;i<*nk;i++){
97 	nout++;
98 	if(inum[i]>0) noutplus++;
99 	if(inum[i]<0) noutmin++;
100       }
101     }
102   }else{
103     nout=*nk;
104   }
105 
106   /* storing the internal state variables in the nodes */
107 
108   iselect=1;
109   nstate_=15;
110 
111   frdset(filab,set,&iset,istartset,iendset,ialset,
112 	 inum,&noutloc,&nout,nset,&noutmin,&noutplus,&iselect,
113 	 ngraph);
114 
115   frdheader(&icounter,&oner,time,&pi,noddiam,cs,&null,mode,
116 	    &noutloc,description,kode,nmethod,f1,output,istep,iinc);
117 
118   fprintf(f1," -4  CT3D-MIS  %3" ITGFORMAT "    1\n",nstate_);
119   fprintf(f1," -5  DOM_STEP    1    1    1    1\n");
120   fprintf(f1," -5  DeltaKEQ    1    1    1    1\n");
121   fprintf(f1," -5  KEQMIN      1    1    1    1\n");
122   fprintf(f1," -5  KEQMAX      1    1    1    1\n");
123   fprintf(f1," -5  K1WORST     1    1    1    1\n");
124   fprintf(f1," -5  K2WORST     1    1    1    1\n");
125   fprintf(f1," -5  K3WORST     1    1    1    1\n");
126   fprintf(f1," -5  PHI(DEG)    1    1    1    1\n");
127   fprintf(f1," -5  R           1    1    1    1\n");
128   fprintf(f1," -5  DADN        1    1    1    1\n");
129   fprintf(f1," -5  KTH         1    1    1    1\n");
130   fprintf(f1," -5  INC         1    1    1    1\n");
131   fprintf(f1," -5  CYCLES      1    1    1    1\n");
132   fprintf(f1," -5  CRLENGTH    1    1    1    1\n");
133   fprintf(f1," -5  DOM_SLIP    1    1    1    1\n");
134 
135   for(i=0;i<nstate_;i++){
136     ifieldstate[i]=1;icompstate[i]=i;
137   }
138   nfield[0]=nstate_;
139 
140   NNEW(xstaten,double,nstate_**nk);
141 
142   for(i=0;i<*nk;i++){
143     xstaten[nstate_*i]=domstepglob[i];
144     xstaten[nstate_*i+1]=dkeqglob[i];
145     xstaten[nstate_*i+2]=xkeqminglob[i];
146     xstaten[nstate_*i+3]=xkeqmaxglob[i];
147     xstaten[nstate_*i+4]=wk1glob[i];
148     xstaten[nstate_*i+5]=wk2glob[i];
149     xstaten[nstate_*i+6]=wk3glob[i];
150     xstaten[nstate_*i+7]=phiglob[i]*180./pi;
151     xstaten[nstate_*i+8]=nullr;
152     xstaten[nstate_*i+9]=dadnglob[i];
153     xstaten[nstate_*i+10]=nullr;
154     xstaten[nstate_*i+11]=1.0*iincglob[i];
155     xstaten[nstate_*i+12]=dnglob[i];
156     xstaten[nstate_*i+13]=acrackglob[i];
157     xstaten[nstate_*i+14]=nullr;
158   }
159 
160   frdselect(xstaten,xstaten,&iset,&nkcoords,inum,m1,istartset,iendset,
161 	    ialset,ngraph,&nstate_,ifieldstate,icompstate,
162 	    nfield,&iselect,m2,f1,output,m3);
163 
164   SFREE(xstaten);
165 
166   fclose(f1);
167   return;
168 
169 }
170