Exemple #1
0
NOX::Abstract::Group::ReturnType
LOCA::Homotopy::Group::computeNewton(Teuchos::ParameterList& params) 
{
  if (isValidNewton)
    return NOX::Abstract::Group::Ok;

  string callingFunction = 
    "LOCA::Homotopy::Group::computeNewton()";
  NOX::Abstract::Group::ReturnType status, finalStatus;
  
  if (newtonVecPtr == Teuchos::null)
    newtonVecPtr = gVecPtr->clone(NOX::ShapeCopy);
  
  finalStatus = computeF();
  globalData->locaErrorCheck->checkReturnType(finalStatus, callingFunction);
  
  status = computeJacobian();
  finalStatus = 
    globalData->locaErrorCheck->combineAndCheckReturnTypes(status, finalStatus,
							   callingFunction);

  status = applyJacobianInverse(params, *gVecPtr, *newtonVecPtr);
  finalStatus = 
    globalData->locaErrorCheck->combineAndCheckReturnTypes(status, finalStatus,
							   callingFunction);

  newtonVecPtr->scale(-1.0);
  
  isValidNewton = true;
  
  return finalStatus;
}
Exemple #2
0
  bool Model::
  computeCOM(Vector & com, Matrix * opt_jcom) const
  {
    com = Vector::Zero(3);
    if (opt_jcom) {
      *opt_jcom = Matrix::Zero(3, ndof_);
    }
    double mtotal(0);
    for (size_t ii(0); ii < ndof_; ++ii) {
      taoDNode * const node(kgm_tree_->info[ii].node);
      deVector3 wpos;
      wpos.multiply(node->frameGlobal()->rotation(), *(node->center()));
      wpos += node->frameGlobal()->translation();
      if (opt_jcom) {
	Matrix wjcom;
	if ( ! computeJacobian(node, wpos[0], wpos[1], wpos[2], wjcom)) {
	  return false;
	}
	*opt_jcom += *(node->mass()) * wjcom.block(0, 0, 3, wjcom.cols());
      }
      wpos *= *(node->mass());
      mtotal += *(node->mass());
      com += Vector::Map(&wpos[0], 3);
    }
    if (fabs(mtotal) > 1e-3) {
      com /= mtotal;
      if (opt_jcom) {
	*opt_jcom /= mtotal;
      }
    }
    return true;
  }
Exemple #3
0
  void SurfaceBasis<EvalT, Traits>::evaluateFields(typename Traits::EvalData workset)
  {
    for (std::size_t cell(0); cell < workset.numCells; ++cell) {
      // for the reference geometry
      // compute the mid-plane coordinates
      computeReferenceMidplaneCoords(referenceCoords, refMidplaneCoords);

      // compute basis vectors
      computeReferenceBaseVectors(refMidplaneCoords, refBasis);

      // compute the dual
      computeDualBaseVectors(refMidplaneCoords, refBasis, refNormal, refDualBasis);

      // compute the Jacobian
      computeJacobian(refBasis, refDualBasis, refArea);

      if (needCurrentBasis) {
        // for the current configuration
        // compute the mid-plane coordinates
        computeCurrentMidplaneCoords(currentCoords, currentMidplaneCoords);

        // compute base vectors
        computeCurrentBaseVectors(currentMidplaneCoords, currentBasis);
      }
    }
  }
