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
writenewmesh(ITG * nktet,ITG * netet_,double * cotet,ITG * iquad,ITG * kontet,ITG * iedgmid,ITG * iedtet,ITG * mi,char * matname,ITG * ithermal,char * jobnamec,char * output,ITG * nmat)24 void writenewmesh(ITG *nktet,ITG *netet_,double *cotet,ITG *iquad,
25 ITG *kontet,ITG *iedgmid,ITG *iedtet,ITG *mi,
26 char *matname,ITG *ithermal,char *jobnamec,
27 char *output,ITG *nmat){
28
29 /* writing the new mesh in a mesh refinement calculation */
30
31 FILE *f1;
32
33 char *lakonnew=NULL,filabnew[5]=" ",*description=NULL,*set=NULL,
34 fnewmesh[132]="",fneig[132]="",outputnew[5]="bin ";
35
36 ITG nknew,nenew,*ipkonnew=NULL,*konnew=NULL,i,j,netet,*inum=NULL,
37 nmethod=0,kode=1,*ielmatnew=NULL,nstate_=0,istep,iinc,mode=-1,
38 noddiam=-1,*inotr=NULL,ntrans,*ielorien=NULL,norien,*ipneigh=NULL,
39 *neigh=NULL,ngraph,nset,*istartset=NULL,*iendset=NULL,*ialset=NULL,
40 mortar=0,*ielprop=NULL;
41
42 double *conew=NULL,*v=NULL,*stn=NULL,*een=NULL,*t1=NULL,*fn=NULL,
43 time=0.,*epn=NULL,*enern=NULL,*xstaten=NULL,*qfn=NULL,*trab=NULL,
44 *orab=NULL,*stx=NULL,*vr=NULL,*vi=NULL,*stnr=NULL,*stni=NULL,
45 *vmax=NULL,*stnmax=NULL,*veold=NULL,*ener=NULL,*cs=NULL,*eenmax=NULL,
46 *fnr=NULL,*fni=NULL,*emn=NULL,*thicke=NULL,*qfx=NULL,*cdn=NULL,
47 *cdnr=NULL,*cdni=NULL,*prop=NULL,*sti=NULL;
48
49 strcpy(fnewmesh,jobnamec);
50 strcat(fnewmesh,".rfn");
51
52 nknew=*nktet;
53 nenew=*netet_;
54
55 NNEW(conew,double,3*nknew);
56 memcpy(&conew[0],&cotet[0],sizeof(double)*3*nknew);
57
58 NNEW(ipkonnew,ITG,nenew);
59 NNEW(konnew,ITG,10*nenew);
60 NNEW(lakonnew,char,8*nenew);
61 NNEW(ielmatnew,ITG,mi[2]*nenew);
62
63 for(i=0;i<nenew;i++){
64 ipkonnew[i]=-1;
65 }
66
67 if(*iquad==0) {
68 netet=0;
69 for(i=0;i<nenew;i++){
70 if(kontet[i*4]==0) continue;
71 ipkonnew[i]=4*netet;
72 for(j=0;j<4;j++) {
73 konnew[4*netet+j]=kontet[4*i+j];
74 }
75 strcpy1(&lakonnew[8*i],"C3D4 ",8);
76 netet++;
77 }
78 RENEW(konnew,ITG,4*netet);
79 }
80 else if(*iquad==1) {
81 netet=0;
82 for(i=0;i<nenew;i++){
83 if(kontet[i*4]==0) continue;
84 ipkonnew[i]=10*netet;
85 for(j=0;j<4;j++) {
86 konnew[10*netet+j]=kontet[4*i+j];
87 }
88 for(j=4;j<10;j++){
89 konnew[10*netet+j]=iedgmid[iedtet[6*i+j-4]-1];
90 }
91
92 strcpy1(&lakonnew[8*i],"C3D10 ",8);
93 netet++;
94 }
95 RENEW(konnew,ITG,10*netet);
96 }
97
98 strcpy(fneig,fnewmesh);
99 strcat(fneig,".frd");
100
101 if((f1=fopen(fneig,"wb"))==NULL){
102 printf("*EOR in frd: cannot open frd file for writing...");
103 exit(0);
104 }
105
106 fclose(f1);
107
108 /* creating the tetrahedral mesh in frd format*/
109
110 frd(conew,&nknew,konnew,ipkonnew,lakonnew,&nenew,v,stn,inum,&nmethod,
111 &kode,filabnew,een,t1,fn,&time,epn,ielmatnew,matname,enern,xstaten,
112 &nstate_,&istep,&iinc,ithermal,qfn,&mode,&noddiam,trab,inotr,
113 &ntrans,orab,ielorien,&norien,description,ipneigh,neigh,
114 mi,stx,vr,vi,stnr,stni,vmax,stnmax,&ngraph,veold,ener,&nenew,
115 cs,set,&nset,istartset,iendset,ialset,eenmax,fnr,fni,emn,
116 thicke,fnewmesh,outputnew,qfx,cdn,&mortar,cdnr,cdni,nmat,ielprop,
117 prop,sti);
118
119 strcat(fnewmesh,".frd");
120 if((f1=fopen(fnewmesh,"ab"))==NULL){
121 printf("*ERROR in frd: cannot open frd file for writing...");
122 exit(0);
123 }
124 fprintf(f1," 9999\n");
125 fclose(f1);
126
127 SFREE(conew);SFREE(ipkonnew);SFREE(konnew);SFREE(lakonnew);SFREE(ielmatnew);
128
129 return;
130
131 }
132