package run;
import java.util.*;

import java.io.*;

import run.readers.FembicReader;

import uka.karmi.rmi.RemoteException;

import jp.sync.*;

import jp.lang.*;

public class Smack implements uka.patch.Patchable, uka.transport.Transportable {
   public void createPatch(Object _copy, uka.patch.PatchOutput po) throws java.io.IOException {
      Smack copy = (Smack)_copy;
      if (po.writeDiff(this.nr_of_CPUs, copy.nr_of_CPUs)) copy.nr_of_CPUs = this.nr_of_CPUs;
      if (po.writeDiff(this.autostep, copy.autostep)) copy.autostep = this.autostep;
      if (po.writeDiff(this.failure_is_set, copy.failure_is_set)) copy.failure_is_set = this.failure_is_set;
      if (po.writeDiff(this.timestep, copy.timestep)) copy.timestep = this.timestep;
      if (po.writeDiff(this.number_of_loads, copy.number_of_loads)) copy.number_of_loads = this.number_of_loads;
      if (po.writeDiff(this.number_of_constraints, copy.number_of_constraints)) copy.number_of_constraints = this.number_of_constraints;
      if (po.writeDiff(this.state, copy.state)) copy.state = this.state;
      if (po.writeDiff(this.i, copy.i)) copy.i = this.i;
      if (po.writeDiff(this.ttemp, copy.ttemp)) copy.ttemp = this.ttemp;
      if (po.writeDiff(this.time, copy.time)) copy.time = this.time;
      if (po.writeDiff(this.number_of_controls, copy.number_of_controls)) copy.number_of_controls = this.number_of_controls;
      if (po.writeDiff(this.number_of_materials, copy.number_of_materials)) copy.number_of_materials = this.number_of_materials;
      if (po.writeDiff(this.number_of_nodes, copy.number_of_nodes)) copy.number_of_nodes = this.number_of_nodes;
      if (po.writeDiff(this.number_of_trackers, copy.number_of_trackers)) copy.number_of_trackers = this.number_of_trackers;
      if (po.writeDiff(this.number_of_elements, copy.number_of_elements)) copy.number_of_elements = this.number_of_elements;
      copy.filename = this.filename = (java.lang.String)po.writeDiff(this.filename, copy.filename);
      copy.trackwriter = this.trackwriter = (run.TrackWriter)po.writeDiff(this.trackwriter, copy.trackwriter);
      copy.resultwriter = this.resultwriter = (run.Writer)po.writeDiff(this.resultwriter, copy.resultwriter);
      copy.temporary_node = this.temporary_node = (run.Node)po.writeDiff(this.temporary_node, copy.temporary_node);
      copy.temporary_constraint = this.temporary_constraint = (run.Constraint)po.writeDiff(this.temporary_constraint, copy.temporary_constraint);
      copy.temporary_tracker = this.temporary_tracker = (run.Tracker)po.writeDiff(this.temporary_tracker, copy.temporary_tracker);
      copy.temporary_element = this.temporary_element = (run.Element)po.writeDiff(this.temporary_element, copy.temporary_element);
      copy.controlset = this.controlset = (run.Controlset)po.writeDiff(this.controlset, copy.controlset);
      copy.loadlist = this.loadlist = (run.RplVector)po.writeDiff(this.loadlist, copy.loadlist);
      copy.constraintlist = this.constraintlist = (run.RplVector)po.writeDiff(this.constraintlist, copy.constraintlist);
      copy.materiallist = this.materiallist = (run.RplVector)po.writeDiff(this.materiallist, copy.materiallist);
      copy.trackerlist = this.trackerlist = (run.RplVector)po.writeDiff(this.trackerlist, copy.trackerlist);
      copy.elementlist = this.elementlist = (run.RplVector)po.writeDiff(this.elementlist, copy.elementlist);
      copy.nodelist = this.nodelist = (run.RplVector)po.writeDiff(this.nodelist, copy.nodelist);
   }
   public void applyPatch(Object _copy, uka.patch.PatchInput pi) throws java.io.IOException, ClassNotFoundException {
      Smack copy = (Smack)_copy;
      if (pi.hasDiff()) copy.nr_of_CPUs = this.nr_of_CPUs = pi.getDiffAsInt();
      if (pi.hasDiff()) copy.autostep = this.autostep = pi.getDiffAsBoolean();
      if (pi.hasDiff()) copy.failure_is_set = this.failure_is_set = pi.getDiffAsBoolean();
      if (pi.hasDiff()) copy.timestep = this.timestep = pi.getDiffAsDouble();
      if (pi.hasDiff()) copy.number_of_loads = this.number_of_loads = pi.getDiffAsInt();
      if (pi.hasDiff()) copy.number_of_constraints = this.number_of_constraints = pi.getDiffAsInt();
      if (pi.hasDiff()) copy.state = this.state = pi.getDiffAsInt();
      if (pi.hasDiff()) copy.i = this.i = pi.getDiffAsInt();
      if (pi.hasDiff()) copy.ttemp = this.ttemp = pi.getDiffAsDouble();
      if (pi.hasDiff()) copy.time = this.time = pi.getDiffAsDouble();
      if (pi.hasDiff()) copy.number_of_controls = this.number_of_controls = pi.getDiffAsInt();
      if (pi.hasDiff()) copy.number_of_materials = this.number_of_materials = pi.getDiffAsInt();
      if (pi.hasDiff()) copy.number_of_nodes = this.number_of_nodes = pi.getDiffAsInt();
      if (pi.hasDiff()) copy.number_of_trackers = this.number_of_trackers = pi.getDiffAsInt();
      if (pi.hasDiff()) copy.number_of_elements = this.number_of_elements = pi.getDiffAsInt();
      if (pi.hasDiff()) copy.filename = this.filename = (java.lang.String)pi.getDiffAsObject();
      if (pi.hasDiff()) copy.trackwriter = this.trackwriter = (run.TrackWriter)pi.getDiffAsObject();
      if (pi.hasDiff()) copy.resultwriter = this.resultwriter = (run.Writer)pi.getDiffAsObject();
      if (pi.hasDiff()) copy.temporary_node = this.temporary_node = (run.Node)pi.getDiffAsObject();
      if (pi.hasDiff()) copy.temporary_constraint = this.temporary_constraint = (run.Constraint)pi.getDiffAsObject();
      if (pi.hasDiff()) copy.temporary_tracker = this.temporary_tracker = (run.Tracker)pi.getDiffAsObject();
      if (pi.hasDiff()) copy.temporary_element = this.temporary_element = (run.Element)pi.getDiffAsObject();
      if (pi.hasDiff()) copy.controlset = this.controlset = (run.Controlset)pi.getDiffAsObject();
      if (pi.hasDiff()) copy.loadlist = this.loadlist = (run.RplVector)pi.getDiffAsObject();
      if (pi.hasDiff()) copy.constraintlist = this.constraintlist = (run.RplVector)pi.getDiffAsObject();
      if (pi.hasDiff()) copy.materiallist = this.materiallist = (run.RplVector)pi.getDiffAsObject();
      if (pi.hasDiff()) copy.trackerlist = this.trackerlist = (run.RplVector)pi.getDiffAsObject();
      if (pi.hasDiff()) copy.elementlist = this.elementlist = (run.RplVector)pi.getDiffAsObject();
      if (pi.hasDiff()) copy.nodelist = this.nodelist = (run.RplVector)pi.getDiffAsObject();
   }
   public void descendReferences(uka.patch.ReferenceConsumer c) throws java.io.IOException {
      c.descend(this.filename);
      c.descend(this.trackwriter);
      c.descend(this.resultwriter);
      c.descend(this.temporary_node);
      c.descend(this.temporary_constraint);
      c.descend(this.temporary_tracker);
      c.descend(this.temporary_element);
      c.descend(this.controlset);
      c.descend(this.loadlist);
      c.descend(this.constraintlist);
      c.descend(this.materiallist);
      c.descend(this.trackerlist);
      c.descend(this.elementlist);
      c.descend(this.nodelist);
   }
   public void filterReferences(uka.patch.ReferenceFilter f) {
      this.filename = (java.lang.String)f.filter(this.filename);
      this.trackwriter = (run.TrackWriter)f.filter(this.trackwriter);
      this.resultwriter = (run.Writer)f.filter(this.resultwriter);
      this.temporary_node = (run.Node)f.filter(this.temporary_node);
      this.temporary_constraint = (run.Constraint)f.filter(this.temporary_constraint);
      this.temporary_tracker = (run.Tracker)f.filter(this.temporary_tracker);
      this.temporary_element = (run.Element)f.filter(this.temporary_element);
      this.controlset = (run.Controlset)f.filter(this.controlset);
      this.loadlist = (run.RplVector)f.filter(this.loadlist);
      this.constraintlist = (run.RplVector)f.filter(this.constraintlist);
      this.materiallist = (run.RplVector)f.filter(this.materiallist);
      this.trackerlist = (run.RplVector)f.filter(this.trackerlist);
      this.elementlist = (run.RplVector)f.filter(this.elementlist);
      this.nodelist = (run.RplVector)f.filter(this.nodelist);
   }
   public Object clone() {
      try {
         return super.clone();
      }  catch (CloneNotSupportedException ex) {
         throw new AssertionError("Declared Cloneable but clone() is still unsupported");
      }
   }
   public static final uka.transport.TransportDescriptor TRANSPORT_DESCRIPTOR = new uka.transport.TransportDescriptor(){
      public Object unmarshalReference(uka.transport.UnmarshalStream s, int id) throws java.io.IOException, ClassNotFoundException {
         return new Smack(s, id);
      }
      public boolean unmarshal(Object obj, uka.transport.UnmarshalStream s) throws ClassNotFoundException, java.io.IOException {
         ((Smack)obj).unmarshal(s);
         return false;
      }
      public void marshalReference(Object obj, uka.transport.MarshalStream s) throws java.io.IOException {
         ((Smack)obj).marshalReference(s);
      }
      public void marshal(Object obj, uka.transport.MarshalStream s) throws java.io.IOException {
         ((Smack)obj).marshal(s);
      }
      public Object deepClone(Object orig, int id, uka.transport.DeepClone _helper) throws CloneNotSupportedException {
         try {
            return new Smack((Smack)orig, id, _helper);
         }  catch (java.io.IOException ex) {
            throw (CloneNotSupportedException)new CloneNotSupportedException().initCause(ex);
         }
      }
      public boolean deepCloneReferences(Object orig, Object copy, uka.transport.DeepClone _helper) throws CloneNotSupportedException {
         ((Smack)copy).deepCloneReferences((Smack)orig, _helper);
         return false;
      }
      public Class getType() {
         return Smack.class;
      }
   };
   public uka.transport.TransportDescriptor getTransportDescriptor() {
      return TRANSPORT_DESCRIPTOR;
   }
   private static final int _SIZE = uka.transport.BasicIO.SIZEOF_int + uka.transport.BasicIO.SIZEOF_boolean + uka.transport.BasicIO.SIZEOF_boolean + uka.transport.BasicIO.SIZEOF_double + uka.transport.BasicIO.SIZEOF_int + uka.transport.BasicIO.SIZEOF_int + uka.transport.BasicIO.SIZEOF_int + uka.transport.BasicIO.SIZEOF_int + uka.transport.BasicIO.SIZEOF_double + uka.transport.BasicIO.SIZEOF_double + uka.transport.BasicIO.SIZEOF_int + uka.transport.BasicIO.SIZEOF_int + uka.transport.BasicIO.SIZEOF_int + uka.transport.BasicIO.SIZEOF_int + uka.transport.BasicIO.SIZEOF_int;
   public Smack(uka.transport.UnmarshalStream _stream, int _id) throws java.io.IOException, ClassNotFoundException {
      _stream.register(this, _id);
   }
   public void unmarshal(uka.transport.UnmarshalStream _stream) throws java.io.IOException, ClassNotFoundException {
      _stream.request(Smack._SIZE);
      byte[] _buffer = _stream.getBuffer();
      int _pos = _stream.getPosition();
      this.nr_of_CPUs = uka.transport.BasicIO.extractInt(_buffer, _pos);
      _pos += uka.transport.BasicIO.SIZEOF_int;
      this.autostep = uka.transport.BasicIO.extractBoolean(_buffer, _pos);
      _pos += uka.transport.BasicIO.SIZEOF_boolean;
      this.failure_is_set = uka.transport.BasicIO.extractBoolean(_buffer, _pos);
      _pos += uka.transport.BasicIO.SIZEOF_boolean;
      this.timestep = uka.transport.BasicIO.extractDouble(_buffer, _pos);
      _pos += uka.transport.BasicIO.SIZEOF_double;
      this.number_of_loads = uka.transport.BasicIO.extractInt(_buffer, _pos);
      _pos += uka.transport.BasicIO.SIZEOF_int;
      this.number_of_constraints = uka.transport.BasicIO.extractInt(_buffer, _pos);
      _pos += uka.transport.BasicIO.SIZEOF_int;
      this.state = uka.transport.BasicIO.extractInt(_buffer, _pos);
      _pos += uka.transport.BasicIO.SIZEOF_int;
      this.i = uka.transport.BasicIO.extractInt(_buffer, _pos);
      _pos += uka.transport.BasicIO.SIZEOF_int;
      this.ttemp = uka.transport.BasicIO.extractDouble(_buffer, _pos);
      _pos += uka.transport.BasicIO.SIZEOF_double;
      this.time = uka.transport.BasicIO.extractDouble(_buffer, _pos);
      _pos += uka.transport.BasicIO.SIZEOF_double;
      this.number_of_controls = uka.transport.BasicIO.extractInt(_buffer, _pos);
      _pos += uka.transport.BasicIO.SIZEOF_int;
      this.number_of_materials = uka.transport.BasicIO.extractInt(_buffer, _pos);
      _pos += uka.transport.BasicIO.SIZEOF_int;
      this.number_of_nodes = uka.transport.BasicIO.extractInt(_buffer, _pos);
      _pos += uka.transport.BasicIO.SIZEOF_int;
      this.number_of_trackers = uka.transport.BasicIO.extractInt(_buffer, _pos);
      _pos += uka.transport.BasicIO.SIZEOF_int;
      this.number_of_elements = uka.transport.BasicIO.extractInt(_buffer, _pos);
      _pos += uka.transport.BasicIO.SIZEOF_int;
      _stream.accept(Smack._SIZE);
      this.filename = (java.lang.String)_stream.readReference();
      this.trackwriter = (run.TrackWriter)_stream.readReference();
      this.resultwriter = (run.Writer)_stream.readReference();
      this.temporary_node = (run.Node)_stream.readReference();
      this.temporary_constraint = (run.Constraint)_stream.readReference();
      this.temporary_tracker = (run.Tracker)_stream.readReference();
      this.temporary_element = (run.Element)_stream.readReference();
      this.controlset = (run.Controlset)_stream.readReference();
      this.loadlist = (run.RplVector)_stream.readReference();
      this.constraintlist = (run.RplVector)_stream.readReference();
      this.materiallist = (run.RplVector)_stream.readReference();
      this.trackerlist = (run.RplVector)_stream.readReference();
      this.elementlist = (run.RplVector)_stream.readReference();
      this.nodelist = (run.RplVector)_stream.readReference();
   }
   public void marshalReference(uka.transport.MarshalStream _stream) throws java.io.IOException {
   }
   public void marshal(uka.transport.MarshalStream _stream) throws java.io.IOException {
      _stream.reserve(Smack._SIZE);
      byte[] _buffer = _stream.getBuffer();
      int _pos = _stream.getPosition();
      _pos = uka.transport.BasicIO.insert(_buffer, _pos, this.nr_of_CPUs);
      _pos = uka.transport.BasicIO.insert(_buffer, _pos, this.autostep);
      _pos = uka.transport.BasicIO.insert(_buffer, _pos, this.failure_is_set);
      _pos = uka.transport.BasicIO.insert(_buffer, _pos, this.timestep);
      _pos = uka.transport.BasicIO.insert(_buffer, _pos, this.number_of_loads);
      _pos = uka.transport.BasicIO.insert(_buffer, _pos, this.number_of_constraints);
      _pos = uka.transport.BasicIO.insert(_buffer, _pos, this.state);
      _pos = uka.transport.BasicIO.insert(_buffer, _pos, this.i);
      _pos = uka.transport.BasicIO.insert(_buffer, _pos, this.ttemp);
      _pos = uka.transport.BasicIO.insert(_buffer, _pos, this.time);
      _pos = uka.transport.BasicIO.insert(_buffer, _pos, this.number_of_controls);
      _pos = uka.transport.BasicIO.insert(_buffer, _pos, this.number_of_materials);
      _pos = uka.transport.BasicIO.insert(_buffer, _pos, this.number_of_nodes);
      _pos = uka.transport.BasicIO.insert(_buffer, _pos, this.number_of_trackers);
      _pos = uka.transport.BasicIO.insert(_buffer, _pos, this.number_of_elements);
      _stream.deliver(_SIZE);
      _stream.writeReference(this.filename);
      _stream.writeReference(this.trackwriter);
      _stream.writeReference(this.resultwriter);
      _stream.writeReference(this.temporary_node);
      _stream.writeReference(this.temporary_constraint);
      _stream.writeReference(this.temporary_tracker);
      _stream.writeReference(this.temporary_element);
      _stream.writeReference(this.controlset);
      _stream.writeReference(this.loadlist);
      _stream.writeReference(this.constraintlist);
      _stream.writeReference(this.materiallist);
      _stream.writeReference(this.trackerlist);
      _stream.writeReference(this.elementlist);
      _stream.writeReference(this.nodelist);
   }
   public Smack(Smack _orig, int _id, uka.transport.DeepClone _helper) throws CloneNotSupportedException, java.io.IOException {
      _helper.add(_id, this);
      this.nr_of_CPUs = _orig.nr_of_CPUs;
      this.autostep = _orig.autostep;
      this.failure_is_set = _orig.failure_is_set;
      this.timestep = _orig.timestep;
      this.number_of_loads = _orig.number_of_loads;
      this.number_of_constraints = _orig.number_of_constraints;
      this.state = _orig.state;
      this.i = _orig.i;
      this.ttemp = _orig.ttemp;
      this.time = _orig.time;
      this.number_of_controls = _orig.number_of_controls;
      this.number_of_materials = _orig.number_of_materials;
      this.number_of_nodes = _orig.number_of_nodes;
      this.number_of_trackers = _orig.number_of_trackers;
      this.number_of_elements = _orig.number_of_elements;
   }
   public void deepCloneReferences(Smack _orig, uka.transport.DeepClone _helper) throws CloneNotSupportedException {
      this.filename = (java.lang.String)_helper.internalDeepClone(_orig.filename);
      this.trackwriter = (run.TrackWriter)_helper.internalDeepClone(_orig.trackwriter);
      this.resultwriter = (run.Writer)_helper.internalDeepClone(_orig.resultwriter);
      this.temporary_node = (run.Node)_helper.internalDeepClone(_orig.temporary_node);
      this.temporary_constraint = (run.Constraint)_helper.internalDeepClone(_orig.temporary_constraint);
      this.temporary_tracker = (run.Tracker)_helper.internalDeepClone(_orig.temporary_tracker);
      this.temporary_element = (run.Element)_helper.internalDeepClone(_orig.temporary_element);
      this.controlset = (run.Controlset)_helper.internalDeepClone(_orig.controlset);
      this.loadlist = (run.RplVector)_helper.internalDeepClone(_orig.loadlist);
      this.constraintlist = (run.RplVector)_helper.internalDeepClone(_orig.constraintlist);
      this.materiallist = (run.RplVector)_helper.internalDeepClone(_orig.materiallist);
      this.trackerlist = (run.RplVector)_helper.internalDeepClone(_orig.trackerlist);
      this.elementlist = (run.RplVector)_helper.internalDeepClone(_orig.elementlist);
      this.nodelist = (run.RplVector)_helper.internalDeepClone(_orig.nodelist);
   }
   private int number_of_elements;
   private int number_of_trackers;
   private int number_of_nodes;
   private int number_of_materials;
   private int number_of_controls;
   private RplVector nodelist;
   private RplVector elementlist;
   private RplVector trackerlist;
   private RplVector materiallist;
   private volatile double time;
   private volatile double ttemp;
   private int i;
   private int state;
   private RplVector constraintlist;
   private RplVector loadlist;
   private int number_of_constraints;
   private int number_of_loads;
   private Controlset controlset;
   private Element temporary_element;
   private Tracker temporary_tracker;
   private Constraint temporary_constraint;
   private Node temporary_node;
   private Writer resultwriter;
   private TrackWriter trackwriter;
   private java.lang.String filename;
   private double timestep;
   private boolean failure_is_set = false;
   private boolean autostep;
   private int nr_of_CPUs;
   public Smack(int nr_of_CPUs) {
      super();
      this.nr_of_CPUs = nr_of_CPUs;
   }
   public void assembleMassMatrix() throws Error {
      int i;
      Node temp_node;
      Element temp_element;
      Constraint temp_constraint;
      try {
         System.out.println("Assembling Elements");
         for (i = 0; i < run.Smack.this.number_of_elements; i++) {
            temp_element = (Element)run.Smack.this.elementlist.elementAt(i);
            temp_element.assembleMassMatrix();
         }
      }  catch (ArrayIndexOutOfBoundsException e) {
         throw new Error("\n* Error during Assembly phase - Terminating" + e);
      } catch (NullPointerException e) {
         throw new Error("\n* Error during Assembly phase of Element\n* This error could be the result of a missing (or wrong) parameter in the indata file \n* " + e);
      } catch (Error e) {
         throw new Error("\n* Error during Assembly phase of Element\n* This error could be the result of a missing (or wrong) parameter in the indata file \n* " + e);
      }
      try {
         System.out.println("Assembling Nodes");
         for (i = 0; i < run.Smack.this.nodelist.size(); i++) {
            temp_node = (Node)run.Smack.this.nodelist.elementAt(i);
            temp_node.determineMassMatrix();
         }
      }  catch (ArrayIndexOutOfBoundsException e) {
         throw new Error("\n* Error during Assembly phase - Terminating" + e);
      } catch (NullPointerException e) {
         throw new Error("\n* Error during Assembly phase of Node \n* This error could be the result of a missing (or wrong) parameter in the indata file \n* " + e);
      } catch (Error e) {
         throw new Error("\n* Error during Assembly phase of Node \n* This error could be the result of a missing (or wrong) parameter in the indata file \n* " + e);
      }
      try {
         System.out.println("Assembling Constraints");
         for (i = 0; i < run.Smack.this.number_of_constraints; i++) {
            temp_constraint = (Constraint)run.Smack.this.constraintlist.elementAt(i);
            temp_constraint.determineMassMatrix(run.Smack.this.nodelist);
         }
      }  catch (ArrayIndexOutOfBoundsException e) {
         throw new Error("\n* Error during Assembly phase - Terminating" + e);
      } catch (NullPointerException e) {
         throw new Error("\n* Error during Assembly phase of Constraint \n* This error could be the result of a missing (or wrong) parameter in the indata file \n* " + e);
      } catch (Error e) {
         throw new Error("\n* Error during Assembly phase of Constraint \n* This error could be the result of a missing (or wrong) parameter in the indata file \n* " + e);
      }
   }
   public void initialize(String fname) throws Error, RemoteException {
      run.Smack.this.filename = new String(fname);
      Reader indatafile = new FembicReader(run.Smack.this.filename);
      try {
         run.Smack.this.number_of_elements = indatafile.numberOfElements();
         run.Smack.this.number_of_trackers = indatafile.numberOfTrackers();
         run.Smack.this.number_of_materials = indatafile.numberOfMaterials();
         run.Smack.this.number_of_nodes = indatafile.numberOfNodes();
         run.Smack.this.number_of_constraints = indatafile.numberOfConstraints();
         run.Smack.this.number_of_loads = indatafile.numberOfLoads();
         run.Smack.this.number_of_controls = indatafile.numberOfControls();
      }  catch (java.text.ParseException e) {
         throw new Error("Error in initialization phase \n" + e);
      }
      run.Smack.this.elementlist = new RplVector(run.Smack.this.number_of_elements);
      run.Smack.this.trackerlist = new RplVector(run.Smack.this.number_of_trackers);
      run.Smack.this.materiallist = new RplVector(run.Smack.this.number_of_materials);
      run.Smack.this.nodelist = new RplVector(run.Smack.this.number_of_nodes);
      run.Smack.this.constraintlist = new RplVector(run.Smack.this.number_of_constraints);
      run.Smack.this.loadlist = new RplVector(run.Smack.this.number_of_loads);
      run.Smack.this.controlset = new Controlset();
      try {
         System.out.println("Reading Constraints");
         indatafile.open();
         for (run.Smack.this.i = 0; run.Smack.this.i < run.Smack.this.number_of_constraints; run.Smack.this.i++) {
            run.Smack.this.constraintlist.addElement(indatafile.getNextConstraint(run.Smack.this.nodelist));
         }
         indatafile.close();
         System.out.println("Filled constraintlist");
         System.out.println("Reading Loads");
         indatafile.open();
         for (run.Smack.this.i = 0; run.Smack.this.i < run.Smack.this.number_of_loads; run.Smack.this.i++) {
            run.Smack.this.loadlist.addElement(indatafile.getNextLoad(run.Smack.this.nodelist));
         }
         indatafile.close();
         System.out.println("Filled loadlist");
         indatafile.open();
         System.out.println("Reading Nodes");
         for (run.Smack.this.i = 0; run.Smack.this.i < run.Smack.this.number_of_nodes; run.Smack.this.i++) {
            run.Smack.this.nodelist.addElement(indatafile.getNextNode(run.Smack.this.constraintlist, run.Smack.this.loadlist));
         }
         indatafile.close();
         System.out.println("Filled nodelist");
         indatafile.open();
         System.out.println("Reading Materials");
         Material m;
         for (run.Smack.this.i = 0; run.Smack.this.i < run.Smack.this.number_of_materials; run.Smack.this.i++) {
            m = indatafile.getNextMaterial();
            if (m.failure_strain_is_set || m.failure_stress_is_set) {
               run.Smack.this.failure_is_set = true;
            }
            run.Smack.this.materiallist.addElement(m);
         }
         indatafile.close();
         System.out.println("Filled materiallist");
         indatafile.open();
         System.out.println("Reading Elements");
         for (run.Smack.this.i = 0; run.Smack.this.i < run.Smack.this.number_of_elements; run.Smack.this.i++) {
            run.Smack.this.elementlist.addElement(indatafile.getNextElement(run.Smack.this.materiallist, run.Smack.this.nodelist, run.Smack.this.loadlist));
         }
         indatafile.close();
         System.out.println("Filled elementlist");
         indatafile.open();
         System.out.println("Reading Trackers");
         for (run.Smack.this.i = 0; run.Smack.this.i < run.Smack.this.number_of_trackers; run.Smack.this.i++) {
            run.Smack.this.trackerlist.addElement(indatafile.getNextTracker(run.Smack.this.nodelist, run.Smack.this.elementlist));
         }
         indatafile.close();
         System.out.println("Filled trackerlist");
         indatafile.open();
         System.out.println("Reading Controls");
         for (run.Smack.this.i = 0; run.Smack.this.i < run.Smack.this.number_of_controls; run.Smack.this.i++) {
            indatafile.getControlSet(run.Smack.this.controlset);
         }
         indatafile.close();
         System.out.println("Filled controlset");
         run.Smack.this.resultwriter = indatafile.getWriter(run.Smack.this.nodelist, run.Smack.this.elementlist, run.Smack.this.controlset, null);
         run.Smack.this.trackwriter = indatafile.getTrackWriter(run.Smack.this.trackerlist, run.Smack.this.controlset, null);
      }  catch (java.text.ParseException e) {
         throw new Error("Parameter error in indata file \n" + e + " in line " + e.getErrorOffset());
      } catch (Error e) {
         throw e;
      }
      try {
         run.Smack.this.resultwriter.initialize();
      }  catch (Error e) {
         throw new Error("Initialization error of writer");
      }
      try {
         run.Smack.this.trackwriter.initialize();
      }  catch (Error e) {
         throw new Error("Initialization error of trackwriter");
      }
   }
   public void post() {
   }
   private void print() {
      System.out.println();
      System.out.println();
      System.out.println("time:" + run.Smack.this.time);
      try {
         run.Smack.this.resultwriter.write(run.Smack.this.filename, run.Smack.this.time);
         run.Smack.this.trackwriter.write(run.Smack.this.time);
      }  catch (IOException ioe) {
         System.out.println(ioe);
         return;
      }
   }
   public void setInitialConditions() {
      int i;
      int j;
      Node temp_node;
      Node neighbour_node;
      Element temp_element;
      Tracker temp_tracker;
      Constraint temp_constraint;
      double total_mass;
      System.out.println("Initializing nodes");
      for (i = 0; i < run.Smack.this.nodelist.size(); i++) {
         temp_node = (Node)run.Smack.this.nodelist.elementAt(i);
         temp_node.setInitialConditions();
      }
      System.out.println("Setting up node neighbour handles");
      for (j = 0; j < run.Smack.this.nodelist.size(); j++) {
         temp_node = (Node)run.Smack.this.nodelist.elementAt(j);
         if (j < run.Smack.this.nodelist.size() - 1) {
            temp_node.setRight_neighbour((Node)run.Smack.this.nodelist.elementAt(j + 1));
         }
         if (j > 0) {
            temp_node.setLeft_neighbour((Node)run.Smack.this.nodelist.elementAt(j - 1));
         }
      }
      System.out.println("Sorting nodes");
      for (j = 0; j < run.Smack.this.nodelist.size(); j++) {
         for (i = 0; i < run.Smack.this.nodelist.size(); i++) {
            temp_node = (Node)run.Smack.this.nodelist.elementAt(i);
            temp_node.checkNeighbours();
         }
      }
      System.out.println("Determining optimal model distribution for nodes");
      temp_node = (Node)run.Smack.this.nodelist.firstElement();
      while (temp_node.getLeft_neighbour() != null) temp_node = temp_node.getLeft_neighbour();
      for (i = 0; i < run.Smack.this.nodelist.size(); i++) {
         temp_node.setCpu_number(i * run.Smack.this.nr_of_CPUs / run.Smack.this.nodelist.size());
         temp_node = temp_node.getRight_neighbour();
      }
      System.out.println("Initializing elements");
      for (i = 0; i < run.Smack.this.number_of_elements; i++) {
         temp_element = (Element)run.Smack.this.elementlist.elementAt(i);
         temp_element.setInitialConditions();
      }
      System.out.println("Initializing trackers");
      for (i = 0; i < run.Smack.this.number_of_trackers; i++) {
         temp_tracker = (Tracker)run.Smack.this.trackerlist.elementAt(i);
         temp_tracker.setInitialConditions();
      }
      System.out.println("Initializing constraints");
      for (i = 0; i < run.Smack.this.number_of_constraints; i++) {
         temp_constraint = (Constraint)run.Smack.this.constraintlist.elementAt(i);
         temp_constraint.setInitialConditions();
      }
      run.Smack.this.controlset.setInitialConditions();
      System.out.println("Determining smallest timestep size");
      if (run.Smack.this.controlset.getTimestep(0) == 0) {
         run.Smack.this.timestep = 1.0E10;
         run.Smack.this.autostep = true;
         for (i = 0; i < run.Smack.this.number_of_elements; i++) {
            run.Smack.this.timestep = ((Element)run.Smack.this.elementlist.elementAt(i)).checkTimestep(run.Smack.this.timestep);
         }
      } else {
         run.Smack.this.timestep = run.Smack.this.controlset.getTimestep(0);
         run.Smack.this.autostep = false;
      }
      System.out.println("Determined timestep:" + run.Smack.this.timestep);
      System.out.println("Calculating total model mass");
      total_mass = 0;
      for (i = 0; i < run.Smack.this.nodelist.size(); i++) {
         temp_node = (Node)run.Smack.this.nodelist.elementAt(i);
         total_mass += temp_node.getMass();
      }
      System.out.println("Total model mass = " + total_mass);
   }
   public void solve() {
      int j;
      long time_info;
      long time_info_tmp;
      long time_remained;
      int number_of_integration_points;
      int time_h;
      int time_m;
      int time_s;
      String time_str;
      Thread[] tsolve;
      Worker[] worker;
      final Barrier barrier;
      long stime;
      time_info = new Date().getTime();
      run.Smack.this.ttemp = 1.0E10;
      tsolve = new Thread[run.Smack.this.nr_of_CPUs];
      worker = new Worker[run.Smack.this.nr_of_CPUs];
      barrier = BarrierFactory.createBarrier(run.Smack.this.nr_of_CPUs + 1);
      run.Smack.this.time = run.Smack.this.controlset.getStarttime();
      for (run.Smack.this.i = 0; run.Smack.this.i < run.Smack.this.nr_of_CPUs; run.Smack.this.i++) {
         worker[run.Smack.this.i] =  /** @at i */ new Worker(jp.lang.Node.getNode(run.Smack.this.i), barrier, run.Smack.this.time, run.Smack.this.timestep, run.Smack.this.autostep);
         tsolve[run.Smack.this.i] = new Thread(worker[run.Smack.this.i]);
      }
      System.out.println("Distributing the model on " + run.Smack.this.nr_of_CPUs + "CPU:s");
      for (int i = 0; i < run.Smack.this.elementlist.size(); i++) {
         run.Smack.this.temporary_element = (Element)run.Smack.this.elementlist.elementAt(i);
         worker[run.Smack.this.temporary_element.getCpu_number()].addElement(run.Smack.this.temporary_element);
      }
      for (int i = 0; i < run.Smack.this.nodelist.size(); i++) {
         run.Smack.this.temporary_node = (Node)run.Smack.this.nodelist.elementAt(i);
         worker[run.Smack.this.temporary_node.getCpu_number()].addNode(run.Smack.this.temporary_node);
      }
      for (run.Smack.this.i = 0; run.Smack.this.i < run.Smack.this.nr_of_CPUs; run.Smack.this.i++) tsolve[run.Smack.this.i].start();
      for (run.Smack.this.time = run.Smack.this.controlset.getStarttime(); run.Smack.this.time < run.Smack.this.controlset.getEndtime(); run.Smack.this.time += run.Smack.this.timestep) {
         for (run.Smack.this.i = 0; run.Smack.this.i < run.Smack.this.nr_of_CPUs; run.Smack.this.i++) {
            worker[run.Smack.this.i].setTime(run.Smack.this.time);
            worker[run.Smack.this.i].setTimestep(run.Smack.this.timestep);
            worker[run.Smack.this.i].setAutostep(run.Smack.this.autostep);
         }
         try {
            barrier.sync();
         }  catch (InterruptedException e2) {
            e2.printStackTrace();
         }
         stime = System.currentTimeMillis();
         try {
            barrier.sync();
         }  catch (InterruptedException e) {
            e.printStackTrace();
         }
         stime = System.currentTimeMillis();
         if (run.Smack.this.failure_is_set) {
            for (run.Smack.this.i = 0; run.Smack.this.i < run.Smack.this.number_of_elements; run.Smack.this.i++) {
               run.Smack.this.temporary_element = (Element)run.Smack.this.elementlist.elementAt(run.Smack.this.i);
               if (run.Smack.this.temporary_element.hasFailed()) {
                  run.Smack.this.number_of_elements--;
                  run.Smack.this.elementlist.removeElementAt(run.Smack.this.i);
                  System.out.println("Failed element: " + run.Smack.this.temporary_element.getNumber());
                  run.Smack.this.i--;
                  Node internal_node = run.Smack.this.temporary_element.getInternalNode();
                  if (internal_node != null) {
                     run.Smack.this.nodelist.remove(internal_node);
                  }
               }
            }
         }
         for (run.Smack.this.i = 0; run.Smack.this.i < run.Smack.this.number_of_constraints; run.Smack.this.i++) {
            run.Smack.this.temporary_constraint = (Constraint)run.Smack.this.constraintlist.elementAt(run.Smack.this.i);
            run.Smack.this.temporary_constraint.update();
         }
         stime = System.currentTimeMillis();
         for (run.Smack.this.i = 0; run.Smack.this.i < run.Smack.this.nodelist.size(); run.Smack.this.i++) {
            run.Smack.this.temporary_node = (Node)run.Smack.this.nodelist.elementAt(run.Smack.this.i);
            run.Smack.this.temporary_node.calculateNewPosition(run.Smack.this.timestep, run.Smack.this.time);
            run.Smack.this.temporary_node.checkNeighbours();
         }
         stime = System.currentTimeMillis();
         for (run.Smack.this.i = 0; run.Smack.this.i < run.Smack.this.number_of_trackers; run.Smack.this.i++) {
            run.Smack.this.temporary_tracker = (Tracker)run.Smack.this.trackerlist.elementAt(run.Smack.this.i);
            run.Smack.this.temporary_tracker.collectData();
            run.Smack.this.temporary_tracker.calculate();
         }
         stime = System.currentTimeMillis();
         if (run.Smack.this.controlset.getTimestep(run.Smack.this.time) == 0) {
            for (run.Smack.this.i = 0; run.Smack.this.i < run.Smack.this.nr_of_CPUs; run.Smack.this.i++) {
               run.Smack.this.ttemp = Math.min(run.Smack.this.ttemp, worker[run.Smack.this.i].getTtemp());
            }
            run.Smack.this.timestep = run.Smack.this.ttemp;
            run.Smack.this.ttemp = 1.0E10;
            run.Smack.this.autostep = true;
         } else {
            run.Smack.this.timestep = run.Smack.this.controlset.getTimestep(run.Smack.this.time);
            run.Smack.this.autostep = false;
         }
         if (run.Smack.this.controlset.timeToPrint(run.Smack.this.time)) {
            System.out.println();
            System.out.println();
            time_info_tmp = new Date().getTime();
            time_remained = (time_info_tmp - time_info) * (int)((run.Smack.this.controlset.getEndtime() - run.Smack.this.time) / run.Smack.this.controlset.getPrintstep()) / 1000;
            time_h = (int)(time_remained / 3600);
            time_m = (int)(time_remained / 60 - time_h * 60);
            time_s = (int)(time_remained - (int)(time_remained / 60) * 60);
            time_str = "";
            if (time_h < 10) {
               time_str += "0" + time_h;
            } else {
               time_str += time_h;
            }
            if (time_m < 10) {
               time_str += ":0" + time_m;
            } else {
               time_str += ":" + time_m;
            }
            if (time_s < 10) {
               time_str += ":0" + time_s;
            } else {
               time_str += ":" + time_s;
            }
            System.out.println("time:" + run.Smack.this.time + "\tRemaining time (hh:mm:ss) " + time_str);
            time_info = time_info_tmp;
            try {
               run.Smack.this.resultwriter.write(run.Smack.this.filename, run.Smack.this.time);
            }  catch (IOException ioe) {
               System.out.println(ioe);
               return;
            }
         }
         if (run.Smack.this.controlset.timeToPrintTracker(run.Smack.this.time)) {
            run.Smack.this.trackwriter.write(run.Smack.this.time);
         }
         try {
            barrier.sync();
         }  catch (InterruptedException e1) {
            e1.printStackTrace();
         }
         stime = System.currentTimeMillis();
         try {
            barrier.sync();
         }  catch (InterruptedException e2) {
            e2.printStackTrace();
         }
      }
      for (run.Smack.this.i = 0; run.Smack.this.i < run.Smack.this.nr_of_CPUs; run.Smack.this.i++) worker[run.Smack.this.i].setKeep_running(false);
      this.post();
   }
}
