UserDefinedContinuousImplicitDynamicSystem.java

/*
 * Created on 2007/07/16
 * Copyright (C) 2007 Koga Laboratory. All rights reserved.
 *
 */
package org.mklab.tool.control.system.continuous;

import java.lang.reflect.InvocationTargetException;

import org.mklab.nfc.matrix.ComplexNumericalMatrix;
import org.mklab.nfc.matrix.RealNumericalMatrix;
import org.mklab.nfc.ode.SolverStopException;
import org.mklab.nfc.scalar.ComplexNumericalScalar;
import org.mklab.nfc.scalar.RealNumericalScalar;


/**
 * ユーザ定義連続時間動的システムを表わすクラスです。
 * 
 * @author koga
 * @version $Revision: 1.14 $, 2007/07/16
 * @param <RS> type of real scalar
 * @param <RM> type of real matrix
 * @param <CS> type of complex scalar
 * @param <CM> type of complex matrix
 */
public class UserDefinedContinuousImplicitDynamicSystem<RS extends RealNumericalScalar<RS,RM,CS,CM>, RM extends RealNumericalMatrix<RS,RM,CS,CM>, CS extends ComplexNumericalScalar<RS,RM,CS,CM>, CM extends ComplexNumericalMatrix<RS,RM,CS,CM>> extends UserDefinedContinuousDynamicSystem<RS,RM,CS,CM> implements ContinuousImplicitDynamicSystem<RS,RM,CS,CM> {
  /**
   * 新しく生成された<code>UserDefinedDynamicSystem</code>オブジェクトを初期化します。
   * 
   * @param obj 呼び出し対象オブジェクト。nullの場合は静的メソッドを参照します
   * @param sunit unit of scalar
   */
  public UserDefinedContinuousImplicitDynamicSystem(Object obj, RS sunit) {
    super(obj, sunit);
  }

  /**
   * 新しく生成された<code>UserDefinedContinuousDynamicSystem</code>オブジェクトを初期化します。
   * @param sunit unit of scalar
   */
  public UserDefinedContinuousImplicitDynamicSystem(RS sunit) {
    this(null, sunit);
  }

  /**
   * {@inheritDoc}
   */
  @Override
  public RM stateEquation(RS t, RM x, RM dx, RM u) throws SolverStopException {
    try {
      return (RM)this.stateFunction.invoke(this.object, t, x, dx, u);
    } catch (IllegalArgumentException e) {
      throw new SolverStopException(e);
    } catch (IllegalAccessException e) {
      throw new SolverStopException(e);
    } catch (InvocationTargetException e) {
      throw new SolverStopException(e.getTargetException());
    } catch (Exception e) {
      throw new SolverStopException(e);
    }
  }

  /**
   * {@inheritDoc}
   */
  @Override
  final public RM differentialEquation(final RS t, final RM x, RM dx, final RM inputOutput) throws SolverStopException {
    final RM u = inputOutput.getRowVectors(1, getInputSize());
    return stateEquation(t, x, dx, u);
  }
}