ALPS MPS Codes
Reference documentation.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Public Types | Public Member Functions | Protected Attributes | List of all members
ALPSModel< Matrix, SymmGroup > Class Template Reference

#include <model.hpp>

Inheritance diagram for ALPSModel< Matrix, SymmGroup >:
model_impl< Matrix, SymmGroup >

Public Types

typedef base::table_type table_type
 
typedef base::table_ptr table_ptr
 
typedef base::tag_type tag_type
 
typedef base::term_descriptor value_term
 
typedef alps::expression::Term
< value_type > 
expression_type
 
typedef ::term_descriptor
< expression_type
expression_term
 
typedef base::terms_type terms_type
 
typedef base::op_t op_t
 
typedef base::measurements_type measurements_type
 
typedef base::initializer_ptr initializer_ptr
 
typedef base::size_t size_t
 
typedef std::vector< std::pair
< std::vector< op_t >, bool > > 
meas_operators_type
 
typedef std::pair< std::string,
int > 
opkey_type
 
typedef std::map< opkey_type,
tag_type
opmap_type
 
typedef opmap_type::const_iterator opmap_const_iterator
 
typedef SymmGroup::charge charge
 
typedef ::term_descriptor
< typename Matrix::value_type > 
term_descriptor
 

Public Member Functions

 ALPSModel (Lattice const &lattice_, const alps::Parameters &parms_)
 
void update (BaseParameters const &p)
 
Index< SymmGroup > const & phys_dim (size_t type) const
 
SymmGroup::charge total_quantum_numbers (BaseParameters &parms_) const
 
tag_type identity_matrix_tag (size_t type) const
 
tag_type filling_matrix_tag (size_t type) const
 
tag_type get_operator_tag (std::string const &name, size_t type) const
 
table_ptr operators_table () const
 
initializer_ptr initializer (Lattice const &lat, BaseParameters &p_) const
 
boost::ptr_vector< measurement
< Matrix, SymmGroup > > 
measurements () const
 
virtual op_t const & identity_matrix (size_t type) const
 
virtual op_t const & filling_matrix (size_t type) const
 
virtual terms_type const & hamiltonian_terms () const
 
virtual op_t const & get_operator (std::string const &name, size_t type) const
 

Protected Attributes

terms_type terms_
 

Detailed Description

template<class Matrix, class SymmGroup>
class ALPSModel< Matrix, SymmGroup >

Definition at line 55 of file model.hpp.

Member Typedef Documentation

template<class Matrix, class SymmGroup>
typedef SymmGroup::charge ALPSModel< Matrix, SymmGroup >::charge

Definition at line 94 of file model.hpp.

template<class Matrix, class SymmGroup>
typedef ::term_descriptor<expression_type> ALPSModel< Matrix, SymmGroup >::expression_term

Definition at line 80 of file model.hpp.

template<class Matrix, class SymmGroup>
typedef alps::expression::Term<value_type> ALPSModel< Matrix, SymmGroup >::expression_type

Definition at line 79 of file model.hpp.

template<class Matrix, class SymmGroup>
typedef base::initializer_ptr ALPSModel< Matrix, SymmGroup >::initializer_ptr

Definition at line 84 of file model.hpp.

template<class Matrix, class SymmGroup>
typedef std::vector<std::pair<std::vector<op_t>, bool> > ALPSModel< Matrix, SymmGroup >::meas_operators_type

Definition at line 88 of file model.hpp.

template<class Matrix, class SymmGroup>
typedef base::measurements_type ALPSModel< Matrix, SymmGroup >::measurements_type

Definition at line 83 of file model.hpp.

template<class Matrix, class SymmGroup>
typedef base::op_t ALPSModel< Matrix, SymmGroup >::op_t

Definition at line 82 of file model.hpp.

template<class Matrix, class SymmGroup>
typedef std::pair<std::string, int> ALPSModel< Matrix, SymmGroup >::opkey_type

Definition at line 90 of file model.hpp.

template<class Matrix, class SymmGroup>
typedef opmap_type::const_iterator ALPSModel< Matrix, SymmGroup >::opmap_const_iterator

Definition at line 92 of file model.hpp.

template<class Matrix, class SymmGroup>
typedef std::map<opkey_type, tag_type> ALPSModel< Matrix, SymmGroup >::opmap_type

