MBDyn-1.7.3
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups
userelem.cc
Go to the documentation of this file.
1 /* $Header: /var/cvs/mbdyn/mbdyn/mbdyn-1.0/mbdyn/base/userelem.cc,v 1.22 2017/01/12 14:46:11 masarati Exp $ */
2 /*
3  * MBDyn (C) is a multibody analysis code.
4  * http://www.mbdyn.org
5  *
6  * Copyright (C) 1996-2017
7  *
8  * Pierangelo Masarati <masarati@aero.polimi.it>
9  * Paolo Mantegazza <mantegazza@aero.polimi.it>
10  *
11  * Dipartimento di Ingegneria Aerospaziale - Politecnico di Milano
12  * via La Masa, 34 - 20156 Milano, Italy
13  * http://www.aero.polimi.it
14  *
15  * Changing this copyright notice is forbidden.
16  *
17  * This program is free software; you can redistribute it and/or modify
18  * it under the terms of the GNU General Public License as published by
19  * the Free Software Foundation (version 2 of the License).
20  *
21  *
22  * This program is distributed in the hope that it will be useful,
23  * but WITHOUT ANY WARRANTY; without even the implied warranty of
24  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25  * GNU General Public License for more details.
26  *
27  * You should have received a copy of the GNU General Public License
28  * along with this program; if not, write to the Free Software
29  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
30  */
31 
32 #include "mbconfig.h" /* This goes first in every *.c,*.cc file */
33 
34 #include "dataman.h"
35 #include "userelem.h"
36 
37 // include here known loadable element parsers that go into InitUDE()
38 #include "loadable.h"
39 
40 #ifdef STATIC_MODULES
45 #ifdef HAVE_CHARM
46 #include "module-charm/mbcharm.h"
47 #endif // HAVE_CHARM
48 #endif // STATIC_MODULES
49 
50 typedef std::map<std::string, UserDefinedElemRead *, ltstrcase> UDEMapType;
52 
54  bool IsWord(const std::string& s) const {
55  return ::UDEMap.find(std::string(s)) != ::UDEMap.end();
56  };
57 };
59 
61 ParseUserDefinedElem(unsigned uLabel, DofOwner* pDO,
62  DataManager* const pDM, MBDynParser& HP)
63 {
64  DEBUGCOUTFNAME("ParseUserDefinedElem(" << uLabel << ")");
65 
66  const char *s = HP.IsWord(::UDEWordSet);
67  if (s == 0) {
68  silent_cerr("ParseUserDefinedElem(" << uLabel << "): "
69  "unknown user-defined element type "
70  "at line " << HP.GetLineData() << std::endl);
72  }
73 
74  UDEMapType::iterator i = ::UDEMap.find(std::string(s));
75  if (i == ::UDEMap.end()) {
76  silent_cerr("ParseUserDefinedElem(" << uLabel << "): "
77  "unknown user-defined element type \"" << s << "\" "
78  "at line " << HP.GetLineData() << std::endl);
80  }
81 
82  return i->second->Read(uLabel, pDO, pDM, HP);
83 }
84 
85 // legacy
86 Elem *
88  const DofOwner* pDO, unsigned int uLabel)
89 {
90  UDEMapType::iterator i = UDEMap.find("loadable");
91  ASSERT(i != UDEMap.end());
92 
93  return i->second->Read(uLabel, pDO, pDM, HP);
94 }
95 
96 bool
97 SetUDE(const std::string &s, UserDefinedElemRead *rude)
98 {
99  pedantic_cout("registering user-defined element \"" << s << "\""
100  << std::endl );
101  return UDEMap.insert(UDEMapType::value_type(s, rude)).second;
102 }
103 
104 static unsigned done = 0;
105 
106 void
107 InitUDE(void)
108 {
109  if (::done++ > 0) {
110  return;
111  }
112 
113  bool b;
114 
115  b = SetUDE("loadable", new LoadableElemRead);
116  ASSERT(b != false);
117 #ifdef STATIC_MODULES
118  b = wheel2_set();
119  ASSERT(b != false);
121  ASSERT(b != false);
122  b = inline_friction_set();
123  ASSERT(b != false);
124  b = mbdyn_cyclocopter_set();
125  ASSERT(b != false);
126 #ifdef HAVE_CHARM
127  b = mbcharm_set();
128  ASSERT(b != false);
129 #endif // HAVE_CHARM
130 #endif // STATIC_MODULES
131 }
132 
133 void
135 {
136  if (::done == 0) {
137  silent_cerr("DestroyUDE() called once too many" << std::endl);
139  }
140 
141  if (--done > 0) {
142  return;
143  }
144 
145  for (UDEMapType::iterator i = UDEMap.begin(); i != UDEMap.end(); ++i) {
146  delete i->second;
147  }
148  UDEMap.clear();
149 }
150 
151 // base class for user-defined elements
152 UserDefinedElem::UserDefinedElem(unsigned uLabel, const DofOwner* pDO)
153 : Elem(uLabel, flag(0)),
154 InitialAssemblyElem(uLabel, flag(0)),
155 AerodynamicElem(uLabel, pDO, flag(0)),
156 ElemGravityOwner(uLabel, flag(0)),
157 needsAirProperties(false)
158 {
159  NO_OP;
160 }
161 
163 {
164  NO_OP;
165 }
166 
167 bool
169 {
170  return needsAirProperties;
171 }
172 
173 void
175 {
176  needsAirProperties = yesno;
177 }
178 
179 Elem::Type
181 {
182  return Elem::LOADABLE;
183 }
184 
187 {
189 }
190 
long int flag
Definition: mbdyn.h:43
#define MBDYN_EXCEPT_ARGS
Definition: except.h:63
#define DEBUGCOUTFNAME(fname)
Definition: myassert.h:256
bool inline_friction_set(void)
virtual const char * IsWord(const HighParser::WordSet &ws)
Definition: parser.cc:977
std::map< std::string, UserDefinedElemRead *, ltstrcase > UDEMapType
Definition: userelem.cc:50
bool IsWord(const std::string &s) const
Definition: userelem.cc:54
#define NO_OP
Definition: myassert.h:74
static UDEMapType UDEMap
Definition: userelem.cc:51
virtual ~UserDefinedElem(void)
Definition: userelem.cc:162
Definition: mbdyn.h:76
bool asynchronous_machine_set(void)
Elem * ReadLoadable(DataManager *pDM, MBDynParser &HP, const DofOwner *pDO, unsigned int uLabel)
Definition: userelem.cc:87
bool wheel2_set(void)
bool NeedsAirProperties(void) const
Definition: userelem.cc:168
#define ASSERT(expression)
Definition: colamd.c:977
static UDEWordSetType UDEWordSet
Definition: userelem.cc:58
Definition: elem.h:75
Type
Definition: elem.h:91
bool SetUDE(const std::string &s, UserDefinedElemRead *rude)
Definition: userelem.cc:97
UserDefinedElem(unsigned uLabel, const DofOwner *pDO)
Definition: userelem.cc:152
void InitUDE(void)
Definition: userelem.cc:107
bool mbdyn_cyclocopter_set(void)
virtual AerodynamicElem::Type GetAerodynamicElemType(void) const
Definition: userelem.cc:186
static unsigned done
Definition: userelem.cc:104
virtual HighParser::ErrOut GetLineData(void) const
Definition: parsinc.cc:697
bool needsAirProperties
Definition: userelem.h:48
UserDefinedElem * ParseUserDefinedElem(unsigned uLabel, DofOwner *pDO, DataManager *const pDM, MBDynParser &HP)
Definition: userelem.cc:61
virtual Elem::Type GetElemType(void) const
Definition: userelem.cc:180
void DestroyUDE(void)
Definition: userelem.cc:134