Exemplo n.º 1
0
 void 
 TrialWaveFunction::evaluateDeltaLog (MCWalkerConfiguration &W,  
				      vector<RealType>& logpsi_fixed,
				      vector<RealType>& logpsi_opt,  
				      GradMatrix_t&  fixedG,
				      ValueMatrix_t& fixedL)
 {
   for (int iw=0; iw<logpsi_fixed.size(); iw++) {
     logpsi_opt[iw] = RealType();
     logpsi_fixed[iw] = RealType();
   }
   fixedG = GradType();
   fixedL = RealType();

   // First, sum optimizable part, using fixedG and fixedL as temporaries
   for (int i=0,ii=RECOMPUTE_TIMER; i<Z.size(); i++,ii+=TIMER_SKIP) {
     myTimers[ii]->start();
     if (Z[i]->Optimizable) {
       Z[i]->addLog(W, logpsi_opt);
       Z[i]->gradLapl(W, fixedG, fixedL);
     }
   }
   for (int iw=0; iw<W.WalkerList.size(); iw++) 
     for (int ptcl=0; ptcl<fixedG.cols(); ptcl++) {
       W[iw]->Grad[ptcl] = fixedG(iw, ptcl);
       W[iw]->Lap[ptcl]  = fixedL(iw, ptcl);
     }
   
   // Reset them, then accumulate the fixe part
   fixedG = GradType();
   fixedL = RealType();
  
   for (int i=0,ii=NL_TIMER; i<Z.size(); i++,ii+=TIMER_SKIP) {
     if (!Z[i]->Optimizable) {
       Z[i]->addLog(W, logpsi_fixed);
       Z[i]->gradLapl(W, fixedG, fixedL);
     }
     myTimers[ii]->stop();	
   }
   
   // Add on the fixed part to the total laplacian and gradient
   for (int iw=0; iw<W.WalkerList.size(); iw++) 
     for (int ptcl=0; ptcl<fixedG.cols(); ptcl++) {
       W[iw]->Grad[ptcl] += fixedG(iw, ptcl);
       W[iw]->Lap[ptcl]  += fixedL(iw, ptcl);
     }
 }
Exemplo n.º 2
0
 param_type(IntervalIter intervals_first, IntervalIter intervals_last,
            WeightIter weight_first)
   : _intervals(intervals_first, intervals_last)
 {
     if(_intervals.size() < 2) {
         _intervals.clear();
         _weights.push_back(RealType(1));
         _weights.push_back(RealType(1));
         _intervals.push_back(RealType(0));
         _intervals.push_back(RealType(1));
     } else {
         _weights.reserve(_intervals.size());
         for(std::size_t i = 0; i < _intervals.size(); ++i) {
             _weights.push_back(*weight_first++);
         }
     }
 }
Exemplo n.º 3
0
 /**
  * return the 95% confidence interval:
  *
  * That is returns c, such that we have 95% confidence that the
  * true mean is within 2c of the Average (x):
  *
  *   x - c <= true mean <= x + c
  *
  */
 void get95percentConfidenceInterval(ResultType &ret) {
   assert(Count_ != 0);
   ResultType sd;
   this->getStdDev(sd);
   for (unsigned int i =0; i < N_INTERACTION_FAMILIES; i++) {        
     ret[i] = 1.960 * sd[i] / sqrt(RealType(Count_));
   }
   return;
 }
Exemplo n.º 4
0
  void 
  TrialWaveFunction::evaluateLog (MCWalkerConfiguration &W,
				  vector<RealType> &logPsi)
  {
    for (int iw=0; iw<logPsi.size(); iw++)
      logPsi[iw] = RealType();
    for (int i=0; i<Z.size(); i++) 
      Z[i]->addLog (W, logPsi);
  }
 result_type operator()(Engine& eng)
 {
   // TODO: This is O(_mean), but it should be O(log(_mean)) for large _mean
   RealType product = RealType(1);
   for(result_type m = 0; ; ++m) {
     product *= eng();
     if(product <= _exp_mean)
       return m;
   }
 }
Exemplo n.º 6
0
 RootsOfUnity(unsigned maxVal)
     : maxVal(maxVal)
     , table(maxVal + 1, 1)
 {
     static const std::complex<RealType> ci(0, 1);
     for (unsigned i = 2; i <= maxVal; ++i) {
         auto base = ci * RealType(2.0 * M_PI / i);
         table[i] = std::exp(base);
     }
 }