Definition at line 91 of file model.hpp.

template<class Matrix, class SymmGroup>
typedef base::size_t ALPSModel< Matrix, SymmGroup >::size_t

Definition at line 86 of file model.hpp.

template<class Matrix, class SymmGroup>
typedef base::table_ptr ALPSModel< Matrix, SymmGroup >::table_ptr

Definition at line 75 of file model.hpp.

template<class Matrix, class SymmGroup>
typedef base::table_type ALPSModel< Matrix, SymmGroup >::table_type

Definition at line 74 of file model.hpp.

template<class Matrix, class SymmGroup>
typedef base::tag_type ALPSModel< Matrix, SymmGroup >::tag_type

Definition at line 76 of file model.hpp.

template<class Matrix, class SymmGroup>
typedef ::term_descriptor<typename Matrix::value_type> model_impl< Matrix, SymmGroup >::term_descriptor
inherited

Definition at line 55 of file model.h.

template<class Matrix, class SymmGroup>
typedef base::terms_type ALPSModel< Matrix, SymmGroup >::terms_type

Definition at line 81 of file model.hpp.

template<class Matrix, class SymmGroup>
typedef base::term_descriptor ALPSModel< Matrix, SymmGroup >::value_term

Definition at line 78 of file model.hpp.

Constructor & Destructor Documentation

template<class Matrix, class SymmGroup>
ALPSModel< Matrix, SymmGroup >::ALPSModel ( Lattice const &  lattice_,
const alps::Parameters &  parms_ 
)
inline

Definition at line 97 of file model.hpp.

