variable.h
Go to the documentation of this file.
1 // The libMesh Finite Element Library.
2 // Copyright (C) 2002-2018 Benjamin S. Kirk, John W. Peterson, Roy H. Stogner
3 
4 // This library is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU Lesser General Public
6 // License as published by the Free Software Foundation; either
7 // version 2.1 of the License, or (at your option) any later version.
8 
9 // This library is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 // Lesser General Public License for more details.
13 
14 // You should have received a copy of the GNU Lesser General Public
15 // License along with this library; if not, write to the Free Software
16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 
18 #ifndef LIBMESH_VARIABLE_H
19 #define LIBMESH_VARIABLE_H
20 
21 // Local Includes
22 #include "libmesh/libmesh_common.h"
23 #include "libmesh/fe_type.h"
24 #include "libmesh/id_types.h"
25 
26 // C++ includes
27 #include <set>
28 #include <string>
29 #include <vector>
30 
31 namespace libMesh
32 {
33 
34 // Forward Declaration
35 class System;
36 
49 class Variable
50 {
51 public:
52 
58  Variable (System * sys,
59  const std::string & var_name,
60  const unsigned int var_number,
61  const unsigned int first_scalar_num,
62  const FEType & var_type) :
63  _sys(sys),
64  _name(var_name),
66  _number(var_number),
67  _first_scalar_number(first_scalar_num),
68  _type(var_type)
69  {}
70 
75  Variable (System * sys,
76  const std::string & var_name,
77  const unsigned int var_number,
78  const unsigned int first_scalar_num,
79  const FEType & var_type,
80  const std::set<subdomain_id_type> & var_active_subdomains) :
81  _sys(sys),
82  _name(var_name),
83  _active_subdomains(var_active_subdomains),
84  _number(var_number),
85  _first_scalar_number(first_scalar_num),
86  _type(var_type)
87  {}
88 
92  System * system() const
93  {
94  return _sys;
95  }
96 
100  const std::string & name() const
101  { return _name; }
102 
106  unsigned int number() const
107  { return _number; }
108 
113  unsigned int first_scalar_number() const
114  { return _first_scalar_number; }
115 
119  const FEType & type() const
120  { return _type; }
121 
125  unsigned int n_components() const
126  { return type().family == SCALAR ? _type.order.get_order() : 1; }
127 
137  { return (_active_subdomains.empty() || _active_subdomains.count(sid)); }
138 
144  bool implicitly_active () const
145  { return _active_subdomains.empty(); }
146 
150  const std::set<subdomain_id_type> & active_subdomains() const
151  { return _active_subdomains; }
152 
153 protected:
155  std::string _name;
156  std::set<subdomain_id_type> _active_subdomains;
157  unsigned int _number;
158  unsigned int _first_scalar_number;
160 };
161 
162 
163 
172 class VariableGroup : public Variable
173 {
174 public:
181  const std::vector<std::string> & var_names,
182  const unsigned int var_number,
183  const unsigned int first_scalar_num,
184  const FEType & var_type) :
185  Variable (sys,
186  "var_group",
187  var_number,
188  first_scalar_num,
189  var_type),
190  _names(var_names)
191  {}
192 
193 
199  const std::vector<std::string> & var_names,
200  const unsigned int var_number,
201  const unsigned int first_scalar_num,
202  const FEType & var_type,
203  const std::set<subdomain_id_type> & var_active_subdomains) :
204 
205  Variable (sys,
206  "var_group",
207  var_number,
208  first_scalar_num,
209  var_type,
210  var_active_subdomains),
211  _names(var_names)
212  {}
213 
217  unsigned int n_variables () const
218  { return cast_int<unsigned int>(_names.size()); }
219 
224  Variable variable (unsigned int v) const
225  {
226  libmesh_assert_less (v, this->n_variables());
227  return Variable (this->system(),
228  this->name(v),
229  this->number(v),
230  this->first_scalar_number(v),
231  this->type(),
232  this->active_subdomains());
233  }
234 
240  Variable operator() (unsigned int v) const
241  { return this->variable(v); }
242 
246  const std::string & name(unsigned int v) const
247  {
248  libmesh_assert_less (v, this->n_variables());
249  return _names[v];
250  }
251 
255  unsigned int number(unsigned int v) const
256  {
257  libmesh_assert_less (v, this->n_variables());
258  return _number + v;
259  }
260 
261  // Don't let number(uint) hide number()
262  using Variable::number;
263 
268  unsigned int first_scalar_number(unsigned int v) const
269  {
270  libmesh_assert_less (v, this->n_variables());
271  return _first_scalar_number+v;
272  }
273 
279  void append (const std::string & var_name)
280  { _names.push_back (var_name); }
281 
282 protected:
283  std::vector<std::string> _names;
284 };
285 
286 } // namespace libMesh
287 
288 #endif // LIBMESH_VARIABLE_H
Manages the family, order, etc. parameters for a given FE.
Definition: fe_type.h:179
FEFamily family
Definition: fe_type.h:204
std::set< subdomain_id_type > _active_subdomains
Definition: variable.h:156
std::string _name
Definition: variable.h:155
VariableGroup(System *sys, const std::vector< std::string > &var_names, const unsigned int var_number, const unsigned int first_scalar_num, const FEType &var_type, const std::set< subdomain_id_type > &var_active_subdomains)
Definition: variable.h:198
Variable(System *sys, const std::string &var_name, const unsigned int var_number, const unsigned int first_scalar_num, const FEType &var_type)
Definition: variable.h:58
OrderWrapper order
Definition: fe_type.h:198
const std::string & name(unsigned int v) const
Definition: variable.h:246
VariableGroup(System *sys, const std::vector< std::string > &var_names, const unsigned int var_number, const unsigned int first_scalar_num, const FEType &var_type)
Definition: variable.h:180
Variable(System *sys, const std::string &var_name, const unsigned int var_number, const unsigned int first_scalar_num, const FEType &var_type, const std::set< subdomain_id_type > &var_active_subdomains)
Definition: variable.h:75
unsigned int _first_scalar_number
Definition: variable.h:158
unsigned int first_scalar_number() const
Definition: variable.h:113
A variable which is solved for in a System of equations.
Definition: variable.h:49
const std::set< subdomain_id_type > & active_subdomains() const
Definition: variable.h:150
unsigned int n_variables() const
Definition: variable.h:217
unsigned int n_components() const
Definition: variable.h:125
Manages consistently variables, degrees of freedom, and coefficient vectors.
Definition: system.h:92
std::vector< std::string > _names
Definition: variable.h:283
bool active_on_subdomain(subdomain_id_type sid) const
Definition: variable.h:136
void append(const std::string &var_name)
Definition: variable.h:279
Variable variable(unsigned int v) const
Definition: variable.h:224
Variable operator()(unsigned int v) const
Definition: variable.h:240
bool implicitly_active() const
Definition: variable.h:144
int get_order() const
Definition: fe_type.h:78
System * _sys
Definition: variable.h:154
System * system() const
Definition: variable.h:92
unsigned int number(unsigned int v) const
Definition: variable.h:255
unsigned int _number
Definition: variable.h:157
const std::string & name() const
Definition: variable.h:100
unsigned int number() const
Definition: variable.h:106
unsigned int first_scalar_number(unsigned int v) const
Definition: variable.h:268
const FEType & type() const
Definition: variable.h:119