libMesh
Loading...
Searching...
No Matches
rb_theta_expansion.C
Go to the documentation of this file.
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
28namespace libMesh
29{
30
32{
33 return cast_int<unsigned int>
34 (_A_theta_vector.size());
35}
36
38{
39 return cast_int<unsigned int>
40 (_F_theta_vector.size());
41}
42
44{
45 return cast_int<unsigned int>
46 (_output_theta_vector.size());
47}
48
49unsigned int RBThetaExpansion::get_n_output_terms(unsigned int index) const
50{
51 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 (_output_theta_vector[index].size());
55}
56
58{
59 unsigned int sum = 0;
60 for (const auto & vec : _output_theta_vector)
61 sum += vec.size();
62 return sum;
63}
64
65unsigned int RBThetaExpansion::output_index_1D(unsigned int n, unsigned int q_l) const
66{
67 // Start with index of the current term
68 unsigned int index = q_l;
69
70 // Add to it the number of terms for all outputs prior to n
71 for (auto i : make_range(n))
72 index += _output_theta_vector[i].size();
73
74 return index;
75}
76
78{
79 libmesh_assert(theta_q_a);
80
81 _A_theta_vector.push_back(theta_q_a);
82}
83
84void RBThetaExpansion::attach_multiple_A_theta(std::vector<std::unique_ptr<RBTheta>> & theta_q_a)
85{
86 for (std::size_t i=0; i<theta_q_a.size(); i++)
87 {
88 libmesh_assert(theta_q_a[i]);
89 _A_theta_vector.push_back(theta_q_a[i].get());
90 }
91}
92
94{
95 libmesh_assert(theta_q_f);
96
97 _F_theta_vector.push_back(theta_q_f);
98}
99
100void RBThetaExpansion::attach_multiple_F_theta(std::vector<std::unique_ptr<RBTheta>> & theta_q_f)
101{
102 for (std::size_t i=0; i<theta_q_f.size(); i++)
103 {
104 libmesh_assert(theta_q_f[i]);
105 _F_theta_vector.push_back(theta_q_f[i].get());
106 }
107}
108
109void RBThetaExpansion::attach_output_theta(std::vector<std::unique_ptr<RBTheta>> & theta_q_l)
110{
111 std::vector<RBTheta *> theta_q_l_ptr;
112 for(std::size_t i=0; i<theta_q_l.size(); i++)
113 {
114 theta_q_l_ptr.push_back( theta_q_l[i].get() );
115 }
116 _output_theta_vector.push_back(theta_q_l_ptr);
117}
118
119void RBThetaExpansion::attach_output_theta(std::vector<RBTheta *> theta_q_l)
120{
121 _output_theta_vector.push_back(std::move(theta_q_l));
122}
123
125{
126 libmesh_assert(theta_q_l);
127
128 std::vector<RBTheta *> theta_l_vector(1);
129 theta_l_vector[0] = theta_q_l;
130
131 attach_output_theta(theta_l_vector);
132}
133
135 const RBParameters & mu) const
136{
137 libmesh_error_msg_if(q >= get_n_A_terms(), "Error: We must have q < get_n_A_terms in eval_A_theta.");
139
140 return _A_theta_vector[q]->evaluate( mu );
141}
142
143std::vector<Number> RBThetaExpansion::eval_A_theta(unsigned int q,
144 const std::vector<RBParameters> & mus) const
145{
146 libmesh_error_msg_if(q >= get_n_A_terms(), "Error: We must have q < get_n_A_terms in eval_A_theta.");
148
149 return _A_theta_vector[q]->evaluate_vec(mus);
150}
151
153 const RBParameters & mu) const
154{
155 libmesh_error_msg_if(q >= get_n_F_terms(), "Error: We must have q < get_n_F_terms in eval_F_theta.");
157
158 return _F_theta_vector[q]->evaluate( mu );
159}
160
161std::vector<Number> RBThetaExpansion::eval_F_theta(unsigned int q,
162 const std::vector<RBParameters> & mus) const
163{
164 libmesh_error_msg_if(q >= get_n_F_terms(), "Error: We must have q < get_n_F_terms in eval_F_theta.");
166
167 return _F_theta_vector[q]->evaluate_vec(mus);
168}
169
171 unsigned int q_l,
172 const RBParameters & mu) const
173{
174 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 libmesh_assert(_output_theta_vector[output_index][q_l]);
179
180 return _output_theta_vector[output_index][q_l]->evaluate( mu );
181}
182
183std::vector<Number>
184RBThetaExpansion::eval_output_theta(unsigned int output_index,
185 unsigned int q_l,
186 const std::vector<RBParameters> & mus) const
187{
188 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 libmesh_assert(_output_theta_vector[output_index][q_l]);
193
194 return _output_theta_vector[output_index][q_l]->evaluate_vec(mus);
195}
196
197}
This class is part of the rbOOmit framework.
virtual Number eval_F_theta(unsigned int q, const RBParameters &mu) const
Evaluate theta_q_f at the current parameter.
virtual void attach_F_theta(RBTheta *theta_q_f)
Attach a pointer to a functor object that defines one of the theta_q_a terms.
unsigned int get_total_n_output_terms() const
Returns the total number of affine terms associated with all outputs.
std::vector< RBTheta * > _F_theta_vector
Vector storing the RBTheta functors for the affine expansion of the rhs.
virtual void attach_A_theta(RBTheta *theta_q_a)
Attach a pointer to a functor object that defines one of the theta_q_a terms.
unsigned int get_n_F_terms() const
Get Q_f, the number of terms in the affine expansion for the right-hand side.
unsigned int get_n_A_terms() const
Get Q_a, the number of terms in the affine expansion for the bilinear form.
std::vector< std::vector< RBTheta * > > _output_theta_vector
Vector storing the RBTheta functors for the affine expansion of the outputs.
unsigned int output_index_1D(unsigned int n, unsigned int q_l) const
Computes the one-dimensional index for output n, term q_l implied by a "row-major" ordering of the ou...
virtual Number eval_A_theta(unsigned int q, const RBParameters &mu) const
Evaluate theta_q_a at the current parameter.
std::vector< RBTheta * > _A_theta_vector
Vector storing the pointers to the RBTheta functors for A.
unsigned int get_n_output_terms(unsigned int output_index) const
Get the number of affine terms associated with the specified output.
virtual void attach_multiple_A_theta(std::vector< std::unique_ptr< RBTheta > > &theta_q_a)
Attach a vector of pointers to functor objects that each define one of the theta_q_a terms.
unsigned int get_n_outputs() const
Get n_outputs, the number output functionals.
virtual void attach_multiple_F_theta(std::vector< std::unique_ptr< RBTheta > > &theta_q_f)
Attach a vector of pointers to functor objects that each define one of the theta_q_f terms.
virtual void attach_output_theta(std::vector< std::unique_ptr< RBTheta > > &theta_q_l)
Attach a vector of pointers to functor objects that define one of the outputs.
virtual Number eval_output_theta(unsigned int output_index, unsigned int q_l, const RBParameters &mu) const
Evaluate theta_q_l at the current parameter.
This class is part of the rbOOmit framework.
Definition rb_theta.h:47
The libMesh namespace provides an interface to certain functionality in the library.
libmesh_assert(ctx)
IntRange< T > make_range(T beg, T end)
The 2-parameter make_range() helper function returns an IntRange<T> when both input parameters are of...
Definition int_range.h:176