98  : parms(parms_)
99  , raw_lattice(lattice_)
100  , lattice(detail::get_graph(lattice_))
101  , model(lattice, parms, true)
102  , tag_handler(new table_type())
103  {
104  locale_shared i;
105 
106  size_t num_vertex_types = alps::maximum_vertex_type(lattice.graph())+1;
107  symm_basis.reserve(num_vertex_types);
108  basis_descriptors.reserve(num_vertex_types);
109  site_bases.reserve(num_vertex_types);
110 
111  /// Parsing conserved quantum numbers
112  for (int type=0; type<=alps::maximum_vertex_type(lattice.graph()); ++type) {
113  std::set<std::string> type_qn = model.quantum_numbers(type);
114  all_qn.insert(type_qn.begin(), type_qn.end());
115  }
116 
117  if (parms.defined("CONSERVED_QUANTUMNUMBERS")) {
118  boost::char_separator<char> sep(" ,");
119  std::string qn_string = parms["CONSERVED_QUANTUMNUMBERS"];
120  tokenizer qn_tokens(qn_string, sep);
121  int n=0;
122  for (tokenizer::iterator it=qn_tokens.begin(); it != qn_tokens.end(); it++) {
123  if (parms.defined(*it + "_total")) {
124  if (all_qn.find(*it) != all_qn.end())
125  all_conserved_qn.insert( std::make_pair(*it, n++) );
126  else
127  throw std::runtime_error("quantumnumber "+(*it)+" not defined in the model.");
128  }
129  }
130  }
131 
132  /// Load all possible basis
133  for (int type=0; type<=alps::maximum_vertex_type(lattice.graph()); ++type) {
134  basis_descriptors.push_back(model.site_basis(type));
135  site_bases.push_back(alps::site_basis<I>(basis_descriptors[type]));
136  symm_basis.push_back(symmetric_basis_descriptor<SymmGroup>(basis_descriptors[type], all_conserved_qn));
137 
138  op_t ident, fill;
139  for (int i=0; i<symm_basis[type].size(); ++i) {
140  charge c = symm_basis[type].charge(i);
141  size_t bsize = symm_basis[type].block_size(i);
142  // maquis::cout << "Inserting " << c << " for " << site_bases[type][i] << std::endl;
143 
144  if (!ident.has_block(c, c))
145  ident.insert_block(Matrix::identity_matrix(bsize), c, c);
146 
147  int sign = (alps::is_fermionic(basis_descriptors[type], site_bases[type][i])) ? -1 : 1;
148  if (!fill.has_block(c, c))
149  fill.insert_block(Matrix::identity_matrix(bsize), c, c);
150  fill(symm_basis[type].coords(i), symm_basis[type].coords(i)) = sign;
151  }
152  operators[opkey_type("ident", type)] = tag_handler->register_op(ident, tag_detail::bosonic);
153  operators[opkey_type("fill", type)] = tag_handler->register_op(fill, tag_detail::bosonic);
154  }
155 
156 
157  /// site_term loop with cache to avoid recomputing matrices
158  std::vector<std::vector<std::pair<value_type, tag_type> > > site_terms(num_vertex_types);
159  for (graph_type::site_iterator it=lattice.sites().first; it!=lattice.sites().second; ++it) {
160  int p = lattice.vertex_index(*it);
161  int type = lattice.site_type(*it);
162 
163  if (site_terms[type].size() == 0) {
164  typedef std::vector<boost::tuple<alps::expression::Term<value_type>,alps::SiteOperator> > V;
165  V ops = model.site_term(type).template templated_split<value_type>();
166 
167  for (int n=0; n<ops.size(); ++n) {
168  SiteOperator op = boost::get<1>(ops[n]);
169  opmap_const_iterator match = operators.find(opkey_type(simplify_name(op), type));
170  if (match == operators.end())
171  match = register_operator(op, type, parms);
172  // site_terms[type].push_back( std::make_pair(boost::get<0>(ops[n]).value(), match->second) );
173 
174  expression_term term;
175  term.coeff = boost::get<0>(ops[n]);
176  term.is_fermionic = false;
177  term.push_back( boost::make_tuple(p, match->second) );
178  expression_coeff.insert( std::make_pair(term.coeff, value_type()) );
179  expression_terms.push_back(term);
180  }
181  }
182 
183  // All site terms summed into one
184 // if (site_terms[type].size() > 0) {
185 // opmap_const_iterator match = operators.find(opkey_type("site_terms", type));
186 // if (match == operators.end()) {
187 // op_t op_matrix;
188 // for (int n=0; n<site_terms[type].size(); ++n)
189 // op_matrix += site_terms[type][n].first * tag_handler->get_op(site_terms[type][n].second);
190 // tag_type mytag = tag_handler->register_op(op_matrix, tag_detail::bosonic);
191 // boost::tie(match, boost::tuples::ignore) = operators.insert( std::make_pair(opkey_type("site_terms", type), mytag) );
192 // }
193 //
194 // term_descriptor term;
195 // term.coeff = 1.;
196 // term.is_fermionic = false;
197 // term.push_back( boost::make_tuple(p, match->second) );
198 // this->terms_.push_back(term);
199 // }
200 
201 
202  }
203 
204  /// bond terms loop
205  for (graph_type::bond_iterator it=lattice.bonds().first; it!=lattice.bonds().second; ++it) {
206  int p_s = lattice.source(*it);
207  int p_t = lattice.target(*it);
208  int type = lattice.bond_type(*it);
209  int type_s = lattice.site_type(lattice.source(*it));
210  int type_t = lattice.site_type(lattice.target(*it));
211 
212  bool wrap_pbc = boost::get(alps::boundary_crossing_t(), lattice.graph(), *it);
213 
214  BondOperator bondop = model.bond_term(type);
215 
216  typedef std::vector<boost::tuple<alps::expression::Term<value_type>,alps::SiteOperator,alps::SiteOperator > > V;
217  alps::SiteBasisDescriptor<I> const& b1 = basis_descriptors[type_s];
218  alps::SiteBasisDescriptor<I> const& b2 = basis_descriptors[type_t];
219 
220 
221  V ops = bondop.template templated_split<value_type>(b1,b2);
222  for (typename V::iterator tit=ops.begin(); tit!=ops.end();++tit) {
223  SiteOperator op1 = boost::get<1>(*tit);
224  SiteOperator op2 = boost::get<2>(*tit);
225 
226  opmap_const_iterator match1 = operators.find(opkey_type(simplify_name(op1), type_s));
227  if (match1 == operators.end())
228  match1 = register_operator(op1, type_s, parms);
229  opmap_const_iterator match2 = operators.find(opkey_type(simplify_name(op2), type_t));
230  if (match2 == operators.end())
231  match2 = register_operator(op2, type_t, parms);
232 
233  bool with_sign = fermionic(b1, op1, b2, op2);
234 
235  expression_term term;
236  term.coeff = boost::get<0>(*tit);
237  term.is_fermionic = with_sign;
238 
239  {
240  tag_type mytag = match1->second;
241  if (with_sign && !wrap_pbc) {
242  // Note inverse notation because of notation in operator.
243  std::pair<tag_type, value_type> ptag = tag_handler->get_product_tag(operators[opkey_type("fill",type_s)],
244  mytag);
245  mytag = ptag.first;
246  term.coeff *= ptag.second;
247  }
248  if (with_sign && wrap_pbc)
249  term.coeff *= value_type(-1.);
250  term.push_back( boost::make_tuple(p_s, mytag) );
251  }
252  {
253  tag_type mytag = match2->second;
254  if (with_sign && wrap_pbc) {
255  // Note inverse notation because of notation in operator.
256  std::pair<tag_type, value_type> ptag = tag_handler->get_product_tag(operators[opkey_type("fill",type_t)],
257  mytag);
258  mytag = ptag.first;
259  term.coeff *= ptag.second;
260  }
261  term.push_back( boost::make_tuple(p_t, mytag) );
262  }
263 
264  expression_coeff.insert( std::make_pair(term.coeff, value_type()) );
265  expression_terms.push_back(term);
266  }
267  }
268 
269  generate_terms();
270  }
base::op_t op_t
Definition: model.hpp:82
alps::graph_helper const & get_graph(Lattice const &lat_)
Definition: model.hpp:47
::term_descriptor< expression_type > expression_term
Definition: model.hpp:80
base::table_type table_type
Definition: model.hpp:74
SymmGroup::charge charge
Definition: model.hpp:94
block_matrix< Matrix, SymmGroup > identity_matrix(Index< SymmGroup > const &size)
std::pair< std::string, int > opkey_type
Definition: model.hpp:90
std::size_t locale_shared
opmap_type::const_iterator opmap_const_iterator
Definition: model.hpp:92
base::tag_type tag_type
Definition: model.hpp:76

