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 namespace libMesh
26 {
27 
28 // ------------------------------------------------------------
29 // RBThetaExpansion implementation
30 
RBThetaExpansion()31 RBThetaExpansion::RBThetaExpansion()
32 {
33 }
34 
get_n_A_terms()35 unsigned int RBThetaExpansion::get_n_A_terms() const
36 {
37   return cast_int<unsigned int>
38     (_A_theta_vector.size());
39 }
40 
get_n_F_terms()41 unsigned int RBThetaExpansion::get_n_F_terms() const
42 {
43   return cast_int<unsigned int>
44     (_F_theta_vector.size());
45 }
46 
get_n_outputs()47 unsigned int RBThetaExpansion::get_n_outputs() const
48 {
49   return cast_int<unsigned int>
50     (_output_theta_vector.size());
51 }
52 
get_n_output_terms(unsigned int index)53 unsigned int RBThetaExpansion::get_n_output_terms(unsigned int index) const
54 {
55   libmesh_error_msg_if(index >= get_n_outputs(), "Error: We must have index < n_outputs in get_Q_l.");
56 
57   return cast_int<unsigned int>
58     (_output_theta_vector[index].size());
59 }
60 
attach_A_theta(RBTheta * theta_q_a)61 void RBThetaExpansion::attach_A_theta(RBTheta * theta_q_a)
62 {
63   libmesh_assert(theta_q_a);
64 
65   _A_theta_vector.push_back(theta_q_a);
66 }
67 
attach_multiple_A_theta(std::vector<std::unique_ptr<RBTheta>> & theta_q_a)68 void RBThetaExpansion::attach_multiple_A_theta(std::vector<std::unique_ptr<RBTheta>> & theta_q_a)
69 {
70   for (std::size_t i=0; i<theta_q_a.size(); i++)
71     {
72       libmesh_assert(theta_q_a[i]);
73       _A_theta_vector.push_back(theta_q_a[i].get());
74     }
75 }
76 
attach_F_theta(RBTheta * theta_q_f)77 void RBThetaExpansion::attach_F_theta(RBTheta * theta_q_f)
78 {
79   libmesh_assert(theta_q_f);
80 
81   _F_theta_vector.push_back(theta_q_f);
82 }
83 
attach_multiple_F_theta(std::vector<std::unique_ptr<RBTheta>> & theta_q_f)84 void RBThetaExpansion::attach_multiple_F_theta(std::vector<std::unique_ptr<RBTheta>> & theta_q_f)
85 {
86   for (std::size_t i=0; i<theta_q_f.size(); i++)
87     {
88       libmesh_assert(theta_q_f[i]);
89       _F_theta_vector.push_back(theta_q_f[i].get());
90     }
91 }
92 
attach_output_theta(std::vector<std::unique_ptr<RBTheta>> & theta_q_l)93 void RBThetaExpansion::attach_output_theta(std::vector<std::unique_ptr<RBTheta>> & theta_q_l)
94 {
95   std::vector<RBTheta *> theta_q_l_ptr;
96   for(std::size_t i=0; i<theta_q_l.size(); i++)
97   {
98     theta_q_l_ptr.push_back( theta_q_l[i].get() );
99   }
100   _output_theta_vector.push_back(theta_q_l_ptr);
101 }
102 
attach_output_theta(std::vector<RBTheta * > theta_q_l)103 void RBThetaExpansion::attach_output_theta(std::vector<RBTheta *> theta_q_l)
104 {
105   _output_theta_vector.push_back(theta_q_l);
106 }
107 
attach_output_theta(RBTheta * theta_q_l)108 void RBThetaExpansion::attach_output_theta(RBTheta * theta_q_l)
109 {
110   libmesh_assert(theta_q_l);
111 
112   std::vector<RBTheta *> theta_l_vector(1);
113   theta_l_vector[0] = theta_q_l;
114 
115   attach_output_theta(theta_l_vector);
116 }
117 
eval_A_theta(unsigned int q,const RBParameters & mu)118 Number RBThetaExpansion::eval_A_theta(unsigned int q,
119                                       const RBParameters & mu)
120 {
121   libmesh_error_msg_if(q >= get_n_A_terms(), "Error: We must have q < get_n_A_terms in eval_A_theta.");
122   libmesh_assert(_A_theta_vector[q]);
123 
124   return _A_theta_vector[q]->evaluate( mu );
125 }
126 
eval_A_theta(unsigned int q,const std::vector<RBParameters> & mus)127 std::vector<Number> RBThetaExpansion::eval_A_theta(unsigned int q,
128                                                    const std::vector<RBParameters> & mus)
129 {
130   libmesh_error_msg_if(q >= get_n_A_terms(), "Error: We must have q < get_n_A_terms in eval_A_theta.");
131   libmesh_assert(_A_theta_vector[q]);
132 
133   return _A_theta_vector[q]->evaluate_vec(mus);
134 }
135 
eval_F_theta(unsigned int q,const RBParameters & mu)136 Number RBThetaExpansion::eval_F_theta(unsigned int q,
137                                       const RBParameters & mu)
138 {
139   libmesh_error_msg_if(q >= get_n_F_terms(), "Error: We must have q < get_n_F_terms in eval_F_theta.");
140   libmesh_assert(_F_theta_vector[q]);
141 
142   return _F_theta_vector[q]->evaluate( mu );
143 }
144 
eval_F_theta(unsigned int q,const std::vector<RBParameters> & mus)145 std::vector<Number> RBThetaExpansion::eval_F_theta(unsigned int q,
146                                                    const std::vector<RBParameters> & mus)
147 {
148   libmesh_error_msg_if(q >= get_n_F_terms(), "Error: We must have q < get_n_F_terms in eval_F_theta.");
149   libmesh_assert(_F_theta_vector[q]);
150 
151   return _F_theta_vector[q]->evaluate_vec(mus);
152 }
153 
eval_output_theta(unsigned int output_index,unsigned int q_l,const RBParameters & mu)154 Number RBThetaExpansion::eval_output_theta(unsigned int output_index,
155                                            unsigned int q_l,
156                                            const RBParameters & mu)
157 {
158   libmesh_error_msg_if((output_index >= get_n_outputs()) || (q_l >= get_n_output_terms(output_index)),
159                        "Error: We must have output_index < n_outputs and "
160                        "q_l < get_n_output_terms(output_index) in eval_output_theta.");
161 
162   libmesh_assert(_output_theta_vector[output_index][q_l]);
163 
164   return _output_theta_vector[output_index][q_l]->evaluate( mu );
165 }
166 
167 
168 }
169