Ejemplo n.º 1
0
  void Newton<_Type>::iterate(DenseVector<_Type>& x) {
    // length of the vector
    unsigned N = x.size();
    // Jacobian
    DenseMatrix<_Type> J(N, N, 0.0);
    // NVectors
    DenseVector<_Type> oldFn(N, 0.0), newFn(N, 0.0);
    // linear system object - native because no LAPACK complex at the moment
    DenseLinearSystem<_Type> system(&J, &oldFn, "native");
    system.set_monitor_det(MONITOR_DET);
    // iteration counter
    unsigned itn = 0;
    do {
      // increment the counter
      ++itn;

      // evaluate the residuals and jacobian at the current state
      p_RESIDUAL -> update(x);
      // get the residuals
      oldFn = p_RESIDUAL -> residual();
#ifdef DEBUG
      std::cout << " DEBUG: starting with |Residuals|  = " << oldFn.inf_norm() << "\n";
#endif

      if((std::abs(oldFn.inf_norm()) < TOL) || (itn == MAX_STEPS)) {
        break;
      }
      // retrieve the current jacobian
      J = p_RESIDUAL -> jacobian();

      // linear solver
      // \todo LU interface to LAPACK for complex matrices
      system.solve();

#ifdef DEBUG
      std::cout << " DEBUG: Iteration number    = " << itn << "\n";
      std::cout << " DEBUG: |Newton correction| = " << oldFn.inf_norm() << "\n";
#endif

      // must *subtract* delta
      x -= oldFn;
    } while(true);

    // More the 'MAX_STEPS' iterations currently triggers a failure.
    if(itn == MAX_STEPS) {
      std::string problem;
      problem = " The Newton.iterate method took too many iterations. \n";
      problem += " At the moment, this is set as a failure. \n";
      throw ExceptionItn(problem, itn, oldFn.inf_norm());
    }
    LAST_DET_SIGN = system.get_det_sign();
    if(MONITOR_DET) {
      if(system.get_det_sign() * LAST_DET_SIGN < 0) {
        std::string problem;
        problem = "[ INFO ] : Determinant monitor has changed signs in ODE_BVP.\n";
        problem += "[ INFO ] : Bifurcation detected.\n";
        throw ExceptionBifurcation(problem);
      }
    }
  }
Ejemplo n.º 2
0
void ArpFileNameControl::MessageReceived(BMessage* msg)
{
	if (msg->WasDropped() || msg->what == B_REFS_RECEIVED) {
		BString16		newFn(mFileName);
		entry_ref fileRef;
		if (msg->FindRef("refs", &fileRef) == B_OK) {
			BEntry		e(&fileRef);
			if (e.InitCheck() == B_OK && e.Exists()) {
				BPath	p(&e);
				if (p.InitCheck() == B_OK) {
					newFn = p.Path();
				}
			}
		}
		if (newFn != mFileName) {
			mFileName = newFn;
/*
			BMessenger		mg(mTarget);
			if (!mg.IsValid()) mg = BMessenger(this);
			if (mInvokedMsg && mg.IsValid()) {
*/
				Invoke();
/*
				BMessage		m(*mInvokedMsg);
				m.AddString("arp:file name", mFileName);
				mg.SendMessage(&m);
			}
*/
			Invalidate();
		}
		return;
	}
	
	inherited::MessageReceived(msg);
}