1 /*
2 * This program is free software; you can redistribute it and/or
3 * modify it under the terms of the GNU General Public License as
4 * published by the Free Software Foundation; either version 2 of the
5 * License, or (at your option) any later version.
6 *
7 * This program is distributed in the hope that it will be useful, but
8 * WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOUSE. See the GNU
10 * General Public License for more details.
11 *
12 * You should have recieved a copy of the GNU General Public License
13 * along with this program; if not write to the Free Software
14 * Foundation, inc., 59 Temple Place, Suite 330, Boston MA 02111-1307
15 * USA
16 */
17
18 package run;
19 /**
20 * Topology optimization of structure.
21 *
22 * @author: Yuriy Mikhaylovskiy
23 */
24
25 import java.io.*;
26 import java.util.*;
27
28 import j3d.*;
29 import gui.*;
30
31 public class ImpactOpt implements Runnable, ExceptionListener {
32 public static final String ver = "Impact Topology optimization of structure (2006.03.11)";
33 public byte steps = 20;
34 public float ignore_stress_i = 35, ignore_strain_i = 35;
35 public Hashtable stress_i = new Hashtable(), strain_i = new Hashtable();
36 public String sourcefile;
37 private _In infile;
38 private float maxei=0,maxsi=0;
39 private String[] args;
40 private Set exception_listeners;
41
ImpactOpt()42 public ImpactOpt(){ }
43
ImpactOpt(String[] args)44 public ImpactOpt(String[] args) {
45 this.args = args;
46 exception_listeners = Collections.synchronizedSet(new HashSet());
47 }
48
run()49 public void run() {
50 System.out.println("\n"+ver);
51 System.out.println("Start topology optimization of structure.");
52 if(args.length > 0){
53 try {
54 parseArgs(args);
55 show_parametrs();
56 solve();
57 } catch (Exception e) {
58 if (e instanceof InterruptedException)
59 System.out.println("*** Solution interrupted by user, ending ***");
60 else {
61 System.out.println("*** Error in optimization, terminating");
62 e.printStackTrace();
63 sendException(e); // Notify GUI
64 }
65 }
66 }else show_syntax();
67 System.out.println("\nStop topology optimization of structure.");
68 }
69
parseArgs(String[] args)70 private void parseArgs(String[] args){
71 for(int i=0; i<args.length; i++){
72 try{
73 System.out.println("Parse command line switche ["+i+"]\t"+args[i]);
74 if(args[i].toUpperCase().endsWith(".IN")) sourcefile = args[i];
75 else if(args[i].toUpperCase().startsWith("STEPS")){
76 StringTokenizer stt = new StringTokenizer(args[i],"=");
77 stt.nextToken();
78 steps=Byte.parseByte(stt.nextToken());
79 }else if(args[i].toUpperCase().startsWith("IGNORE.STRESS_I")){
80 StringTokenizer stt = new StringTokenizer(args[i],"=");
81 stt.nextToken();
82 ignore_stress_i=Float.parseFloat(stt.nextToken());
83 }else if(args[i].toUpperCase().startsWith("IGNORE.STRAIN_I")){
84 StringTokenizer stt = new StringTokenizer(args[i],"=");
85 stt.nextToken();
86 ignore_strain_i=Float.parseFloat(stt.nextToken());
87 }
88 }catch(Exception e){System.out.println(e);}
89 }
90 }
91
show_syntax()92 private void show_syntax(){
93 System.out.println("\nThe command line syntax to run "+ver+" is:");
94 System.out.println("java run.ImpactOpt [steps=... ignore.stress_i=... ignore.strain_i=... ...] sourcefile.in");
95 System.out.println("\nCommand Line Switches:");
96 System.out.println("steps\t-\tSteps of optimization. Default "+steps+".");
97 System.out.println("ignore.stress_i\t-\tDefault "+ignore_stress_i+"% from the maximum value stress(i).");
98 System.out.println("ignore.strain_i\t-\tDefault "+ignore_strain_i+"% from the maximum value strain(i).");
99 }
100
show_parametrs()101 private void show_parametrs(){
102 System.out.println("\nInitial parameters for topology optimization of structure:");
103 System.out.println("steps\t=\t"+steps);
104 System.out.println("ignore.stress_i\t=\t"+ignore_stress_i);
105 System.out.println("ignore.strain_i\t=\t"+ignore_strain_i);
106 }
107
solve()108 public void solve() throws Exception {
109
110 for(byte i=0; i<=steps; i++) {
111 System.gc();
112 solve(i);
113
114 if (Thread.currentThread().isInterrupted())
115 break;
116
117 }
118
119 }
120
121 /**
122 * This is where we will end up if the solution is interrupted or fails.
123 *
124 */
exceptionOccurred(Exception e, Object o)125 public void exceptionOccurred(Exception e, Object o) {
126
127 // Pass this error on to the GUI
128 sendException(e);
129
130 // Terminate everything
131 Thread.currentThread().interrupt();
132 }
133
134
135 /**
136 * Add exception listener to the object
137 *
138 * @param l The listener to add
139 */
addExceptionListener(ExceptionListener l)140 public void addExceptionListener(ExceptionListener l) {
141 exception_listeners.add(l);
142 }
143
solve(byte step)144 public void solve(byte step) {
145 infile=null;
146 ModelSmp I;
147 int nr_CPU = Runtime.getRuntime().availableProcessors();
148
149 if(step==0){
150 System.out.println("\nTopology optimization of structure. Step = " + step);
151 System.out.println("Start solving problems .... ");
152 show_parametrs();
153 I = new ModelSmp(nr_CPU,sourcefile);
154 } else {
155 I = new ModelSmp(nr_CPU,opt(step));
156 }
157
158 I.addExceptionListener(this);
159 I.run();
160 }
161
main(String[] args)162 public static void main(String[] args) {
163
164 ImpactOpt opt = new ImpactOpt(args){
165 private void sendException(Exception e) { }
166 };
167 opt.run();
168 System.exit(0);
169 }
170
opt(byte step)171 private String opt(byte step) {
172 String[] args = {sourcefile.substring(0,sourcefile.length()-3)+"."+step+".in"};
173 String resfile,infile;
174 maxei=0;
175 maxsi=0;
176 int id_node=0;
177 if(step==1){
178 resfile=sourcefile+".flavia.res";
179 infile=sourcefile;
180 }else{
181 resfile=sourcefile.substring(0,sourcefile.length()-3)+"."+(step-1)+".in.flavia.res";
182 infile=sourcefile.substring(0,sourcefile.length()-3)+"."+(step-1)+".in";
183 }
184 stress_i.clear();
185 strain_i.clear();
186 System.out.println("\nReading result file: "+resfile);
187 try{
188 RandomAccessFile in = new RandomAccessFile(resfile, "r");
189 String dat;
190 while((dat=in.readLine())!=null){
191 if(dat.indexOf("STRESSES")!=-1){
192 while((dat=in.readLine())!=null && dat.indexOf("LOCAL")==-1 && dat.indexOf("GLOBAL")==-1 && dat.indexOf("DISPLACEMENTS")==-1){
193 StringTokenizer st_t = new StringTokenizer(dat);
194 float maxsii=Float.MIN_VALUE;
195 if(st_t.countTokens()==7){
196 long pos = in.getFilePointer();
197 String dat1=in.readLine();
198 StringTokenizer st_t1=null;
199 if(dat1!=null) st_t1 = new StringTokenizer(dat1);
200 if(dat1==null || st_t1.countTokens()==7 || dat1.indexOf("LOCAL")!=-1 || dat1.indexOf("GLOBAL")!=-1 || dat1.indexOf("DISPLACEMENTS")!=-1){
201 in.seek(pos);
202 }else{
203 dat+=" "+dat1+" "+in.readLine()+" "+in.readLine()+" "+in.readLine()+" "+in.readLine()+" "+in.readLine()+" "+in.readLine();
204 }
205 }
206 String key = st_t.nextToken();
207 float[] arr = toArrayFloat(dat);
208 if(arr.length==6){
209 maxsii=(float)Math.max(maxsii,Math.sqrt(2)/2*Math.sqrt(Math.pow(arr[0]-arr[1],2)+Math.pow(arr[1]-arr[2],2)+Math.pow(arr[2]-arr[0],2)+6*(arr[3]*arr[3]+arr[4]*arr[4]+arr[5]*arr[5])));
210 }else{
211 maxsii=(float)Math.max(maxsii,Math.sqrt(2)/2*Math.sqrt(Math.pow(arr[0]-arr[1],2)+Math.pow(arr[1]-arr[2],2)+Math.pow(arr[2]-arr[0],2)+6*(arr[3]*arr[3]+arr[4]*arr[4]+arr[5]*arr[5])));
212 maxsii=(float)Math.max(maxsii,Math.sqrt(2)/2*Math.sqrt(Math.pow(arr[6]-arr[7],2)+Math.pow(arr[7]-arr[8],2)+Math.pow(arr[8]-arr[6],2)+6*(arr[9]*arr[9]+arr[10]*arr[10]+arr[11]*arr[11])));
213 maxsii=(float)Math.max(maxsii,Math.sqrt(2)/2*Math.sqrt(Math.pow(arr[12]-arr[13],2)+Math.pow(arr[13]-arr[14],2)+Math.pow(arr[14]-arr[12],2)+6*(arr[15]*arr[15]+arr[16]*arr[16]+arr[17]*arr[17])));
214 maxsii=(float)Math.max(maxsii,Math.sqrt(2)/2*Math.sqrt(Math.pow(arr[18]-arr[19],2)+Math.pow(arr[19]-arr[20],2)+Math.pow(arr[20]-arr[18],2)+6*(arr[21]*arr[21]+arr[22]*arr[22]+arr[23]*arr[23])));
215 maxsii=(float)Math.max(maxsii,Math.sqrt(2)/2*Math.sqrt(Math.pow(arr[24]-arr[25],2)+Math.pow(arr[25]-arr[26],2)+Math.pow(arr[26]-arr[24],2)+6*(arr[27]*arr[27]+arr[28]*arr[28]+arr[29]*arr[29])));
216 maxsii=(float)Math.max(maxsii,Math.sqrt(2)/2*Math.sqrt(Math.pow(arr[30]-arr[31],2)+Math.pow(arr[31]-arr[32],2)+Math.pow(arr[32]-arr[30],2)+6*(arr[33]*arr[33]+arr[34]*arr[34]+arr[35]*arr[35])));
217 maxsii=(float)Math.max(maxsii,Math.sqrt(2)/2*Math.sqrt(Math.pow(arr[36]-arr[37],2)+Math.pow(arr[36]-arr[38],2)+Math.pow(arr[38]-arr[36],2)+6*(arr[39]*arr[39]+arr[40]*arr[40]+arr[41]*arr[41])));
218 maxsii=(float)Math.max(maxsii,Math.sqrt(2)/2*Math.sqrt(Math.pow(arr[42]-arr[43],2)+Math.pow(arr[43]-arr[44],2)+Math.pow(arr[44]-arr[42],2)+6*(arr[45]*arr[45]+arr[46]*arr[46]+arr[47]*arr[47])));
219 }
220 maxsi=(float)Math.max(maxsi,maxsii);
221 Object m = stress_i.get(key);
222 if(m!=null){
223 maxsii = Math.max(maxsii,((Float)m).floatValue());
224 }
225 stress_i.put(key,new Float(maxsii));
226 }
227 }
228 if(dat.indexOf("STRAINS")!=-1){
229 while((dat=in.readLine())!=null && dat.indexOf("LOCAL")==-1 && dat.indexOf("GLOBAL")==-1 && dat.indexOf("DISPLACEMENTS")==-1){
230 StringTokenizer st_t = new StringTokenizer(dat);
231 float maxeii=Float.MIN_VALUE;
232 if(st_t.countTokens()==7){
233 long pos = in.getFilePointer();
234 String dat1=in.readLine();
235 StringTokenizer st_t1=null;
236 if(dat1!=null) st_t1 = new StringTokenizer(dat1);
237 if(dat1==null || st_t1.countTokens()==7 || dat1.indexOf("LOCAL")!=-1 || dat1.indexOf("GLOBAL")!=-1 || dat1.indexOf("DISPLACEMENTS")!=-1){
238 in.seek(pos);
239 }else{
240 dat+=" "+dat1+" "+in.readLine()+" "+in.readLine()+" "+in.readLine()+" "+in.readLine()+" "+in.readLine()+" "+in.readLine();
241 }
242 }
243 String key = st_t.nextToken();
244 float[] arr = toArrayFloat(dat);
245 if(arr.length==6){
246 maxeii=(float)Math.max(maxeii,Math.sqrt(2)/3*Math.sqrt(Math.pow(arr[0]-arr[1],2)+Math.pow(arr[1]-arr[2],2)+Math.pow(arr[2]-arr[0],2)+1.5*(arr[3]*arr[3]+arr[4]*arr[4]+arr[5]*arr[5])));
247 }else{
248 maxeii=(float)Math.max(maxeii,Math.sqrt(2)/3*Math.sqrt(Math.pow(arr[0]-arr[1],2)+Math.pow(arr[1]-arr[2],2)+Math.pow(arr[2]-arr[0],2)+1.5*(arr[3]*arr[3]+arr[4]*arr[4]+arr[5]*arr[5])));
249 maxeii=(float)Math.max(maxeii,Math.sqrt(2)/3*Math.sqrt(Math.pow(arr[6]-arr[7],2)+Math.pow(arr[7]-arr[8],2)+Math.pow(arr[8]-arr[6],2)+1.5*(arr[9]*arr[9]+arr[10]*arr[10]+arr[11]*arr[11])));
250 maxeii=(float)Math.max(maxeii,Math.sqrt(2)/3*Math.sqrt(Math.pow(arr[12]-arr[13],2)+Math.pow(arr[13]-arr[14],2)+Math.pow(arr[14]-arr[12],2)+1.5*(arr[15]*arr[15]+arr[16]*arr[16]+arr[17]*arr[17])));
251 maxeii=(float)Math.max(maxeii,Math.sqrt(2)/3*Math.sqrt(Math.pow(arr[18]-arr[19],2)+Math.pow(arr[19]-arr[20],2)+Math.pow(arr[20]-arr[18],2)+1.5*(arr[21]*arr[21]+arr[22]*arr[22]+arr[23]*arr[23])));
252 maxeii=(float)Math.max(maxeii,Math.sqrt(2)/3*Math.sqrt(Math.pow(arr[24]-arr[25],2)+Math.pow(arr[25]-arr[26],2)+Math.pow(arr[26]-arr[24],2)+1.5*(arr[27]*arr[27]+arr[28]*arr[28]+arr[29]*arr[29])));
253 maxeii=(float)Math.max(maxeii,Math.sqrt(2)/3*Math.sqrt(Math.pow(arr[30]-arr[31],2)+Math.pow(arr[31]-arr[32],2)+Math.pow(arr[32]-arr[30],2)+1.5*(arr[33]*arr[33]+arr[34]*arr[34]+arr[35]*arr[35])));
254 maxeii=(float)Math.max(maxeii,Math.sqrt(2)/3*Math.sqrt(Math.pow(arr[36]-arr[37],2)+Math.pow(arr[36]-arr[38],2)+Math.pow(arr[38]-arr[36],2)+1.5*(arr[39]*arr[39]+arr[40]*arr[40]+arr[41]*arr[41])));
255 maxeii=(float)Math.max(maxeii,Math.sqrt(2)/3*Math.sqrt(Math.pow(arr[42]-arr[43],2)+Math.pow(arr[43]-arr[44],2)+Math.pow(arr[44]-arr[42],2)+1.5*(arr[45]*arr[45]+arr[46]*arr[46]+arr[47]*arr[47])));
256 }
257 maxei=(float)Math.max(maxei,maxeii);
258 Object m = strain_i.get(key);
259 if(m!=null){
260 maxeii = Math.max(maxeii,((Float)m).floatValue());
261 }
262 strain_i.put(key,new Float(maxeii));
263 }
264 }
265 }
266 in.close();
267 }catch(Exception e){e.printStackTrace();}
268
269 System.out.println("\nEdit model: "+infile);
270 in_load(infile);
271 System.out.println("\nRemeshing model");
272 in_remesh(step);
273 System.out.println("\nSave new model: "+args[0]);
274 in_save(args[0]);
275 System.out.println("\nTopology optimization of structure. Step = "+step);
276 System.out.println("Start solving problems .... ");
277
278 return args[0];
279 }
280
toArrayFloat(String st)281 public float[] toArrayFloat(String st)throws Exception{
282 StringTokenizer st_t = new StringTokenizer(st);
283 float[] arr = new float[st_t.countTokens()-1];
284 st_t.nextToken();
285 for(int i=0; i<arr.length; i++){
286 arr[i]= Float.parseFloat(st_t.nextToken());
287 }
288 return arr;
289 }
290
in_load(String fin)291 public void in_load(String fin){
292 infile = new _In(fin);
293 infile.set_Id("");
294 infile.reset(true);
295 }
296
in_remesh(byte step)297 public void in_remesh(byte step){
298
299 System.out.println("\nRemoving elements ignore.stress(i) = "+(ignore_stress_i/steps*step));
300 for(Enumeration en = stress_i.keys(); en.hasMoreElements();){
301 String key = en.nextElement()+"";
302 float volue = ((Float)stress_i.get(key)).floatValue();
303 if(maxsi/100*ignore_stress_i/steps*step>=volue){
304 for(int i=0; i<infile.elementsDB.size(); i++){
305 _Object obj = (_Object)infile.elementsDB.elementAt(i);
306 String id = obj.get_Id();
307 if(id.equalsIgnoreCase(key)){
308 System.out.println(obj.toString()+"\tStress(i) = "+volue);
309 infile.elementsDB.removeElementAt(i);
310 i--;
311 }
312 }
313 }
314 }
315
316 System.out.println("\nRemoving elements ignore.strain(i) = "+(ignore_strain_i/steps*step));
317 for(Enumeration en = strain_i.keys(); en.hasMoreElements();){
318 String key = en.nextElement()+"";
319 float volue = ((Float)strain_i.get(key)).floatValue();
320 if(maxei/100*ignore_strain_i/steps*step>=volue){
321 for(int i=0; i<infile.elementsDB.size(); i++){
322 _Object obj = (_Object)infile.elementsDB.elementAt(i);
323 String id = obj.get_Id();
324 if(id.equalsIgnoreCase(key)){
325 System.out.println(obj.toString()+"\tStrain(i) = "+volue);
326 infile.elementsDB.removeElementAt(i);
327 i--;
328 }
329 }
330 }
331 }
332
333 boolean isNext = true;
334 while(isNext){
335 isNext=false;
336 System.out.println("\nRemoving free elements");
337 for(int i=0; i<infile.elementsDB.size(); i++){
338 boolean isFree = true;
339 _Object obj = (_Object)infile.elementsDB.elementAt(i);
340 _Node[] n = obj.get_Nodes();
341 int count_elements = 0;
342 for(int j=0; j<infile.elementsDB.size(); j++){
343 if(j==i)continue;
344 byte join_nodes=0;
345 _Object obj_to = (_Object)infile.elementsDB.elementAt(j);
346 _Node[] n_to = obj_to.get_Nodes();
347 for(int k=0; k<n.length; k++){
348 for(int m=0; m<n_to.length; m++){
349 if(n[k].equals(n_to[m]))join_nodes++;
350 }
351 }
352 if(isFree)isFree = join_nodes<2;
353 if(join_nodes>1)count_elements++;
354 }
355 if(isFree || count_elements<2){
356 System.out.println(obj.toString());
357 infile.elementsDB.removeElementAt(i);
358 isNext=true;
359 i--;
360 }
361 }
362 }
363
364
365 System.out.println("\nRemoving free nodes");
366 for(int i=0; i<infile.nodesDB.size(); i++){
367 boolean isFree = true;
368 _Node n = (_Node)infile.nodesDB.elementAt(i);
369 for(int j=0; (j<infile.elementsDB.size() && isFree); j++){
370 _Object obj = (_Object)infile.elementsDB.elementAt(j);
371 _Node[] n_obj = obj.get_Nodes();
372 for(int m=0; (m<n_obj.length && isFree); m++){
373 if(n.equals(n_obj[m]))isFree=false;
374 }
375 }
376 if(isFree){
377 System.out.println(n.toString());
378 infile.nodesDB.removeElementAt(i);
379 i--;
380 }
381 }
382 }
383
in_save(String fout)384 public void in_save(String fout){
385 File file = new File(fout);
386 file.delete();
387 if(infile==null)return;
388 try{
389 RandomAccessFile out = new RandomAccessFile(fout, "rw");
390 out.writeBytes("# "+ver+"\n");
391 out.writeBytes("# Model: \t"+sourcefile+"\n");
392 out.writeBytes("# "+new Date()+"\n\n");
393 out.writeBytes(infile.ContpolsDB+"\n");
394 out.writeBytes(infile.TrackersDB+"\n");
395 for(Enumeration en = infile.LoadDB.keys(); en.hasMoreElements();){
396 String key = en.nextElement()+"";
397 Loads ld = (Loads)infile.LoadDB.get(key);
398 out.writeBytes("\nLOADS\n"+ld.toString()+"\n");
399 }
400 out.writeBytes("\n");
401 for(Enumeration en = infile.ConstDB.keys(); en.hasMoreElements();){
402 String key = en.nextElement()+"";
403 Constraints con = (Constraints)infile.ConstDB.get(key);
404 out.writeBytes("\nCONSTRAINTS OF TYPE "+con.type+"\n");
405 out.writeBytes(con.toString()+"\n\n");
406 }
407 out.writeBytes("\n");
408 for(Enumeration en = infile.MatDB.keys(); en.hasMoreElements();){
409 String key = en.nextElement()+"";
410 gui.Material mat = (gui.Material)infile.MatDB.get(key);
411 out.writeBytes("\nMATERIALS OF TYPE "+mat.type+"\n");
412 out.writeBytes(mat.name + mat.description+"\n\n");
413 }
414 out.writeBytes("\n");
415 out.writeBytes("NODES\n");
416 for(int i=0; i<infile.nodesDB.size(); i++){
417 _Node n = (_Node)infile.nodesDB.elementAt(i);
418 String st = n.get_Id()+" \tX = "+n.x+" \tY = "+n.y+" \tZ = "+n.z;
419 if(n.constraint!=null) st+=" \tConstraint = "+n.constraint.name;
420 if(n.load!=null) st+=" \tLoad = "+n.load.name;
421 if(n.M!=null) st+=" \tM = "+n.M;
422 if(n.Ixx!=null) st+=" \tIxx = "+n.Ixx;
423 if(n.Iyy!=null) st+=" \tIyy = "+n.Iyy;
424 if(n.Izz!=null) st+=" \tIzz = "+n.Izz;
425 if(n.Ixy!=null) st+=" \tIxy = "+n.Ixy;
426 if(n.Iyz!=null) st+=" \tIyz = "+n.Iyz;
427 if(n.Ixz!=null) st+=" \tIxz = "+n.Ixz;
428 out.writeBytes(st+"\n");
429 }
430 out.writeBytes("\n");
431 String st_elements = "";
432 StringBuffer st_elements_Rod_2=new StringBuffer("ELEMENTS OF TYPE Rod_2\n");
433 StringBuffer st_elements_Beam_2=new StringBuffer("ELEMENTS OF TYPE Beam_2\n");
434 StringBuffer st_elements_Beam_Spring_2=new StringBuffer("ELEMENTS OF TYPE Beam_Spring_2\n");
435 StringBuffer st_elements_Contact_Line=new StringBuffer("ELEMENTS OF TYPE Contact_Line\n");
436 StringBuffer st_elements_Contact_Triangle=new StringBuffer("ELEMENTS OF TYPE Contact_Triangle\n");
437 StringBuffer st_elements_Shell_C0_3=new StringBuffer("ELEMENTS OF TYPE Shell_C0_3\n");
438 StringBuffer st_elements_Shell_BT_4=new StringBuffer("ELEMENTS OF TYPE Shell_BT_4\n");
439 StringBuffer st_elements_Solid_Iso_4=new StringBuffer("ELEMENTS OF TYPE Solid_Iso_4\n");
440 StringBuffer st_elements_Solid_Iso_6=new StringBuffer("ELEMENTS OF TYPE Solid_Iso_6\n");
441 for(int i=0; i<infile.elementsDB.size(); i++){
442 _Object obj = (_Object)infile.elementsDB.elementAt(i);
443 String st = obj.get_Id();
444 if(obj instanceof _Element2 && ((_Element2)obj).msh_type==Canvas3D.MESH_Beam_2){
445 _Element2 el = (_Element2)obj;
446 st+=" \tnodes = ["+el.node1.get_Id()+","+el.node2.get_Id()+"] \tD = "+el.diameter+"\tMaterial = "+el.material.name+"\n";
447 st_elements_Beam_2.append(st);
448 }else if(obj instanceof _Element2 && ((_Element2)obj).msh_type==Canvas3D.MESH_Contact_Line){
449 _Element2 el = (_Element2)obj;
450 st+=" \tnodes = ["+el.node1.get_Id()+","+el.node2.get_Id()+"] \tD = "+el.diameter;
451 if(el.factor!=null) st+=" \tFactor = "+el.factor;
452 if(el.friction!=null) st+=" \tFriction = "+el.friction;
453 if(el.contact.compareToIgnoreCase("OFF")==0) st+=" \tContact = OFF";
454 st_elements_Contact_Line.append(st+"\n");
455 }else if(obj instanceof _Element2 && ((_Element2)obj).msh_type==Canvas3D.MESH_Rod_2){
456 _Element2 el = (_Element2)obj;
457 st+=" \tnodes = ["+el.node1.get_Id()+","+el.node2.get_Id()+"] \tD = "+el.diameter+"\tMaterial = "+el.material.name;
458 if(el.factor!=null) st+=" \tFactor = "+el.factor;
459 if(el.friction!=null) st+=" \tFriction = "+el.friction;
460 if(el.contact!=null && el.contact.compareToIgnoreCase("OFF")==0) st+=" \tContact = OFF";
461 st_elements_Rod_2.append(st+"\n");
462 }else if(obj instanceof _Element3 && ((_Element3)obj).msh_type==Canvas3D.MESH_Contact_Triangle){
463 _Element3 el = (_Element3)obj;
464 st+=" \tnodes = ["+el.node1.get_Id()+","+el.node2.get_Id()+","+el.node3.get_Id()+"] \tT = "+el.thickness;
465 if(el.factor!=null) st+=" \tFactor = "+el.factor;
466 if(el.friction!=null) st+=" \tFriction = "+el.friction;
467 st_elements_Contact_Triangle.append(st+"\n");
468 }else if(obj instanceof _Element3 && ((_Element3)obj).msh_type==Canvas3D.MESH_Shell_C0_3){
469 _Element3 el = (_Element3)obj;
470 st+=" \tnodes = ["+el.node1.get_Id()+","+el.node2.get_Id()+","+el.node3.get_Id()+"] \tT = "+el.thickness+" \tMaterial = "+el.material.name;
471 if(el.NIP!=null) st+=" \tNIP = "+el.NIP;
472 if(el.PIP!=null) st+=" \tPIP = "+el.PIP;
473 if(el.load!=null) st+=" \tLoad = "+el.load.name;
474 if(el.factor!=null) st+=" \tFactor = "+el.factor;
475 if(el.contact!=null && el.contact.length()!=0) st+=" \tContact = "+el.contact;
476 if(el.friction!=null) st+=" \tFriction = "+el.friction;
477 if(el.thinning!=null && el.thinning.compareToIgnoreCase("OFF")==0) st+=" \tThinning = OFF";
478 st_elements_Shell_C0_3.append(st+"\n");
479 }else if(obj instanceof _Element4 && ((_Element4)obj).msh_type==Canvas3D.MESH_Shell_BT_4){
480 _Element4 el = (_Element4)obj;
481 st+=" \tnodes = ["+el.node1.get_Id()+","+el.node2.get_Id()+","+el.node3.get_Id()+","+el.node4.get_Id()+"] \tT = "+el.thickness+" \tMaterial = "+el.material.name;
482 if(el.NIP!=null) st+=" \tNIP = "+el.NIP;
483 if(el.PIP!=null) st+=" \tPIP = "+el.PIP;
484 if(el.load!=null) st+=" \tLoad = "+el.load.name;
485 if(el.factor!=null) st+=" \tFactor = "+el.factor;
486 if(el.contact!=null && el.contact.length()!=0) st+=" \tContact = "+el.contact;
487 if(el.friction!=null) st+=" \tFriction = "+el.friction;
488 if(el.thinning!=null && el.thinning.compareToIgnoreCase("OFF")==0) st+=" \tThinning = OFF";
489 if(el.shear_factor!=null) st+=" \tSHEAR_FACTOR = "+el.shear_factor;
490 if(el.hourglass!=null && el.hourglass.compareToIgnoreCase("OFF")==0) st+=" \tHOURGLASS = OFF";
491 if(el.MHC!=null) st+=" \tMHC = "+el.MHC;
492 if(el.OOPHC!=null) st+=" \tOOPHC = "+el.OOPHC;
493 if(el.RHC!=null) st+=" \tRHC = "+el.RHC;
494 st_elements_Shell_BT_4.append(st+"\n");
495 }else if(obj instanceof _Element4 && ((_Element4)obj).msh_type==Canvas3D.MESH_Solid_Iso_4){
496 _Element4 el = (_Element4)obj;
497 st+=" \tnodes = ["+el.node1.get_Id()+","+el.node2.get_Id()+","+el.node3.get_Id()+","+el.node4.get_Id()+"] \tMaterial = "+el.material.name;
498 if(el.NIP!=null) st+=" \tNIP = "+el.NIP;
499 st_elements_Solid_Iso_4.append(st+"\n");
500 }else if(obj instanceof _Element8){
501 _Element8 el = (_Element8)obj;
502 st+=" \tnodes = ["+el.node1.get_Id()+","+el.node2.get_Id()+","+el.node3.get_Id()+","+el.node4.get_Id()+","+el.node5.get_Id()+","+el.node6.get_Id()+","+el.node7.get_Id()+","+el.node8.get_Id()+"] \tNIP = 8 \tMaterial = "+el.material.name+"\n";
503 st_elements_Solid_Iso_6.append(st);
504 }
505 }
506 st_elements=(st_elements_Rod_2.length()>35?st_elements_Rod_2.toString()+"\n\n":"")
507 +(st_elements_Beam_2.length()>35?st_elements_Beam_2.toString()+"\n\n":"")
508 +(st_elements_Beam_Spring_2.length()>35?st_elements_Beam_Spring_2.toString()+"\n\n":"")
509 +(st_elements_Contact_Line.length()>35?st_elements_Contact_Line.toString()+"\n\n":"")
510 +(st_elements_Contact_Triangle.length()>35?st_elements_Contact_Triangle.toString()+"\n\n":"")
511 +(st_elements_Shell_C0_3.length()>35?st_elements_Shell_C0_3.toString()+"\n\n":"")
512 +(st_elements_Shell_BT_4.length()>35?st_elements_Shell_BT_4.toString()+"\n\n":"")
513 +(st_elements_Solid_Iso_4.length()>35?st_elements_Solid_Iso_4.toString()+"\n\n":"")
514 +(st_elements_Solid_Iso_6.length()>35?st_elements_Solid_Iso_6.toString():"");
515 out.writeBytes(st_elements);
516 }catch(Exception e){e.printStackTrace();}
517 }
518
519 /**
520 * This method sends an exception to registred listeners.
521 * This is needed since exception migrates normally only to the run() method and not outside.
522 *
523 * @param e The exception to send
524 */
sendException(Exception e)525 private void sendException(Exception e) {
526 if (exception_listeners.size() == 0) {
527 e.printStackTrace();
528 return;
529 }
530
531 Iterator iter = exception_listeners.iterator();
532
533 while (iter.hasNext()) {
534 ExceptionListener l = (ExceptionListener) iter.next();
535 l.exceptionOccurred(e,this);
536 }
537 }
538
539 }
540
541