Exemple #4
0
void
ADNodalBCTempl<T, compute_stage>::computeOffDiagJacobian(unsigned int jvar)
{
  if (jvar == _var.number())
    computeJacobian();
  else
  {
    auto ad_offset = jvar * _sys.getMaxVarNDofsPerNode();
    auto residual = computeQpResidual();
    const std::vector<dof_id_type> & cached_rows = _var.dofIndices();

    // Note: this only works for Lagrange variables...
    dof_id_type cached_col = _current_node->dof_number(_sys.number(), jvar, 0);

    // Cache the user's computeQpJacobian() value for later use.
    for (auto tag : _matrix_tags)
      if (_sys.hasMatrix(tag))
        for (size_t i = 0; i < cached_rows.size(); ++i)
          _fe_problem.assembly(0).cacheJacobianContribution(
              cached_rows[i],
              cached_col,
              conversionHelper(residual, i).derivatives()[ad_offset + i],
              tag);
  }
}
Vector2d leastSquareSolverCalib::pointAlignerLoop( Vector2d &x,  MatrixXd &Z, int iterations,  Vector2d &result)
{
    result=x;
    MatrixXd H(2,2);
    H.setZero();

    MatrixXd b(2,1);
    b.setZero();

    Vector2d X;
    std::cout << Z.transpose()<< std::endl;
    for(int i = 0; i < iterations; i++){
        std::cout<<"iteration "<<i <<std::endl;
        X=x;
        for(int j=0;j<Z.cols();j++){

            Matrix2d J = computeJacobian(j,Z);
            Vector2d e=computeError(j,Z);
            std:: cout << "error: "<< e<< std::endl<<std::endl;
            H+=J.transpose()*J;
            b+=J.transpose()*e;
        }
    }
    Vector2d dx;
    std::cout << "H: "<<std::endl<<H<<std::endl<<std::endl<<std::endl;
    std::cout << "b: "<<std::endl<<b<<std::endl;
    LDLT<MatrixXd> ldlt(-H);
    dx=ldlt.solve(b); // using a LDLT factorizationldlt;
    return dx;

}
Exemple #6
0
CMUK_ERROR_CODE cmuk::computeFootDK( LegIndex leg,
                                     const vec3f& q, 
                                     mat3f* jac,
                                     vec3f* pos,
                                     vec4f* orient,
                                     mat3f* axes ) const {

  if (!jac) {
    return CMUK_INSUFFICIENT_ARGUMENTS;
  }

  Transform3f t[4];

  CMUK_ERROR_CODE e = computeLegTransforms( leg, q, t );
  if (e != CMUK_OKAY) { return e; }

  mat3f a;

  computeJointAxes( t, &a );

  const vec3f& fpos = t[3].translation();

  computeJacobian( t, a, fpos, jac );

  if (pos) { *pos = fpos; }
  if (orient) { *orient = t[3].rotation(); }
  if (axes) { *axes = a; }

  return CMUK_OKAY;

}
Exemple #7
0
CMUK_ERROR_CODE cmuk::computePointDK( LegIndex leg,
                                      JointOffset link,
                                      const vec3f& q,
                                      const vec3f& p,
                                      mat3f* jac,
                                      mat3f* axes) const {

  if ((int)link < HIP_RX_OFFSET || (int)link >= NUM_OFFSETS) {
    return CMUK_BAD_JOINT_OFFSET;
  }
  if (!jac) {
    return CMUK_INSUFFICIENT_ARGUMENTS;
  }

  Transform3f t[4];

  CMUK_ERROR_CODE e = computeLegTransforms( leg, q, t );
  if (e != CMUK_OKAY) { return e; }

  mat3f a;

  computeJointAxes( t, &a );

  computeJacobian( t, a, p, jac, link );

  if (axes) { *axes = a; }

  return CMUK_OKAY;

}
Exemple #8
0
void
ADIntegratedBCTempl<T, compute_stage>::computeJacobianBlock(MooseVariableFEBase & jvar)
{
  auto jvar_num = jvar.number();

  if (jvar_num == _var.number())
    computeJacobian();
  else
  {
    DenseMatrix<Number> & ke = _assembly.jacobianBlock(_var.number(), jvar_num);
    if (jvar.phiFaceSize() != ke.n())
      return;

    size_t ad_offset = jvar_num * _sys.getMaxVarNDofsPerElem();

    for (_i = 0; _i < _test.size(); _i++)
      for (_qp = 0; _qp < _qrule->n_points(); _qp++)
      {
        DualReal residual = _ad_JxW[_qp] * _coord[_qp] * computeQpResidual();

        for (_j = 0; _j < jvar.phiFaceSize(); _j++)
          ke(_i, _j) += residual.derivatives()[ad_offset + _j];
      }
  }
}
Exemple #9
0
void
DiracKernel::computeOffDiagJacobian(unsigned int jvar)
{
    if (jvar == _var.number())
    {
        computeJacobian();
    }
    else
    {
        DenseMatrix<Number> & ke = _assembly.jacobianBlock(_var.number(), jvar);

        const std::vector<unsigned int> * multiplicities = _drop_duplicate_points ? NULL : &_local_dirac_kernel_info.getPoints()[_current_elem].second;
        unsigned int local_qp = 0;
        Real multiplicity = 1.0;

        for (_qp = 0; _qp < _qrule->n_points(); _qp++)
        {
            _current_point = _physical_point[_qp];
            if (isActiveAtPoint(_current_elem, _current_point))
            {
                if (!_drop_duplicate_points)
                    multiplicity = (*multiplicities)[local_qp++];

                for (_i=0; _i<_test.size(); _i++)
                    for (_j=0; _j<_phi.size(); _j++)
                        ke(_i, _j) += multiplicity * computeQpOffDiagJacobian(jvar);
            }
        }
    }
}
Exemple #10
0
NOX::Abstract::Group::ReturnType
LOCA::Homotopy::Group::computeGradient() 
{
  if (isValidGradient)
    return NOX::Abstract::Group::Ok;

  string callingFunction = 
    "LOCA::Homotopy::Group::computeGradient()";
  NOX::Abstract::Group::ReturnType status, finalStatus;

  if (gradVecPtr == Teuchos::null)
    gradVecPtr = gVecPtr->clone(NOX::ShapeCopy);

  finalStatus = computeF();
  globalData->locaErrorCheck->checkReturnType(finalStatus, callingFunction);
  
  status = computeJacobian();
  finalStatus = 
    globalData->locaErrorCheck->combineAndCheckReturnTypes(status, finalStatus,
							   callingFunction);

  status = applyJacobianTranspose(*gVecPtr, *gradVecPtr);
  finalStatus = 
    globalData->locaErrorCheck->combineAndCheckReturnTypes(status, finalStatus,
							   callingFunction);
  
  return finalStatus;
}
    //Evaluate the constraints for Chompification
    void TSRConstraint::evaluateConstraints(const MatX& qt, 
                                             MatX& h, 
                                             MatX& H)
    {
        //the pos is equivalent to the position of the 
        // end-effector in the robot frame. 
        double xyzrpy[6];
        
        //the position of the ee. 
        Transform pos;

        //get the position of the ee
        forwardKinematics( qt, pos );

        //get the position of the ee in the TSR frame
        endeffectorToTSRFrame( pos, xyzrpy );
        
        //the dimensionality of the configuration space
        size_t DoF = qt.size() ;
        
        //format h (constraint value vector).
        if (size_t(h.rows()) != _dim_constraint || h.cols() != 1)
        {
            h.resize(_dim_constraint, 1);
        }
        
        int current_dim = 0;

        std::vector< int > active_dims;
        
        for ( int i = 0; i < _dim_constraint; i ++ )
        {
            const int dim = _dimension_id[i];
            
            //if the robot's position goes over the TSR's upper bound:
            if ( xyzrpy[dim] > _Bw(dim, 1) ){
                h(current_dim) = xyzrpy[ dim ] - _Bw(dim, 1);
                active_dims.push_back( dim );
                current_dim ++;
            }
            //if the robot's position goes below the TSR's lower bound:
            else if ( xyzrpy[dim] < _Bw( dim, 0 ) ){
                h(current_dim) = xyzrpy[ dim ] - _Bw(dim, 0);
                active_dims.push_back( dim );
                current_dim ++;
            }
        }

        
        if ( current_dim != _dim_constraint ){
            h.conservativeResize( current_dim, 1 );
        }
        if ( H.rows() != current_dim || size_t( H.cols() ) != DoF ){
            H.resize( current_dim, DoF );
        }
        computeJacobian( qt, pos, H, active_dims );

    }
