MBDyn-1.7.3
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups
streamoutelem.h
Go to the documentation of this file.
1 /* $Header: /var/cvs/mbdyn/mbdyn/mbdyn-1.0/mbdyn/base/streamoutelem.h,v 1.19 2017/09/09 09:18:21 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 #ifndef STREAMOUTELEM_H
33 #define STREAMOUTELEM_H
34 
35 #include "elem.h"
36 #include "scalarvalue.h"
37 #include "bufmod.h"
38 
39 #define UNIX_PATH_MAX 108
40 #define DEFAULT_PORT 9011 /* intentionally unassigned by IANA */
41 #define DEFAULT_HOST "127.0.0.1"
42 
43 /* StreamOutElem - begin */
44 
45 class StreamOutElem : virtual public Elem {
46 public:
47  enum Type {
48  UNDEFINED = -1,
49 
53  };
54 
55 protected:
56  std::string name;
57 
58  /* output with lower ratio */
59  unsigned int OutputEvery;
60  mutable unsigned int OutputCounter;
61 
62 public:
63  StreamOutElem(unsigned int uL, const std::string& name, unsigned int oe);
64 
65  virtual ~StreamOutElem(void);
66 
67  virtual Elem::Type GetElemType(void) const;
68  virtual void WorkSpaceDim(integer* piRows, integer* piCols) const;
69  virtual SubVectorHandler&
70  AssRes(SubVectorHandler& WorkVec, doublereal dCoef,
71  const VectorHandler& X, const VectorHandler& XP);
72  virtual VariableSubMatrixHandler&
74  const VectorHandler& X, const VectorHandler& XP);
75 };
76 
77 /* StreamOutElem - end */
78 
79 /* StreamContent - begin */
80 
82 public:
83  enum Type {
84  UNKNOWN = -1,
85 
86  VALUES = 0,
87  MOTION = 1,
88 
90  };
91 
92  class Modifier {
93  public:
94  virtual ~Modifier(void);
95 
96  virtual void Set(size_t size, const char *buf) = 0;
97  virtual void Modify(void) = 0;
98 
99  virtual const void *GetOutBuf(void) const = 0;
100  virtual int GetOutSize(void) const = 0;
101  };
102 
103  class Copy : public Modifier {
104  protected:
105  size_t m_size;
106  const char *m_outbuf;
107 
108  public:
109  Copy(size_t size, const char *buf);
110 
111  void Set(size_t size, const char *buf);
112  void Modify(void);
113 
114  virtual const void *GetOutBuf(void) const;
115  virtual int GetOutSize(void) const;
116  };
117 
118 protected:
119  /* Stream buffer */
120  std::vector<char> buf;
121 
123 
124 public:
125  StreamContent(size_t size, Modifier *pMod);
126  virtual ~StreamContent(void);
127 
128  void *GetBuf(void) const;
129  int GetSize(void) const;
130 
131  const void *GetOutBuf(void) const;
132  int GetOutSize(void) const;
133 
134  virtual void Prepare(void) = 0;
135  virtual unsigned GetNumChannels(void) const = 0;
136 
137 };
138 
139 extern StreamContent*
141 
144 
145 /* StreamContent - end */
146 
147 /* StreamContentValue - begin */
148 
150 protected:
151  std::vector<ScalarValue *> Values;
152 
153 public:
154  StreamContentValue(const std::vector<ScalarValue *>& v,
156  virtual ~StreamContentValue(void);
157 
158  void Prepare(void);
159  unsigned GetNumChannels(void) const;
160 };
161 
163 protected:
164  size_t m_size;
165  const char *m_buf;
166  std::vector<char> m_outbuf;
167  std::vector<BufCast *> m_data;
168 
169 public:
170  StreamContentCopyCast(size_t size, const char *buf, size_t outsize, const std::vector<BufCast *>& data);
171 
172  void Set(size_t size, const char *buf);
173  void Modify(void);
174 
175  const void *GetOutBuf(void) const;
176  int GetOutSize(void) const;
177 };
178 
179 
180 /* StreamContentValue - end */
181 
182 /* StreamOutEcho - begin */
183 
185 private:
186  std::string sOutFileName;
187  std::ofstream outFile;
190 
191 public:
193  ~StreamOutEcho(void);
194  bool Init(const std::string& msg, unsigned uLabel, unsigned nChannels);
195  void Echo(const doublereal *pbuf, unsigned nChannels);
196 };
197 
198 extern StreamOutEcho *
200 
201 /* StreamOutEcho - end */
202 
203 extern Elem *
204 ReadOutputElem(DataManager *pDM, MBDynParser& HP, unsigned int uLabel,
206 
207 /*----------------------------------------------------------------------------
208 management of 'content type' for stream output element ('values','motion', etc)
209 ------------------------------------------------------------------------------
210 
211 Rearranged by Luca Conti (May 2017) on the basis of previous existing code
212 (fully working, just rearranged).
213 
214 Edited in order to apply the same mechanism with 'readers' and 'maps' (std::map)
215  already in use for constitutive laws and drives
216 */
217 
218 /* stream output content type reader: every content type must inherit
219 from this struct and implement its own Read method */
221  virtual StreamContent* Read(DataManager* pDM, MBDynParser& HP) = 0;
223 };
224 
225 /* default content type options: reader for 'motion' */
227  virtual StreamContent* Read(DataManager* pDM, MBDynParser& HP);
228 };
229 
230 /* default content type options: reader for 'values' */
232  virtual StreamContent* Read(DataManager* pDM, MBDynParser& HP);
233 };
234 
235 /* bag of content-type readers - every content type is registered inside
236 of it by using SetStreamOutputContentType(...) */
237 typedef std::map<std::string,StreamOutputContentTypeReader*> StreamOutputContentTypeMap;
239 
240 /* stream output content type parsing checker: allows the parser
241 to understand if the next keyword is a content type */
243  virtual bool IsWord(const std::string& s) const;
244 };
245 
247 
248 /* registration function: call it to register a new content type -
249 it is also used by InitStreamOutputContentTypes(void) in order to load default
250 options ('values','motion') */
252 
253 /* initialization counter: counts how many times InitStreamOutputContentTypes
254 is called */
255 extern unsigned streamOutputInitFunctionCalls;
256 
257 /* initialization function: called by mbpar.cc in order to load default
258 options ('values','motion') */
260 
261 /* deallocation of all content types in streamOutputContentTypeMap - called by mbpar.cc */
263 
264 #endif /* STREAMOUTELEM_H */
const char * m_outbuf
virtual ~StreamOutputContentTypeReader(void)
std::vector< ScalarValue * > Values
StreamContent * ReadStreamContent(DataManager *pDM, MBDynParser &HP, StreamContent::Type type)
virtual int GetOutSize(void) const
void Set(size_t size, const char *buf)
unsigned int OutputCounter
Definition: streamoutelem.h:60
std::map< std::string, StreamOutputContentTypeReader * > StreamOutputContentTypeMap
doublereal dShift
Elem * ReadOutputElem(DataManager *pDM, MBDynParser &HP, unsigned int uLabel, StreamOutElem::Type eType, StreamContent::Type sType)
StreamContentValue(const std::vector< ScalarValue * > &v, StreamContent::Modifier *pMod)
virtual void Modify(void)=0
void Set(size_t size, const char *buf)
StreamOutElem(unsigned int uL, const std::string &name, unsigned int oe)
virtual StreamContent * Read(DataManager *pDM, MBDynParser &HP)
std::vector< char > m_outbuf
void Echo(const doublereal *pbuf, unsigned nChannels)
virtual const void * GetOutBuf(void) const =0
std::string name
Definition: streamoutelem.h:56
virtual ~StreamContent(void)
virtual void WorkSpaceDim(integer *piRows, integer *piCols) const
void * GetBuf(void) const
const void * GetOutBuf(void) const
virtual const void * GetOutBuf(void) const
#define NO_OP
Definition: myassert.h:74
StreamOutEcho(std::string &sOutFileName, int iPrecision, doublereal dShift)
virtual bool IsWord(const std::string &s) const
virtual SubVectorHandler & AssRes(SubVectorHandler &WorkVec, doublereal dCoef, const VectorHandler &X, const VectorHandler &XP)
virtual unsigned GetNumChannels(void) const =0
bool Init(const std::string &msg, unsigned uLabel, unsigned nChannels)
unsigned int OutputEvery
Definition: streamoutelem.h:59
virtual void Set(size_t size, const char *buf)=0
void DestroyStreamOutputContentTypes(void)
std::ofstream outFile
virtual void Prepare(void)=0
std::vector< char > buf
unsigned GetNumChannels(void) const
StreamOutputContentTypeMap streamOutputContentTypeMap
virtual Elem::Type GetElemType(void) const
virtual int GetOutSize(void) const =0
std::vector< BufCast * > m_data
StreamOutputContentTypeWordSetType streamOutputContentTypeWordSet
bool SetStreamOutputContentType(const char *name, StreamOutputContentTypeReader *rf)
StreamContent::Modifier * ReadStreamContentModifier(MBDynParser &HP, integer nCh)
unsigned streamOutputInitFunctionCalls
const void * GetOutBuf(void) const
Copy(size_t size, const char *buf)
void InitStreamOutputContentTypes(void)
Definition: elem.h:75
StreamOutEcho * ReadStreamOutEcho(MBDynParser &HP)
Type
Definition: elem.h:91
virtual VariableSubMatrixHandler & AssJac(VariableSubMatrixHandler &WorkMat, doublereal dCoef, const VectorHandler &X, const VectorHandler &XP)
struct mbrtai_msg_t msg
Modifier * m_pMod
std::string sOutFileName
virtual StreamContent * Read(DataManager *pDM, MBDynParser &HP)
StreamContentCopyCast(size_t size, const char *buf, size_t outsize, const std::vector< BufCast * > &data)
virtual ~StreamOutElem(void)
static doublereal buf[BUFSIZE]
Definition: discctrl.cc:333
virtual StreamContent * Read(DataManager *pDM, MBDynParser &HP)=0
double doublereal
Definition: colamd.c:52
int GetOutSize(void) const
long int integer
Definition: colamd.c:51
virtual ~StreamContentValue(void)
int GetOutSize(void) const
int GetSize(void) const
StreamContent(size_t size, Modifier *pMod)