Member Function Documentation

template<class Matrix, class SymmGroup>
virtual op_t const& model_impl< Matrix, SymmGroup >::filling_matrix ( size_t  type) const
inlinevirtualinherited

Definition at line 69 of file model.h.

69 { return operators_table()->get_op( filling_matrix_tag(type) ); }
virtual table_ptr operators_table() const =0
virtual tag_type filling_matrix_tag(size_t type) const =0
template<class Matrix, class SymmGroup>
tag_type ALPSModel< Matrix, SymmGroup >::filling_matrix_tag ( size_t  type) const
inlinevirtual

Implements model_impl< Matrix, SymmGroup >.

Definition at line 293 of file model.hpp.

294  {
295  return operators[opkey_type("fill", type)]; // TODO: avoid using map here
296  }
std::pair< std::string, int > opkey_type
Definition: model.hpp:90
template<class Matrix, class SymmGroup>
virtual op_t const& model_impl< Matrix, SymmGroup >::get_operator ( std::string const &  name,
size_t  type 
) const
inlinevirtualinherited

Definition at line 77 of file model.h.

77 { return operators_table()->get_op( get_operator_tag(name, type) ); }
virtual tag_type get_operator_tag(std::string const &name, size_t type) const =0
virtual table_ptr operators_table() const =0
template<class Matrix, class SymmGroup>
tag_type ALPSModel< Matrix, SymmGroup >::get_operator_tag ( std::string const &  name,
size_t  type 
) const
inlinevirtual

Implements model_impl< Matrix, SymmGroup >.

Definition at line 298 of file model.hpp.

299  {
300  if (name == "id" || name == "ident" || name == "identity") {
301  return operators[opkey_type("ident", type)];
302  } else {
303  opmap_const_iterator match = operators.find(opkey_type(name, type));
304  if (match == operators.end()) {
305  SiteOperator op = make_site_term(name, parms);
306  match = register_operator(op, type, parms);
307  }
308  return match->second;
309  }
310  }
std::pair< std::string, int > opkey_type
Definition: model.hpp:90
opmap_type::const_iterator opmap_const_iterator
Definition: model.hpp:92
template<class Matrix, class SymmGroup>
virtual terms_type const& model_impl< Matrix, SymmGroup >::hamiltonian_terms ( ) const
inlinevirtualinherited

Definition at line 74 of file model.h.

