Example #1
0
 TestState() :
     x(0.0),
     v(0.0)
 {
     Covariance.resize(ndim(), ndim());
     Covariance.setIdentity();
 };
 PitchRollState()
 {
     Omega.setZero();
     GyroBias.setZero();
     AccelBias.setZero();
     Covariance.resize(ndim(), ndim());
     Covariance.setIdentity();
 };
Example #3
0
 Eigen::VectorXd
 boxminus(const struct PositionMeasurement& other) const
 {
     Eigen::VectorXd offset(ndim());
     offset(0) = x-other.x;
     return offset;
 };
 bool ParsedName::operator< (const ParsedName& pn) const
 {
   for (size_t i = 0; i < ndim(); i++)
     if (index (i) != pn.index (i))
       return (index (i) < pn.index (i));
   return false;
 }
//---------
doublevar HEG_system::calcLocPerturb(Sample_point * sample) { 

  doublevar pot=0;
  int nd=ndim();
  for(int p=0; p < nperturb; p++) { 
    Array1 <doublevar> dist(nd), epos(nd);
    int s=perturb_spin(p);
    int estart, eend;
    doublevar r=0;
    if(s==0) { estart=0; eend=nspin(0); } 
    else { estart=nspin(0); eend=totnelectrons; } 
    for(int e=estart; e< eend; e++) { 
      sample->getElectronPos(e,epos);
      r=0;
      for(int d=0; d< nd; d++) { 
        doublevar del=epos(d)-perturb_pos(p,d);
        while(del > latVec(d,d)*0.5) del-=latVec(d,d);
        while(del < -latVec(d,d)*0.5) del+=latVec(d,d);
        r+=del*del;
      }
      pot+=perturb_strength(p)*exp(-perturb_alpha(p)*r);
    }
  }
  return pot;
}
 Eigen::VectorXd boxminus(const struct IMUOrientationMeasurement& other) const
 {
     Eigen::VectorXd diff(ndim());
     diff.segment<3>(0) = acceleration - other.acceleration;
     diff.segment<3>(3) = omega - other.omega;
     return diff;
 };
Example #7
0
void
CompositeCoordinateSystem::setAxis( int axis, const BasicCoordinateSystemInfo & bcs, int subAxis )
{
    CARTA_ASSERT( axis >= 0 && axis < ndim() );
    CARTA_ASSERT( subAxis >= 0 && subAxis < bcs.ndim() );
    m_cs[axis] = bcs;
    m_subAxis[axis] = subAxis;
}
Example #8
0
 Eigen::VectorXd
 boxminus(const struct TestState& other) const
 {
     Eigen::VectorXd offset(ndim());
     offset(0) = x - other.x;
     offset(1) = v - other.v;
     return offset;
 }