Exemplo n.º 7
0
 param_type(const std::initializer_list<T>& il, F f)
   : _intervals(il.begin(), il.end())
 {
     if(_intervals.size() < 2) {
         _intervals.clear();
         _weights.push_back(RealType(1));
         _weights.push_back(RealType(1));
         _intervals.push_back(RealType(0));
         _intervals.push_back(RealType(1));
     } else {
         _weights.reserve(_intervals.size());
         for(typename std::vector<RealType>::const_iterator
             iter = _intervals.begin(), end = _intervals.end();
             iter != end; ++iter)
         {
             _weights.push_back(f(*iter));
         }
     }
 }
Exemplo n.º 8
0
 /**
  * Return the fraction part of the RandomNumber as a floating point number
  * of type RealType rounded to the nearest multiple of
  * 1/2<sup><i>p</i></sup>, where \e p =
  * std::numeric_limits<RealType>::digits, and, if necessary, creating
  * additional digits of the number.
  *
  * @tparam RealType the floating point type to convert to.
  * @tparam Random the type of the random generator.
  * @param[in,out] r a random generator for generating the necessary digits.
  * @return the fraction of the RandomNumber rounded to a RealType.
  **********************************************************************/
 template<typename RealType, typename Random> RealType Fraction(Random& r) {
   STATIC_ASSERT(!std::numeric_limits<RealType>::is_integer,
                 "RandomNumber::Fraction: invalid real type RealType");
   const int d = std::numeric_limits<RealType>::digits;
   const int k = (d + bits - 1)/bits;
   const int kg = (d + bits)/bits; // For guard bit
   RealType y = 0;
   if (Digit(r, kg - 1) & (1U << (kg * bits - d - 1)))
     // if guard bit is set, round up.
     y += std::pow(RealType(2), -d);
   const RealType fact = std::pow(RealType(2), -bits);
   RealType mult = RealType(1);
   for (int i = 0; i < k; ++i) {
     mult *= fact;
     y += mult * RealType(i < k - 1 ? RawDigit(i) :
                          RawDigit(i) & (~0U << (k * bits - d)));
   }
   return y;
 }
Exemplo n.º 9
0
 /**
  * return the 95% confidence interval:
  *
  * That is returns c, such that we have 95% confidence that the
  * true mean is within 2c of the Average (x):
  *
  *   x - c <= true mean <= x + c
  *
  */
 void get95percentConfidenceInterval(ResultType &ret) {
   assert(Count_ != 0);
   Mat3x3d sd;
   this->getStdDev(sd);
   for (unsigned int i = 0; i < 3; i++) {
     for (unsigned int j = 0; j < 3; j++) {
       ret(i,j) = 1.960 * sd(i,j) / sqrt(RealType(Count_));
     }
   }
   return;
 }
Exemplo n.º 10
0
 void 
 TrialWaveFunction::evaluateOptimizableLog (MCWalkerConfiguration &W,  
					    vector<RealType>& logpsi_opt,  
					    GradMatrix_t&  optG,
					    ValueMatrix_t& optL)
 {
   for (int iw=0; iw<W.getActiveWalkers(); iw++) 
     logpsi_opt[iw] = RealType();
   optG = GradType();
   optL = RealType();
   
   // Sum optimizable part of log Psi
   for (int i=0,ii=RECOMPUTE_TIMER; i<Z.size(); i++,ii+=TIMER_SKIP) {
     myTimers[ii]->start();
     if (Z[i]->Optimizable) {
       Z[i]->addLog(W, logpsi_opt);
       Z[i]->gradLapl(W, optG, optL);
     }
     myTimers[ii]->stop();
   }
 }
Exemplo n.º 11
0
   inline RealType quantile(const complemented2_type<hypergeometric_distribution<RealType, Policy>, RealType>& c)
   {
      BOOST_MATH_STD_USING // for ADL of std functions

      // Checking function argument
      RealType result = 0;
      const char* function = "quantile(const complemented2_type<hypergeometric_distribution<%1%>, %1%>&)";
      if (false == c.dist.check_params(function, &result)) return result;
      if(false == detail::check_probability(function, c.param, &result, Policy())) return result;

      return static_cast<RealType>(detail::hypergeometric_quantile(RealType(1 - c.param), c.param, c.dist.sample_count(), c.dist.defective(), c.dist.total(), Policy()));
   } // quantile
