1 package devisor2.foundation.base; 2 3 import devisor2.foundation.elements.*; 4 import devisor2.foundation.boundary.*; 5 import devisor2.foundation.boundary.*; 6 7 import java.io.*; 8 import java.util.*; 9 10 11 12 /** 13 * This class is an extended version of the original BasicDomain class 14 * which additionally provides support for giving statistics about 15 * the domain. For convenience, the all-important methods returns 16 * a completely formatted String which just has to be passed to 17 * the displaying GUI dialog. <br> 18 * See the MainActionListener for a description of how this class 19 * is used in contrast to the original Domain class. 20 * 21 * @version 0.9 (all but BoundaryNodes supported) 22 * @author Christian Becker, Dominik Goeddeke 23 */ 24 public abstract class DomainStatistics extends BasicDomain 25 { 26 27 28 /** 29 * the all-important method :-) 30 */ getStatistics()31 public String getStatistics () 32 { 33 StringBuffer ges = new StringBuffer(); 34 35 StringBuffer sb = new StringBuffer(); 36 37 Enumeration enum = db.getBoundaries().elements (); 38 while (enum.hasMoreElements()) 39 { 40 Boundary b = (Boundary)enum.nextElement (); 41 sb.append(" #Segments on Boundary "+(b.getNumber())+": "+ b.getSegmentCount()+"\n"); 42 } 43 44 double ar = 0.0; 45 double lar = 0.0; 46 47 double hmin = 10000000000000.0; 48 double hmax = 0.0; 49 50 double gar = 0.0; 51 double ghmin = 10000000000000.0; 52 double ghmax = 0.0; 53 54 enum = cells.elements (); 55 while (enum.hasMoreElements ()) 56 { 57 Node[] nodez = ((Cell2D)enum.nextElement()).getNodes(); 58 59 double[] ee = new double[4]; 60 61 for (int e=0;e<=3;e++) 62 ee[e] = Math.sqrt((nodez[e].getCoord(0)-nodez[(e+1)%4].getCoord(0))* 63 (nodez[e].getCoord(0)-nodez[(e+1)%4].getCoord(0)) + 64 (nodez[e].getCoord(1)-nodez[(e+1)%4].getCoord(1))* 65 (nodez[e].getCoord(1)-nodez[(e+1)%4].getCoord(1))); 66 67 hmin = 10000000000000.0; 68 hmax = 0.0; 69 ar = 0.0; 70 71 for (int e=0;e<=3;e++) 72 { 73 if (ee[e]<hmin) hmin=ee[e]; 74 if (ee[e]>hmax) hmax=ee[e]; 75 76 if (ee[e]>ee[(e+1)%4]) 77 lar=ee[e]/ee[(e+1)%4]; 78 else 79 lar=ee[(e+1)%4]/ee[e]; 80 81 if (lar>ar) ar=lar; 82 83 } 84 85 if (hmin<ghmin) ghmin=hmin; 86 if (hmax>ghmax) ghmax=hmax; 87 if (ar>gar) gar=ar; 88 89 } 90 91 ges.append ("Statistics for the current domain\n" + "+++++++++++++++++++++++++++++++++\n \n"); 92 ges.append ("General information:\n"); 93 ges.append ("hmin = " + ghmin + "\n"); 94 ges.append ("hmax = "+ghmax+"\n"); 95 ges.append ("AR = " + gar + "\n"); 96 ges.append ("\n"); 97 ges.append ("File and Format: \n"); 98 ges.append ("Filename: " + domainfilename + "\n"); 99 ges.append ("Fileformat: " + domainfileformat + "\n"); 100 ges.append ("\n"); 101 ges.append ("Object statistics\n"); 102 ges.append ("#Cells :" + getCellCount() + "\n"); 103 ges.append ("#Nodes(All): " + getNodeCount() + "\n"); 104 ges.append ("#Nodes(Bound.) :"+getBoundaryNodeCount()+"\n"); 105 ges.append ("#Nodes(Inner) :"+ (getNodeCount() - getBoundaryNodeCount())+"\n"); 106 ges.append ("#Edges :"+getEdgeCount()+"\n"); 107 ges.append ("#Boundaries :"+db.getBoundaryCount()+"\n"); 108 ges.append (sb.toString()+"\n"); 109 ges.append ("===========================================\n"); 110 111 return ges.toString (); 112 } 113 114 115 /** 116 * prints out the whole domain without boundary 117 */ printDomain()118 public void printDomain () 119 { 120 printNodeVector (); 121 printEdgeVector (); 122 printCellVector (); 123 db.printDomainBoundary (); 124 } 125 printNodeVector()126 public void printNodeVector () 127 { 128 System.out.println ("current Node vector..."); 129 if (nodes == null) 130 { 131 System.out.println (" Domain Node Vector is null"); 132 } 133 else 134 { 135 Enumeration enum = nodes.elements (); 136 while (enum.hasMoreElements ()) 137 { 138 Node n = (Node) enum.nextElement (); 139 System.out.print ("Index: " + nodes.indexOf (n)); 140 System.out.print (", Number: " + n.getNumber ()); 141 //System.out.print (" (x,y)=("+n.getCoord(0)+","+n.getCoord(1)+")"); 142 if (n.getFathers() == null) 143 { 144 System.out.println (" No parents"); 145 } 146 else 147 { 148 System.out.print (" Parents:"); 149 Enumeration edges = n.getFathers().elements (); 150 if (!edges.hasMoreElements()) 151 { 152 System.out.print ("none"); 153 } 154 while (edges.hasMoreElements()) 155 { 156 Edge e = (Edge)edges.nextElement (); 157 System.out.print (" "+e.getNumber ()); 158 } 159 } 160 if (n instanceof BoundaryNode) 161 { 162 BoundaryNode b = (BoundaryNode)n; 163 System.out.print ("; on "+b.getBoundary().getNumber()+" @segment "+b.getSegment()+" w/ par "+b.getParaValue()); 164 } 165 System.out.println (); 166 } 167 } 168 } 169 printEdgeVector()170 public void printEdgeVector () 171 { 172 System.out.println ("current Edge vector"); 173 if (edges == null) 174 { 175 System.out.println ("Domain Edge Vector is null"); 176 } 177 else 178 { 179 Enumeration enum = edges.elements (); 180 while (enum.hasMoreElements ()) 181 { 182 Edge e = (Edge) enum.nextElement (); 183 System.out.print ("Index: " + edges.indexOf (e)); 184 System.out.print (", Number: " + e.getNumber ()); 185 System.out.print (", n0 = "+e.getNode(0).getNumber()); 186 System.out.print (", n1 = "+e.getNode(1).getNumber()); 187 if (e.getFathers() == null) 188 { 189 System.out.println (", no parents"); 190 } 191 else 192 { 193 System.out.print (", Parents:"); 194 Enumeration cells = e.getFathers().elements (); 195 while (cells.hasMoreElements()) 196 { 197 Cell c = (Cell)cells.nextElement (); 198 System.out.print (" "+c.getNumber ()); 199 } 200 System.out.println (); 201 } 202 } 203 } 204 } 205 206 printCellVector()207 public void printCellVector () 208 { 209 System.out.println ("current Cell vector"); 210 if (cells == null) 211 { 212 System.out.println (" Domain Cell Vector is null"); 213 } 214 else 215 { 216 Enumeration enum = cells.elements (); 217 while (enum.hasMoreElements ()) 218 { 219 Cell c = (Cell) enum.nextElement (); 220 System.out.print ("Index: " + cells.indexOf (c)); 221 System.out.print (", Number: " + c.getNumber ()); 222 if (c.getParent() == null) 223 System.out.print (", no parent "); 224 else 225 System.out.print (", Parent " + c.getParent().getNumber ()); 226 if (c instanceof Tri) 227 System.out.println (", Type: Tri"); 228 if (c instanceof Quad) 229 System.out.println (", Type: Quad"); 230 if (c instanceof Macro) 231 System.out.println (", Type: Macro"); 232 //print neighbour cells by number 233 if (c.getNeighbours() == null) 234 { 235 System.out.println ("No neighbours"); 236 } 237 else 238 { 239 System.out.print ("Neighbours: "); 240 for (int i=0; i<c.getNeighbours().length-1;i++) 241 { 242 System.out.print (c.getNeighbours()[i].getNumber ()); 243 } 244 System.out.println (c.getNeighbours()[c.getNeighbours().length-1].getNumber ()); 245 } 246 // print children cells by number 247 if (c.getChildren() == null) 248 { 249 System.out.println ("No children"); 250 } 251 else 252 { 253 System.out.print ("children: "); 254 for (int i=0; i<c.getChildren().length-1;i++) 255 { 256 System.out.print (c.getChildren()[i].getNumber ()); 257 } 258 System.out.println (c.getChildren()[c.getChildren().length-1].getNumber ()); 259 } 260 // print nodes by number 261 if (c.getNodes() == null) 262 { 263 System.out.println ("No nodes"); 264 } 265 else 266 { 267 System.out.print ("nodes: "); 268 for (int i=0; i<c.getNodes().length-1;i++) 269 { 270 System.out.print (c.getNodes()[i].getNumber () + " "); 271 } 272 System.out.println (c.getNodes()[c.getNodes().length-1].getNumber ()); 273 } 274 } 275 } 276 } 277 278 279 } 280