BaseContinuousExplicitDynamicSystem.java
/*
* $Id: BaseContinuousDynamicSystem.java,v 1.21 2008/06/26 10:10:34 koga Exp $
*
* Copyright (C) 2004 Koga Laboratory. All rights reserved.
*
*/
package org.mklab.tool.control.system.continuous;
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 Laboratory
* @version $Revision: 1.21 $, 2004/11/09
* @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 abstract class BaseContinuousExplicitDynamicSystem<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 BaseContinuousDynamicSystem<RS,RM,CS,CM> implements ContinuousExplicitDynamicSystem<RS,RM,CS,CM> {
/** M行列 */
private RM matrixM;
/** ヤコビ行列 */
private RM jacobian;
/** 微分代数方程式で表せるシステムならばtrue */
private boolean isDifferentialAlgebraicSystem = false;
/** ヤコビ行列を持っていればtrue */
private boolean hasJacobianMatrix = false;
/** 状態と状態の微分の初期値が整合していればtrue */
private boolean hasConsistentInitialValue = false;
/**
* 新しく生成された<code>BaseContinuousDynamicSystem</code>オブジェクトを初期化します。
*
* @param inputSize 入力の数
* @param outputSize 出力の数
* @param stateSize 状態の数
* @param sunit unit of scalar
*/
public BaseContinuousExplicitDynamicSystem(final int inputSize, final int outputSize, final int stateSize, RS sunit) {
super(inputSize, outputSize, stateSize, sunit);
this.matrixM = sunit.createUnitGrid(stateSize);
this.jacobian = sunit.createZeroGrid(stateSize, stateSize);
}
/**
* {@inheritDoc}
*/
@Override
public int hashCode() {
final int prime = 31;
int result = super.hashCode();
result = prime * result + (this.hasConsistentInitialValue ? 1231 : 1237);
result = prime * result + (this.hasJacobianMatrix ? 1231 : 1237);
result = prime * result + (this.isDifferentialAlgebraicSystem ? 1231 : 1237);
result = prime * result + ((this.jacobian == null) ? 0 : this.jacobian.hashCode());
result = prime * result + ((this.matrixM == null) ? 0 : this.matrixM.hashCode());
return result;
}
/**
* {@inheritDoc}
*/
@Override
public boolean equals(Object obj) {
if (this == obj) return true;
if (!super.equals(obj)) return false;
if (getClass() != obj.getClass()) return false;
BaseContinuousExplicitDynamicSystem<RS,RM,CS,CM> other = (BaseContinuousExplicitDynamicSystem<RS,RM,CS,CM>)obj;
if (this.hasConsistentInitialValue != other.hasConsistentInitialValue) return false;
if (this.hasJacobianMatrix != other.hasJacobianMatrix) return false;
if (this.isDifferentialAlgebraicSystem != other.isDifferentialAlgebraicSystem) return false;
if (this.jacobian == null) {
if (other.jacobian != null) return false;
} else if (!this.jacobian.equals(other.jacobian)) return false;
if (this.matrixM == null) {
if (other.matrixM != null) return false;
} else if (!this.matrixM.equals(other.matrixM)) return false;
return true;
}
/**
* {@inheritDoc}
*/
@Override
public BaseContinuousExplicitDynamicSystem<RS,RM,CS,CM> clone() {
final BaseContinuousExplicitDynamicSystem<RS,RM,CS,CM> inst = (BaseContinuousExplicitDynamicSystem<RS,RM,CS,CM>)super.clone();
inst.jacobian = this.jacobian == null ? null : this.jacobian.createClone();
inst.matrixM = this.matrixM == null ? null : this.matrixM.createClone();
inst.hasConsistentInitialValue = this.hasConsistentInitialValue;
inst.hasJacobianMatrix = this.hasJacobianMatrix;
inst.isDifferentialAlgebraicSystem = this.isDifferentialAlgebraicSystem;
return inst;
}
/**
* {@inheritDoc}
*/
final public RM differentialEquation(final RS t, final RM x, final RM inputOutput) throws SolverStopException {
final RM u = inputOutput.getRowVectors(1, getInputSize());
return stateEquation(t, x, u);
}
/**
* {@inheritDoc}
*/
public RM matrixM() throws SolverStopException {
throw new SolverStopException(Messages.getString("BaseContinuousDynamicSystem.2")); //$NON-NLS-1$
}
/**
* {@inheritDoc}
*/
public RM getMatrixM() {
return this.matrixM;
}
/**
* {@inheritDoc}
*/
public RM getJacobianMatrix(RS t, RM x, RM u) {
return this.jacobian;
}
/**
* Mx'=f(t,x,u)のM行列を設定します。
* @param matrixM M行列
*/
public void setMatrixM(RM matrixM) {
this.matrixM = matrixM;
}
/**
* {@inheritDoc}
*/
public boolean isDifferentialAlgebraicSystem() {
return this.isDifferentialAlgebraicSystem;
}
/**
* 微分代数方程式で表されるシステムであるか設定します。
* @param isDifferentialAlgebraicSystem 微分代数方程式で表されるシステムならばtrue
*/
protected void setDifferentialAlgebraicSystem(boolean isDifferentialAlgebraicSystem) {
this.isDifferentialAlgebraicSystem = isDifferentialAlgebraicSystem;
}
/**
* 状態と状態の微分の初期値が整合するか設定します。
* @param hasConsistentInitialValue 状態と状態の微分の初期値が整合すればtrue
*/
public void setHasConsistentInitialValue(boolean hasConsistentInitialValue) {
this.hasConsistentInitialValue = hasConsistentInitialValue;
}
/**
* ヤコビ行列を持っているか設定します。
* @param hasJacobianMatrix ヤコビ行列をもっていればtrue
*/
public void setHasJacobianMatrix(boolean hasJacobianMatrix) {
this.hasJacobianMatrix = hasJacobianMatrix;
}
/**
* {@inheritDoc}
*/
public boolean hasJacobianMatrix() {
return this.hasJacobianMatrix;
}
/**
* {@inheritDoc}
*/
public boolean hasConsistentInitialValue() {
return this.hasConsistentInitialValue;
}
}