Exemplo n.º 12
0
   inline RealType quantile(const hypergeometric_distribution<RealType, Policy>& dist, const RealType& p)
   {
      BOOST_MATH_STD_USING // for ADL of std functions

         // Checking function argument
         RealType result = 0;
      const char* function = "boost::math::quantile(const hypergeometric_distribution<%1%>&, %1%)";
      if (false == dist.check_params(function, &result)) return result;
      if(false == detail::check_probability(function, p, &result, Policy())) return result;

      return static_cast<RealType>(detail::hypergeometric_quantile(p, RealType(1 - p), dist.sample_count(), dist.defective(), dist.total(), Policy()));
   } // quantile
Exemplo n.º 13
0
  void 
  TrialWaveFunction::evaluateDeltaLog(MCWalkerConfiguration &W, 
				      vector<RealType>& logpsi_opt)
  {
    for (int iw=0; iw<logpsi_opt.size(); iw++)
      logpsi_opt[iw] = RealType();
    for (int i=0,ii=RECOMPUTE_TIMER; i<Z.size(); i++,ii+=TIMER_SKIP) {
      myTimers[ii]->start();
      if (Z[i]->Optimizable)
	Z[i]->addLog(W, logpsi_opt);
      myTimers[ii]->stop();	
    }
  }
Exemplo n.º 14
0
 explicit param_type(RealType mean_lower = RealType(-1),
                     RealType mean_upper = RealType(+1),
                     RealType variance = RealType(1),
                     RealType correlation = RealType(0.3),
                     RealType coef_lower = RealType(-1),
                     RealType coef_upper = RealType(+1))
   : mean_lower(mean_lower),
     mean_upper(mean_upper),
     variance(variance),
     correlation(correlation),
     coef_lower(coef_lower),
     coef_upper(coef_upper) {
   check();
 }
Exemplo n.º 15
0
 /**
  * Return the value of the RandomNumber rounded to nearest floating point
  * number of type RealType and, if necessary, creating additional digits of
  * the number.
  *
  * @tparam RealType the floating point type to convert to.
  * @tparam Random the type of the random generator.
  * @param[in,out] r a random generator for generating the necessary digits.
  * @return the value of the RandomNumber rounded to a RealType.
  **********************************************************************/
 template<typename RealType, class Random> RealType Value(Random& r) {
   // Ignore the possibility of overflow here (OK because int doesn't
   // currently overflow any real type).  Assume the real type supports
   // denormalized numbers.  Need to treat rounding explicitly since the
   // missing digits always imply rounding up.
   STATIC_ASSERT(!std::numeric_limits<RealType>::is_integer,
                 "RandomNumber::Value: invalid real type RealType");
   const int digits = std::numeric_limits<RealType>::digits,
     min_exp = std::numeric_limits<RealType>::min_exponent;
   RealType y;
   int lead;               // Position of leading bit (0.5 = position 0)
   if (_n) lead = highest_bit_idx(_n);
   else {
     int i = 0;
     while ( Digit(r, i) == 0 && i < (-min_exp)/bits ) ++i;
     lead = highest_bit_idx(RawDigit(i)) - (i + 1) * bits;
     // To handle denormalized numbers set lead = max(lead, min_exp)
     lead = lead > min_exp ? lead : min_exp;
   }
   int trail = lead - digits; // Position of guard bit (0.5 = position 0)
   if (trail > 0) {
     y = RealType(_n & (~0U << trail));
     if (_n & (1U << (trail - 1)))
       y += std::pow(RealType(2), trail);
   } else {
     y = RealType(_n);
     int k = (-trail)/bits;  // Byte with guard bit
     if (Digit(r, k) & (1U << ((k + 1) * bits + trail - 1)))
       // If guard bit is set, round bit (some subsequent bit will be 1).
       y += std::pow(RealType(2), trail);
     // Byte with trailing bit (can be negative)
     k = (-trail - 1 + bits)/bits - 1;
     const RealType fact = std::pow(RealType(2), -bits);
     RealType mult = RealType(1);
     for (int i = 0; i <= k; ++i) {
       mult *= fact;
       y += mult *
         RealType(i < k ? RawDigit(i) :
                  RawDigit(i) & (~0U << ((k + 1) * bits + trail)));
     }
   }
   if (_s < 0) y *= -1;
   return y;
 }
Exemplo n.º 16
0
 /**
  * Constructs a uniform_real object. @c min and @c max are the
  * parameters of the distribution.
  *
  * Requires: min <= max
  */
 explicit uniform_real(RealType min_arg = RealType(0.0),
                       RealType max_arg = RealType(1.0))
   : base_type(min_arg, max_arg)
 {
     BOOST_ASSERT(min_arg < max_arg);
 }
