1 /*
2 Copyright (C) 1998 Dennis Roddeman
3 email: dennis.roddeman@feat.nl
4
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software Foundation
17 59 Temple Place, Suite 330, Boston, MA, 02111-1307, USA
18 */
19
20 #include "tochnog.h"
21
print_matlab(void)22 void print_matlab( void )
23
24 {
25 long int nnol=0, inod=0, ipuknwn=0, iuknwn=0, icontrol=0,
26 icalcul=0, ncalcul=0, swit=0, element=0, max_element=0,
27 itask=0, ntask=0, length=0, name=0, iplot=0, nplot=0,
28 print_coord=0, print_unknown=0, print_calcul=0, ready=0, ldum=0,
29 *plot_nodes=NULL, *dof_label=NULL, *nodes=NULL, *el=NULL;
30 double ddum[1], *coord=NULL, *node_dof=NULL, *node_dof_calcul=NULL;
31 char str[MCHAR], x_name[MCHAR], y_name[MCHAR], z_name[MCHAR], unknown_name[MCHAR];
32
33 swit = set_swit(-1,-1,"print_matlab");
34 if ( swit ) pri( "In routine PRINT_MATLAB" );
35
36 plot_nodes = get_new_int(MAXIMUM_NODE);
37 dof_label = get_new_int(MUKNWN);
38 nodes = get_new_int(MAXIMUM_NODE);
39 el = get_new_int(1+MNOL);
40
41 db( ICONTROL, 0, &icontrol, ddum, ldum, VERSION_NORMAL, GET );
42 db( DOF_LABEL, 0, dof_label, ddum, ldum, VERSION_NORMAL, GET_IF_EXISTS );
43 db_max_index( ELEMENT, max_element, VERSION_NORMAL, GET );
44 if ( db_max_index( POST_CALCUL_SCAL_VEC_MAT, ldum, VERSION_NORMAL, GET ) >=0 )
45 ncalcul = db_len( POST_CALCUL_SCAL_VEC_MAT, 0, VERSION_NORMAL );
46 long_to_a( icontrol, str );
47
48 ntask = 1; // coordinates
49 ntask += npuknwn; // primary unknowns
50 ntask += ncalcul; // calcul results
51
52 // empty the files
53 for ( itask=0; itask<ntask; itask++ ) {
54 if ( itask>=0 && itask<1 ) {
55 ;
56 }
57 else if ( itask>=1 && itask<1+npuknwn ) {
58 ipuknwn = itask - 1;
59 iuknwn = ipuknwn*nder;
60 }
61 else {
62 icalcul = itask - (1+npuknwn);
63 }
64 strcpy( x_name, "x." );
65 strcat( x_name, str );
66 ofstream x_out( x_name );
67 x_out.precision(TN_PRECISION);
68 strcpy( y_name, "y." );
69 strcat( y_name, str );
70 ofstream y_out( y_name );
71 y_out.precision(TN_PRECISION);
72 strcpy( z_name, "z." );
73 strcat( z_name, str );
74 ofstream z_out( z_name );
75 z_out.precision(TN_PRECISION);
76 strcpy( unknown_name, db_name(dof_label[iuknwn]) );
77 strcat( unknown_name, "." );
78 strcat( unknown_name, str );
79 ofstream unknown_out( unknown_name );
80 unknown_out.precision(TN_PRECISION);
81 strcpy( unknown_name, post_calcul_names[icalcul] );
82 strcat( unknown_name, "." );
83 strcat( unknown_name, str );
84 ofstream calcul_out( unknown_name );
85 calcul_out.precision(TN_PRECISION);
86 x_out.close();
87 y_out.close();
88 z_out.close();
89 unknown_out.close();
90 calcul_out.close();
91 }
92
93 // print
94 for ( itask=0; itask<ntask; itask++ ) {
95 if ( swit ) pri( "itask", itask );
96 print_coord = print_unknown = print_calcul = 0;
97 if ( itask>=0 && itask<1 ) {
98 print_coord = 1;
99 if ( swit ) pri( "print_coord" );
100 }
101 else if ( itask>=1 && itask<1+npuknwn ) {
102 ipuknwn = itask - 1;
103 iuknwn = ipuknwn*nder;
104 print_unknown = 1;
105 if ( swit ) pri( "print_unknown" );
106 }
107 else {
108 icalcul = itask - (1+npuknwn);
109 print_calcul = 1;
110 if ( swit ) pri( "print_calcul" );
111 }
112 strcpy( x_name, "x." );
113 strcat( x_name, str );
114 ofstream x_out( x_name, ios::app );
115 x_out.precision(TN_PRECISION);
116 strcpy( y_name, "y." );
117 strcat( y_name, str );
118 ofstream y_out( y_name, ios::app );
119 y_out.precision(TN_PRECISION);
120 strcpy( z_name, "z." );
121 strcat( z_name, str );
122 ofstream z_out( z_name, ios::app );
123 z_out.precision(TN_PRECISION);
124 strcpy( unknown_name, db_name(dof_label[iuknwn]) );
125 strcat( unknown_name, "." );
126 strcat( unknown_name, str );
127 ofstream unknown_out( unknown_name, ios::app );
128 unknown_out.precision(TN_PRECISION);
129 strcpy( unknown_name, post_calcul_names[icalcul] );
130 strcat( unknown_name, "." );
131 strcat( unknown_name, str );
132 ofstream calcul_out( unknown_name, ios::app );
133 calcul_out.precision(TN_PRECISION);
134 ready = 0;
135 for ( iplot=0; !ready; iplot++ ) {
136 if ( swit ) pri( "iplot", iplot );
137 for ( element=0; element<=max_element; element++ ) {
138 if ( db_active_index( ELEMENT, element, VERSION_NORMAL ) ) {
139 if ( swit ) pri( "element", element );
140 db( ELEMENT, element, el, ddum, length, VERSION_NORMAL, GET );
141 name = el[0]; nnol = length - 1; array_move( &el[1], nodes, nnol );
142 if ( name==-BAR2 ) {
143 nplot = 2;
144 plot_nodes[0] = nodes[0];
145 plot_nodes[1] = nodes[1];
146 }
147 else if ( name==-BAR3 ) {
148 nplot = 2;
149 plot_nodes[0] = nodes[0];
150 plot_nodes[1] = nodes[2];
151 }
152 else if ( name==-BAR4 ) {
153 nplot = 2;
154 plot_nodes[0] = nodes[0];
155 plot_nodes[1] = nodes[3];
156 }
157 else if ( name==-TRIA3 ) {
158 nplot = 4;
159 plot_nodes[0] = nodes[0];
160 plot_nodes[1] = nodes[0];
161 plot_nodes[2] = nodes[1];
162 plot_nodes[3] = nodes[2];
163 }
164 else if ( name==-QUAD4 ) {
165 nplot = 4;
166 plot_nodes[0] = nodes[0];
167 plot_nodes[1] = nodes[1];
168 plot_nodes[2] = nodes[3];
169 plot_nodes[3] = nodes[2];
170 }
171 else if ( name==-QUAD9 ) {
172 nplot = 4;
173 plot_nodes[0] = nodes[0];
174 plot_nodes[1] = nodes[2];
175 plot_nodes[2] = nodes[8];
176 plot_nodes[3] = nodes[6];
177 }
178 else if ( name==-QUAD16 ) {
179 nplot = 4;
180 plot_nodes[0] = nodes[0];
181 plot_nodes[1] = nodes[3];
182 plot_nodes[2] = nodes[15];
183 plot_nodes[3] = nodes[12];
184 }
185 else if ( name==-TET4 ) {
186 nplot = 8;
187 plot_nodes[0] = nodes[0];
188 plot_nodes[1] = nodes[0];
189 plot_nodes[2] = nodes[0];
190 plot_nodes[3] = nodes[0];
191 plot_nodes[4] = nodes[1];
192 plot_nodes[5] = nodes[1];
193 plot_nodes[6] = nodes[2];
194 plot_nodes[7] = nodes[3];
195 }
196 else if ( name==-HEX8 ) {
197 nplot = 8;
198 plot_nodes[0] = nodes[0];
199 plot_nodes[1] = nodes[1];
200 plot_nodes[2] = nodes[3];
201 plot_nodes[3] = nodes[2];
202 plot_nodes[4] = nodes[4];
203 plot_nodes[5] = nodes[5];
204 plot_nodes[6] = nodes[7];
205 plot_nodes[7] = nodes[6];
206 }
207 else if ( name==-HEX27 ) {
208 nplot = 8;
209 plot_nodes[0] = nodes[0];
210 plot_nodes[1] = nodes[2];
211 plot_nodes[2] = nodes[8];
212 plot_nodes[3] = nodes[6];
213 plot_nodes[4] = nodes[18];
214 plot_nodes[5] = nodes[20];
215 plot_nodes[6] = nodes[26];
216 plot_nodes[7] = nodes[24];
217 }
218 else if ( name==-HEX64 ) {
219 nplot = 8;
220 plot_nodes[0] = nodes[0];
221 plot_nodes[1] = nodes[3];
222 plot_nodes[2] = nodes[15];
223 plot_nodes[3] = nodes[12];
224 plot_nodes[4] = nodes[48];
225 plot_nodes[5] = nodes[51];
226 plot_nodes[6] = nodes[63];
227 plot_nodes[7] = nodes[60];
228 }
229 else {
230 pri( "Error: CONTROL_PRINT_MATLAB not available for ", name );
231 exit(TN_EXIT_STATUS );
232 }
233 if ( swit ) pri( "plot_nodes", plot_nodes, nplot );
234 inod = plot_nodes[iplot];
235 if ( swit ) pri( "inod", inod );
236 if ( print_coord ) {
237 coord = db_dbl( NODE, inod, VERSION_NORMAL );
238 if ( db_active_index( NODE_DOF, inod, VERSION_NORMAL ) )
239 node_dof = db_dbl( NODE_DOF, inod, VERSION_NORMAL );
240 if ( ndim>0 ) {
241 if ( materi_displacement )
242 x_out << coord[0]+node_dof[dis_indx+0*nder] << " ";
243 else
244 x_out << coord[0] << " ";
245 }
246 if ( ndim>1 ) {
247 if ( materi_displacement )
248 y_out << coord[1]+node_dof[dis_indx+1*nder] << " ";
249 else
250 y_out << coord[1] << " ";
251 }
252 if ( ndim>2 ) {
253 if ( materi_displacement )
254 z_out << coord[2]+node_dof[dis_indx+2*nder] << " ";
255 else
256 z_out << coord[2] << " ";
257 }
258 }
259 else if ( print_unknown ) {
260 node_dof = db_dbl( NODE_DOF, inod, VERSION_NORMAL );
261 unknown_out << node_dof[iuknwn] << " ";
262 }
263 else {
264 assert( print_calcul );
265 node_dof_calcul = db_dbl( NODE_DOF_CALCUL, inod, VERSION_NORMAL );
266 calcul_out << node_dof_calcul[icalcul] << " ";
267 }
268 }
269 }
270 ready = ( iplot==(nplot-1) );
271 if ( print_coord ) {
272 x_out << "\n";
273 y_out << "\n";
274 z_out << "\n";
275 }
276 else if ( print_unknown ) {
277 unknown_out << "\n";
278 }
279 else {
280 assert( print_calcul );
281 calcul_out << "\n";
282 }
283 }
284 x_out.close();
285 y_out.close();
286 z_out.close();
287 unknown_out.close();
288 calcul_out.close();
289 }
290
291 delete[] plot_nodes;
292 delete[] dof_label;
293 delete[] nodes;
294 delete[] el;
295
296 if ( swit ) pri( "Out routine PRINT_MATLAB" );
297 }
298