コード例 #1
0
void LogicalSparseOpsUnitTest::setUp() {
  double val;

  val = urand.number();
  a_dfad = DFadType(n,val);
  a_ls = LSType(n,val);
  
  val = urand.number();
  b_dfad = DFadType(n,val);
  b_ls = LSType(n,val);

  val = urand.number();
  c_dfad = val;
  c_ls = val;

  for (int i=0; i<n; i++) {
    val = urand.number();
    a_dfad.fastAccessDx(i) = val;
    a_ls.fastAccessDx(i) = 1;

    val = urand.number();
    b_dfad.fastAccessDx(i) = val;
    b_ls.fastAccessDx(i) = 1;
  }
}
コード例 #2
0
void
DruckerPragerModel<EvalT, Traits>::ResidualJacobian(std::vector<ScalarT> & X,
  std::vector<ScalarT> & R, std::vector<ScalarT> & dRdX,
  const ScalarT ptr, const ScalarT qtr, const ScalarT eqN,
  const ScalarT mu, const ScalarT kappa)
{
  std::vector<DFadType> Rfad(4);
  std::vector<DFadType> Xfad(4);
  // initialize DFadType local unknown vector Xfad
  // Note that since Xfad is a temporary variable
  // that gets changed within local iterations
  // when we initialize Xfad, we only pass in the values of X,
  // NOT the system sensitivity information
  std::vector<ScalarT> Xval(4);
  for (std::size_t i = 0; i < 4; ++i) {
    Xval[i] = Sacado::ScalarValue<ScalarT>::eval(X[i]);
    Xfad[i] = DFadType(4, i, Xval[i]);
  }

  DFadType pFad = Xfad[0];
  DFadType qFad = Xfad[1];
  DFadType alphaFad = Xfad[2];
  DFadType deqFad = Xfad[3];

  DFadType betaFad = alphaFad - b0_;  
  
  // check this
  DFadType eqFad = eqN + deqFad; // (eqFad + deqFad??)
  
  // have to break down 3.0 * mu * deqFad;
  // other wise there wil be compiling error
  DFadType dq = deqFad;
  dq = mu * dq;
  dq = 3.0 * dq;
  
  // local system of equations
  Rfad[0] = pFad - ptr + kappa * betaFad * deqFad;
  Rfad[1] = qFad - qtr + dq;
  Rfad[2] = alphaFad 
    - (a0_ + a1_ * eqFad * std::exp(a2_ * pFad - a3_ * eqFad));
  Rfad[3] = qFad + alphaFad * pFad - Cf_;   

  // get ScalarT Residual
  for (int i = 0; i < 4; i++)
    R[i] = Rfad[i].val();

  // get local Jacobian
  for (int i = 0; i < 4; i++)
    for (int j = 0; j < 4; j++)
      dRdX[i + 4 * j] = Rfad[i].dx(j);      

}// end of ResidualJacobian