557 boost::ptr_vector<measurement<Matrix, SymmGroup> > meas;
559 int ntypes = alps::maximum_vertex_type(lattice.graph())+1;
561 std::vector<op_t> identitities(ntypes), fillings(ntypes);
562 for (
int type=0; type<ntypes; ++type) {
568 boost::regex average_expr(
"^MEASURE_AVERAGE\\[(.*)]$");
569 boost::regex locale_expr(
"^MEASURE_LOCAL\\[(.*)]$");
571 for (alps::Parameters::const_iterator it=parms.begin();it != parms.end();++it) {
572 std::string lhs = it->key();
575 enum {not_found, is_local, is_average} meas_found = not_found;
576 if (boost::regex_match(lhs, what, average_expr)) {
577 meas_found = is_average;
578 obsname = what.str(1);
580 if (boost::regex_match(lhs, what, locale_expr)) {
581 meas_found = is_local;
582 obsname = what.str(1);
585 if (meas_found != not_found) {
587 if (model.has_bond_operator(it->value())) {
588 BondOperator bondop = model.get_bond_operator(it->value());
590 typedef std::vector<op_t> op_vec;
591 typedef std::vector<std::pair<op_vec, bool> > bond_element;
592 typedef std::vector<boost::tuple<alps::expression::Term<value_type>,alps::SiteOperator,alps::SiteOperator > > V;
594 std::vector<op_t> tops1(ntypes), tops2(ntypes);
596 std::vector<bond_element> operators;
597 std::set<int> used1, used2;
598 for (
int type1=0; type1<ntypes; ++type1)
599 for (
int type2=0; type2<ntypes; ++type2) {
600 if (used1.find(type1) != used1.end() && used2.find(type2) != used2.end())
603 alps::SiteBasisDescriptor<I>
const& b1 = basis_descriptors[type1];
604 alps::SiteBasisDescriptor<I>
const& b2 = basis_descriptors[type2];
606 V ops = bondop.template templated_split<value_type>(b1,b2);
607 if (operators.size() < ops.size()) operators.resize(ops.size(), bond_element(2, std::make_pair(op_vec(ntypes),
false)) );
609 for (
typename V::iterator tit=ops.begin(); tit!=ops.end();++tit) {
610 SiteOperator op1 = boost::get<1>(*tit);
611 SiteOperator op2 = boost::get<2>(*tit);
613 if (!b1.has_operator(simplify_name(op1)) || !b2.has_operator(simplify_name(op2)))
616 unsigned ii = std::distance(ops.begin(), tit);
618 operators[ii][0].second = b1.is_fermionic(simplify_name(op1));
619 op_t & m = operators[ii][0].first[type1];
620 if (operators[ii][0].second)
624 m = boost::get<0>(*tit).value() * m;
627 operators[ii][1].second = b2.is_fermionic(simplify_name(op2));
628 op_t & m = operators[ii][1].first[type2];
635 if (num_done == ops.size()) { used1.insert(type1); used2.insert(type2); }
638 if (meas_found == is_average)
643 std::vector<op_t> tops(ntypes);
644 for (
int type=0; type<ntypes; ++type) {
645 alps::SiteBasisDescriptor<I>
const& b = basis_descriptors[type];
646 if (b.has_operator(it->value())) {
647 SiteOperator op = make_site_term(it->value(), parms);
648 if (b.is_fermionic(simplify_name(op)))
649 throw std::runtime_error(
"Cannot measure local fermionic operators.");
654 if (meas_found == is_average)
664 boost::regex expression(
"^MEASURE_LOCAL_AT\\[(.*)]$");
666 for (alps::Parameters::const_iterator it=parms.begin();it != parms.end();++it) {
667 std::string lhs = it->key();
668 std::string value = it->value();
669 if (boost::regex_match(lhs, what, expression)) {
672 std::string name = what.str(1);
674 boost::char_separator<char> part_sep(
"|");
675 tokenizer part_tokens(value, part_sep);
676 std::vector<std::string> parts;
677 std::copy( part_tokens.begin(), part_tokens.end(), std::back_inserter(parts) );
679 if (parts.size() != 2)
680 throw std::runtime_error(
"MEASURE_LOCAL_AT must contain a `|` delimiter.");
684 boost::tie(operators, boost::tuples::ignore) = operators_for_meas(parts[0],
false);
687 std::vector<std::vector<std::size_t> > positions;
688 boost::regex pos_re(
"\\(([^(^)]*)\\)");
689 boost::sregex_token_iterator it_pos(parts[1].begin(), parts[1].end(), pos_re, 1);
690 boost::sregex_token_iterator it_pos_end;
691 for (; it_pos != it_pos_end; ++it_pos)
693 boost::char_separator<char> int_sep(
", ");
694 std::string raw = *it_pos;
695 tokenizer int_tokens(raw, int_sep);
697 std::vector<std::size_t> pos;
698 BOOST_FOREACH(std::string t, int_tokens) {
699 pos.push_back(boost::lexical_cast<std::size_t, std::string>(t));
701 positions.push_back(pos);
704 throw std::runtime_error(
"Number of fermionic operators has to be even.");
712 boost::regex expression(
"^MEASURE_MPS_BONDS\\[(.*)]$");
714 for (alps::Parameters::const_iterator it=parms.begin();it != parms.end();++it) {
715 std::string lhs = it->key();
718 if (boost::regex_match(lhs, what, expression)) {
719 throw std::runtime_error(
"MEASURE_MPS_BONDS not yet implemented in new version.");
731 boost::regex expression(
"^MEASURE_CORRELATIONS\\[(.*)]$");
732 boost::regex expression_half(
"^MEASURE_HALF_CORRELATIONS\\[(.*)]$");
733 boost::regex expression_nn(
"^MEASURE_NN_CORRELATIONS\\[(.*)]$");
734 boost::regex expression_halfnn(
"^MEASURE_HALF_NN_CORRELATIONS\\[(.*)]$");
736 for (alps::Parameters::const_iterator it=parms.begin();it != parms.end();++it) {
737 std::string lhs = it->key();
739 std::string name, value;
740 bool half_only=
true, nearest_neighbors_only=
false;
741 if (boost::regex_match(lhs, what, expression)) {
745 nearest_neighbors_only =
false;
747 if (boost::regex_match(lhs, what, expression_half)) {
751 nearest_neighbors_only =
false;
753 if (boost::regex_match(lhs, what, expression_nn)) {
757 nearest_neighbors_only =
true;
759 if (boost::regex_match(lhs, what, expression_halfnn)) {
763 nearest_neighbors_only =
true;
767 std::vector<std::string> value_split;
768 boost::split( value_split, value, boost::is_any_of(
"@"));
772 boost::tie(operators, ops_type) = operators_for_meas(value_split[0],
true);
774 if (ops_type == 2) nearest_neighbors_only =
true;
777 std::vector<std::size_t> positions;
778 if (value_split.size() > 1) {
779 boost::char_separator<char> pos_sep(
", ");
780 tokenizer pos_tokens(value_split[1], pos_sep);
781 BOOST_FOREACH(std::string t, pos_tokens) {
782 positions.push_back(boost::lexical_cast<std::size_t, std::string>(t));
787 half_only, nearest_neighbors_only,
virtual op_t const & get_operator(std::string const &name, size_t type) const
virtual op_t const & identity_matrix(size_t type) const
std::vector< std::pair< std::vector< op_t >, bool > > meas_operators_type
void gemm(block_matrix< Matrix1, SymmGroup > const &A, block_matrix< Matrix2, SymmGroup > const &B, block_matrix< Matrix3, SymmGroup > &C)
virtual op_t const & filling_matrix(size_t type) const