74 { return terms_; }
terms_type terms_
Definition: model.h:85
template<class Matrix, class SymmGroup>
virtual op_t const& model_impl< Matrix, SymmGroup >::identity_matrix ( size_t  type) const
inlinevirtualinherited

Definition at line 67 of file model.h.

67 { return operators_table()->get_op( identity_matrix_tag(type) ); }
virtual table_ptr operators_table() const =0
virtual tag_type identity_matrix_tag(size_t type) const =0
template<class Matrix, class SymmGroup>
tag_type ALPSModel< Matrix, SymmGroup >::identity_matrix_tag ( size_t  type) const
inlinevirtual

Implements model_impl< Matrix, SymmGroup >.

Definition at line 288 of file model.hpp.

289  {
290  return operators[opkey_type("ident", type)]; // TODO: avoid using map here
291  }
std::pair< std::string, int > opkey_type
Definition: model.hpp:90
template<class Matrix , class SymmGroup >
ALPSModel< Matrix, SymmGroup >::initializer_ptr ALPSModel< Matrix, SymmGroup >::initializer ( Lattice const &  lat,
BaseParameters p_ 
) const
virtual

Reimplemented from model_impl< Matrix, SymmGroup >.

Definition at line 506 of file model.hpp.

507 {
508  if ( p_["init_state"] == "local_quantumnumbers" ) {
509  int max_site_type = 0;
510  std::vector<int> site_types(lat.size(), 0);
511  for (int p = 0; p < lat.size(); ++p) {
512  site_types[p] = lat.get_prop<int>("type", p);
513  max_site_type = std::max(site_types[p], max_site_type);
514  }
515 
516  std::cout << "site_types: ";
517  std::copy(site_types.begin(), site_types.end(), std::ostream_iterator<int>(std::cout, " "));
518  std::cout << std::endl;
519 
520  std::vector<Index<SymmGroup> > phys_bases(symm_basis.size());
521  for (int type = 0; type < phys_bases.size(); ++type) {
522  phys_bases[type] = symm_basis[type].phys_dim();
523  maquis::cout << "phys["<< type <<"]: " << phys_bases[type] << std::endl;
524  }
525 
526  // TODO: avoid QN of size=1
527  std::map<std::string, std::vector<double> > initial_local_charges;
528  for(std::set<std::string>::const_iterator it = all_qn.begin(); it != all_qn.end(); ++it) {
529  const std::string pname = "initial_local_" + *it;
530  if (!p_.defined(pname))
531  throw std::runtime_error(pname + " required for local_quantumnumbers initial state.");
532  initial_local_charges[*it] = p_[pname].as<std::vector<double> >();
533  }
534 
535  std::vector<boost::tuple<charge, size_t> > state(lat.size());
536  for (size_t p=0; p<lat.size(); ++p) {
537  const int type = site_types[p];
538  alps::SiteBasisDescriptor<I> const& b = basis_descriptors[type];
539  alps::site_state<I> local_state;
540  for (size_t i=0; i<b.size(); ++i)
541  local_state.push_back( initial_local_charges[b[i].name()][p] );
542  state[p] = symm_basis[type].coords(site_bases[type].index(local_state));
543  }
544 
545  return initializer_ptr(new basis_mps_init_generic<Matrix, SymmGroup>(state, phys_bases, this->total_quantum_numbers(p_), site_types));
546  } else {
547  return base::initializer(lat, p_);
548  }
549 }
SymmGroup::charge total_quantum_numbers(BaseParameters &parms_) const
Definition: model.hpp:283
virtual initializer_ptr initializer(Lattice const &lat, BaseParameters &parms) const
base::initializer_ptr initializer_ptr
Definition: model.hpp:84
template<class Matrix , class SymmGroup >
boost::ptr_vector< measurement< Matrix, SymmGroup > > ALPSModel< Matrix, SymmGroup >::measurements ( ) const
virtual

Implements model_impl< Matrix, SymmGroup >.

Definition at line 555 of file model.hpp.

