1 /* 2 * Copyright © 2005 Ondra Kamenik 3 * Copyright © 2019 Dynare Team 4 * 5 * This file is part of Dynare. 6 * 7 * Dynare is free software: you can redistribute it and/or modify 8 * it under the terms of the GNU General Public License as published by 9 * the Free Software Foundation, either version 3 of the License, or 10 * (at your option) any later version. 11 * 12 * Dynare is distributed in the hope that it will be useful, 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * GNU General Public License for more details. 16 * 17 * You should have received a copy of the GNU General Public License 18 * along with Dynare. If not, see <http://www.gnu.org/licenses/>. 19 */ 20 21 #include "fine_container.hh" 22 23 #include <cmath> 24 25 /* Here we construct the vector of new sizes of containers (before 26 nc) and copy all remaining sizes behind nc. */ 27 SizeRefinement(const IntSequence & s,int nc,int max)28SizeRefinement::SizeRefinement(const IntSequence &s, int nc, int max) 29 { 30 new_nc = 0; 31 for (int i = 0; i < nc; i++) 32 { 33 int nr = s[i]/max; 34 if (s[i] % max != 0) 35 nr++; 36 int ss = (nr > 0) ? static_cast<int>(round(static_cast<double>(s[i])/nr)) : 0; 37 for (int j = 0; j < nr - 1; j++) 38 { 39 rsizes.push_back(ss); 40 ind_map.push_back(i); 41 new_nc++; 42 } 43 rsizes.push_back(s[i]-(nr-1)*ss); 44 ind_map.push_back(i); 45 new_nc++; 46 } 47 48 for (int i = nc; i < s.size(); i++) 49 { 50 rsizes.push_back(s[i]); 51 ind_map.push_back(i); 52 } 53 } 54