25#ifndef _chemistry_qc_lmp2_arraydef_h
26#define _chemistry_qc_lmp2_arraydef_h
35 for (
typename Array<N>::blockmap_t::const_iterator
36 aiter = blocks_.begin();
37 aiter != blocks_.end();
40 const double *data = aiter->second;
45 for (
int i=0; i<N; i++) {
46 o <<
" " << iter.index(i)
47 + index(i).block_offset(info.block(i));
51 o << std::showpoint << std::fixed
52 << std::setw(11) << std::setprecision(8)
53 << data[iter.offset()];
59 for (
int i=0; i<N; i++) {
60 o <<
" " << iter.index(i);
73 bool distributed, std::ostream&o)
const {
79 if (grp && distributed) {
80 if (grp->me() == 0) o <<
"array " << name_ <<
":" << std::endl;
81 for (
int i=0; i<grp->n(); i++) {
83 o <<
"node " << i <<
":" << std::endl;
91 else if (grp.
null() || (grp && grp->n() == 1)) {
96 template <
int N,
class V>
98 apply_denominator(Array<N> &array,
double denominator_offset,
99 const std::vector<V> &eigenvalues)
101 if (N != eigenvalues.size()) {
102 throw std::runtime_error(
"apply_denominator: eigenvalues.size() != N");
105 const bool print_factor_info =
false;
106 double smallest_factor = 0.0;
107 double largest_factor = 0.0;
108 const typename Array<N>::blockmap_t &bmap = array.blockmap();
109 for (
typename Array<N>::blockmap_t::const_iterator bmapiter = bmap.begin();
110 bmapiter != bmap.end();
112 const BlockInfo<N> &binfo = bmapiter->first;
113 double *data = bmapiter->second;
115 for (
int i=0; i<N; i++) {
116 off[i] = array.index(i).block_offset(binfo.block(i));
118 BlockIter<N> biter(array.indices(),binfo);
119 for (biter.start(); biter.ready(); biter++) {
120 int offset = biter.offset();
121 double denom = denominator_offset;
122 for (
int i=0; i<N; i++) {
123 denom += (*eigenvalues[i])[biter.index(i) + off[i]];
125 data[offset] /= denom;
126 if (print_factor_info) {
128 largest_factor = smallest_factor = denom;
131 if (smallest_factor > denom) smallest_factor = denom;
132 if (largest_factor < denom) largest_factor = denom;
137 if (inited && print_factor_info) {
139 <<
"The denominators are in the range ["
static std::ostream & out0()
Return an ostream that writes from node 0.
A template class that maintains references counts.
Definition ref.h:361
bool null() const
Return true if this is a reference to a null object.
Definition ref.h:423
Implements a block sparse tensor.
Definition sma.h:1247
void print_local(std::ostream &o=sc::ExEnv::outn()) const
Print the array.
Definition arraydef.h:34
BlockInfo stores info about a block of data.
Definition sma.h:200
BlockIter loops through the all the indices within a block.
Definition sma.h:2189
bool ready() const
Returns true if the iterator is valid.
Definition sma.h:2213
void start()
Initialize the iterator.
Definition sma.h:2211
Contains all MPQC code up to version 3.
Definition mpqcin.h:14