Exemplo n.º 17
0
 /**
  * Constructs the parameters of a uniform_real distribution.
  *
  * Requires: min <= max
  */
 explicit param_type(RealType min_arg = RealType(0.0),
                     RealType max_arg = RealType(1.0))
   : base_type::param_type(min_arg, max_arg)
 {}
Exemplo n.º 18
0
    static void BlockHessenberg(
        MatrixView<T> A, VectorView<T> Ubeta)
    {
        // Much like the block version of Bidiagonalize, we try to maintain
        // the operation of several successive Householder matrices in
        // a block form, where the net Block Householder is I - YZYt.
        //
        // But as with the bidiagonlization algorithm (and unlike a simple
        // block QR decomposition), we update the matrix from both the left 
        // and the right, so we also need to keep track of the product
        // ZYtm in addition.
        //
        // The block update at the end of the block loop is
        // m' = (I-YZYt) m (I-YZtYt)
        //
        // The Y matrix is stored in the first K columns of m,
        // and the Hessenberg portion of these columns is updated as we go.
        // For the right-hand-side update, m -= mYZtYt, the m on the right
        // needs to be the full original matrix m, including the original
        // versions of these K columns.  Therefore, we can't wait until 
        // the end for this calculation.  
        //
        // Instead, we keep track of mYZt as we progress, so the final update
        // is:
        //
        // m' = (I-YZYt) (m - mYZt Y)
        //
        // We also need to do this same calculation for each column as we
        // progress through the block.
        //
        const ptrdiff_t N = A.rowsize();

#ifdef XDEBUG
        Matrix<T> A0(A);
#endif

        TMVAssert(A.rowsize() == A.colsize());
        TMVAssert(N > 0);
        TMVAssert(Ubeta.size() == N-1);
        TMVAssert(!Ubeta.isconj());
        TMVAssert(Ubeta.step()==1);

        ptrdiff_t ncolmax = MIN(HESS_BLOCKSIZE,N-1);
        Matrix<T,RowMajor> mYZt_full(N,ncolmax);
        UpperTriMatrix<T,NonUnitDiag|ColMajor> Z_full(ncolmax);

        T det(0); // Ignore Householder Determinant calculations
        T* Uj = Ubeta.ptr();
        for(ptrdiff_t j1=0;j1<N-1;) {
            ptrdiff_t j2 = MIN(N-1,j1+HESS_BLOCKSIZE);
            ptrdiff_t ncols = j2-j1;
            MatrixView<T> mYZt = mYZt_full.subMatrix(0,N-j1,0,ncols);
            UpperTriMatrixView<T> Z = Z_full.subTriMatrix(0,ncols);

            for(ptrdiff_t j=j1,jj=0;j<j2;++j,++jj,++Uj) { // jj = j-j1

                // Update current column of A
                //
                // m' = (I - YZYt) (m - mYZt Yt)
                // A(0:N,j)' = A(0:N,j) - mYZt(0:N,0:j) Y(j,0:j)t
                A.col(j,j1+1,N) -= mYZt.Cols(0,j) * A.row(j,0,j).Conjugate();
                //
                // A(0:N,j)'' = A(0:N,j) - Y Z Yt A(0:N,j)'
                // 
                // Let Y = (L)     where L is unit-diagonal, lower-triangular,
                //         (M)     and M is rectangular
                //
                LowerTriMatrixView<T> L = 
                    LowerTriMatrixViewOf(A.subMatrix(j1+1,j+1,j1,j),UnitDiag);
                MatrixView<T> M = A.subMatrix(j+1,N,j1,j);
                // Use the last column of Z as temporary storage for Yt A(0:N,j)'
                VectorView<T> YtAj = Z.col(jj,0,jj);
                YtAj = L.adjoint() * A.col(j,j1+1,j+1);
                YtAj += M.adjoint() * A.col(j,j+1,N);
                YtAj = Z.subTriMatrix(0,jj) * YtAj;
                A.col(j,j1+1,j+1) -= L * YtAj;
                A.col(j,j+1,N) -= M * YtAj;

                // Do the Householder reflection 
                VectorView<T> u = A.col(j,j+1,N);
                T bu = Householder_Reflect(u,det);
#ifdef TMVFLDEBUG
                TMVAssert(Uj >= Ubeta._first);
                TMVAssert(Uj < Ubeta._last);
#endif
                *Uj = bu;

                // Save the top of the u vector, which isn't actually part of u
                T& Atemp = *u.cptr();
                TMVAssert(IMAG(Atemp) == RealType(T)(0));
                RealType(T) Aorig = REAL(Atemp);
                Atemp = RealType(T)(1);

                // Update Z
                VectorView<T> Zj = Z.col(jj,0,jj);
                Zj = -bu * M.adjoint() * u;
                Zj = Z * Zj;
                Z(jj,jj) = -bu;

                // Update mYtZt:
                //
                // mYZt(0:N,j) = m(0:N,0:N) Y(0:N,0:j) Zt(0:j,j)
                //             = m(0:N,j+1:N) Y(j+1:N,j) Zt(j,j)
                //             = bu* m(0:N,j+1:N) u 
                //
                mYZt.col(jj) = CONJ(bu) * A.subMatrix(j1,N,j+1,N) * u;

                // Restore Aorig, which is actually part of the Hessenberg matrix.
                Atemp = Aorig;
            }

            // Update the rest of the matrix:
            // A(j2,j2-1) needs to be temporarily changed to 1 for use in Y
            T& Atemp = *(A.ptr() + j2*A.stepi() + (j2-1)*A.stepj());
            TMVAssert(IMAG(Atemp) == RealType(T)(0));
            RealType(T) Aorig = Atemp;
            Atemp = RealType(T)(1);

            // m' = (I-YZYt) (m - mYZt Y)
            MatrixView<T> m = A.subMatrix(j1,N,j2,N);
            ConstMatrixView<T> Y = A.subMatrix(j2+1,N,j1,j2);
            m -= mYZt * Y.adjoint();
            BlockHouseholder_LMult(Y,Z,m);

            // Restore A(j2,j2-1)
            Atemp = Aorig;
            j1 = j2;
        }

#ifdef XDEBUG
        Matrix<T> U(N,N,T(0));
        U.subMatrix(1,N,1,N) = A.subMatrix(1,N,0,N-1);
        U.upperTri().setZero();
        U(0,0) = T(1);
        Vector<T> Ubeta2(N);
        Ubeta2.subVector(1,N) = Ubeta;
        Ubeta2(0) = T(0);
        GetQFromQR(U.view(),Ubeta2);
        Matrix<T> H = A;
        if (N>2) LowerTriMatrixViewOf(H).offDiag(2).setZero();
        Matrix<T> AA = U*H*U.adjoint();
        if (Norm(A0-AA) > 0.001*Norm(A0)) {
            cerr<<"NonBlock Hessenberg: A = "<<Type(A)<<"  "<<A0<<endl;
            cerr<<"A = "<<A<<endl;
            cerr<<"Ubeta = "<<Ubeta<<endl;
            cerr<<"U = "<<U<<endl;
            cerr<<"H = "<<H<<endl;
            cerr<<"UHUt = "<<AA<<endl;
            Matrix<T,ColMajor> A2 = A0;
            Vector<T> Ub2(Ubeta.size());
            NonBlockHessenberg(A2.view(),Ub2.view());
            cerr<<"cf NonBlock: A -> "<<A2<<endl;
            cerr<<"Ubeta = "<<Ub2<<endl;
            abort();
        }
#endif
    }
