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_em(ITG * nmethod,ITG * neq,double * b,double * fext,double * f,ITG * iexpl,ITG * nactdof,double * aux1,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 * ithermal)33 void calcresidual_em(ITG *nmethod, ITG *neq, double *b, double *fext, double *f,
34         ITG *iexpl, ITG *nactdof, double *aux1, 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 *ithermal){
40 
41     ITG j,k,mt=mi[1]+1,jstart;
42 
43     /* residual for a static analysis */
44 
45     if(*nmethod!=4){
46 	for(k=0;k<neq[1];++k){
47 	    b[k]=fext[k]-f[k];
48 	}
49     }
50 
51     /* residual for implicit dynamics */
52 
53     else{
54 
55 	if(*ithermal<2){
56 	    jstart=1;
57 	}else{
58 	    jstart=0;
59 	}
60 
61         /* calculating a pseudo-velocity */
62 
63 /*	for(k=0;k<*nk;++k){
64 	    for(j=jstart;j<mt;++j){
65 		if(nactdof[mt*k+j]>0){aux2[nactdof[mt*k+j]-1]=(vold[mt*k+j]-vini[mt*k+j])/(*dtime);}
66 	    }
67 	    }*/
68 
69 	for(k=0;k<*nk;++k){
70 	    for(j=jstart;j<1;++j){
71 		if(nactdof[mt*k+j]>0){aux2[nactdof[mt*k+j]-1]=(vold[mt*k+j]-vini[mt*k+j])/(*dtime);}
72 	    }
73 	}
74 
75 	for(k=0;k<*nk;++k){
76 	    for(j=1;j<mt;++j){
77 		if(nactdof[mt*k+j]>0){aux2[nactdof[mt*k+j]-1]=(-vini[mt*k+j])/(*dtime);}
78 	    }
79 	}
80 
81         /* calculating "capacity"-matrix times pseudo-velocity */
82 
83 	if(*nasym==0){
84 	    FORTRAN(op,(&neq[1],aux2,b,adb,aub,jq,irow));
85 	}else{
86 	    FORTRAN(opas,(&neq[1],aux2,b,adb,aub,jq,irow,nzs));
87 	}
88 
89 	for(k=0;k<neq[1];++k){
90 	    b[k]=fext[k]-f[k]-b[k];
91 	}
92     }
93 
94     return;
95 }
96