예제 #1
0
  /** Main loop: Wait for new measurement, Get new step, maybe deal with
   *  bounds,  see to it that everything happens in the required
   *  timeframe. */
  SensAlgorithmExitStatus SensAlgorithm::Run()
  {
    DBG_START_METH("SensAlgorithm::Run", dbg_verbosity);

    SensAlgorithmExitStatus retval = SOLVE_SUCCESS;

    /* Loop through all steps */
    SmartPtr<IteratesVector> sol = IpData().curr()->MakeNewIteratesVector();
    SmartPtr<DenseVector> delta_u;
    SmartPtr<const Vector> unscaled_x;
    SmartPtr<const Vector> unscaled_yc;

    
    
    SmartPtr<IteratesVector> trialcopy;
    for (Index step_i=0; step_i<n_sens_steps_; ++step_i) {
      sens_step_calc_->SetSchurDriver(driver_vec_[step_i]);
      delta_u = measurement_->GetMeasurement(step_i+1);
      delta_u->Print(Jnlst(),J_VECTOR,J_USER1,"delta_u");
      sens_step_calc_->Step(*delta_u, *sol);
      SmartPtr<IteratesVector> saved_sol = sol->MakeNewIteratesVectorCopy();
      saved_sol->Print(Jnlst(),J_VECTOR,J_USER1,"sol_vec");

      // unscale solution...
      UnScaleIteratesVector(&saved_sol) ;

      // update variables
      measurement_->SetSolution(step_i+1, saved_sol);

      // get sensitivity vector
      GetDirectionalDerivatives() ;
      
    }

    return retval;
  }
예제 #2
0
  SensAlgorithmExitStatus SensAlgorithm::ComputeSensitivityMatrix(void) {
    
    DBG_START_METH("SensAlgorithm::ComputeSensitivityMatrix", dbg_verbosity);

    SensAlgorithmExitStatus retval = SOLVE_SUCCESS;

    /* Loop through all steps */
    SmartPtr<IteratesVector> sol = IpData().curr()->MakeNewIteratesVector();
    SmartPtr<const Vector> unscaled_x;
    SmartPtr<const Vector> unscaled_yc;
    
    SmartPtr<IteratesVector> trialcopy;

    SmartPtr<DenseVectorSpace> delta_u_space;
    delta_u_space = new DenseVectorSpace(2);

    SmartPtr<DenseVector> delta_u = new DenseVector(GetRawPtr(ConstPtr(delta_u_space)));

    Number* du_val = delta_u->Values();

    std::string state;
    std::string statevalue;

    state      = "sens_init_constr";
    statevalue = "sens_init_constr";

    SmartPtr<const DenseVectorSpace> x_owner_space_ = dynamic_cast<const DenseVectorSpace*>(GetRawPtr(IpData().curr()->y_c()->OwnerSpace())) ;
    //= dynamic_cast<const DenseVectorSpace*>(GetRawPtr(IpData().curr()->x()->OwnerSpace()));

    const std::vector<Index> idx_ipopt = x_owner_space_->GetIntegerMetaData(state.c_str());

    char buffer[250] ;

    Index col = 0 ;
    for (Index Scol =0; Scol < idx_ipopt.size(); ++Scol) {

      if ( idx_ipopt[Scol] > 0 ) {

	// reset rhs vector to zero
	for (Index j = 0; j < idx_ipopt.size(); ++j) {
	  if ( idx_ipopt[j] > 0 ) du_val[ idx_ipopt[j] - 1 ] = 0 ;
	}

	sprintf(buffer,"Column %i",idx_ipopt[Scol]) ;

	sens_step_calc_->SetSchurDriver(driver_vec_[0]);

	// set rhs to 1 (eq. 9-10)
	du_val[idx_ipopt[Scol]-1] = 1;

	delta_u->SetValues(du_val) ;
	//delta_u->Print(Jnlst(),J_VECTOR,J_USER1,"delta_u 1234567");
	sens_step_calc_->Step(*delta_u, *sol);
	SmartPtr<IteratesVector> saved_sol = sol->MakeNewIteratesVectorCopy();
	saved_sol->Print(Jnlst(),J_VECTOR,J_USER1,"sol_vec");

	// unscale solution...
	UnScaleIteratesVector(&saved_sol) ;

	saved_sol->Print(Jnlst(),J_VECTOR,J_USER1,buffer);
	
	// Save column
	GetSensitivityMatrix(col) ;
	++col ; // increase column counter
      }
    }
    return retval ;
  }