libMesh
variable.h
Go to the documentation of this file.
1 // The libMesh Finite Element Library.
2 // Copyright (C) 2002-2017 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 
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 
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 
265  unsigned int first_scalar_number(unsigned int v) const
266  {
267  libmesh_assert_less (v, this->n_variables());
268  return _first_scalar_number+v;
269  }
270 
276  void append (const std::string & var_name)
277  { _names.push_back (var_name); }
278 
279 protected:
280  std::vector<std::string> _names;
281 };
282 
283 } // namespace libMesh
284 
285 #endif // LIBMESH_VARIABLE_H
class FEType hides (possibly multiple) FEFamily and approximation orders, thereby enabling specialize...
Definition: fe_type.h:178
FEFamily family
The type of finite element.
Definition: fe_type.h:203
int get_order() const
Explicitly request the order as an int.
Definition: fe_type.h:77
const FEType & type() const
Definition: variable.h:119
std::set< subdomain_id_type > _active_subdomains
Definition: variable.h:156
std::string _name
Definition: variable.h:155
unsigned int first_scalar_number(unsigned int v) const
Definition: variable.h:265
const std::string & name() const
Definition: variable.h:100
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)
Constructor.
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)
Constructor.
Definition: variable.h:58
ImplicitSystem & sys
OrderWrapper order
The approximation order of the element.
Definition: fe_type.h:197
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)
Constructor.
Definition: variable.h:180
The libMesh namespace provides an interface to certain functionality in the library.
bool implicitly_active() const
Definition: variable.h:144
unsigned int first_scalar_number() const
Definition: variable.h:113
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)
Constructor.
Definition: variable.h:75
unsigned int number() const
Definition: variable.h:106
unsigned int _first_scalar_number
Definition: variable.h:158
This class defines the notion of a variable in the system.
Definition: variable.h:49
unsigned int number(unsigned int v) const
Definition: variable.h:255
unsigned int n_variables() const
Definition: variable.h:217
This is the base class for classes which contain information related to any physical process that mig...
Definition: system.h:76
bool active_on_subdomain(subdomain_id_type sid) const
Definition: variable.h:136
std::vector< std::string > _names
Definition: variable.h:280
void append(const std::string &var_name)
Appends a variable to the group.
Definition: variable.h:276
Variable variable(unsigned int v) const
Definition: variable.h:224
This class defines a logically grouped set of variables in the system.
Definition: variable.h:172
System * _sys
Definition: variable.h:154
unsigned int n_components() const
Definition: variable.h:125
System * system() const
Definition: variable.h:92
const std::set< subdomain_id_type > & active_subdomains() const
Definition: variable.h:150
unsigned int _number
Definition: variable.h:157
const std::string & name(unsigned int v) const
Definition: variable.h:246