DoubleBlockContinuousImplicitDynamicSystem.java

  1. /**
  2.  * $Id$
  3.  *
  4.  * Copyright (C) 2004-2005 Koga Laboratory. All rights reserved.
  5.  */

  6. package org.mklab.tool.control.system.continuous;

  7. import java.util.List;

  8. import org.mklab.nfc.matrix.DoubleMatrix;
  9. import org.mklab.nfc.ode.SolverStopException;
  10. import org.mklab.tool.control.system.DoubleSystemOperator;


  11. /**
  12.  * 陰的微分方程式で表現されるブロック連続時間動的システムを表わすクラスです。
  13.  *
  14.  * @author koga
  15.  * @version $Revision$
  16.  */
  17. public class DoubleBlockContinuousImplicitDynamicSystem extends DoubleBlockContinuousDynamicSystem implements DoubleContinuousImplicitDynamicSystem {
  18.   /**
  19.    * 新しく生成された<code>BlockContinuousDynamicSystem</code>オブジェクトを初期化します。
  20.    *
  21.    * @param elements 隣接行列
  22.    * @param inputNodes 入力ノードの番号のリスト(番号は1から始まります)
  23.    * @param outputNodes 出力ノードの番号のリスト(番号は1から始まります)
  24.    */
  25.   public DoubleBlockContinuousImplicitDynamicSystem(final DoubleSystemOperator[][] elements, final List<Integer> inputNodes, final List<Integer> outputNodes) {
  26.     super(elements, inputNodes, outputNodes);
  27.   }

  28.   /**
  29.    * {@inheritDoc}
  30.    */
  31.   public DoubleMatrix stateEquation(final double t, final DoubleMatrix x, DoubleMatrix dx,  final DoubleMatrix u) throws SolverStopException {
  32.     setState(x);
  33.     setStateDerivative(dx);

  34.     DoubleMatrix e = new DoubleMatrix(0, 1);
  35.     for (final DoubleContinuousDynamicSystem system : this.continuousDynamicSystems) {
  36.       if (system instanceof DoubleContinuousImplicitDynamicSystem) {
  37.         e = e.appendDown(((DoubleContinuousImplicitDynamicSystem)system).stateEquation(t, system.getState(),  system.getStateDerivative(), getInputNodeValueOf((DoubleSystemOperator)system)));
  38.       } else {
  39.         if (((DoubleContinuousExplicitDynamicSystem)system).isDifferentialAlgebraicSystem()) {
  40.           final DoubleMatrix m = ((DoubleContinuousExplicitDynamicSystem)system).getMatrixM();
  41.           final DoubleMatrix leftHandSide = m.multiply(system.getStateDerivative());
  42.           final DoubleMatrix rightHandSide = ((DoubleContinuousExplicitDynamicSystem)system).stateEquation(t, system.getState(), getInputNodeValueOf((DoubleSystemOperator)system));
  43.           e = e.appendDown(leftHandSide.subtract(rightHandSide));
  44.         } else {
  45.           final DoubleMatrix leftHandSide = system.getStateDerivative();
  46.           final DoubleMatrix rightHandSide = ((DoubleContinuousExplicitDynamicSystem)system).stateEquation(t, system.getState(), getInputNodeValueOf((DoubleSystemOperator)system));
  47.           e = e.appendDown(leftHandSide.subtract(rightHandSide));
  48.         }
  49.       }
  50.     }

  51.     return e;
  52.   }

  53.   /**
  54.    * {@inheritDoc}
  55.    */
  56.   public DoubleMatrix differentialEquation(final double t, final DoubleMatrix x, final DoubleMatrix dx, final DoubleMatrix inputOutput) throws SolverStopException {
  57.     final DoubleMatrix u = inputOutput.getSubVector(1, getInputSize());
  58.     return stateEquation(t, x, dx, u);
  59.   }
  60. }