1 package run; 2 import jp.sync.Barrier; 3 4 import java.util.*; 5 6 public class Worker implements uka.patch.Patchable, uka.transport.Transportable, Runnable { createPatch(Object _copy, uka.patch.PatchOutput po)7 public void createPatch(Object _copy, uka.patch.PatchOutput po) throws java.io.IOException { 8 Worker copy = (Worker)_copy; 9 if (po.writeDiff(this.autostep, copy.autostep)) copy.autostep = this.autostep; 10 if (po.writeDiff(this.keep_running, copy.keep_running)) copy.keep_running = this.keep_running; 11 if (po.writeDiff(this.ttemp, copy.ttemp)) copy.ttemp = this.ttemp; 12 if (po.writeDiff(this.timestep, copy.timestep)) copy.timestep = this.timestep; 13 if (po.writeDiff(this.time, copy.time)) copy.time = this.time; 14 copy.exception_listeners = this.exception_listeners = (java.util.Set)po.writeDiff(this.exception_listeners, copy.exception_listeners); 15 copy.barrier = this.barrier = (jp.sync.Barrier)po.writeDiff(this.barrier, copy.barrier); 16 copy.nodelist = this.nodelist = (java.util.Vector)po.writeDiff(this.nodelist, copy.nodelist); 17 copy.elementlist = this.elementlist = (java.util.Vector)po.writeDiff(this.elementlist, copy.elementlist); 18 copy.temporary_node = this.temporary_node = (run.Node)po.writeDiff(this.temporary_node, copy.temporary_node); 19 copy.temporary_element = this.temporary_element = (run.Element)po.writeDiff(this.temporary_element, copy.temporary_element); 20 } applyPatch(Object _copy, uka.patch.PatchInput pi)21 public void applyPatch(Object _copy, uka.patch.PatchInput pi) throws java.io.IOException, ClassNotFoundException { 22 Worker copy = (Worker)_copy; 23 if (pi.hasDiff()) copy.autostep = this.autostep = pi.getDiffAsBoolean(); 24 if (pi.hasDiff()) copy.keep_running = this.keep_running = pi.getDiffAsBoolean(); 25 if (pi.hasDiff()) copy.ttemp = this.ttemp = pi.getDiffAsDouble(); 26 if (pi.hasDiff()) copy.timestep = this.timestep = pi.getDiffAsDouble(); 27 if (pi.hasDiff()) copy.time = this.time = pi.getDiffAsDouble(); 28 if (pi.hasDiff()) copy.exception_listeners = this.exception_listeners = (java.util.Set)pi.getDiffAsObject(); 29 if (pi.hasDiff()) copy.barrier = this.barrier = (jp.sync.Barrier)pi.getDiffAsObject(); 30 if (pi.hasDiff()) copy.nodelist = this.nodelist = (java.util.Vector)pi.getDiffAsObject(); 31 if (pi.hasDiff()) copy.elementlist = this.elementlist = (java.util.Vector)pi.getDiffAsObject(); 32 if (pi.hasDiff()) copy.temporary_node = this.temporary_node = (run.Node)pi.getDiffAsObject(); 33 if (pi.hasDiff()) copy.temporary_element = this.temporary_element = (run.Element)pi.getDiffAsObject(); 34 } descendReferences(uka.patch.ReferenceConsumer c)35 public void descendReferences(uka.patch.ReferenceConsumer c) throws java.io.IOException { 36 c.descend(this.exception_listeners); 37 c.descend(this.barrier); 38 c.descend(this.nodelist); 39 c.descend(this.elementlist); 40 c.descend(this.temporary_node); 41 c.descend(this.temporary_element); 42 } filterReferences(uka.patch.ReferenceFilter f)43 public void filterReferences(uka.patch.ReferenceFilter f) { 44 this.exception_listeners = (java.util.Set)f.filter(this.exception_listeners); 45 this.barrier = (jp.sync.Barrier)f.filter(this.barrier); 46 this.nodelist = (java.util.Vector)f.filter(this.nodelist); 47 this.elementlist = (java.util.Vector)f.filter(this.elementlist); 48 this.temporary_node = (run.Node)f.filter(this.temporary_node); 49 this.temporary_element = (run.Element)f.filter(this.temporary_element); 50 } flatClone()51 public Object flatClone() { 52 try { 53 return super.clone(); 54 } catch (CloneNotSupportedException ex) { 55 throw new AssertionError("Declared Cloneable but clone() is still unsupported"); 56 } 57 } 58 public static final uka.transport.TransportDescriptor TRANSPORT_DESCRIPTOR = new uka.transport.TransportDescriptor(){ 59 public Object unmarshalReference(uka.transport.UnmarshalStream s, int id) throws java.io.IOException, ClassNotFoundException { 60 return new Worker(s, id); 61 } 62 public boolean unmarshal(Object obj, uka.transport.UnmarshalStream s) throws ClassNotFoundException, java.io.IOException { 63 ((Worker)obj).unmarshal(s); 64 return false; 65 } 66 public void marshalReference(Object obj, uka.transport.MarshalStream s) throws java.io.IOException { 67 ((Worker)obj).marshalReference(s); 68 } 69 public void marshal(Object obj, uka.transport.MarshalStream s) throws java.io.IOException { 70 ((Worker)obj).marshal(s); 71 } 72 public Object deepClone(Object orig, int id, uka.transport.DeepClone _helper) throws CloneNotSupportedException { 73 try { 74 return new Worker((Worker)orig, id, _helper); 75 } catch (java.io.IOException ex) { 76 throw (CloneNotSupportedException)new CloneNotSupportedException().initCause(ex); 77 } 78 } 79 public boolean deepCloneReferences(Object orig, Object copy, uka.transport.DeepClone _helper) throws CloneNotSupportedException { 80 ((Worker)copy).deepCloneReferences((Worker)orig, _helper); 81 return false; 82 } 83 public Class getType() { 84 return Worker.class; 85 } 86 }; getTransportDescriptor()87 public uka.transport.TransportDescriptor getTransportDescriptor() { 88 return TRANSPORT_DESCRIPTOR; 89 } 90 private static final int _SIZE = uka.transport.BasicIO.SIZEOF_boolean + uka.transport.BasicIO.SIZEOF_boolean + uka.transport.BasicIO.SIZEOF_double + uka.transport.BasicIO.SIZEOF_double + uka.transport.BasicIO.SIZEOF_double; Worker(uka.transport.UnmarshalStream _stream, int _id)91 public Worker(uka.transport.UnmarshalStream _stream, int _id) throws java.io.IOException, ClassNotFoundException { 92 _stream.register(this, _id); 93 } unmarshal(uka.transport.UnmarshalStream _stream)94 public void unmarshal(uka.transport.UnmarshalStream _stream) throws java.io.IOException, ClassNotFoundException { 95 _stream.request(Worker._SIZE); 96 byte[] _buffer = _stream.getBuffer(); 97 int _pos = _stream.getPosition(); 98 this.autostep = uka.transport.BasicIO.extractBoolean(_buffer, _pos); 99 _pos += uka.transport.BasicIO.SIZEOF_boolean; 100 this.keep_running = uka.transport.BasicIO.extractBoolean(_buffer, _pos); 101 _pos += uka.transport.BasicIO.SIZEOF_boolean; 102 this.ttemp = uka.transport.BasicIO.extractDouble(_buffer, _pos); 103 _pos += uka.transport.BasicIO.SIZEOF_double; 104 this.timestep = uka.transport.BasicIO.extractDouble(_buffer, _pos); 105 _pos += uka.transport.BasicIO.SIZEOF_double; 106 this.time = uka.transport.BasicIO.extractDouble(_buffer, _pos); 107 _pos += uka.transport.BasicIO.SIZEOF_double; 108 _stream.accept(Worker._SIZE); 109 this.exception_listeners = (java.util.Set)_stream.readReference(); 110 this.barrier = (jp.sync.Barrier)_stream.readReference(); 111 this.nodelist = (java.util.Vector)_stream.readReference(); 112 this.elementlist = (java.util.Vector)_stream.readReference(); 113 this.temporary_node = (run.Node)_stream.readReference(); 114 this.temporary_element = (run.Element)_stream.readReference(); 115 } marshalReference(uka.transport.MarshalStream _stream)116 public void marshalReference(uka.transport.MarshalStream _stream) throws java.io.IOException { 117 } marshal(uka.transport.MarshalStream _stream)118 public void marshal(uka.transport.MarshalStream _stream) throws java.io.IOException { 119 _stream.reserve(Worker._SIZE); 120 byte[] _buffer = _stream.getBuffer(); 121 int _pos = _stream.getPosition(); 122 _pos = uka.transport.BasicIO.insert(_buffer, _pos, this.autostep); 123 _pos = uka.transport.BasicIO.insert(_buffer, _pos, this.keep_running); 124 _pos = uka.transport.BasicIO.insert(_buffer, _pos, this.ttemp); 125 _pos = uka.transport.BasicIO.insert(_buffer, _pos, this.timestep); 126 _pos = uka.transport.BasicIO.insert(_buffer, _pos, this.time); 127 _stream.deliver(_SIZE); 128 _stream.writeReference(this.exception_listeners); 129 _stream.writeReference(this.barrier); 130 _stream.writeReference(this.nodelist); 131 _stream.writeReference(this.elementlist); 132 _stream.writeReference(this.temporary_node); 133 _stream.writeReference(this.temporary_element); 134 } Worker(Worker _orig, int _id, uka.transport.DeepClone _helper)135 public Worker(Worker _orig, int _id, uka.transport.DeepClone _helper) throws CloneNotSupportedException, java.io.IOException { 136 _helper.add(_id, this); 137 this.autostep = _orig.autostep; 138 this.keep_running = _orig.keep_running; 139 this.ttemp = _orig.ttemp; 140 this.timestep = _orig.timestep; 141 this.time = _orig.time; 142 } deepCloneReferences(Worker _orig, uka.transport.DeepClone _helper)143 public void deepCloneReferences(Worker _orig, uka.transport.DeepClone _helper) throws CloneNotSupportedException { 144 this.exception_listeners = (java.util.Set)_helper.internalDeepClone(_orig.exception_listeners); 145 this.barrier = (jp.sync.Barrier)_helper.internalDeepClone(_orig.barrier); 146 this.nodelist = (java.util.Vector)_helper.internalDeepClone(_orig.nodelist); 147 this.elementlist = (java.util.Vector)_helper.internalDeepClone(_orig.elementlist); 148 this.temporary_node = (run.Node)_helper.internalDeepClone(_orig.temporary_node); 149 this.temporary_element = (run.Element)_helper.internalDeepClone(_orig.temporary_element); 150 } 151 private Element temporary_element; 152 private Node temporary_node; 153 private Vector elementlist; 154 private Vector nodelist; 155 private Barrier barrier; 156 private double time; 157 private double timestep; 158 private double ttemp; 159 private boolean keep_running; 160 private boolean autostep; 161 private Set exception_listeners; Worker(Barrier barrier, double time, double timestep, boolean autostep)162 public Worker(Barrier barrier, double time, double timestep, boolean autostep) { 163 super(); 164 this.barrier = barrier; 165 this.time = time; 166 this.timestep = timestep; 167 this.autostep = autostep; 168 this.elementlist = new Vector(); 169 this.nodelist = new Vector(); 170 this.exception_listeners = Collections.synchronizedSet(new HashSet()); 171 } addElement(Element el)172 public void addElement(Element el) { 173 this.elementlist.addElement(el); 174 } removeElement(Element el)175 public void removeElement(Element el) { 176 this.elementlist.removeElement(el); 177 } addNode(Node node)178 public void addNode(Node node) { 179 this.nodelist.addElement(node); 180 } removeNode(Node node)181 public void removeNode(Node node) { 182 this.nodelist.removeElement(node); 183 } run()184 public void run() { 185 int i; 186 int j; 187 int number_of_integration_points; 188 int number_of_nodes = this.nodelist.size(); 189 try { 190 while (true) { 191 this.barrier.sync(); 192 if (this.autostep == true) { 193 this.ttemp = 1.0E10; 194 } 195 for (i = 0; i < this.elementlist.size(); i++) { 196 this.temporary_element = (Element)this.elementlist.elementAt(i); 197 if (!this.temporary_element.isDeActivated()) { 198 this.temporary_element.updateLocalCoordinateSystem(); 199 number_of_integration_points = this.temporary_element.getNumberOfIntegrationPoints(); 200 for (j = 0; j < number_of_integration_points; j++) { 201 this.temporary_element.calculateStrain(this.timestep, j); 202 this.temporary_element.calculateStress(j, this.timestep); 203 } 204 for (j = 0; j < number_of_integration_points; j++) { 205 this.temporary_element.calculateNodalForces(j, this.timestep); 206 } 207 this.temporary_element.calculateExternalForces(this.time); 208 this.temporary_element.calculateContactForces(); 209 if (this.autostep == true) { 210 this.ttemp = this.temporary_element.checkTimestep(this.ttemp); 211 } 212 } 213 } 214 this.barrier.sync(); 215 this.barrier.sync(); 216 for (i = 0; i < this.nodelist.size(); i++) { 217 this.temporary_node = (Node)this.nodelist.elementAt(i); 218 if (!this.temporary_node.isDeActivated()) { 219 this.temporary_node.clearNodalForces(); 220 } 221 } 222 this.barrier.sync(); 223 } 224 } catch (InterruptedException e) { 225 try { 226 this.barrier.sync(); 227 } catch (Exception eb) { 228 } 229 System.err.println("\nWorker Interrupted: Time: " + this.time + " Time step: " + this.timestep); 230 sendException(e); 231 return; 232 } catch (Exception e) { 233 try { 234 this.barrier.sync(); 235 } catch (Exception eb) { 236 } 237 System.err.println("\nWorker Exception: Time: " + this.time + " Time step: " + this.timestep); 238 sendException(e); 239 return; 240 } 241 } getTime()242 public double getTime() { 243 return this.time; 244 } setTime(double time)245 public void setTime(double time) { 246 this.time = time; 247 } getTimestep()248 public double getTimestep() { 249 return this.timestep; 250 } setTimestep(double timestep)251 public void setTimestep(double timestep) { 252 this.timestep = timestep; 253 } getTtemp()254 public double getTtemp() { 255 return this.ttemp; 256 } isAutostep()257 public boolean isAutostep() { 258 return this.autostep; 259 } setAutostep(boolean autostep)260 public void setAutostep(boolean autostep) { 261 this.autostep = autostep; 262 } sendException(Exception e)263 private void sendException(Exception e) { 264 if (this.exception_listeners.size() == 0) { 265 e.printStackTrace(); 266 return; 267 } 268 Iterator iter = this.exception_listeners.iterator(); 269 while (iter.hasNext()) { 270 ExceptionListener l = (ExceptionListener)iter.next(); 271 l.exceptionOccurred(e, this); 272 } 273 } addExceptionListener(ExceptionListener l)274 void addExceptionListener(ExceptionListener l) { 275 this.exception_listeners.add(l); 276 } 277 } 278