libmesh解析
本工作只是尝试解析原libmesh的代码,供学习使用
 全部  命名空间 文件 函数 变量 类型定义 枚举 枚举值 友元 
variable.h
浏览该文件的文档.
1 // The libMesh Finite Element Library.
2 // Copyright (C) 2002-2023 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  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(std::move(var_name)),
66  _number(var_number),
67  _first_scalar_number(first_scalar_num),
68  _type(var_type)
69  {}
70 
75  Variable (System * sys,
76  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(std::move(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  Variable (const Variable &) = default;
93  Variable & operator= (const Variable &) = default;
94  Variable (Variable &&) = default;
95  Variable & operator= (Variable &&) = default;
96 
101  bool operator== ( const Variable & other) const
102  {
103  return (_sys == other._sys) &&
104  (_name == other._name) &&
107  (_type == other._type);
108  }
109 
113  System * system() const
114  {
115  return _sys;
116  }
117 
121  const std::string & name() const
122  { return _name; }
123 
127  unsigned int number() const
128  { return _number; }
129 
134  unsigned int first_scalar_number() const
135  { return _first_scalar_number; }
136 
140  const FEType & type() const
141  { return _type; }
142 
146  unsigned int n_components() const
147  { return type().family == SCALAR ? _type.order.get_order() : 1; }
148 
158  { return (_active_subdomains.empty() || _active_subdomains.count(sid)); }
159 
165  bool implicitly_active () const
166  { return _active_subdomains.empty(); }
167 
171  const std::set<subdomain_id_type> & active_subdomains() const
172  { return _active_subdomains; }
173 
174 protected:
175  System * _sys;
176  std::string _name;
177  std::set<subdomain_id_type> _active_subdomains;
178  unsigned int _number;
179  unsigned int _first_scalar_number;
180  FEType _type;
181 };
182 
183 
184 
193 class VariableGroup : public Variable
194 {
195 public:
201  VariableGroup (System * sys,
202  std::vector<std::string> var_names,
203  const unsigned int var_number,
204  const unsigned int first_scalar_num,
205  const FEType & var_type) :
206  Variable (sys,
207  "var_group",
208  var_number,
209  first_scalar_num,
210  var_type),
211  _names(std::move(var_names))
212  {}
213 
214 
219  VariableGroup (System * sys,
220  std::vector<std::string> var_names,
221  const unsigned int var_number,
222  const unsigned int first_scalar_num,
223  const FEType & var_type,
224  const std::set<subdomain_id_type> & var_active_subdomains) :
225 
226  Variable (sys,
227  "var_group",
228  var_number,
229  first_scalar_num,
230  var_type,
231  var_active_subdomains),
232  _names(std::move(var_names))
233  {}
234 
238  VariableGroup (const VariableGroup &) = default;
239  VariableGroup & operator= (const VariableGroup &) = default;
240  VariableGroup (VariableGroup &&) = default;
241  VariableGroup & operator= (VariableGroup &&) = default;
242 
247  bool operator== ( const VariableGroup & other) const
248  {
249  return (this->Variable::operator==(other)) &&
250  (_names == other._names);
251  }
252 
256  unsigned int n_variables () const
257  { return cast_int<unsigned int>(_names.size()); }
258 
263  Variable variable (unsigned int v) const
264  {
265  libmesh_assert_less (v, this->n_variables());
266  return Variable (this->system(),
267  this->name(v),
268  this->number(v),
269  this->first_scalar_number(v),
270  this->type(),
271  this->active_subdomains());
272  }
273 
279  Variable operator() (unsigned int v) const
280  { return this->variable(v); }
281 
285  const std::string & name(unsigned int v) const
286  {
287  libmesh_assert_less (v, this->n_variables());
288  return _names[v];
289  }
290 
294  unsigned int number(unsigned int v) const
295  {
296  libmesh_assert_less (v, this->n_variables());
297  return _number + v;
298  }
299 
300  // Don't let number(uint) hide number()
301  using Variable::number;
302 
307  unsigned int first_scalar_number(unsigned int v) const
308  {
309  libmesh_assert_less (v, this->n_variables());
310  return _first_scalar_number+v;
311  }
312 
318  void append (std::string var_name)
319  { _names.push_back (std::move(var_name)); }
320 
321 protected:
322  std::vector<std::string> _names;
323 };
324 
325 } // namespace libMesh
326 
327 #endif // LIBMESH_VARIABLE_H
const FEType & type() const
Definition: variable.h:140
std::set< subdomain_id_type > _active_subdomains
Definition: variable.h:177
std::string _name
Definition: variable.h:176
unsigned int first_scalar_number(unsigned int v) const
Definition: variable.h:307
VariableGroup(System *sys, 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:219
const std::string & name() const
Definition: variable.h:121
Variable operator()(unsigned int v) const
Support vg(v).
Definition: variable.h:279
VariableGroup & operator=(const VariableGroup &)=default
bool operator==(const Variable &other) const
Definition: variable.h:101
bool operator==(const VariableGroup &other) const
Definition: variable.h:247
bool implicitly_active() const
Definition: variable.h:165
Variable(System *sys, std::string var_name, const unsigned int var_number, const unsigned int first_scalar_num, const FEType &var_type)
Constructor.
Definition: variable.h:58
unsigned int first_scalar_number() const
Definition: variable.h:134
VariableGroup(System *sys, 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:201
unsigned int number() const
Definition: variable.h:127
void append(std::string var_name)
Appends a variable to the group.
Definition: variable.h:318
unsigned int _first_scalar_number
Definition: variable.h:179
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:294
unsigned int n_variables() const
Definition: variable.h:256
Variable & operator=(const Variable &)=default
bool active_on_subdomain(subdomain_id_type sid) const
Definition: variable.h:157
std::vector< std::string > _names
Definition: variable.h:322
Variable variable(unsigned int v) const
Definition: variable.h:263
This class defines a logically grouped set of variables in the system.
Definition: variable.h:193
System * _sys
Definition: variable.h:175
unsigned int n_components() const
Definition: variable.h:146
System * system() const
Definition: variable.h:113
const std::set< subdomain_id_type > & active_subdomains() const
Definition: variable.h:171
unsigned int _number
Definition: variable.h:178
const std::string & name(unsigned int v) const
Definition: variable.h:285
Variable(System *sys, 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