00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef MECHSYS_FEM_NODE_H
00023 #define MECHSYS_FEM_NODE_H
00024
00025 #ifdef HAVE_CONFIG_H
00026 #include "config.h"
00027 #else
00028 #ifndef REAL
00029 #define REAL double
00030 #endif
00031 #endif
00032
00033 #include <map>
00034 #include <sstream>
00035
00036 #include "util/array.h"
00037 #include "util/string.h"
00038 #include "util/exception.h"
00039 #include "util/numstreams.h"
00040 #include "fem/node.h"
00041
00042 using Util::_8s;
00043 using Util::_6;
00044 using Util::_a;
00045
00046 namespace FEM
00047 {
00048
00050 class Node
00051 {
00052 friend std::ostream & operator<< (std::ostream & os, FEM::Node const & node);
00053 public:
00054 Node() : _has_essential_vector(false), _has_natural_vector(false) {}
00055 struct DOFVarsStruct
00056 {
00057 REAL EssentialBry;
00058 REAL NaturalBry;
00059 bool IsEssenPresc;
00060 int EqID;
00061 REAL EssentialVal;
00062 REAL NaturalVal;
00063 REAL _IncEssenVal;
00064 REAL _IncNaturVal;
00065 bool EssenPrescPersist;
00066 };
00067
00068 void Initialize(int Number, REAL X, REAL Y, REAL Z);
00069 void ClearDOF();
00070 void AddDOF(String const & StrEssentialBry, String const & StrNaturalBry);
00071 bool IsEssential(String const & Name) const;
00072 bool HasVar (String const & Name) const;
00073 DOFVarsStruct & DOFVar(String const & Name);
00074 DOFVarsStruct const & DOFVar(String const & Name) const;
00075 Array<Node::DOFVarsStruct> & DOFVars() { return _dof_vars; }
00076 std::string OutMap();
00077 int Number() const { return _number; }
00078 REAL X() const { return _x; }
00079 REAL Y() const { return _y; }
00080 REAL Z() const { return _z; }
00081 int & Refs() { return _refs; };
00082 int const & Refs() const { return _refs; };
00083 void ClearBryValues()
00084 {
00085 for (size_t i=0; i<_dof_vars.size(); ++i)
00086 {
00087
00088 _dof_vars[i].EssentialBry = 0.0;
00089 _dof_vars[i].NaturalBry = 0.0;
00090 _dof_vars[i].IsEssenPresc = false;
00091 _dof_vars[i].EqID = -1;
00092 if (_dof_vars[i].EssenPrescPersist) _dof_vars[i].IsEssenPresc = true;
00093 }
00094 }
00095 String Out(bool PrintCaptionOnly=false) const;
00096
00097 void SetEssentialVector (String const & UX, String const & UY, String const & UZ);
00098 void SetNaturalVector (String const & FX, String const & FY, String const & FZ);
00099 void OutEssentialVector (String & Str) const;
00100 void OutNaturalVector (String & Str) const;
00101 bool HasEssentialVector () const { return _has_essential_vector; }
00102 bool HasNaturalVector () const { return _has_natural_vector; }
00103 int nDOF() const { return _dof_vars.size(); }
00104 private:
00105
00106 struct DOFInfo
00107 {
00108 size_t ArrayPos;
00109 bool IsEssential;
00110 };
00111
00112 int _number;
00113 int _refs;
00114 REAL _x;
00115 REAL _y;
00116 REAL _z;
00117 std::map<String, DOFInfo, std::less<String> > _dof_map;
00118 Array<DOFVarsStruct> _dof_vars;
00119
00120 String _UX;
00121 String _UY;
00122 String _UZ;
00123 String _FX;
00124 String _FY;
00125 String _FZ;
00126 bool _has_essential_vector;
00127 bool _has_natural_vector;
00128 };
00129
00130 std::ostream & operator<< (std::ostream & os, FEM::Node::DOFVarsStruct const & Vars);
00131 std::ostream & operator<< (std::ostream & os, Array<FEM::Node::DOFVarsStruct> const & AVars);
00132 std::ostream & operator<< (std::ostream & os, FEM::Node const & node);
00133 std::ostream & operator<< (std::ostream & os, Array<FEM::Node> const & nodes);
00134
00135
00137
00138
00139 inline void Node::Initialize(int Number, REAL X, REAL Y, REAL Z)
00140 {
00141 _number = Number;
00142 _x = X;
00143 _y = Y;
00144 _z = Z;
00145 _refs = 0;
00146 }
00147
00148
00149
00150 inline void Node::ClearDOF()
00151 {
00152 _dof_vars.resize(0);
00153 _dof_map.clear();
00154 }
00155
00156 inline void Node::AddDOF(String const & StrEssentialBry, String const & StrNaturalBry)
00157 {
00158
00159 if (_dof_map.find(StrEssentialBry)==_dof_map.end())
00160 {
00161
00162 size_t n_dof = _dof_map.size()/2;
00163
00164
00165 DOFInfo dof_info = {n_dof,true};
00166 _dof_map[StrEssentialBry] = dof_info;
00167
00168
00169 dof_info.ArrayPos = n_dof;
00170 dof_info.IsEssential = false;
00171 _dof_map[StrNaturalBry] = dof_info;
00172
00173
00174 DOFVarsStruct dof_struct = {0,0,false,-1,0,0,0,0,false};
00175 _dof_vars.push_back(dof_struct);
00176 }
00177 }
00178
00179
00180
00181 inline bool Node::IsEssential(String const & Name) const
00182 {
00183 std::map<String, DOFInfo>::const_iterator it = _dof_map.find(Name);
00184 if (it==_dof_map.end())
00185 throw new Fatal(_("Node::IsEssential: Could not find DOF variable name < %s > inside Node"), Name.c_str());
00186 return it->second.IsEssential;
00187 }
00188
00189
00190
00191 inline bool Node::HasVar(String const & Name) const
00192 {
00193 std::map<String, DOFInfo>::const_iterator it = _dof_map.find(Name);
00194 if (it==_dof_map.end()) return false;
00195 return true;
00196 }
00197
00198
00199
00200 inline Node::DOFVarsStruct & Node::DOFVar(String const & Name)
00201 {
00202
00203 std::map<String, DOFInfo>::const_iterator it = _dof_map.find(Name);
00204 if (it==_dof_map.end())
00205 throw new Fatal(_("Node::DOFVarsStruct: Node coords=<%.6f; %.6f; %.6f>. Could not find DOF variable name < %s > inside Node"), _x, _y, _z, Name.c_str());
00206
00207
00208 return _dof_vars[ it->second.ArrayPos ];
00209 }
00210
00211
00212
00213 inline Node::DOFVarsStruct const & Node::DOFVar(String const & Name) const
00214 {
00215
00216 std::map<String, DOFInfo>::const_iterator it = _dof_map.find(Name);
00217 if (it==_dof_map.end())
00218 throw new Fatal(_("Node::DOFVarsStruct: Node coords=<%.6f; %.6f; %.6f>. Could not find DOF variable name < %s > inside Node"), _x, _y, _z, Name.c_str());
00219
00220
00221 return _dof_vars[ it->second.ArrayPos ];
00222 }
00223
00224
00225
00226 inline std::string Node::OutMap()
00227 {
00228 std::ostringstream oss;
00229 std::map<String, DOFInfo>::const_iterator it;
00230 for (it=_dof_map.begin(); it!=_dof_map.end(); ++it)
00231 {
00232 oss << _6()<< it->first << _8s()<< it->second.ArrayPos << _a()<< it->second.IsEssential << std::endl;
00233 }
00234 return oss.str();
00235 }
00236
00237
00238
00239 inline String Node::Out(bool PrintCaptionOnly) const
00240 {
00241
00242 std::ostringstream oss;
00243 std::map<String, DOFInfo>::const_iterator it;
00244
00245
00246 if (PrintCaptionOnly)
00247 {
00248
00249 for (it=_dof_map.begin(); it!=_dof_map.end(); ++it)
00250 if (it->second.IsEssential==true)
00251 oss << _8s()<< it->first;
00252
00253
00254 for (it=_dof_map.begin(); it!=_dof_map.end(); ++it)
00255 if (it->second.IsEssential==false)
00256 oss << _8s()<< it->first;
00257
00258 oss << std::endl;
00259 }
00260 else
00261 {
00262
00263 for (it=_dof_map.begin(); it!=_dof_map.end(); ++it)
00264 if (it->second.IsEssential==true)
00265 oss << _8s()<< _dof_vars[ it->second.ArrayPos ].EssentialVal ;
00266
00267
00268 for (it=_dof_map.begin(); it!=_dof_map.end(); ++it)
00269 if (it->second.IsEssential==false)
00270 oss << _8s()<< _dof_vars[ it->second.ArrayPos ].NaturalVal ;
00271
00272 oss << std::endl;
00273 }
00274
00275 return oss.str();
00276 }
00277
00278 inline void Node::SetEssentialVector(String const & UX, String const & UY, String const & UZ)
00279 {
00280 _UX = UX;
00281 _UY = UY;
00282 _UZ = UZ;
00283 _has_essential_vector = true;
00284 }
00285
00286 inline void Node::SetNaturalVector(String const & FX, String const & FY, String const & FZ)
00287 {
00288 _FX = FX;
00289 _FY = FY;
00290 _FZ = FZ;
00291 _has_natural_vector = true;
00292 }
00293
00294 inline void Node::OutEssentialVector(String & Str) const
00295 {
00296 if (_has_essential_vector)
00297 {
00298 std::map<String, DOFInfo>::const_iterator it;
00299 it=_dof_map.find(_UX); REAL ux=_dof_vars[ it->second.ArrayPos ].EssentialVal;
00300 it=_dof_map.find(_UY); REAL uy=_dof_vars[ it->second.ArrayPos ].EssentialVal;
00301 it=_dof_map.find(_UZ); REAL uz=_dof_vars[ it->second.ArrayPos ].EssentialVal;
00302 Str.Printf(_(" %e %e %e "),ux,uy,uz);
00303 }
00304 else Str.Printf(_(" 0 0 0 "));
00305
00306 }
00307
00308 inline void Node::OutNaturalVector(String & Str) const
00309 {
00310 if (_has_natural_vector)
00311 {
00312 std::map<String, DOFInfo>::const_iterator it;
00313 it=_dof_map.find(_FX); REAL fx=_dof_vars[ it->second.ArrayPos ].NaturalVal;
00314 it=_dof_map.find(_FY); REAL fy=_dof_vars[ it->second.ArrayPos ].NaturalVal;
00315 it=_dof_map.find(_FZ); REAL fz=_dof_vars[ it->second.ArrayPos ].NaturalVal;
00316 Str.Printf(_(" %e %e %e "),fx,fy,fz);
00317 }
00318 else Str.Printf(_(" 0 0 0 "));
00319
00320 }
00321
00322
00323
00324 std::ostream & operator<< (std::ostream & os, FEM::Node::DOFVarsStruct const & V)
00325 {
00326 os << _8s()<< V.EssentialBry << _8s()<< V.NaturalBry << _a()<< V.IsEssenPresc << _6()<< V.EqID << _8s()<< V.EssentialVal << _8s()<< V.NaturalVal;
00327 return os;
00328 }
00329
00330 std::ostream & operator<< (std::ostream & os, Array<FEM::Node::DOFVarsStruct> const & AVars)
00331 {
00332 for (size_t i=0; i<AVars.size(); ++i)
00333 os << AVars[i] << std::endl;
00334 return os;
00335 }
00336
00337 std::ostream & operator<< (std::ostream & os, FEM::Node const & node)
00338 {
00339 os << _8s()<< node._x << _8s()<< node._y << _8s()<< node._z << std::endl;
00340 for (size_t i=0; i<node._dof_vars.size(); ++i)
00341 {
00342 os << node._dof_vars[i];
00343 if (i!=node._dof_vars.size()-1) os << std::endl;
00344 }
00345 os << std::endl;
00346 return os;
00347 }
00348
00349 std::ostream & operator<< (std::ostream & os, Array<FEM::Node> const & nodes)
00350 {
00351 os << _("Number of nodes = ") << nodes.size() << std::endl;
00352 for (size_t i=0; i<nodes.size(); ++i)
00353 os << _6()<< i+1 << nodes[i];
00354 return os;
00355 }
00356
00357
00358
00359 };
00360
00361 #endif // MECHSYS_FEM_NODE_H
00362
00363