package run;

import jp.sync.Barrier;

import java.util.Vector;

import jp.lang.*;



public class Worker_instance_impl extends jp.lang.RemoteObject_instance_impl
  implements Worker_instance_intf
{

  private run.Element temporary_element;

  /** Remote variable access: get Worker.temporary_element */
  public final run.Element run_Worker_temporary_element_get_() 
  {
    // application code
    return this.temporary_element;
  }

  /** Remote variable access: set Worker.temporary_element */
  public final run.Element run_Worker_temporary_element_set_(run.Element _value_) 
  {
    // application code
    return this.temporary_element = _value_;
  }

  private run.Node temporary_node;

  /** Remote variable access: get Worker.temporary_node */
  public final run.Node run_Worker_temporary_node_get_() 
  {
    // application code
    return this.temporary_node;
  }

  /** Remote variable access: set Worker.temporary_node */
  public final run.Node run_Worker_temporary_node_set_(run.Node _value_) 
  {
    // application code
    return this.temporary_node = _value_;
  }

  private java.util.Vector elementlist;

  /** Remote variable access: get Worker.elementlist */
  public final java.util.Vector run_Worker_elementlist_get_() 
  {
    // application code
    return this.elementlist;
  }

  /** Remote variable access: set Worker.elementlist */
  public final java.util.Vector run_Worker_elementlist_set_(java.util.Vector _value_) 
  {
    // application code
    return this.elementlist = _value_;
  }

  private java.util.Vector nodelist;

  /** Remote variable access: get Worker.nodelist */
  public final java.util.Vector run_Worker_nodelist_get_() 
  {
    // application code
    return this.nodelist;
  }

  /** Remote variable access: set Worker.nodelist */
  public final java.util.Vector run_Worker_nodelist_set_(java.util.Vector _value_) 
  {
    // application code
    return this.nodelist = _value_;
  }

  private jp.sync.Barrier barrier;

  /** Remote variable access: get Worker.barrier */
  public final jp.sync.Barrier run_Worker_barrier_get_() 
  {
    // application code
    return this.barrier;
  }

  /** Remote variable access: set Worker.barrier */
  public final jp.sync.Barrier run_Worker_barrier_set_(jp.sync.Barrier _value_) 
  {
    // application code
    return this.barrier = _value_;
  }

  private double time;

  /** Remote variable access: get Worker.time */
  public final double run_Worker_time_get_() 
  {
    // application code
    return this.time;
  }

  /** Remote variable access: set Worker.time */
  public final double run_Worker_time_set_(double _value_) 
  {
    // application code
    return this.time = _value_;
  }

  /** Remote variable access: increment Worker.time */
  public final double run_Worker_time_inc_(double _value_, boolean _post_) 
  {
    // application code
    if (_post_) {
      double _before_ = this.time;
      this.time += _value_;
      return _before_;
    } else {
      return this.time += _value_;
    }
  }

  private double timestep;

  /** Remote variable access: get Worker.timestep */
  public final double run_Worker_timestep_get_() 
  {
    // application code
    return this.timestep;
  }

  /** Remote variable access: set Worker.timestep */
  public final double run_Worker_timestep_set_(double _value_) 
  {
    // application code
    return this.timestep = _value_;
  }

  /** Remote variable access: increment Worker.timestep */
  public final double run_Worker_timestep_inc_(double _value_, boolean _post_) 
  {
    // application code
    if (_post_) {
      double _before_ = this.timestep;
      this.timestep += _value_;
      return _before_;
    } else {
      return this.timestep += _value_;
    }
  }

  private double ttemp;

  /** Remote variable access: get Worker.ttemp */
  public final double run_Worker_ttemp_get_() 
  {
    // application code
    return this.ttemp;
  }

  /** Remote variable access: set Worker.ttemp */
  public final double run_Worker_ttemp_set_(double _value_) 
  {
    // application code
    return this.ttemp = _value_;
  }

  /** Remote variable access: increment Worker.ttemp */
  public final double run_Worker_ttemp_inc_(double _value_, boolean _post_) 
  {
    // application code
    if (_post_) {
      double _before_ = this.ttemp;
      this.ttemp += _value_;
      return _before_;
    } else {
      return this.ttemp += _value_;
    }
  }

  private boolean keep_running;

  /** Remote variable access: get Worker.keep_running */
  public final boolean run_Worker_keep_running_get_() 
  {
    // application code
    return this.keep_running;
  }

  /** Remote variable access: set Worker.keep_running */
  public final boolean run_Worker_keep_running_set_(boolean _value_) 
  {
    // application code
    return this.keep_running = _value_;
  }

  private boolean autostep;

  /** Remote variable access: get Worker.autostep */
  public final boolean run_Worker_autostep_get_() 
  {
    // application code
    return this.autostep;
  }

  /** Remote variable access: set Worker.autostep */
  public final boolean run_Worker_autostep_set_(boolean _value_) 
  {
    // application code
    return this.autostep = _value_;
  }

  public Worker_instance_impl(Barrier barrier, double time, double timestep, boolean autostep) throws uka.karmi.rmi.RemoteException {
    super();;
    this.barrier = barrier;
    this.keep_running = true;
    this.time = time;
    this.timestep = timestep;
    this.autostep = autostep;
    this.elementlist = new Vector();
    this.nodelist = new Vector();
    ;
  }

  /** Application method of class Worker */
  public void addElement(run.Element el) 
  {
    // application code
    {
       this.elementlist.addElement(el);
    }
  }

  /** Application method of class Worker */
  public void removeElement(run.Element el) 
  {
    // application code
    {
       this.elementlist.removeElement(el);
    }
  }

  /** Application method of class Worker */
  public void addNode(run.Node node) 
  {
    // application code
    {
       this.nodelist.addElement(node);
    }
  }

  /** Application method of class Worker */
  public void removeNode(run.Node node) 
  {
    // application code
    {
       this.nodelist.removeElement(node);
    }
  }

  /** Application method of class Worker */
  public void run() 
  {
    // application code
    {
       int i;
       int j;
       int number_of_integration_points;
       while (this.keep_running == true) {
          try {
             this.barrier.sync();
          }  catch (InterruptedException e3) {
             e3.printStackTrace();
          }
          if (this.autostep == true) {
             this.ttemp = 1.0E10;
          }
          for (i = 0; i < this.elementlist.size(); i++) {
             this.temporary_element = (Element)this.elementlist.elementAt(i);
             this.temporary_element.updateLocalCoordinateSystem();
             number_of_integration_points = this.temporary_element.getNumberOfIntegrationPoints();
             for (j = 0; j < number_of_integration_points; j++) {
                this.temporary_element.calculateStrain(this.timestep, j);
                this.temporary_element.calculateStress(j, this.timestep);
             }
             for (j = 0; j < number_of_integration_points; j++) {
                this.temporary_element.calculateNodalForces(j);
             }
             this.temporary_element.calculateExternalForces(this.time);
             this.temporary_element.calculateContactForces();
             if (this.autostep == true) {
                this.ttemp = this.temporary_element.checkTimestep(this.ttemp);
             }
          }
          try {
             this.barrier.sync();
          }  catch (InterruptedException e) {
             e.printStackTrace();
          }
          try {
             this.barrier.sync();
          }  catch (InterruptedException e1) {
             e1.printStackTrace();
          }
          for (i = 0; i < this.nodelist.size(); i++) {
             this.temporary_node = (Node)this.nodelist.elementAt(i);
             this.temporary_node.clearNodalForces();
          }
          try {
             this.barrier.sync();
          }  catch (InterruptedException e2) {
             e2.printStackTrace();
          }
       }
    }
  }

  /** Application method of class Worker */
  public void setKeep_running(boolean keep_running) 
  {
    // application code
    {
       this.keep_running = keep_running;
    }
  }

  /** Application method of class Worker */
  public double getTime() 
  {
    // application code
    {
       return this.time;
    }
  }

  /** Application method of class Worker */
  public void setTime(double time) 
  {
    // application code
    {
       this.time = time;
    }
  }

  /** Application method of class Worker */
  public double getTimestep() 
  {
    // application code
    {
       return this.timestep;
    }
  }

  /** Application method of class Worker */
  public void setTimestep(double timestep) 
  {
    // application code
    {
       this.timestep = timestep;
    }
  }

  /** Application method of class Worker */
  public double getTtemp() 
  {
    // application code
    {
       return this.ttemp;
    }
  }

  /** Application method of class Worker */
  public boolean isAutostep() 
  {
    // application code
    {
       return this.autostep;
    }
  }

  /** Application method of class Worker */
  public void setAutostep(boolean autostep) 
  {
    // application code
    {
       this.autostep = autostep;
    }
  }

  /** @see RemoteObject.__init() */
  protected void __init() {
    _this = new Worker((jp.lang.Marker) null);
    _this._init(_getRef());
  }

  /** Called to free heap space after object migration.
      @see RemoteObject._cleanup() */
  protected void _cleanup() {
    super._cleanup();
    this.temporary_element = null;
    this.temporary_node = null;
    this.elementlist = null;
    this.nodelist = null;
    this.barrier = null;
  }

  /** Worker is declared to be resident, the method
      counter has no longer to be allocated. */
  protected final void _init() {
    __init();
  }

  /** Worker is declared to be resident,
      there is no method counter, do nothing if _inc()
      is called from inherited methods */
  protected final void _inc() {}

  /** Worker is declared to be resident,
      there is no method counter, do nothing if _dec()
      is called from inherited methods */
  protected final void _dec() {}

}
