Line data Source code
1 : // rbOOmit: An implementation of the Certified Reduced Basis method. 2 : // Copyright (C) 2009, 2010 David J. Knezevic 3 : 4 : // This file is part of rbOOmit. 5 : 6 : // rbOOmit is free software; you can redistribute it and/or 7 : // modify it under the terms of the GNU Lesser General Public 8 : // License as published by the Free Software Foundation; either 9 : // version 2.1 of the License, or (at your option) any later version. 10 : 11 : // rbOOmit 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 GNU 14 : // Lesser General Public License for more details. 15 : 16 : // You should have received a copy of the GNU Lesser General Public 17 : // License along with this library; if not, write to the Free Software 18 : // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 19 : 20 : // rbOOmit includes 21 : #include "libmesh/rb_theta_expansion.h" 22 : #include "libmesh/rb_theta.h" 23 : #include "libmesh/rb_parameters.h" 24 : 25 : // libMesh includes 26 : #include "libmesh/int_range.h" // make_range 27 : 28 : namespace libMesh 29 : { 30 : 31 16189713 : unsigned int RBThetaExpansion::get_n_A_terms() const 32 : { 33 : return cast_int<unsigned int> 34 17396917 : (_A_theta_vector.size()); 35 : } 36 : 37 17803476 : unsigned int RBThetaExpansion::get_n_F_terms() const 38 : { 39 : return cast_int<unsigned int> 40 19257354 : (_F_theta_vector.size()); 41 : } 42 : 43 136193550 : unsigned int RBThetaExpansion::get_n_outputs() const 44 : { 45 : return cast_int<unsigned int> 46 148264642 : (_output_theta_vector.size()); 47 : } 48 : 49 83741566 : unsigned int RBThetaExpansion::get_n_output_terms(unsigned int index) const 50 : { 51 83741566 : libmesh_error_msg_if(index >= get_n_outputs(), "Error: We must have index < n_outputs in get_Q_l."); 52 : 53 : return cast_int<unsigned int> 54 98625910 : (_output_theta_vector[index].size()); 55 : } 56 : 57 0 : unsigned int RBThetaExpansion::get_total_n_output_terms() const 58 : { 59 0 : unsigned int sum = 0; 60 0 : for (const auto & vec : _output_theta_vector) 61 0 : sum += vec.size(); 62 0 : return sum; 63 : } 64 : 65 0 : unsigned int RBThetaExpansion::output_index_1D(unsigned int n, unsigned int q_l) const 66 : { 67 : // Start with index of the current term 68 0 : unsigned int index = q_l; 69 : 70 : // Add to it the number of terms for all outputs prior to n 71 0 : for (auto i : make_range(n)) 72 0 : index += _output_theta_vector[i].size(); 73 : 74 0 : return index; 75 : } 76 : 77 1704 : void RBThetaExpansion::attach_A_theta(RBTheta * theta_q_a) 78 : { 79 48 : libmesh_assert(theta_q_a); 80 : 81 1704 : _A_theta_vector.push_back(theta_q_a); 82 1704 : } 83 : 84 0 : void RBThetaExpansion::attach_multiple_A_theta(std::vector<std::unique_ptr<RBTheta>> & theta_q_a) 85 : { 86 0 : for (std::size_t i=0; i<theta_q_a.size(); i++) 87 : { 88 0 : libmesh_assert(theta_q_a[i]); 89 0 : _A_theta_vector.push_back(theta_q_a[i].get()); 90 : } 91 0 : } 92 : 93 1988 : void RBThetaExpansion::attach_F_theta(RBTheta * theta_q_f) 94 : { 95 56 : libmesh_assert(theta_q_f); 96 : 97 1988 : _F_theta_vector.push_back(theta_q_f); 98 1988 : } 99 : 100 0 : void RBThetaExpansion::attach_multiple_F_theta(std::vector<std::unique_ptr<RBTheta>> & theta_q_f) 101 : { 102 0 : for (std::size_t i=0; i<theta_q_f.size(); i++) 103 : { 104 0 : libmesh_assert(theta_q_f[i]); 105 0 : _F_theta_vector.push_back(theta_q_f[i].get()); 106 : } 107 0 : } 108 : 109 0 : void RBThetaExpansion::attach_output_theta(std::vector<std::unique_ptr<RBTheta>> & theta_q_l) 110 : { 111 0 : std::vector<RBTheta *> theta_q_l_ptr; 112 0 : for(std::size_t i=0; i<theta_q_l.size(); i++) 113 : { 114 0 : theta_q_l_ptr.push_back( theta_q_l[i].get() ); 115 : } 116 0 : _output_theta_vector.push_back(theta_q_l_ptr); 117 0 : } 118 : 119 1136 : void RBThetaExpansion::attach_output_theta(std::vector<RBTheta *> theta_q_l) 120 : { 121 1136 : _output_theta_vector.push_back(std::move(theta_q_l)); 122 1136 : } 123 : 124 1136 : void RBThetaExpansion::attach_output_theta(RBTheta * theta_q_l) 125 : { 126 32 : libmesh_assert(theta_q_l); 127 : 128 1136 : std::vector<RBTheta *> theta_l_vector(1); 129 1136 : theta_l_vector[0] = theta_q_l; 130 : 131 2240 : attach_output_theta(theta_l_vector); 132 1136 : } 133 : 134 12525723 : Number RBThetaExpansion::eval_A_theta(unsigned int q, 135 : const RBParameters & mu) const 136 : { 137 12525723 : libmesh_error_msg_if(q >= get_n_A_terms(), "Error: We must have q < get_n_A_terms in eval_A_theta."); 138 996492 : libmesh_assert(_A_theta_vector[q]); 139 : 140 13522215 : return _A_theta_vector[q]->evaluate( mu ); 141 : } 142 : 143 0 : std::vector<Number> RBThetaExpansion::eval_A_theta(unsigned int q, 144 : const std::vector<RBParameters> & mus) const 145 : { 146 0 : libmesh_error_msg_if(q >= get_n_A_terms(), "Error: We must have q < get_n_A_terms in eval_A_theta."); 147 0 : libmesh_assert(_A_theta_vector[q]); 148 : 149 0 : return _A_theta_vector[q]->evaluate_vec(mus); 150 : } 151 : 152 14409182 : Number RBThetaExpansion::eval_F_theta(unsigned int q, 153 : const RBParameters & mu) const 154 : { 155 14409182 : libmesh_error_msg_if(q >= get_n_F_terms(), "Error: We must have q < get_n_F_terms in eval_F_theta."); 156 1192574 : libmesh_assert(_F_theta_vector[q]); 157 : 158 15601756 : return _F_theta_vector[q]->evaluate( mu ); 159 : } 160 : 161 0 : std::vector<Number> RBThetaExpansion::eval_F_theta(unsigned int q, 162 : const std::vector<RBParameters> & mus) const 163 : { 164 0 : libmesh_error_msg_if(q >= get_n_F_terms(), "Error: We must have q < get_n_F_terms in eval_F_theta."); 165 0 : libmesh_assert(_F_theta_vector[q]); 166 : 167 0 : return _F_theta_vector[q]->evaluate_vec(mus); 168 : } 169 : 170 27705688 : Number RBThetaExpansion::eval_output_theta(unsigned int output_index, 171 : unsigned int q_l, 172 : const RBParameters & mu) const 173 : { 174 27705688 : libmesh_error_msg_if((output_index >= get_n_outputs()) || (q_l >= get_n_output_terms(output_index)), 175 : "Error: We must have output_index < n_outputs and " 176 : "q_l < get_n_output_terms(output_index) in eval_output_theta."); 177 : 178 2474776 : libmesh_assert(_output_theta_vector[output_index][q_l]); 179 : 180 32655240 : return _output_theta_vector[output_index][q_l]->evaluate( mu ); 181 : } 182 : 183 : std::vector<Number> 184 0 : RBThetaExpansion::eval_output_theta(unsigned int output_index, 185 : unsigned int q_l, 186 : const std::vector<RBParameters> & mus) const 187 : { 188 0 : libmesh_error_msg_if((output_index >= get_n_outputs()) || (q_l >= get_n_output_terms(output_index)), 189 : "Error: We must have output_index < n_outputs and " 190 : "q_l < get_n_output_terms(output_index) in eval_output_theta."); 191 : 192 0 : libmesh_assert(_output_theta_vector[output_index][q_l]); 193 : 194 0 : return _output_theta_vector[output_index][q_l]->evaluate_vec(mus); 195 : } 196 : 197 : }