Exemple #12
0
vec& LinkedTreeRobot::getQDot(const vec& desired, vec& qdot, vec& axes) {
  vec P(3 * _numEffectors);
  getEffectorPositions(P); // position of the effectors currently

  vec F = clamp(desired - P, 0.5);

  mat J;
  computeJacobian(desired, J, axes);

  mat Jc;
  //cout << "++ Going to compute constraint jacobian ++" << endl;
  computeConstraintJacobian(desired, axes, Jc);
  //cout << "++ Finished computed constraint jacobian ++" << endl;
  //cout << "Jc:" << endl << Jc << endl;

  vec ga = trans(J) * F;
  //cout << "ga:" << endl << ga << endl;

  vec gc;
  if (Jc.n_elem == 0 || is_all_zeros(Jc)) // no constraints, or all constraints OK
    gc.zeros(ga.n_elem);
  else {
    vec b = -Jc * ga;
    //cout << "b:" << endl << b << endl;
    
    mat JcT = trans(Jc);

    mat A = Jc * JcT;
    //cout << "A:" << endl << A << endl;

    vec d;
    mat U, V;
    if (!svd(U, d, V, A))
      cerr << "could not compute SVD" << endl;

    //cout << "U:" << endl << U << endl;
    //cout << "V:" << endl << V << endl;
    //cout << "d:" << endl << d << endl;

    //vec lambda = V * inv(D) * trans(U) * b; // too naive

    vec utb = trans(U) * b;

    vec dinv_ut_b(d.n_elem);
    dinv_ut_b.zeros();

    for (size_t d_idx = 0; d_idx < d.n_elem; d_idx++) {
      double elem = d[d_idx];
      if (!double_equals(elem, 0.0))
        dinv_ut_b[d_idx] = 1.0 / elem * utb[d_idx];
    }

    gc = JcT * (V * dinv_ut_b); // Jc^T * lambda
  }

  qdot = ga + gc; // qdot
  return qdot;
}
Exemple #13
0
CMUK_ERROR_CODE cmuk::computePointFootDK( LegIndex leg,
                                          JointOffset  link,
                                          const vec3f& q,
                                          const vec3f& p,
                                          mat3f* jac,
                                          vec3f* fpos,
                                          float* det,
                                          float det_tol,
                                          float lambda ) const {

  if ((int)link < HIP_RX_OFFSET || (int)link >= NUM_OFFSETS) {
    return CMUK_BAD_JOINT_OFFSET;
  }
  if (!jac) {
    return CMUK_INSUFFICIENT_ARGUMENTS;
  }

  if (link == FOOT_OFFSET) { link = KNEE_RY_OFFSET; }

  Transform3f t[4];

  CMUK_ERROR_CODE e = computeLegTransforms( leg, q, t );
  if (e != CMUK_OKAY) { return e; }

  mat3f a;

  computeJointAxes( t, &a );

  mat3f J_p, J_f, J_f_inv;

  vec3f f;
  f = t[3].translation();
  
  computeJacobian( t, a, f, &J_f );
  computeJacobian( t, a, p, &J_p, link );

  CMUK_ERROR_CODE err = computeDKInverse( J_f, &J_f_inv, 
                                          det, det_tol, lambda );
  
  *jac = J_p * J_f_inv;
  if (fpos) { *fpos = f; }

  return err;
    
}
Exemple #14
0
  bool Model::
  computeJacobian(taoDNode const * node,
		  Matrix & jacobian) const
  {
    if ( ! node) {
      return false;
    }
    deVector3 const & gpos(node->frameGlobal()->translation());
    return computeJacobian(node, gpos[0], gpos[1], gpos[2], jacobian);
  }
