예제 #1
0
  void Vector::AddVectorQuotientImpl(Number a, const Vector& z,
                                     const Vector& s, Number c)
  {
    DBG_ASSERT(Dim() == z.Dim());
    DBG_ASSERT(Dim() == s.Dim());

    if (c==0.) {
      AddOneVector(a, z, 0.);
      ElementWiseDivide(s);
    }
    else {
      SmartPtr<Vector> tmp = MakeNew();
      tmp->Copy(z);
      tmp->ElementWiseDivide(s);
      AddOneVector(a, *tmp, c);
    }
  }
예제 #2
0
  SmartPtr<const Vector> AugRestoSystemSolver::Sigma_tilde_n_c_inv(
    const SmartPtr<const Vector>& sigma_n_c,
    Number delta_x,
    const Vector& any_vec_in_c)
  {
    DBG_START_METH("AugRestoSystemSolver::Sigma_tilde_n_c_inv",dbg_verbosity);
    SmartPtr<Vector> retVec;
    if (IsValid(sigma_n_c) || delta_x != 0.0) {
      std::vector<const TaggedObject*> deps(1);
      std::vector<Number> scalar_deps(1);
      deps[0] = GetRawPtr(sigma_n_c);
      scalar_deps[0] = delta_x;
      if (!sigma_tilde_n_c_inv_cache_.GetCachedResult(retVec, deps, scalar_deps)) {
        DBG_PRINT((1,"Not found in cache\n"));
        retVec = any_vec_in_c.MakeNew();
        if (IsValid(sigma_n_c)) {
          if (delta_x != 0.) {
            retVec->Copy(*sigma_n_c);
            retVec->AddScalar(delta_x);
            retVec->ElementWiseReciprocal();
          }
          else {
            // Given a "homogenous vector" implementation (such as in
            // DenseVector) the following should be more efficient
            retVec->Set(1.);
            retVec->ElementWiseDivide(*sigma_n_c);
          }
        }
        else {
          retVec->Set(1./delta_x);
        }

        sigma_tilde_n_c_inv_cache_.AddCachedResult(retVec, deps, scalar_deps);
      }
    }

    return ConstPtr(retVec);
  }
예제 #3
0
  SmartPtr<const Vector> AugRestoSystemSolver::Sigma_tilde_p_d_inv(
    const SmartPtr<const Vector>& sigma_p_d,
    Number delta_x,
    const Vector& any_vec_in_p_d)
  {
    DBG_START_METH("AugRestoSystemSolver::Sigma_tilde_p_d_inv",dbg_verbosity);
    SmartPtr<Vector> retVec;
    if (IsValid(sigma_p_d) || delta_x != 0) {
      std::vector<const TaggedObject*> deps(1);
      std::vector<Number> scalar_deps(1);
      deps[0] = GetRawPtr(sigma_p_d);
      scalar_deps[0] = delta_x;
      if (!sigma_tilde_p_d_inv_cache_.GetCachedResult(retVec, deps, scalar_deps)) {
        DBG_PRINT((1,"Not found in cache\n"));
        retVec = any_vec_in_p_d.MakeNew();

        if (IsValid(sigma_p_d)) {
          if (delta_x != 0.) {
            retVec->Copy(*sigma_p_d);
            retVec->AddScalar(delta_x);
            retVec->ElementWiseReciprocal();
          }
          else {
            retVec->Set(1.);
            retVec->ElementWiseDivide(*sigma_p_d);
          }
        }
        else {
          retVec->Set(1./delta_x);
        }

        sigma_tilde_p_d_inv_cache_.AddCachedResult(retVec, deps, scalar_deps);
      }
    }

    return ConstPtr(retVec);
  }