Exemplo n.º 19
0
 explicit bernoulli_distribution(const RealType& p = RealType(0.5)) 
   : _p(p)
 {
   assert(p >= 0);
   assert(p <= 1);
 }
Exemplo n.º 20
0
      RealType quantile_imp(const binomial_distribution<RealType, Policy>& dist, const RealType& p, const RealType& q, bool comp)
      { // Quantile or Percent Point Binomial function.
        // Return the number of expected successes k,
        // for a given probability p.
        //
        // Error checks:
        BOOST_MATH_STD_USING  // ADL of std names
        RealType result = 0;
        RealType trials = dist.trials();
        RealType success_fraction = dist.success_fraction();
        if(false == binomial_detail::check_dist_and_prob(
           "boost::math::quantile(binomial_distribution<%1%> const&, %1%)",
           trials,
           success_fraction,
           p,
           &result, Policy()))
        {
           return result;
        }

        // Special cases:
        //
        if(p == 0)
        {  // There may actually be no answer to this question,
           // since the probability of zero successes may be non-zero,
           // but zero is the best we can do:
           return 0;
        }
        if(p == 1)
        {  // Probability of n or fewer successes is always one,
           // so n is the most sensible answer here:
           return trials;
        }
        if (p <= pow(1 - success_fraction, trials))
        { // p <= pdf(dist, 0) == cdf(dist, 0)
          return 0; // So the only reasonable result is zero.
        } // And root finder would fail otherwise.
        if(success_fraction == 1)
        {  // our formulae break down in this case:
           return p > 0.5f ? trials : 0;
        }

        // Solve for quantile numerically:
        //
        RealType guess = binomial_detail::inverse_binomial_cornish_fisher(trials, success_fraction, p, q, Policy());
        RealType factor = 8;
        if(trials > 100)
           factor = 1.01f; // guess is pretty accurate
        else if((trials > 10) && (trials - 1 > guess) && (guess > 3))
           factor = 1.15f; // less accurate but OK.
        else if(trials < 10)
        {
           // pretty inaccurate guess in this area:
           if(guess > trials / 64)
           {
              guess = trials / 4;
              factor = 2;
           }
           else
              guess = trials / 1024;
        }
        else
           factor = 2; // trials largish, but in far tails.

        typedef typename Policy::discrete_quantile_type discrete_quantile_type;
        boost::uintmax_t max_iter = policies::get_max_root_iterations<Policy>();
        return detail::inverse_discrete_quantile(
            dist,
            comp ? q : p,
            comp,
            guess,
            factor,
            RealType(1),
            discrete_quantile_type(),
            max_iter);
      } // quantile
