1 // FILE xsplit_data.h : Declaration of class ff_data
2 //////////////////////////////////////////////////////////////////////////
3 //
4 // Copyright 1990-2012 Marcus Mo
5 //
6 // This file is part of the eclib package.
7 //
8 // eclib is free software; you can redistribute it and/or modify it
9 // under the terms of the GNU General Public License as published by the
10 // Free Software Foundation; either version 2 of the License, or (at your
11 // option) any later version.
12 //
13 // eclib is distributed in the hope that it will be useful, but WITHOUT
14 // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 // FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
16 // for more details.
17 //
18 // You should have received a copy of the GNU General Public License
19 // along with eclib; if not, write to the Free Software Foundation,
20 // Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 //
22 //////////////////////////////////////////////////////////////////////////
23 
24 #ifndef _ECLIB_XSPLIT_DATA_H
25 #define _ECLIB_XSPLIT_DATA_H
26 
27 // Include headers
28 #include <iostream>
29 #include <cstdlib>
30 #include <cassert>
31 #include <vector>
32 
33 // Disable multithreading
34 // #undef ECLIB_MULTITHREAD
35 
36 #ifdef ECLIB_MULTITHREAD
37 #include <boost/thread/mutex.hpp>
38 #endif
39 
40 // Header files for macros and custom data structures
41 #include <eclib/method.h>
42 
43 // Forward declaration of classes ... prevents circular includes.
44 // form_finder only required as pointer
45 class form_finder;
46 
47 // Ennumerate node and child flags, exposed to global scope for outside access
48 enum nodestatus  { INTERNAL, ALL_OLD, FOUND_NEW, MAX_DEPTH };
49 enum childstatus { NOT_COMPLETE, COMPLETE, DESTROYED };
50 
51 /**
52  * ff_data (form_finder_data)
53  *
54  * Class name follows convention of that contained in xsplit.cc for ease of use.
55  */
56 class ff_data {
57   public:
58     // Constructor, destructor.
59     ff_data( form_finder* ff );
60     ~ff_data();
61 
62 #ifdef ECLIB_MULTITHREAD
63     void operator()();                              // Executed upon submission to job queue
64 #endif
65 
66     // Getters (to maintain consistency)
67     nodestatus     status();                        // Return status of current node
68     ssubspace*     abs_space();                     // Return parent absolute subspace
69     ssubspace*     rel_space();                     // Return parent relative subspace
70     long           depth();                         // Return current depth
71     long           subdim();                        // Return subdimension
72     long           eig();                           // Return associated eigenvalue
73     vector< long > eiglist();                       // Return sequence of eigenvalues
74     ff_data*       child( long eig );               // Return pointer to child
75     int            numCompleteChildren();           // Return number of complete children
76     bool           complete();                      // Return true if all children complete
77 
78     // Modifiers (available if needed i.e. not a friend class)
79     void setStatus( nodestatus s );                 // Store status of current node
80 
81     void increaseDepth( long delta = 1 );           // Increase current depth
82     void decreaseDepth( long delta = 1 );           // Decrease current depth
83 
84     void increaseSubmatUsage();                     // Locked counter incrementer
85 
86     void storeBplus( vec bp );                      // Store vector bplus
87     void storeBminus( vec bm );                     // Store vector bminus
88 
89     void addChild( long eig, ff_data &child );      // Store new child of current node
90     void eraseChild( long eig );                    // Destroy child given eigenvalue
91     void eraseChild( int idx );                     // Destroy child given index
92 
93     void setParent( ff_data *parent );              // Store parent node pointer
94     void setEigenvalue( long eig );                 // Store eigenvalue
95 
96     void setChildren( vector<long> eigs );          // Stores number of children
97                                                     //  and eigrange
98     void childStatus( long eig, childstatus flag ); // Sets completed children
99 
100     void eraseChildren();                           // Destroys all children recursively
101 
102     // Make form_finder class a friend to gain access to protected/private methods
103     friend class form_finder;
104 
105   private:
106     form_finder*        ff_;                 // Back-pointer to form_finder class
107                                              // Allows access to form_finder methods
108 
109     nodestatus          status_;             // Status of current node
110     long                depth_;              // Indicator of current depth
111     long                subdim_;             // Dimension of current subspace
112     long                eigenvalue_;         // Corresponding eigenvalue
113     vector< long >      eigrange_;           // List of all of all eigenvalues at this depth (used by map)
114     vector< long >      eiglist_;            // Sequence of eigenvalues leading to current
115     vec                 bplus_, bminus_;
116     ssubspace*          abs_space_;          // Current absolute subspace (dynamically created)
117     ssubspace*          rel_space_;          // Current relative subspace (dynamically created)
118     smat                conjmat_;            // Used only when plus==0 and bigmats==1
119     smat                the_opmat_;
120     smat                submat_;
121 
122     ff_data*            parent_;             // Pointer to parent data node
123     vector<ff_data*>    children_;           // Pointers to corresponding data nodes
124     ff_data*            child_;              // Pointer to favoured child
125     int                 numChildren_;        // Number of children
126     vector<childstatus> completedChildren_;  // Flags for child completion
127     int                 submatUsage_;        // Counter for submat
128 
129 #ifdef ECLIB_MULTITHREAD
130     boost::mutex        childComplete_lock_; // Lock for completed children
131     boost::mutex        submat_lock_;        // Lock for submat usage
132     boost::mutex        go_up_lock_;         // Lock for go_up() method
133 #endif
134 
135     // Helper methods
136     int map( long eig );                    // Map eigenvalue to index
137 };
138 
139 #endif
140 
141 // end of XSPLIT_DATA.H
142