Example #9
0
Bias::Bias(int                             biasIndexInCollection,
           const AwhParams                &awhParams,
           const AwhBiasParams            &awhBiasParams,
           const std::vector<DimParams>   &dimParamsInit,
           double                          beta,
           double                          mdTimeStep,
           int                             numSharingSimulations,
           const std::string              &biasInitFilename,
           ThisRankWillDoIO                thisRankWillDoIO,
           BiasParams::DisableUpdateSkips  disableUpdateSkips) :
    dimParams_(dimParamsInit),
    grid_(dimParamsInit, awhBiasParams.dimParams),
    params_(awhParams, awhBiasParams, dimParams_, beta, mdTimeStep, disableUpdateSkips, numSharingSimulations, grid_.axis(), biasIndexInCollection),
    state_(awhBiasParams, params_.initialHistogramSize, dimParams_, grid_),
    thisRankDoesIO_(thisRankWillDoIO == ThisRankWillDoIO::Yes),
    biasForce_(ndim()),
    alignedTempWorkSpace_(),
    tempForce_(ndim()),
    numWarningsIssued_(0)
{
    /* For a global update updateList covers all points, so reserve that */
    updateList_.reserve(grid_.numPoints());

    state_.initGridPointState(awhBiasParams, dimParams_, grid_, params_, biasInitFilename, awhParams.numBias);

    if (thisRankDoesIO_)
    {
        /* Set up the force correlation object. */

        /* We let the correlation init function set its parameters
         * to something useful for now.
         */
        double blockLength = 0;
        /* Construct the force correlation object. */
        forceCorrelationGrid_ =
            gmx::compat::make_unique<CorrelationGrid>(state_.points().size(), ndim(),
                                                      blockLength, CorrelationGrid::BlockLengthMeasure::Time,
                                                      awhParams.nstSampleCoord*mdTimeStep);

        writer_ = std::unique_ptr<BiasWriter>(new BiasWriter(*this));
    }
}
Example #10
0
void ASDSpinMap<VecType>::diagonal_block(const DimerSubspace<VecType>& subspace) {
  std::shared_ptr<const VecType> Ap = subspace.template ci<0>();
  std::shared_ptr<const VecType> Bp = subspace.template ci<1>();
  std::shared_ptr<const VecType> SA = Ap->spin();
  std::shared_ptr<const VecType> SB = Bp->spin();

  const int nA = subspace.template nstates<0>();
  const int nB = subspace.template nstates<1>();

  const double sz_AB = 0.5 * static_cast<double>(Ap->det()->nspin() * Bp->det()->nspin());

  auto spin_block = std::make_shared<Matrix>(nA*nB, nA*nB);

  std::vector<double> AdotAp;
  std::vector<double> BdotBp;

  for (int iAp = 0; iAp < nA; ++iAp) {
    for (int iA = 0; iA < nA; ++iA)
      AdotAp.push_back(SA->data(iA)->dot_product(*Ap->data(iAp)));
  }

  for (int iBp = 0; iBp < nB; ++iBp) {
    for (int iB = 0; iB < nB; ++iB)
      BdotBp.push_back(SB->data(iB)->dot_product(*Bp->data(iBp)));
  }

  for (int iBp = 0; iBp < nB; ++iBp) {
    for (int iAp = 0; iAp < nA; ++iAp) {
      const int iABp = subspace.dimerindex(iAp, iBp);
      for (int iA = 0; iA < nA; ++iA) // iB = iBp
        spin_block->element(subspace.dimerindex(iA,iBp),iABp) += AdotAp[iA+ nA*iAp];

      for (int iB = 0; iB < nB; ++iB) // iA = iAp
        spin_block->element(subspace.dimerindex(iAp,iB),iABp) += BdotBp[iB+ nB*iBp];

      spin_block->element(iABp, iABp) += sz_AB;
    }
  }

  const int n = spin_block->ndim();
  const int offset = subspace.offset();

  for (int ispin = 0; ispin < n; ++ispin) {
    for (int jspin = 0; jspin < ispin; ++jspin) {
      const double ele = spin_block->element(ispin,jspin);
      if (std::fabs(ele) > 1.0e-4) {
        this->emplace(std::make_pair(ispin + offset, jspin + offset), ele);
        this->emplace(std::make_pair(jspin + offset, ispin + offset), ele);
      }
    }
    const double ele = spin_block->element(ispin, ispin);
    if (std::fabs(ele) > 1.0e-4) this->emplace(std::make_pair(ispin + offset, ispin + offset), ele);
  }
}
Example #11
0
    Eigen::VectorXd
    boxminus(const struct PitchRollState& other) const
    {
        Eigen::VectorXd out(ndim());

        out.segment<3>(0) = Sophus::SO3d::log(Orientation*other.Orientation.inverse());
        out.segment<3>(3) = Omega - other.Omega;
        out.segment<3>(6) = GyroBias - other.GyroBias;
        out.segment<3>(9) = AccelBias - other.AccelBias;

        return out;
    };
Example #12
0
void
ZeroVarianceForce::registerObservables(vector<observable_helper*>& h5list,
                                       hid_t gid) const
{
  QMCHamiltonianBase::registerObservables(h5list, gid);
  vector<int> ndim(2);
  ndim[0]=Nnuc;
  ndim[1]=OHMMS_DIM;
  observable_helper* h5o1 = new observable_helper("F_ZV1");
  observable_helper* h5o2 = new observable_helper("F_ZV2");
  h5o1->set_dimensions(ndim,FirstForceIndex);
  h5o1->open(gid);
  h5list.push_back(h5o1);
  h5o2->set_dimensions(ndim,FirstForceIndex);
  h5o2->open(gid);
  h5list.push_back(h5o2);
}
Example #13
0
      // Conversion part 1 (Python -> C++)
      bool load(py::handle src, bool convert) 
      {
        if (!convert && !py::array_t<T>::check_(src))
          return false;

        auto buf = py::array_t<T, py::array::c_style | py::array::forcecast>::ensure(src);
        if (!buf)
          return false;

        auto dims = buf.ndim();
        if (dims != 2 )
          return false;

        value = rd::Array2D<T>((T*) buf.data(),buf.shape()[1],buf.shape()[0]);

        return true;
      }
void
NonLocalECPotential::registerObservables(vector<observable_helper*>& h5list,
    hid_t gid) const
{
  QMCHamiltonianBase::registerObservables(h5list, gid);
  if (ComputeForces)
  {
    vector<int> ndim(2);
    ndim[0]=Nnuc;
    ndim[1]=OHMMS_DIM;
    observable_helper* h5o1 = new observable_helper("FNL");
    h5o1->set_dimensions(ndim,FirstForceIndex);
    h5o1->open(gid);
    h5list.push_back(h5o1);
    observable_helper* h5o2 = new observable_helper("FNL_Pulay");
    h5o2->set_dimensions(ndim,FirstForceIndex+Nnuc*OHMMS_DIM);
    h5o2->open(gid);
    h5list.push_back(h5o2);
  }
}
    std::string NameParser::get_next_match (std::vector<int>& indices, bool return_seq_index)
    {
      if (!folder)
        folder.reset (new Path::Dir (folder_name));

      std::string fname;
      while ( (fname = folder->read_name()).size()) {
        if (match (fname, indices)) {
          if (return_seq_index) {
            for (size_t i = 0; i < ndim(); i++) {
              if (sequence (i).size()) {
                size_t n = 0;
                while (indices[i] != sequence (i) [n]) n++;
                indices[i] = n;
              }
            }
          }
          return Path::join (folder_name, fname);
        }
      }

      return "";
    }