Exemplo n.º 21
0
bool MomentumEstimator::putSpecial(xmlNodePtr cur, ParticleSet& elns, bool rootNode)
{
  OhmmsAttributeSet pAttrib;
  string hdf5_flag="yes";
  pAttrib.add(hdf5_flag,"hdf5");
  pAttrib.add(M,"samples");
  pAttrib.put(cur);
  hdf5_out = (hdf5_flag=="yes");
//     app_log()<<" MomentumEstimator::putSpecial "<<endl;
  xmlNodePtr kids=cur->children;
  while (kids!=NULL)
  {
    string cname((const char*)(kids->name));
//         app_log()<<" MomentumEstimator::cname : "<<cname<<endl;
    if (cname=="kpoints")
    {
      string ctype("manual");
      OhmmsAttributeSet pAttrib;
      pAttrib.add(ctype,"mode");
      pAttrib.add(kgrid,"grid");
      pAttrib.put(kids);
#if OHMMS_DIM==3
      int numqtwists(6*kgrid+3);
      std::vector<int> qk(0);
      mappedQtonofK.resize(numqtwists,qk);
      compQ.resize(numqtwists);
      RealType qn(4.0*M_PI*M_PI*std::pow(Lattice.Volume,-2.0/3.0));
      mappedQnorms.resize(numqtwists,qn*0.5/RealType(M));
      if (twist[0]==0)
        mappedQnorms[kgrid]=qn/RealType(M);
      if (twist[1]==0)
        mappedQnorms[3*kgrid+1]=qn/RealType(M);
      if (twist[2]==0)
        mappedQnorms[5*kgrid+2]=qn/RealType(M);
//             app_log()<<" Jnorm="<<qn<<endl;
      Q.resize(numqtwists);
      for (int i=-kgrid; i<(kgrid+1); i++)
      {
        PosType kpt;
        kpt[0]=i-twist[0];
        kpt[1]=i-twist[1];
        kpt[2]=i-twist[2];
        kpt=Lattice.k_cart(kpt);
        Q[i+kgrid]=abs(kpt[0]);
        Q[i+kgrid+(2*kgrid+1)]=abs(kpt[1]);
        Q[i+kgrid+(4*kgrid+2)]=abs(kpt[2]);
      }
      app_log()<<" Using all k-space points with (nx^2+ny^2+nz^2)^0.5 < "<< kgrid <<" for Momentum Distribution."<<endl;
      app_log()<<"  My twist is:"<<twist[0]<<"  "<<twist[1]<<"  "<<twist[2]<<endl;
      int indx(0);
      int kgrid_squared=kgrid*kgrid;
      for (int i=-kgrid; i<(kgrid+1); i++)
      {
        for (int j=-kgrid; j<(kgrid+1); j++)
        {
          for (int k=-kgrid; k<(kgrid+1); k++)
          {
            if (i*i+j*j+k*k<=kgrid_squared) //if (std::sqrt(i*i+j*j+k*k)<=kgrid)
            {
              PosType kpt;
              kpt[0]=i-twist[0];
              kpt[1]=j-twist[1];
              kpt[2]=k-twist[2];
              //convert to Cartesian: note that 2Pi is multiplied
              kpt=Lattice.k_cart(kpt);
              kPoints.push_back(kpt);
              mappedQtonofK[i+kgrid].push_back(indx);
              mappedQtonofK[j+kgrid+(2*kgrid+1)].push_back(indx);
              mappedQtonofK[k+kgrid+(4*kgrid+2)].push_back(indx);
              indx++;
            }
          }
        }
      }
#endif
#if OHMMS_DIM==2
      int numqtwists(4*kgrid+2);
      std::vector<int> qk(0);
      mappedQtonofK.resize(numqtwists,qk);
      compQ.resize(numqtwists);
      RealType qn(2.0*M_PI/std::sqrt(Lattice.Volume));
      mappedQnorms.resize(numqtwists,qn*0.5/RealType(M));
      if (twist[0]==0)
        mappedQnorms[kgrid]=qn/RealType(M);
      if (twist[1]==0)
        mappedQnorms[3*kgrid+1]=qn/RealType(M);
//             app_log()<<" Jnorm="<<qn<<endl;
      Q.resize(numqtwists);
      for (int i=-kgrid; i<(kgrid+1); i++)
      {
        PosType kpt;
        kpt[0]=i-twist[0];
        kpt[1]=i-twist[1];
        kpt=Lattice.k_cart(kpt);
        Q[i+kgrid]=abs(kpt[0]);
        Q[i+kgrid+(2*kgrid+1)]=abs(kpt[1]);
      }
      app_log()<<" Using all k-space points with (nx^2+ny^2)^0.5 < "<< kgrid <<" for Momentum Distribution."<<endl;
      app_log()<<"  My twist is:"<<twist[0]<<"  "<<twist[1]<<endl;
      int indx(0);
      int kgrid_squared=kgrid*kgrid;
      for (int i=-kgrid; i<(kgrid+1); i++)
      {
        for (int j=-kgrid; j<(kgrid+1); j++)
        {
          if (i*i+j*j<=kgrid_squared) //if (std::sqrt(i*i+j*j+k*k)<=kgrid)
          {
            PosType kpt;
            kpt[0]=i-twist[0];
            kpt[1]=j-twist[1];
            //convert to Cartesian: note that 2Pi is multiplied
            kpt=Lattice.k_cart(kpt);
            kPoints.push_back(kpt);
            mappedQtonofK[i+kgrid].push_back(indx);
            mappedQtonofK[j+kgrid+(2*kgrid+1)].push_back(indx);
            indx++;
          }
        }
      }
#endif
    }
    kids=kids->next;
  }
  if (rootNode)
  {
    std::stringstream sstr;
    sstr<<"Kpoints";
    for(int i(0); i<OHMMS_DIM; i++)
      sstr<<"_"<<round(100.0*twist[i]);
    sstr<<".dat";
    ofstream fout(sstr.str().c_str());
    fout.setf(ios::scientific, ios::floatfield);
    fout << "# mag_k        ";
    for(int i(0); i<OHMMS_DIM; i++)
      fout << "k_"<<i<<"           ";
    fout <<endl;
    for (int i=0; i<kPoints.size(); i++)
    {
      float khere(std::sqrt(dot(kPoints[i],kPoints[i])));
      fout<<khere;
      for(int j(0); j<OHMMS_DIM; j++)
        fout<<"   "<<kPoints[i][j];
      fout<<endl;
    }
    fout.close();
    sstr.str("");
    sstr<<"Qpoints";
    for(int i(0); i<OHMMS_DIM; i++)
      sstr<<"_"<<round(100.0*twist[i]);
    sstr<<".dat";
    ofstream qout(sstr.str().c_str());
    qout.setf(ios::scientific, ios::floatfield);
    qout << "# mag_q" << endl;
    for (int i=0; i<Q.size(); i++)
    {
      qout<<Q[i]<<endl;
    }
    qout.close();
  }
  nofK.resize(kPoints.size());
  norm_nofK=1.0/RealType(M);
  return true;
}
Exemplo n.º 22
0
 /**
  * Constructs parameters with a given lambda.
  *
  * Requires: lambda > 0
  */
 param_type(RealType lambda_arg = RealType(1.0))
   : _lambda(lambda_arg) { BOOST_ASSERT(_lambda > RealType(0)); }
 /**
  * Construct a param_type object.  @c k and @c p
  * are the parameters of the distribution.
  *
  * Requires: k >=0 && 0 <= p <= 1
  */
 explicit param_type(IntType k_arg = 1, RealType p_arg = RealType (0.5))
   : _k(k_arg), _p(p_arg)
 {}
