1 /*
2 * Copyright (C) 2004-2021 Edward F. Valeev
3 *
4 * This file is part of Libint.
5 *
6 * Libint is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * Libint is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with Libint. If not, see <http://www.gnu.org/licenses/>.
18 *
19 */
20
21 #include <map>
22 #include <iostream>
23 #include <dgvertex.h>
24 #include <entity.h>
25 #include <rr.h>
26 #include <intset_to_ints.h>
27 #include <uncontract.h>
28 #include <extract.h>
29
30 using namespace std;
31 using namespace libint2;
32
33 void
operator ()(const VertexPtr & v)34 ExtractExternSymbols::operator()(const VertexPtr& v)
35 {
36 #if DEBUG
37 std::cout << "ExtractExternSymbols::operator() -- v = " << v->description() << std::endl;
38 #endif
39 if (v->precomputed()) {
40
41 // discard compile-time entities
42 {
43 typedef CTimeEntity<double> cdouble;
44 SafePtr<cdouble> ptr_cast = dynamic_pointer_cast<cdouble,DGVertex>(v);
45 if (ptr_cast) {
46 return;
47 }
48 }
49
50 // discard unrolled integral sets composed of precomputed integrals
51 {
52 SafePtr<DGArcRR> arcrr;
53 if (v->size() == 1 && v->num_exit_arcs() == 1 &&
54 ( (arcrr = dynamic_pointer_cast<DGArcRR,DGArc>(*(v->first_exit_arc()))) != 0 ?
55 dynamic_pointer_cast<IntegralSet_to_Integrals_base,RecurrenceRelation>(arcrr->rr()) != 0 :
56 false ) &&
57 (*(v->first_exit_arc()))->dest()->precomputed()
58 ) {
59 return;
60 }
61 }
62
63 map_[v->label()] = true;
64 }
65
66 }
67
68 const ExtractExternSymbols::Symbols&
symbols() const69 ExtractExternSymbols::symbols() const
70 {
71 symbols_.clear();
72 typedef LabelMap::const_iterator citer;
73 citer end = map_.end();
74 for(citer l=map_.begin(); l!=end; ++l) {
75 symbols_.push_back(l->first);
76 }
77 //symbols_.sort();
78 return symbols_;
79 }
80
81 ////
82
83 void
operator ()(const VertexPtr & v)84 ExtractRR::operator()(const VertexPtr& v)
85 {
86 if (v->num_exit_arcs() != 0) {
87 SafePtr<DGArc> arc = *(v->first_exit_arc());
88 SafePtr<DGArcRR> arc_rr = dynamic_pointer_cast<DGArcRR,DGArc>(arc);
89 if (arc_rr != 0) {
90 SafePtr<RecurrenceRelation> rr = arc_rr->rr();
91 SafePtr<IntegralSet_to_Integrals_base> iset_to_i = dynamic_pointer_cast<IntegralSet_to_Integrals_base,RecurrenceRelation>(rr);
92 SafePtr<Uncontract_Integral_base> unc_i = dynamic_pointer_cast<Uncontract_Integral_base,RecurrenceRelation>(rr);
93 if (iset_to_i == 0 && unc_i == 0) {
94 const SafePtr<RRStack>& rrstack = RRStack::Instance();
95 // RRStack must be guaranteed to have this rr
96 const RRStack::value_type rrstackvalue = rrstack->find(rr);
97 const RRid rrid = rrstackvalue.first;
98 map_[rrid] = true;
99 }
100 }
101 }
102
103 }
104
105 const ExtractRR::RRList&
rrlist() const106 ExtractRR::rrlist() const
107 {
108 rrlist_.clear();
109 typedef RRMap::const_iterator citer;
110 citer end = map_.end();
111 for(citer rr=map_.begin(); rr!=end; ++rr) {
112 rrlist_.push_back(rr->first);
113 }
114 //rrlist_.sort();
115 return rrlist_;
116 }
117