556 {
557  boost::ptr_vector<measurement<Matrix, SymmGroup> > meas;
558 
559  int ntypes = alps::maximum_vertex_type(lattice.graph())+1;
560 
561  std::vector<op_t> identitities(ntypes), fillings(ntypes);
562  for (int type=0; type<ntypes; ++type) {
563  identitities[type] = this->identity_matrix(type);
564  fillings[type] = this->filling_matrix(type);
565  }
566 
567  {
568  boost::regex average_expr("^MEASURE_AVERAGE\\[(.*)]$");
569  boost::regex locale_expr("^MEASURE_LOCAL\\[(.*)]$");
570  boost::smatch what;
571  for (alps::Parameters::const_iterator it=parms.begin();it != parms.end();++it) {
572  std::string lhs = it->key();
573  std::string obsname;
574 
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);
579  }
580  if (boost::regex_match(lhs, what, locale_expr)) {
581  meas_found = is_local;
582  obsname = what.str(1);
583  }
584 
585  if (meas_found != not_found) {
586 
587  if (model.has_bond_operator(it->value())) {
588  BondOperator bondop = model.get_bond_operator(it->value());
589 
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;
593 
594  std::vector<op_t> tops1(ntypes), tops2(ntypes);
595 
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())
601  continue;
602 
603  alps::SiteBasisDescriptor<I> const& b1 = basis_descriptors[type1];
604  alps::SiteBasisDescriptor<I> const& b2 = basis_descriptors[type2];
605 
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)) );
608  int num_done = 0;
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);
612 
613  if (!b1.has_operator(simplify_name(op1)) || !b2.has_operator(simplify_name(op2)))
614  continue;
615 
616  unsigned ii = std::distance(ops.begin(), tit);
617  {
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)
621  gemm(fillings[type1], this->get_operator(simplify_name(op1), type1), m); // Note inverse notation because of notation in operator.
622  else
623  m = this->get_operator(simplify_name(op1), type1);
624  m = boost::get<0>(*tit).value() * m;
625  }
626  {
627  operators[ii][1].second = b2.is_fermionic(simplify_name(op2));
628  op_t & m = operators[ii][1].first[type2];
629  m = this->get_operator(simplify_name(op2), type2);
630  }
631 
632  num_done += 1;
633  }
634 
635  if (num_done == ops.size()) { used1.insert(type1); used2.insert(type2); }
636  }
637 
638  if (meas_found == is_average)
639  meas.push_back( new measurements::average<Matrix, SymmGroup>(obsname, raw_lattice, identitities, fillings, operators) );
640  else
641  meas.push_back( new measurements::local<Matrix, SymmGroup>(obsname, raw_lattice, identitities, fillings, operators) );
642  } else {
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.");
650 
651  tops[type] = this->get_operator(it->value(), type);
652  }
653  }
654  if (meas_found == is_average)
655  meas.push_back( new measurements::average<Matrix, SymmGroup>(obsname, raw_lattice, identitities, fillings, tops) );
656  else
657  meas.push_back( new measurements::local<Matrix, SymmGroup>(obsname, raw_lattice, identitities, fillings, tops) );
658  }
659  }
660  }
661  }
662 
663  { // Example: MEASURE_LOCAL_AT[Custom correlation] = "bdag:b|(1,2),(3,4),(5,6)"
664  boost::regex expression("^MEASURE_LOCAL_AT\\[(.*)]$");
665  boost::smatch what;
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)) {
670  int f_ops = 0;
671 
672  std::string name = what.str(1);
673 
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) );
678 
679  if (parts.size() != 2)
680  throw std::runtime_error("MEASURE_LOCAL_AT must contain a `|` delimiter.");
681 
682  /// parse operators
683  meas_operators_type operators;
684  boost::tie(operators, boost::tuples::ignore) = operators_for_meas(parts[0], false);
685 
686  /// parse positions
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)
692  {
693  boost::char_separator<char> int_sep(", ");
694  std::string raw = *it_pos;
695  tokenizer int_tokens(raw, int_sep);
696 
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));
700  }
701  positions.push_back(pos);
702  }
703  if (f_ops % 2 != 0)
704  throw std::runtime_error("Number of fermionic operators has to be even.");
705 
706  meas.push_back( new measurements::local_at<Matrix, SymmGroup>(name, raw_lattice, positions, identitities, fillings, operators) );
707  }
708  }
709  }
710 
711  {
712  boost::regex expression("^MEASURE_MPS_BONDS\\[(.*)]$");
713  boost::smatch what;
714  for (alps::Parameters::const_iterator it=parms.begin();it != parms.end();++it) {
715  std::string lhs = it->key();
716  std::string value;
717 
718  if (boost::regex_match(lhs, what, expression)) {
719  throw std::runtime_error("MEASURE_MPS_BONDS not yet implemented in new version.");
720 // mterm_t term;
721 // term.name = what.str(1);
722 // term.type = mterm_t::MPSBonds;
723 //
724 // fill_meas_with_operators(term, it->value(), true);
725 // meas.add_term(term);
726  }
727  }
728  }
729 
730  {
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\\[(.*)]$");
735  boost::smatch what;
736  for (alps::Parameters::const_iterator it=parms.begin();it != parms.end();++it) {
737  std::string lhs = it->key();
738 
739  std::string name, value;
740  bool half_only=true, nearest_neighbors_only=false;
741  if (boost::regex_match(lhs, what, expression)) {
742  value = it->value();
743  name = what.str(1);
744  half_only = false;
745  nearest_neighbors_only = false;
746  }
747  if (boost::regex_match(lhs, what, expression_half)) {
748  value = it->value();
749  name = what.str(1);
750  half_only = true;
751  nearest_neighbors_only = false;
752  }
753  if (boost::regex_match(lhs, what, expression_nn)) {
754  value = it->value();
755  name = what.str(1);
756  half_only = false;
757  nearest_neighbors_only = true;
758  }
759  if (boost::regex_match(lhs, what, expression_halfnn)) {
760  value = it->value();
761  name = what.str(1);
762  half_only = true;
763  nearest_neighbors_only = true;
764  }
765  if (!name.empty()) {
766  /// split op1:op2:...@p1,p2,p3,... into {op1:op2:...}, {p1,p2,p3,...}
767  std::vector<std::string> value_split;
768  boost::split( value_split, value, boost::is_any_of("@"));
769 
770  meas_operators_type operators;
771  short ops_type;
772  boost::tie(operators, ops_type) = operators_for_meas(value_split[0], true);
773 
774  if (ops_type == 2) nearest_neighbors_only = true;
775 
776  /// parse positions p1,p2,p3,... (or `space`)
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));
783  }
784  }
785 
786  meas.push_back( new measurements::correlations<Matrix, SymmGroup>(name, raw_lattice, identitities, fillings, operators,
787  half_only, nearest_neighbors_only,
788  positions) );
789  }
790  }
791  }
792 
793 
794  return meas;
795 }
virtual op_t const & get_operator(std::string const &name, size_t type) const
Definition: model.h:77
base::op_t op_t
Definition: model.hpp:82
virtual op_t const & identity_matrix(size_t type) const
Definition: model.h:67
std::vector< std::pair< std::vector< op_t >, bool > > meas_operators_type
Definition: model.hpp:88
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
Definition: model.h:69
template<class Matrix, class SymmGroup>
table_ptr ALPSModel< Matrix, SymmGroup >::operators_table ( ) const
inlinevirtual

