variable.h
Go to the documentation of this file.
1 // The libMesh Finite Element Library.
2 // Copyright (C) 2002-2014 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 // Forward Declaration
34 class System;
35 
44 class Variable
45 {
46 public:
47 
54  const std::string &var_name,
55  const unsigned int var_number,
56  const unsigned int first_scalar_num,
57  const FEType &var_type) :
58  _sys(sys),
59  _name(var_name),
60  _number(var_number),
61  _first_scalar_number(first_scalar_num),
62  _type(var_type),
64  {}
65 
71  const std::string &var_name,
72  const unsigned int var_number,
73  const unsigned int first_scalar_num,
74  const FEType &var_type,
75  const std::set<subdomain_id_type> &var_active_subdomains) :
76  _sys(sys),
77  _name(var_name),
78  _number(var_number),
79  _first_scalar_number(first_scalar_num),
80  _type(var_type),
81  _active_subdomains(var_active_subdomains)
82  {}
83 
87  System * system() const
88  {
89  return _sys;
90  }
91 
95  const std::string & name() const
96  { return _name; }
97 
101  unsigned int number() const
102  { return _number; }
103 
108  unsigned int first_scalar_number() const
109  { return _first_scalar_number; }
110 
114  const FEType & type() const
115  { return _type; }
116 
120  unsigned int n_components() const
121  { return type().family == SCALAR ? _type.order : 1; }
122 
130  { return (_active_subdomains.empty() || _active_subdomains.count(sid)); }
131 
137  bool implicitly_active () const
138  { return _active_subdomains.empty(); }
139 
143  const std::set<subdomain_id_type> & active_subdomains() const
144  { return _active_subdomains; }
145 
146 protected:
148  std::string _name;
149  unsigned int _number;
150  unsigned int _first_scalar_number;
152  std::set<subdomain_id_type> _active_subdomains;
153 };
154 
155 
156 
165 class VariableGroup : public Variable
166 {
167 public:
174  const std::vector<std::string> &var_names,
175  const unsigned int var_number,
176  const unsigned int first_scalar_num,
177  const FEType &var_type) :
178  Variable (sys,
179  "var_group",
180  var_number,
181  first_scalar_num,
182  var_type),
183  _names(var_names)
184  {}
185 
186 
192  const std::vector<std::string> &var_names,
193  const unsigned int var_number,
194  const unsigned int first_scalar_num,
195  const FEType &var_type,
196  const std::set<subdomain_id_type> &var_active_subdomains) :
197 
198  Variable (sys,
199  "var_group",
200  var_number,
201  first_scalar_num,
202  var_type,
203  var_active_subdomains),
204  _names(var_names)
205  {}
206 
210  unsigned int n_variables () const
211  { return libmesh_cast_int<unsigned int>(_names.size()); }
212 
217  Variable variable (unsigned int v) const
218  {
219  libmesh_assert_less (v, this->n_variables());
220  return Variable (this->system(),
221  this->name(v),
222  this->number(v),
223  this->first_scalar_number(v),
224  this->type(),
225  this->active_subdomains());
226  }
227 
231  Variable operator() (unsigned int v) const
232  { return this->variable(v); }
233 
237  const std::string & name(unsigned int v) const
238  {
239  libmesh_assert_less (v, this->n_variables());
240  return _names[v];
241  }
242 
246  unsigned int number(unsigned int v) const
247  {
248  libmesh_assert_less (v, this->n_variables());
249  return _number + v;
250  }
251 
256  unsigned int first_scalar_number(unsigned int v) const
257  {
258  libmesh_assert_less (v, this->n_variables());
259  return _first_scalar_number+v;
260  }
261 
267  void append (const std::string &var_name)
268  { _names.push_back (var_name); }
269 
270 protected:
271  std::vector<std::string> _names;
272 };
273 
274 } // namespace libMesh
275 
276 #endif // LIBMESH_VARIABLE_H

Site Created By: libMesh Developers
Last modified: February 07 2014 16:57:07 UTC

Hosted By:
SourceForge.net Logo