Exemplo n.º 24
0
  void LangevinHullForceManager::postCalculation(){
  
    int nTriangles, thisFacet;
    RealType thisArea;
    vector<Triangle> sMesh;
    Triangle thisTriangle;
    vector<Triangle>::iterator face;
    vector<StuntDouble*> vertexSDs;
    vector<StuntDouble*>::iterator vertex;

    Vector3d unitNormal, centroid, facetVel;
    Vector3d langevinForce, vertexForce;
    Vector3d extPressure, randomForce, dragForce;

    Mat3x3d hydroTensor, S;
    vector<Vector3d> randNums;

    // Compute surface Mesh
    surfaceMesh_->computeHull(localSites_);
    // Get number of surface stunt doubles
    sMesh = surfaceMesh_->getMesh();
    nTriangles = sMesh.size();

    if (doThermalCoupling_) {
      // Generate all of the necessary random forces
      randNums = genTriangleForces(nTriangles, variance_);
    }
    
    // Loop over the mesh faces
    thisFacet = 0;
    for (face = sMesh.begin(); face != sMesh.end(); ++face){
      thisTriangle = *face;
      vertexSDs = thisTriangle.getVertices();
      thisArea = thisTriangle.getArea(); 
      unitNormal = thisTriangle.getUnitNormal();
      centroid = thisTriangle.getCentroid();
      facetVel = thisTriangle.getFacetVelocity();

      langevinForce = V3Zero;

      if (doPressureCoupling_) {
        extPressure = -unitNormal * (targetPressure_ * thisArea) /
          PhysicalConstants::energyConvert;
        langevinForce += extPressure;
      }

      if (doThermalCoupling_) {
        hydroTensor = thisTriangle.computeHydrodynamicTensor(viscosity_);      
        hydroTensor *= PhysicalConstants::viscoConvert;
        CholeskyDecomposition(hydroTensor, S);
        randomForce = S * randNums[thisFacet++];
        dragForce = -hydroTensor * facetVel;
        langevinForce += randomForce + dragForce;
      }
      
      // Apply triangle force to stuntdouble vertices
      for (vertex = vertexSDs.begin(); vertex != vertexSDs.end(); ++vertex){
	if ((*vertex) != NULL){
          vertexForce = langevinForce / RealType(3.0);
	  (*vertex)->addFrc(vertexForce);	   
	}  
      }
    } 
    
    veloMunge->removeComDrift();
    veloMunge->removeAngularDrift();
    
    Snapshot* currSnapshot = info_->getSnapshotManager()->getCurrentSnapshot();
    currSnapshot->setVolume(surfaceMesh_->getVolume());   
    currSnapshot->setHullVolume(surfaceMesh_->getVolume());
    ForceManager::postCalculation();   
  }
Exemplo n.º 25
0
 /**
  * Constructs a @c param_type object from the "alpha" and "beta"
  * parameters.
  *
  * Requires: alpha > 0 && beta > 0
  */
 param_type(const RealType& alpha_arg = RealType(1.0),
            const RealType& beta_arg = RealType(1.0))
   : _alpha(alpha_arg), _beta(beta_arg)
 {
 }
 /**
  * Construct a param_type object.  @c n
  * is the parameter of the distribution.
  *
  * Requires: t >=0 && 0 <= p <= 1
  */
 explicit param_type(RealType n_arg = RealType(1))
   : _n(n_arg)
 {}
Exemplo n.º 27
0
 /** 
  * Constructs the parameters of the distribution.
  *
  * Requires: 0 <= p <= 1
  */
 explicit param_type(RealType p_arg = RealType(0.5))
   : _p(p_arg)
 {
     BOOST_ASSERT(_p >= 0);
     BOOST_ASSERT(_p <= 1);
 }
Exemplo n.º 28
0
 /**
  * Constructs a @c param_type object, representing a distribution
  * that produces values uniformly distributed in the range [0, 1).
  */
 param_type()
 {
     _weights.push_back(WeightType(1));
     _intervals.push_back(RealType(0));
     _intervals.push_back(RealType(1));
 }
Exemplo n.º 29
0
 /** Constructs the parameters with p. */
 explicit param_type(RealType p_arg = RealType(0.5))
   : _p(p_arg)
 {
     BOOST_ASSERT(RealType(0) < _p && _p < RealType(1));
 }
Exemplo n.º 30
0
 /** Constructs the parameters of the cauchy distribution. */
 explicit param_type(RealType median_arg = RealType(0.0),
                     RealType sigma_arg = RealType(1.0))
   : _median(median_arg), _sigma(sigma_arg) {}