Implements model_impl< Matrix, SymmGroup >.

Definition at line 312 of file model.hpp.

313  {
314  return tag_handler;
315  }
template<class Matrix, class SymmGroup>
Index<SymmGroup> const& ALPSModel< Matrix, SymmGroup >::phys_dim ( size_t  type) const
inlinevirtual

Implements model_impl< Matrix, SymmGroup >.

Definition at line 278 of file model.hpp.

279  {
280  return symm_basis[type].phys_dim();
281  }
template<class Matrix, class SymmGroup>
SymmGroup::charge ALPSModel< Matrix, SymmGroup >::total_quantum_numbers ( BaseParameters parms_) const
inlinevirtual

Implements model_impl< Matrix, SymmGroup >.

Definition at line 283 of file model.hpp.

284  {
285  return init_charge<SymmGroup>(parms_, all_conserved_qn);
286  }
template<class Matrix, class SymmGroup>
void ALPSModel< Matrix, SymmGroup >::update ( BaseParameters const &  p)
inlinevirtual

Implements model_impl< Matrix, SymmGroup >.

Definition at line 272 of file model.hpp.

273  {
274  parms << p;
275  generate_terms();
276  }

Member Data Documentation

template<class Matrix, class SymmGroup>
terms_type model_impl< Matrix, SymmGroup >::terms_
protectedinherited

Definition at line 85 of file model.h.


The documentation for this class was generated from the following file: