series_expansion_aux.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00035 #ifndef SERIES_EXPANSION_AUX
00036 #define SERIES_EXPANSION_AUX
00037
00038 #include "fastlib/fastlib.h"
00039
00043 class SeriesExpansionAux {
00044
00045 private:
00046
00047 int dim_;
00048
00049 int max_order_;
00050
00051 Vector factorials_;
00052
00053 ArrayList<int> list_total_num_coeffs_;
00054
00055 Vector inv_multiindex_factorials_;
00056
00057 Vector neg_inv_multiindex_factorials_;
00058
00059 Matrix multiindex_combination_;
00060
00061 ArrayList< ArrayList<int> > multiindex_mapping_;
00062
00068 ArrayList< ArrayList<int> > lower_mapping_index_;
00069
00075 ArrayList< ArrayList<int> > upper_mapping_index_;
00076
00078 Matrix n_choose_k_;
00079
00080 OT_DEF_BASIC(SeriesExpansionAux) {
00081 OT_MY_OBJECT(dim_);
00082 OT_MY_OBJECT(max_order_);
00083 OT_MY_OBJECT(factorials_);
00084 OT_MY_OBJECT(list_total_num_coeffs_);
00085 OT_MY_OBJECT(inv_multiindex_factorials_);
00086 OT_MY_OBJECT(neg_inv_multiindex_factorials_);
00087 OT_MY_OBJECT(multiindex_combination_);
00088 OT_MY_OBJECT(multiindex_mapping_);
00089 OT_MY_OBJECT(lower_mapping_index_);
00090 OT_MY_OBJECT(upper_mapping_index_);
00091 OT_MY_OBJECT(n_choose_k_);
00092 }
00093
00094 public:
00095
00096 void ComputeFactorials() {
00097 factorials_.Init(2 * max_order_ + 1);
00098
00099 factorials_[0] = 1;
00100 for(index_t t = 1; t < factorials_.length(); t++) {
00101 factorials_[t] = t * factorials_[t - 1];
00102 }
00103 }
00104
00105 void ComputeLowerMappingIndex() {
00106
00107 ArrayList<int> diff;
00108 diff.Init(dim_);
00109
00110 int limit = 2 * max_order_;
00111
00112
00113 lower_mapping_index_.Init(list_total_num_coeffs_[limit]);
00114
00115 for(index_t i = 0; i < list_total_num_coeffs_[limit]; i++) {
00116 const ArrayList<int> &outer_mapping = multiindex_mapping_[i];
00117 lower_mapping_index_[i].Init();
00118
00119 for(index_t j = 0; j < list_total_num_coeffs_[limit]; j++) {
00120 const ArrayList<int> &inner_mapping = multiindex_mapping_[j];
00121 int flag = 0;
00122
00123 for(index_t d = 0; d < dim_; d++) {
00124 diff[d] = outer_mapping[d] - inner_mapping[d];
00125
00126 if(diff[d] < 0) {
00127 flag = 1;
00128 break;
00129 }
00130 }
00131
00132 if(flag == 0) {
00133 (lower_mapping_index_[i]).PushBackCopy(j);
00134 }
00135 }
00136 }
00137 }
00138
00139 void ComputeMultiindexCombination() {
00140
00141 int limit = 2 * max_order_;
00142 multiindex_combination_.Init(list_total_num_coeffs_[limit],
00143 list_total_num_coeffs_[limit]);
00144
00145 for(index_t j = 0; j < list_total_num_coeffs_[limit]; j++) {
00146
00147
00148 const ArrayList<int> &beta_mapping = multiindex_mapping_[j];
00149
00150 for(index_t k = 0; k < list_total_num_coeffs_[limit]; k++) {
00151
00152
00153 const ArrayList<int> &alpha_mapping = multiindex_mapping_[k];
00154
00155
00156 multiindex_combination_.set(j, k, 1);
00157
00158 for(index_t i = 0; i < dim_; i++) {
00159 multiindex_combination_.set
00160 (j, k, multiindex_combination_.get(j, k) *
00161 n_choose_k_.get(beta_mapping[i], alpha_mapping[i]));
00162
00163 if(multiindex_combination_.get(j, k) == 0)
00164 break;
00165 }
00166 }
00167 }
00168 }
00169
00170 void ComputeUpperMappingIndex() {
00171
00172 int limit = 2 * max_order_;
00173 ArrayList<int> diff;
00174 diff.Init(dim_);
00175
00176
00177 upper_mapping_index_.Init(list_total_num_coeffs_[limit]);
00178
00179 for(index_t i = 0; i < list_total_num_coeffs_[limit]; i++) {
00180 const ArrayList<int> &outer_mapping = multiindex_mapping_[i];
00181 upper_mapping_index_[i].Init();
00182
00183 for(index_t j = 0; j < list_total_num_coeffs_[limit]; j++) {
00184 const ArrayList<int> &inner_mapping = multiindex_mapping_[j];
00185 int flag = 0;
00186
00187 for(index_t d = 0; d < dim_; d++) {
00188 diff[d] = inner_mapping[d] - outer_mapping[d];
00189
00190 if(diff[d] < 0) {
00191 flag = 1;
00192 break;
00193 }
00194 }
00195
00196 if(flag == 0) {
00197 (upper_mapping_index_[i]).PushBackCopy(j);
00198 }
00199 }
00200 }
00201 }
00202
00203
00204 double factorial(int k) const { return factorials_[k]; }
00205
00206 int get_dimension() const { return dim_; }
00207
00208 int get_total_num_coeffs(int order) const;
00209
00210 int get_max_total_num_coeffs() const;
00211
00212 const Vector& get_inv_multiindex_factorials() const;
00213
00214 const ArrayList< int > * get_lower_mapping_index() const;
00215
00216 int get_max_order() const;
00217
00218 const ArrayList< int > & get_multiindex(int pos) const;
00219
00220 const ArrayList< int > * get_multiindex_mapping() const;
00221
00222 const Vector& get_neg_inv_multiindex_factorials() const;
00223
00224 double get_n_choose_k(int n, int k) const;
00225
00226 double get_n_multichoose_k_by_pos(int n, int k) const;
00227
00228 const ArrayList< int > * get_upper_mapping_index() const;
00229
00230
00231
00235 int ComputeMultiindexPosition(const ArrayList<int> &multiindex) const;
00236
00240 double FarFieldEvaluationCost(int order) const;
00241
00245 double FarFieldToLocalTranslationCost(int order) const;
00246
00250 double DirectLocalAccumulationCost(int order) const;
00251
00256 void Init(int max_order, int dim);
00257
00261 void PrintDebug(const char *name="", FILE *stream=stderr) const;
00262
00263 };
00264
00265 #endif