Exemple #15
0
void
StressDivergenceRZ::computeOffDiagJacobian(unsigned int jvar)
{
  if (jvar == _var.number())
    computeJacobian();
  else
  {
    if (_volumetric_locking_correction)
    {
      // calculate volume averaged value of shape function derivative
      _avg_grad_test.resize(_test.size());
      for (_i = 0; _i < _test.size(); _i++)
      {
        _avg_grad_test[_i].resize(2);
        _avg_grad_test[_i][_component] = 0.0;
        for (_qp = 0; _qp < _qrule->n_points(); _qp++)
        {
          if (_component == 0)
            _avg_grad_test[_i][_component] += (_grad_test[_i][_qp](_component) + _test[_i][_qp] / _q_point[_qp](0)) * _JxW[_qp] * _coord[_qp];
          else
            _avg_grad_test[_i][_component] += _grad_test[_i][_qp](_component) * _JxW[_qp] * _coord[_qp];

        }
        _avg_grad_test[_i][_component] /= _current_elem_volume;
      }

      _avg_grad_phi.resize(_phi.size());
      for (_i = 0; _i < _phi.size(); _i++)
      {
        _avg_grad_phi[_i].resize(3);
        for (unsigned int component = 0; component < 2; component++)
        {
          _avg_grad_phi[_i][component] = 0.0;
          for (_qp = 0; _qp < _qrule->n_points(); _qp++)
          {
            if (component == 0)
              _avg_grad_phi[_i][component] += (_grad_phi[_i][_qp](component) + _phi[_i][_qp] / _q_point[_qp](0)) * _JxW[_qp] * _coord[_qp];
            else
              _avg_grad_phi[_i][component] += _grad_phi[_i][_qp](component) * _JxW[_qp] * _coord[_qp];
          }

          _avg_grad_phi[_i][component] /= _current_elem_volume;
        }
      }
    }

    DenseMatrix<Number> & ke = _assembly.jacobianBlock(_var.number(), jvar);

    for (_i = 0; _i < _test.size(); _i++)
      for (_j = 0; _j < _phi.size(); _j++)
        for (_qp = 0; _qp < _qrule->n_points(); _qp++)
          ke(_i, _j) += _JxW[_qp] * _coord[_qp] * computeQpOffDiagJacobian(jvar);
  }
}
Exemple #16
0
float OptSO3::conjugateGradientCUDA_impl(Matrix3f& R, float res0, uint32_t N,
    uint32_t maxIter)
{
  Timer t0;
  Matrix3f G_prev, G, H, M_t_min, J;
//  Matrix3f R = R0;
  vector<float> res(1,res0);

#ifndef NDEBUG
  cout<<"N="<<N<<endl;
  cout<<"R0="<<endl<<R<<endl;
  cout<<"residual 0 = "<<res[0]<<endl;
#endif

  //float ts[10] = {0.0,0.1,0.2,0.3,0.4,0.5,0.7,1.0,1.5,2.0};
  //float ts[10] = {0.0,0.01,0.02,0.03,0.04,0.05,0.07,.1,.2,.3};
  Timer t1;
  for(uint32_t i =0; i<maxIter; ++i)
  {
    computeJacobian(J,R,N);
#ifndef NDEBUG
  cout<<"J="<<endl<<J<<endl;
#endif
    t0.toctic("--- jacobian ");
    updateGandH(G,G_prev,H,R,J,M_t_min,i%3 == 0); // want first iteration to reset H
#ifndef NDEBUG
  cout<<(i%3 == 2)<<endl;
  cout<<"R="<<endl<<R<<endl;
  cout<<"G="<<endl<<G<<endl;
  cout<<"H="<<endl<<H<<endl;
#endif
    t0.toctic("--- update G and H ");
    float f_t_min = linesearch(R,M_t_min,H,N,t_max_,dt_);
    t0.toctic("--- linesearch ");
    if(f_t_min == 999999.0f) break;

    res.push_back(f_t_min);
    float dresidual = res[res.size()-2] - res[res.size()-1];
    if( abs(dresidual) < 1e-7 )
    {
      cout<<"converged after "<<res.size()<<" delta residual "
        << dresidual <<" residual="<<res[res.size()-1]<<endl;
      break;
    }else{
      cout<<"delta residual " << dresidual
        <<" residual="<<res[res.size()-1]<<endl;
    }
  }
  dtCG_ = t1.toc();
//  R0 = R; // update R
  return  res.back();
}
Exemple #17
0
void
StressDivergenceTruss::computeOffDiagJacobian(unsigned int jvar)
{
  if (jvar == _var.number())
  {
    computeJacobian();
  }
  else
  {
    unsigned int coupled_component = 0;

    bool active(false);

    if ( _xdisp_coupled && jvar == _xdisp_var )
    {
      coupled_component = 0;
      active = true;
    }
    else if ( _ydisp_coupled && jvar == _ydisp_var )
    {
      coupled_component = 1;
      active = true;
    }
    else if ( _zdisp_coupled && jvar == _zdisp_var )
    {
      coupled_component = 2;
      active = true;
    }

    DenseMatrix<Number> & ke = _assembly.jacobianBlock(_var.number(), jvar);

    if (active)
    {
      ColumnMajorMatrix stiff_global(3,3);
      computeStiffness( stiff_global );

      for (_i=0; _i<_test.size(); _i++)
      {
        for (_j=0; _j<_phi.size(); _j++)
        {
          int sign( _i == _j ? 1 : -1 );
          ke(_i,_j) += sign * stiff_global(_component, coupled_component);
        }
      }
    }
    else if ( false ) // Need some code here for coupling with temperature
    {
    }
  }
}
Exemple #18
0
double TimeModeProposal::computeLogJacobian()
{
    double k = rateParameter(_event);
    double T = _event->getTimeToTip();

    double jacobian = computeJacobian(k, T);
    double logJacobian = std::log(jacobian);

    if (_lastTimeModeProposal == TimeConstant) {
        return logJacobian;
    } else {
        return -logJacobian;
    }
}
Exemple #19
0
void
ComputeJacobianThread::onElement(const Elem *elem)
{
  _fe_problem.prepare(elem, _tid);

  _fe_problem.reinitElem(elem, _tid);

  _fe_problem.reinitMaterials(_subdomain, _tid);
  if (_sys.getScalarVariables(_tid).size() > 0)
    _fe_problem.reinitOffDiagScalars(_tid);

  computeJacobian();

  _fe_problem.swapBackMaterials(_tid);
}
Exemple #20
0
void
KernelGrad::computeOffDiagJacobian(unsigned int jvar)
{
  if (jvar == _var.number())
    computeJacobian();
  else
  {
    DenseMatrix<Number> & Ke = _assembly.jacobianBlock(_var.number(), jvar);

    for (_j = 0; _j < _phi.size(); _j++)
      for (_qp = 0; _qp < _qrule->n_points(); _qp++)
        for (_i = 0; _i < _test.size(); _i++)
          Ke(_i, _j) += _JxW[_qp] * _coord[_qp] * computeQpOffDiagJacobian(jvar);
  }
}
Exemple #21
0
void
NodalKernel::computeOffDiagJacobian(unsigned int jvar)
{
  if (jvar == _var.number())
    computeJacobian();
  else
  {
    _qp = 0;
    Real cached_val = computeQpOffDiagJacobian(jvar);
    dof_id_type cached_row = _var.nodalDofIndex();
    // Note: this only works for Lagrange variables...
    dof_id_type cached_col = _current_node->dof_number(_sys.number(), jvar, 0);

    _assembly.cacheJacobianContribution(cached_row, cached_col, cached_val);
  }
}
Exemple #22
0
void
NodalBC::computeOffDiagJacobian(unsigned int jvar)
{
    if (jvar == _var.number())
        computeJacobian();
    else
    {
        _qp = 0;
        Real cached_val = computeQpOffDiagJacobian(jvar);
        dof_id_type cached_row = _var.nodalDofIndex();
        // Note: this only works for Lagrange variables...
        dof_id_type cached_col = _current_node->dof_number(_sys.number(), jvar, 0);

        // Cache the user's computeQpJacobian() value for later use.
        _fe_problem.assembly(0).cacheNodalBCJacobianEntry(cached_row, cached_col, cached_val);
    }
}
Exemple #23
0
NOX::Abstract::Group::ReturnType
LOCA::Homotopy::DeflatedGroup::
computeNewton(Teuchos::ParameterList& params) 
{
  if (isValidNewton)
    return NOX::Abstract::Group::Ok;

  string callingFunction = 
    "LOCA::Homotopy::DeflatedGroup::computeNewton()";
  NOX::Abstract::Group::ReturnType finalStatus = NOX::Abstract::Group::Ok;
  NOX::Abstract::Group::ReturnType status;

  // Make sure F is valid
  if (!isF()) {
    status = computeF();
    finalStatus = 
      globalData->locaErrorCheck->combineAndCheckReturnTypes(status, 
							      finalStatus,
							      callingFunction);
  }
  
  // Make sure Jacobian is valid
  if (!isJacobian()) {
    status = computeJacobian();
    finalStatus = 
      globalData->locaErrorCheck->combineAndCheckReturnTypes(status, 
							      finalStatus,
							      callingFunction);
  }

  // zero out newton vec -- used as initial guess for some linear solvers
  newtonMultiVec.init(0.0);

  status = applyJacobianInverseMultiVector(params, fMultiVec, 
					   newtonMultiVec);
  finalStatus = 
    globalData->locaErrorCheck->combineAndCheckReturnTypes(status, 
							   finalStatus,
							   callingFunction);

  newtonMultiVec.scale(-1.0);

  isValidNewton = true;

  return finalStatus;
}
Exemple #24
0
void
StressDivergence::computeOffDiagJacobian(MooseVariableFEBase & jvar)
{
  size_t jvar_num = jvar.number();
  if (jvar_num == _var.number())
    computeJacobian();
  else
  {
    if (_volumetric_locking_correction)
    {
      // calculate volume averaged value of shape function derivative
      _avg_grad_test.resize(_test.size());
      for (_i = 0; _i < _test.size(); _i++)
      {
        _avg_grad_test[_i].resize(3);
        _avg_grad_test[_i][_component] = 0.0;
        for (_qp = 0; _qp < _qrule->n_points(); _qp++)
          _avg_grad_test[_i][_component] +=
              _grad_test[_i][_qp](_component) * _JxW[_qp] * _coord[_qp];

        _avg_grad_test[_i][_component] /= _current_elem_volume;
      }

      _avg_grad_phi.resize(jvar.phiSize());
      for (_i = 0; _i < jvar.phiSize(); _i++)
      {
        _avg_grad_phi[_i].resize(3);
        for (unsigned int component = 0; component < _mesh.dimension(); component++)
        {
          _avg_grad_phi[_i][component] = 0.0;
          for (_qp = 0; _qp < _qrule->n_points(); _qp++)
            _avg_grad_phi[_i][component] += _grad_phi[_i][_qp](component) * _JxW[_qp] * _coord[_qp];

          _avg_grad_phi[_i][component] /= _current_elem_volume;
        }
      }
    }

    DenseMatrix<Number> & ke = _assembly.jacobianBlock(_var.number(), jvar_num);

    for (_i = 0; _i < _test.size(); _i++)
      for (_j = 0; _j < jvar.phiSize(); _j++)
        for (_qp = 0; _qp < _qrule->n_points(); _qp++)
          ke(_i, _j) += _JxW[_qp] * _coord[_qp] * computeQpOffDiagJacobian(jvar_num);
  }
}
NOX::Abstract::Group::ReturnType
LOCA::LAPACK::Group::computeComplex(double frequency)
{
  string callingFunction = "LOCA::LAPACK::computeComplex()";

#ifdef HAVE_TEUCHOS_COMPLEX
  NOX::Abstract::Group::ReturnType finalStatus;

  freq = frequency;

  // Compute Jacobian
  finalStatus = computeJacobian();
  globalData->locaErrorCheck->checkReturnType(finalStatus, callingFunction);

  // Compute Mass matrix
  bool res = 
    locaProblemInterface.computeShiftedMatrix(0.0, 1.0, xVector,
					      shiftedSolver.getMatrix());

  // Compute complex matrix
  NOX::LAPACK::Matrix<double>& jacobianMatrix = jacSolver.getMatrix();
  NOX::LAPACK::Matrix<double>& massMatrix = shiftedSolver.getMatrix();
  NOX::LAPACK::Matrix< std::complex<double> >& complexMatrix = 
    complexSolver.getMatrix();
  int n = jacobianMatrix.numRows();
  for (int j=0; j<n; j++) {
    for (int i=0; i<n; i++) {
      complexMatrix(i,j) = 
	std::complex<double>(jacobianMatrix(i,j), frequency*massMatrix(i,j));
    }
  }

  if (finalStatus == NOX::Abstract::Group::Ok && res)
    isValidComplex = true;

  if (res)
    return finalStatus;
  else
    return NOX::Abstract::Group::Failed;
#else
  globalData->locaErrorCheck->throwError(
    callingFunction,
    "TEUCHOS_COMPLEX must be enabled for complex support!  Reconfigure with -D Teuchos_ENABLE_COMPLEX");
  return NOX::Abstract::Group::BadDependency;
#endif
}
NOX::Abstract::Group::ReturnType
LOCA::TurningPoint::MooreSpence::ExtendedGroup::computeNewton(
						 Teuchos::ParameterList& params) 
{
  if (isValidNewton)
    return NOX::Abstract::Group::Ok;

  string callingFunction = 
    "LOCA::TurningPoint::MooreSpence::ExtendedGroup::computeNewton()";
  NOX::Abstract::Group::ReturnType finalStatus = NOX::Abstract::Group::Ok;
  NOX::Abstract::Group::ReturnType status;

  // Make sure F is valid
  if (!isF()) {
    status = computeF();
    finalStatus = 
      globalData->locaErrorCheck->combineAndCheckReturnTypes(status, 
							     finalStatus,
							     callingFunction);
  }
  
  // Make sure Jacobian is valid
  if (!isJacobian()) {
    status = computeJacobian();
    finalStatus = 
      globalData->locaErrorCheck->combineAndCheckReturnTypes(status, 
							     finalStatus,
							     callingFunction);
  }

  // zero out newton vec -- used as initial guess for some linear solvers
  newtonMultiVec.init(0.0);

  // solve using contiguous
  status = solverStrategy->solve(params, *ffMultiVec, newtonMultiVec);
  finalStatus = 
    globalData->locaErrorCheck->combineAndCheckReturnTypes(status, finalStatus,
							   callingFunction);

  newtonMultiVec.scale(-1.0);

  isValidNewton = true;

  return finalStatus;
}
Exemple #27
0
void
DGKernel::computeOffDiagJacobian(unsigned int jvar)
{
    if (jvar == _var.number())
        computeJacobian();
    else
    {
        // Compute element-element Jacobian
        computeOffDiagElemNeighJacobian(Moose::ElementElement,jvar);

        // Compute element-neighbor Jacobian
        computeOffDiagElemNeighJacobian(Moose::ElementNeighbor,jvar);

        // Compute neighbor-element Jacobian
        computeOffDiagElemNeighJacobian(Moose::NeighborElement,jvar);

        // Compute neighbor-neighbor Jacobian
        computeOffDiagElemNeighJacobian(Moose::NeighborNeighbor,jvar);
    }
}
Exemple #28
0
NOX::Abstract::Group::ReturnType
LOCA::Homotopy::DeflatedGroup::
computeGradient() 
{
  if (isValidGradient)
    return NOX::Abstract::Group::Ok;

  string callingFunction = 
    "LOCA::Homotopy::DeflatedGroup::computeGradient()";
  NOX::Abstract::Group::ReturnType finalStatus = NOX::Abstract::Group::Ok;
  NOX::Abstract::Group::ReturnType status;

  // Make sure F is valid
  if (!isF()) {
    status = computeF();
    finalStatus = 
      globalData->locaErrorCheck->combineAndCheckReturnTypes(status, 
							      finalStatus,
							      callingFunction);
  }
  
  // Make sure Jacobian is valid
  if (!isJacobian()) {
    status = computeJacobian();
    finalStatus = 
      globalData->locaErrorCheck->combineAndCheckReturnTypes(status, 
							      finalStatus,
							      callingFunction);
  }

  // Compute J^T*f for homotopy group
  status = applyJacobianTranspose(*fVec, *gradientVec);
  finalStatus = 
    globalData->locaErrorCheck->combineAndCheckReturnTypes(status, 
							   finalStatus,
							   callingFunction);

  isValidGradient = true;

  return finalStatus;
}
Exemple #29
0
void
DiracKernel::computeOffDiagJacobian(unsigned int jvar)
{
  if (jvar == _var.number())
  {
    computeJacobian();
  }
  else
  {
    DenseMatrix<Number> & ke = _assembly.jacobianBlock(_var.number(), jvar);

    for (_qp = 0; _qp < _qrule->n_points(); _qp++)
    {
      _current_point = _physical_point[_qp];
      if (isActiveAtPoint(_current_elem, _current_point))
        for (_i=0; _i<_test.size(); _i++)
          for (_j=0; _j<_phi.size(); _j++)
            ke(_i, _j) += computeQpOffDiagJacobian(jvar);
    }
  }
}
Exemple #30
0
void
NodalBC::computeOffDiagJacobian(unsigned int jvar)
{
  if (jvar == _var.number())
    computeJacobian();
  else
  {
    _qp = 0;
    Real cached_val = 0.0;
    cached_val = computeQpOffDiagJacobian(jvar);

    dof_id_type cached_row = _var.nodalDofIndex();
    // Note: this only works for Lagrange variables...
    dof_id_type cached_col = _current_node->dof_number(_sys.number(), jvar, 0);

    // Cache the user's computeQpJacobian() value for later use.
    for (auto tag : _matrix_tags)
      if (_sys.hasMatrix(tag))
        _fe_problem.assembly(0).cacheJacobianContribution(cached_row, cached_col, cached_val, tag);
  }
}