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 <unistd.h>
19 #include <stdio.h>
20 #include <math.h>
21 #include <stdlib.h>
22 #include <string.h>
23 #include <pthread.h>
24 #include "CalculiX.h"
25 
stress_sen_dx(double * co,ITG * nk,ITG * kon,ITG * ipkon,char * lakon,ITG * ne,double * dstn,double * elcon,ITG * nelcon,double * rhcon,ITG * nrhcon,double * alcon,ITG * nalcon,double * alzero,ITG * ielmat,ITG * ielorien,ITG * norien,double * orab,ITG * ntmat_,double * t0,double * t1,ITG * ithermal,double * prestr,ITG * iprestr,char * filab,ITG * iperturb,double * vold,ITG * nmethod,double * dtime,double * time,double * ttime,double * plicon,ITG * nplicon,double * plkcon,ITG * nplkcon,double * xstateini,double * xstate,ITG * npmat_,char * matname,ITG * mi,ITG * ielas,ITG * ncmat_,ITG * nstate_,double * stiini,double * vini,double * emeini,double * enerini,ITG * istep,ITG * iinc,double * springarea,double * reltime,ITG * ne0,double * thicke,double * pslavsurf,double * pmastsurf,ITG * mortar,double * clearini,ITG * ielprop,double * prop,ITG * kscale,ITG * iobject,char * objectset,double * g0,double * dgdx,ITG * nea,ITG * neb,ITG * nasym,double * distmin,ITG * idesvar,double * dstx,ITG * ialdesi,ITG * ialeneigh,ITG * neaneigh,ITG * nebneigh,ITG * ialnneigh,ITG * naneigh,ITG * nbneigh,double * stn,double * expks,ITG * ndesi)26 void stress_sen_dx(double *co,ITG *nk,ITG *kon,ITG *ipkon,char *lakon,ITG *ne,
27 	double *dstn,double *elcon,ITG *nelcon,
28 	double *rhcon,ITG *nrhcon,double *alcon,ITG *nalcon,double *alzero,
29 	ITG *ielmat,ITG *ielorien,ITG *norien,double *orab,ITG *ntmat_,
30 	double *t0,double *t1,ITG *ithermal,double *prestr,ITG *iprestr,
31 	char *filab,ITG *iperturb,double *vold,ITG *nmethod,double *dtime,
32         double *time,double *ttime,double *plicon,ITG *nplicon,double *plkcon,
33 	ITG *nplkcon,double *xstateini,double *xstate,ITG *npmat_,char *matname,
34 	ITG *mi,ITG *ielas,ITG *ncmat_,ITG *nstate_,double *stiini,double *vini,
35 	double *emeini,double *enerini,ITG *istep,ITG *iinc,double *springarea,
36 	double *reltime,ITG *ne0,double *thicke,double *pslavsurf,
37 	double *pmastsurf,ITG *mortar,double *clearini,ITG *ielprop,
38 	double *prop,
39 	ITG *kscale,ITG *iobject,char *objectset,double *g0,double *dgdx,
40 	ITG *nea,ITG *neb,ITG *nasym,double *distmin,ITG*idesvar,double *dstx,
41 	ITG *ialdesi,ITG *ialeneigh,ITG *neaneigh,ITG *nebneigh,ITG *ialnneigh,
42 	ITG *naneigh,ITG *nbneigh,double *stn,double *expks,ITG *ndesi){
43 
44   ITG symmetryflag=0,mt=mi[1]+1,i,iactpos,calcul_fn,list,
45     calcul_qa,calcul_cauchy,ikin=0,nal,iout=2,icmd=3,nener=0,
46     *inum=NULL,nprintl=0,unperturbflag,nfield,ndim,iorienglob,
47     force,mscalmethod=0,*islavelinv=NULL,*irowtloc=NULL,*jqtloc=NULL,
48     mortartrafoflag=0,intscheme=0;
49 
50   double *fn=NULL,*eei=NULL,qa[4]={0.,0.,-1.,0.},*xstiff=NULL,*ener=NULL,
51     *eme=NULL,kspart,dksper,*smscale=NULL,enerscal=0.,*t0g=NULL,*t1g=NULL,
52     *autloc=NULL;
53 
54   char cflag[1];
55 
56   if(*nasym!=0){symmetryflag=2;}
57 
58   NNEW(eme,double,6*mi[0]**ne);
59   NNEW(inum,ITG,*nk);
60 
61   /* calculating the perturbed stresses */
62 
63   NNEW(fn,double,mt**nk);
64   NNEW(eei,double,6*mi[0]**ne);
65 
66   /* setting the output variables */
67 
68   calcul_fn=0;
69   calcul_qa=0;
70   if(iperturb[1]==1){calcul_cauchy=1;}else{calcul_cauchy=0;}
71 
72   list=1;
73   FORTRAN(resultsmech,(co,kon,ipkon,lakon,ne,vold,
74 		       dstx,elcon,nelcon,rhcon,nrhcon,alcon,nalcon,alzero,
75 		       ielmat,ielorien,norien,orab,ntmat_,t0,t1,ithermal,prestr,
76 		       iprestr,eme,iperturb,fn,&iout,qa,vold,
77 		       nmethod,
78 		       vold,dtime,time,ttime,plicon,nplicon,plkcon,nplkcon,
79 		       xstateini,xstiff,xstate,npmat_,matname,mi,ielas,&icmd,
80 		       ncmat_,nstate_,stiini,vini,ener,eei,enerini,istep,iinc,
81 		       springarea,reltime,&calcul_fn,&calcul_qa,&calcul_cauchy,
82 		       &nener,
83 		       &ikin,&nal,ne0,thicke,emeini,
84 		       pslavsurf,pmastsurf,mortar,clearini,nea,neb,ielprop,
85 		       prop,kscale,&list,ialdesi,smscale,&mscalmethod,
86 		       &enerscal,t0g,t1g,islavelinv,autloc,irowtloc,jqtloc,
87 		       &mortartrafoflag,&intscheme));
88 
89   /* extrapolating the stresses */
90 
91   nfield=6;
92   ndim=6;
93   iorienglob=0;
94   force=0;
95   strcpy1(&cflag[0],&filab[2962],1);
96 
97   FORTRAN(extrapolate_se,(dstx,dstn,ipkon,inum,kon,lakon,
98 			  &nfield,nk,ne,mi,&ndim,orab,ielorien,co,&iorienglob,
99 			  cflag,vold,&force,ielmat,thicke,ielprop,prop,
100 			  ialeneigh,
101 			  neaneigh,nebneigh,ialnneigh,naneigh,nbneigh));
102 
103   /* Calculate KS-function and sensitivity */
104 
105   FORTRAN(objective_stress_se,(nk,iobject,mi,dstn,objectset,
106 			       ialnneigh,naneigh,nbneigh,stn,&dksper));
107 
108   dgdx[(*idesvar-1)+(*iobject-1)**ndesi]=dksper/(*distmin**expks);
109 
110   SFREE(fn);SFREE(eei);SFREE(eme);SFREE(inum);
111   SFREE(ener);SFREE(xstiff);
112 
113 }
114