Beispiel #1
0
returnValue ModelData::setModel( const DifferentialEquation& _f )
{
	if( rhs_name.empty() && NX2 == 0 ) {
		differentialEquation = _f;
		Expression rhs;
		differentialEquation.getExpression( rhs );

		NXA = differentialEquation.getNXA();
		NX2 = rhs.getDim() - NXA;
		if( NDX == 0 ) NDX = _f.getNDX();
//		if( _f.getNDX() > 0 && _f.getNDX() != (int)NX2 ) { // TODO: this test returns an error for well-defined models when using a linear input subsystem!
//			std::cout << "nonlinear model of size " << NX2 << " depends on " << _f.getNDX() << " differential state derivatives!" << std::endl;
//			return ACADOERROR( RET_INVALID_OPTION );
//		}
		if( NU == 0 ) NU = _f.getNU();
		if( NP == 0 ) NP = _f.getNP();
		if( NOD == 0 ) NOD = _f.getNOD();

		export_rhs = BT_TRUE;
	}
	else {
		return ACADOERROR( RET_INVALID_OPTION );
	}
	return SUCCESSFUL_RETURN;
}
Beispiel #2
0
returnValue OCPexport::checkConsistency( ) const
{
	//
	// Consistency checks:
	//
	Objective objective;
	ocp.getObjective( objective );
	int hessianApproximation;
	get( HESSIAN_APPROXIMATION, hessianApproximation );

 	if ( ocp.hasObjective( ) == true && !((HessianApproximationMode)hessianApproximation == EXACT_HESSIAN &&
 			(objective.getNumMayerTerms() == 1 || objective.getNumLagrangeTerms() == 1)) ) { // for Exact Hessian RTI
 		return ACADOERROR( RET_INVALID_OBJECTIVE_FOR_CODE_EXPORT );
 	}


	int sensitivityProp;
	get(DYNAMIC_SENSITIVITY, sensitivityProp);

// 	if( (HessianApproximationMode)hessianApproximation == EXACT_HESSIAN && (ExportSensitivityType) sensitivityProp != THREE_SWEEPS ) {
// 		return ACADOERROR( RET_INVALID_OPTION );
// 	}

 	DifferentialEquation f;
 	ocp.getModel( f );

// 	if ( f.isDiscretized( ) == BT_TRUE )
// 		return ACADOERROR( RET_NO_DISCRETE_ODE_FOR_CODE_EXPORT );

 	if ( f.getNUI( ) > 0 )
 		return ACADOERROR( RET_INVALID_ARGUMENTS );

 	if ( f.getNP( ) > 0 )
 		return ACADOERRORTEXT(RET_INVALID_ARGUMENTS,
 				"Free parameters are not supported. For the old functionality use OnlineData class.");

 	if ( (HessianApproximationMode)hessianApproximation != GAUSS_NEWTON && (HessianApproximationMode)hessianApproximation != EXACT_HESSIAN )
 		return ACADOERROR( RET_INVALID_OPTION );

 	int discretizationType;
 	get( DISCRETIZATION_TYPE,discretizationType );
 	if ( ( (StateDiscretizationType)discretizationType != SINGLE_SHOOTING ) &&
 			( (StateDiscretizationType)discretizationType != MULTIPLE_SHOOTING ) )
 		return ACADOERROR( RET_INVALID_OPTION );

	return SUCCESSFUL_RETURN;
}
Beispiel #3
0
returnValue SIMexport::checkConsistency( ) const
{
	// consistency checks:
	// only time-continuous DAEs without parameter and disturbances supported!
	DifferentialEquation f;
	modelData.getModel(f);
	if ( f.isDiscretized( ) == true )
		return ACADOERROR( RET_NO_DISCRETE_ODE_FOR_CODE_EXPORT );
	
	if ( ( f.getNUI( ) > 0 ) || 
		 /*( f.getNP( ) > 0 ) ||*/ ( f.getNPI( ) > 0 ) || ( f.getNW( ) > 0 ) )
		return ACADOERROR( RET_ONLY_STATES_AND_CONTROLS_FOR_CODE_EXPORT );

	int mode;
    get( IMPLICIT_INTEGRATOR_MODE, mode );
    if( (ImplicitIntegratorMode) mode == LIFTED ) return ACADOERROR( RET_NOT_IMPLEMENTED_YET );

	return SUCCESSFUL_RETURN;
}
returnValue EllipsoidalIntegrator::init( const DifferentialEquation &rhs_, const int &N_ ){
 
  if( rhs_.isODE( ) == BT_FALSE ) return ACADOERROR(RET_CANNOT_TREAT_DAE);
  
  nx = rhs_.getDim();
  
  Q.resize(nx,nx);
  for( int i=0; i<nx*nx; i++ ) Q(i) = 0.0;
  N = N_;
  
  IntermediateState derivatives = rhs_.getODEexpansion( N );
  
  IntermediateState gg = derivatives.getCol(0);
  for( int i=0; i<N; i++ ) gg << derivatives.getCol(i+1)/acadoFactorial(i+1);
  
  g  << gg;
  
//   FILE *file = fopen("g.c","w");
//   file << g;
//   fclose(file);
  
  gr << derivatives.getCol(N+1)/acadoFactorial(N+1);
  dg << gg.ADforward( VT_DIFFERENTIAL_STATE, rhs_.getComponents(), nx );
  
  DifferentialState r(nx);
  
  IntermediateState dgg = gg.ADforward( VT_DIFFERENTIAL_STATE, rhs_.getComponents(), r );
  ddg << 0.5*dgg.ADforward( VT_DIFFERENTIAL_STATE, rhs_.getComponents(), r );
  
  return SUCCESSFUL_RETURN;
}
Beispiel #5
0
returnValue SIMexport::checkConsistency( ) const
{
	// Number of differential state derivatives must be either zero or equal to the number of differential states:
	if( !modelData.checkConsistency() ) {
		return ACADOERROR( RET_INVALID_OPTION );
	}

	// consistency checks:
	// only time-continuous DAEs without parameter and disturbances supported!
	DifferentialEquation f;
	modelData.getModel(f);
	if ( f.isDiscretized( ) == BT_TRUE )
		return ACADOERROR( RET_NO_DISCRETE_ODE_FOR_CODE_EXPORT );
	
	if ( ( f.getNUI( ) > 0 ) || 
		 /*( f.getNP( ) > 0 ) ||*/ ( f.getNPI( ) > 0 ) || ( f.getNW( ) > 0 ) )
		return ACADOERROR( RET_ONLY_STATES_AND_CONTROLS_FOR_CODE_EXPORT );

	// only equidistant evaluation grids supported!

	return SUCCESSFUL_RETURN;
}
EllipsoidalIntegrator::EllipsoidalIntegrator( const DifferentialEquation &rhs_, const int &N_ ):AlgorithmicBase(){

    ASSERT( rhs_.isODE( ) == BT_TRUE );
	setupOptions();
    init( rhs_, N_ );
}
Beispiel #7
0
 inline void initPointer()
 {
     if (not itExt) {
         itExt = &(equation->extVars().find(name)->second);
     }
 }
Beispiel #8
0
 inline void initPointer()
 {
     if (not itVar) {
         itVar = &(equation->vars().find(name)->second);
     }
 }