Example #16
0
        double sumsq = 0;
        for (size_t i = 0; i < r.shape(0); i++)
            sumsq += r[i] * r(i); // Either notation works for a 1D array
        return sumsq;
    });

    sm.def("proxy_auxiliaries2", [](py::array_t<double> a) {
        auto r = a.unchecked<2>();
        auto r2 = a.mutable_unchecked<2>();
        return auxiliaries(r, r2);
    });

    // Same as the above, but without a compile-time dimensions specification:
    sm.def("proxy_add2_dyn", [](py::array_t<double> a, double v) {
        auto r = a.mutable_unchecked();
        if (r.ndim() != 2) throw std::domain_error("error: ndim != 2");
        for (size_t i = 0; i < r.shape(0); i++)
            for (size_t j = 0; j < r.shape(1); j++)
                r(i, j) += v;
    }, py::arg().noconvert(), py::arg());
    sm.def("proxy_init3_dyn", [](double start) {
        py::array_t<double, py::array::c_style> a({ 3, 3, 3 });
        auto r = a.mutable_unchecked();
        if (r.ndim() != 3) throw std::domain_error("error: ndim != 3");
        for (size_t i = 0; i < r.shape(0); i++)
        for (size_t j = 0; j < r.shape(1); j++)
        for (size_t k = 0; k < r.shape(2); k++)
            r(i, j, k) = start++;
        return a;
    });
    sm.def("proxy_auxiliaries2_dyn", [](py::array_t<double> a) {
Example #17
0
const BasicCoordinateSystemInfo &
CompositeCoordinateSystem::cs( int axis ) const
{
    CARTA_ASSERT( axis >= 0 && axis < ndim() );
    return m_cs[axis];
}
Example #18
0
int
CompositeCoordinateSystem::subAxis( int axis ) const
{
    CARTA_ASSERT( axis >= 0 && axis < ndim() );
    return m_subAxis[axis];
}
Example #19
0
void ASDSpinMap<VecType>::couple_blocks(const DimerSubspace<VecType>& AB, const DimerSubspace<VecType>& ApBp) {
  const Coupling term_type = coupling_type(AB, ApBp);

  auto spin_block = std::make_shared<Matrix>(AB.dimerstates(), ApBp.dimerstates());

  if ( (term_type == Coupling::abFlip) || (term_type == Coupling::baFlip) ) {
    std::shared_ptr<VecType> SAp, SBp;

    std::shared_ptr<const VecType> A = AB.template ci<0>();
    std::shared_ptr<const VecType> B = AB.template ci<1>();
    switch (term_type) {
      case Coupling::abFlip :
        SAp = ApBp.template ci<0>()->spin_lower(A->det());
        SBp = ApBp.template ci<1>()->spin_raise(B->det());
        break;
      case Coupling::baFlip :
        SAp = ApBp.template ci<0>()->spin_raise(A->det());
        SBp = ApBp.template ci<1>()->spin_lower(B->det());
        break;
      default: assert(false); break; // Control should never be able to reach here...
    }

    const int nA = AB.template nstates<0>();
    const int nB = AB.template nstates<1>();
    const int nAp = ApBp.template nstates<0>();
    const int nBp = ApBp.template nstates<1>();

    std::vector<double> AdotAp, BdotBp;

    for (int iAp = 0; iAp < nAp; ++iAp) {
      for (int iA = 0; iA < nA; ++iA) {
        AdotAp.push_back(SAp->data(iAp)->dot_product(*A->data(iA)));
      }
    }

    for (int iBp = 0; iBp < nBp; ++iBp) {
      for (int iB = 0; iB < nB; ++iB) {
        BdotBp.push_back(SBp->data(iBp)->dot_product(*B->data(iB)));
      }
    }


    for (int iBp = 0; iBp < nBp; ++iBp) {
      for (int iAp = 0; iAp < nAp; ++iAp) {
        const int iABp = ApBp.dimerindex(iAp,iBp);
        int iAB = 0;
        for (int iB = 0; iB < nB; ++iB) {
          for (int iA = 0; iA < nA; ++iA, ++iAB) {
            spin_block->element(iAB,iABp) += AdotAp[iA+ nA*iAp] * BdotBp[iB + nB*iBp];
          }
        }
      }
    }

    const int n = spin_block->ndim();
    const int m = spin_block->mdim();

    const int ioff = AB.offset();
    const int joff = ApBp.offset();

    for (int ispin = 0; ispin < n; ++ispin) {
      for (int jspin = 0; jspin < m; ++jspin) {
        const double ele = spin_block->element(ispin, jspin);
        if ( std::fabs(ele) > 1.0e-4)  {
          this->emplace(std::make_pair(ispin + ioff, jspin + joff), ele);
          this->emplace(std::make_pair(jspin + joff, ispin + ioff), ele);
        }
      }
    }
  }
}