$extrastylesheet
00001 // The libMesh Finite Element Library. 00002 // Copyright (C) 2002-2014 Benjamin S. Kirk, John W. Peterson, Roy H. Stogner 00003 00004 // This library is free software; you can redistribute it and/or 00005 // modify it under the terms of the GNU Lesser General Public 00006 // License as published by the Free Software Foundation; either 00007 // version 2.1 of the License, or (at your option) any later version. 00008 00009 // This library is distributed in the hope that it will be useful, 00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00012 // Lesser General Public License for more details. 00013 00014 // You should have received a copy of the GNU Lesser General Public 00015 // License along with this library; if not, write to the Free Software 00016 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00017 00018 #ifndef LIBMESH_VARIABLE_H 00019 #define LIBMESH_VARIABLE_H 00020 00021 // Local Includes 00022 #include "libmesh/libmesh_common.h" 00023 #include "libmesh/fe_type.h" 00024 #include "libmesh/id_types.h" 00025 00026 // C++ includes 00027 #include <set> 00028 #include <string> 00029 #include <vector> 00030 00031 namespace libMesh { 00032 00033 // Forward Declaration 00034 class System; 00035 00044 class Variable 00045 { 00046 public: 00047 00053 Variable (System *sys, 00054 const std::string &var_name, 00055 const unsigned int var_number, 00056 const unsigned int first_scalar_num, 00057 const FEType &var_type) : 00058 _sys(sys), 00059 _name(var_name), 00060 _active_subdomains(), 00061 _number(var_number), 00062 _first_scalar_number(first_scalar_num), 00063 _type(var_type) 00064 {} 00065 00070 Variable (System *sys, 00071 const std::string &var_name, 00072 const unsigned int var_number, 00073 const unsigned int first_scalar_num, 00074 const FEType &var_type, 00075 const std::set<subdomain_id_type> &var_active_subdomains) : 00076 _sys(sys), 00077 _name(var_name), 00078 _active_subdomains(var_active_subdomains), 00079 _number(var_number), 00080 _first_scalar_number(first_scalar_num), 00081 _type(var_type) 00082 {} 00083 00087 System * system() const 00088 { 00089 return _sys; 00090 } 00091 00095 const std::string & name() const 00096 { return _name; } 00097 00101 unsigned int number() const 00102 { return _number; } 00103 00108 unsigned int first_scalar_number() const 00109 { return _first_scalar_number; } 00110 00114 const FEType & type() const 00115 { return _type; } 00116 00120 unsigned int n_components() const 00121 { return type().family == SCALAR ? _type.order : 1; } 00122 00129 bool active_on_subdomain (subdomain_id_type sid) const 00130 { return (_active_subdomains.empty() || _active_subdomains.count(sid)); } 00131 00137 bool implicitly_active () const 00138 { return _active_subdomains.empty(); } 00139 00143 const std::set<subdomain_id_type> & active_subdomains() const 00144 { return _active_subdomains; } 00145 00146 protected: 00147 System * _sys; 00148 std::string _name; 00149 std::set<subdomain_id_type> _active_subdomains; 00150 unsigned int _number; 00151 unsigned int _first_scalar_number; 00152 FEType _type; 00153 }; 00154 00155 00156 00165 class VariableGroup : public Variable 00166 { 00167 public: 00173 VariableGroup (System *sys, 00174 const std::vector<std::string> &var_names, 00175 const unsigned int var_number, 00176 const unsigned int first_scalar_num, 00177 const FEType &var_type) : 00178 Variable (sys, 00179 "var_group", 00180 var_number, 00181 first_scalar_num, 00182 var_type), 00183 _names(var_names) 00184 {} 00185 00186 00191 VariableGroup (System *sys, 00192 const std::vector<std::string> &var_names, 00193 const unsigned int var_number, 00194 const unsigned int first_scalar_num, 00195 const FEType &var_type, 00196 const std::set<subdomain_id_type> &var_active_subdomains) : 00197 00198 Variable (sys, 00199 "var_group", 00200 var_number, 00201 first_scalar_num, 00202 var_type, 00203 var_active_subdomains), 00204 _names(var_names) 00205 {} 00206 00210 unsigned int n_variables () const 00211 { return cast_int<unsigned int>(_names.size()); } 00212 00217 Variable variable (unsigned int v) const 00218 { 00219 libmesh_assert_less (v, this->n_variables()); 00220 return Variable (this->system(), 00221 this->name(v), 00222 this->number(v), 00223 this->first_scalar_number(v), 00224 this->type(), 00225 this->active_subdomains()); 00226 } 00227 00231 Variable operator() (unsigned int v) const 00232 { return this->variable(v); } 00233 00237 const std::string & name(unsigned int v) const 00238 { 00239 libmesh_assert_less (v, this->n_variables()); 00240 return _names[v]; 00241 } 00242 00246 unsigned int number(unsigned int v) const 00247 { 00248 libmesh_assert_less (v, this->n_variables()); 00249 return _number + v; 00250 } 00251 00256 unsigned int first_scalar_number(unsigned int v) const 00257 { 00258 libmesh_assert_less (v, this->n_variables()); 00259 return _first_scalar_number+v; 00260 } 00261 00267 void append (const std::string &var_name) 00268 { _names.push_back (var_name); } 00269 00270 protected: 00271 std::vector<std::string> _names; 00272 }; 00273 00274 } // namespace libMesh 00275 00276 #endif // LIBMESH_VARIABLE_H