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 <stdio.h>
19 #include <math.h>
20 #include <stdlib.h>
21 #include "CalculiX.h"
22 #ifdef SPOOLES
23 #include "spooles.h"
24 #endif
25 #ifdef SGI
26 #include "sgi.h"
27 #endif
28 #ifdef TAUCS
29 #include "tau.h"
30 #endif
31 
32 
calcresidual(ITG * nmethod,ITG * neq,double * b,double * fext,double * f,ITG * iexpl,ITG * nactdof,double * aux2,double * vold,double * vini,double * dtime,double * accold,ITG * nk,double * adb,double * aub,ITG * jq,ITG * irow,ITG * nzl,double * alpha,double * fextini,double * fini,ITG * islavnode,ITG * nslavnode,ITG * mortar,ITG * ntie,double * f_cm,double * f_cs,ITG * mi,ITG * nzs,ITG * nasym,ITG * idamping,double * veold,double * adc,double * auc,double * cvini,double * cv,double * alpham,ITG * num_cpus)33 void calcresidual(ITG *nmethod, ITG *neq, double *b, double *fext, double *f,
34 		  ITG *iexpl, ITG *nactdof, double *aux2, double *vold,
35 		  double *vini, double *dtime, double *accold, ITG *nk, double *adb,
36 		  double *aub, ITG *jq, ITG *irow, ITG *nzl, double *alpha,
37 		  double *fextini, double *fini, ITG *islavnode, ITG *nslavnode,
38 		  ITG *mortar, ITG *ntie,double *f_cm,
39 		  double* f_cs, ITG *mi,ITG *nzs,ITG *nasym,ITG *idamping,
40 		  double *veold,double *adc,double *auc,double *cvini,double *cv,
41 		  double *alpham,ITG *num_cpus){
42 
43   ITG j,k,mt=mi[1]+1;
44   double scal1;
45 
46   /* residual for a static analysis */
47 
48   if(*nmethod!=4){
49     for(k=0;k<neq[1];++k){
50       b[k]=fext[k]-f[k];
51     }
52   }
53 
54   /* residual for implicit dynamics */
55 
56   else if(*iexpl<=1){
57     for(k=0;k<*nk;++k){
58       if(nactdof[mt*k]>0){
59 	aux2[nactdof[mt*k]-1]=(vold[mt*k]-vini[mt*k])/(*dtime);}
60       for(j=1;j<mt;++j){
61 	if(nactdof[mt*k+j]>0){
62 	  aux2[nactdof[mt*k+j]-1]=accold[mt*k+j];}
63       }
64     }
65     if(*nasym==0){
66       FORTRAN(op,(&neq[1],aux2,b,adb,aub,jq,irow));
67     }else{
68       FORTRAN(opas,(&neq[1],aux2,b,adb,aub,jq,irow,nzs));
69     }
70     scal1=1.+alpha[0];
71     for(k=0;k<neq[0];++k){
72       b[k]=scal1*(fext[k]-f[k])-alpha[0]*(fextini[k]-fini[k])-b[k];
73     }
74     for(k=neq[0];k<neq[1];++k){
75       b[k]=fext[k]-f[k]-b[k];
76     }
77 
78     /* correction for damping */
79 
80     if(*idamping==1){
81       for(k=0;k<*nk;++k){
82 	if(nactdof[mt*k]>0){
83 	  aux2[nactdof[mt*k]-1]=0.;}
84 	for(j=1;j<mt;++j){
85 	  if(nactdof[mt*k+j]>0){
86 	    aux2[nactdof[mt*k+j]-1]=veold[mt*k+j];}
87 	}
88       }
89       if(*nasym==0){
90 	FORTRAN(op,(&neq[1],aux2,cv,adc,auc,jq,irow));
91       }else{
92 	FORTRAN(opas,(&neq[1],aux2,cv,adc,auc,jq,irow,nzs));
93       }
94       for(k=0;k<neq[0];++k){
95 	b[k]-=scal1*cv[k]-alpha[0]*cvini[k];
96       }
97     }
98   }
99 
100   /* residual for explicit dynamics */
101 
102   else{
103     res1parll(&mt,nactdof,aux2,vold,vini,dtime,accold,nk,num_cpus);
104     scal1=1.+alpha[0];
105     res2parll(b,&scal1,fext,f,alpha,fextini,fini,adb,
106 	      aux2,&neq[0],num_cpus);
107     for(k=neq[0];k<neq[1];++k){
108       b[k]=fext[k]-f[k]-adb[k]*aux2[k];
109     }
110 
111     /* correction for damping */
112 
113     if(*idamping==1){
114       res3parll(&mt,nactdof,aux2,veold,nk,num_cpus);
115       res4parll(cv,alpham,adb,aux2,b,&scal1,alpha,
116 		cvini,&neq[0],num_cpus);
117     }
118   }
119 
120   return;
121 }
122