xc
FileDatastore.h
1 // -*-c++-*-
2 //----------------------------------------------------------------------------
3 // XC program; finite element analysis code
4 // for structural analysis and design.
5 //
6 // Copyright (C) Luis C. Pérez Tato
7 //
8 // This program derives from OpenSees <http://opensees.berkeley.edu>
9 // developed by the «Pacific earthquake engineering research center».
10 //
11 // Except for the restrictions that may arise from the copyright
12 // of the original program (see copyright_opensees.txt)
13 // XC is free software: you can redistribute it and/or modify
14 // it under the terms of the GNU General Public License as published by
15 // the Free Software Foundation, either version 3 of the License, or
16 // (at your option) any later version.
17 //
18 // This software is distributed in the hope that it will be useful, but
19 // WITHOUT ANY WARRANTY; without even the implied warranty of
20 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 // GNU General Public License for more details.
22 //
23 //
24 // You should have received a copy of the GNU General Public License
25 // along with this program.
26 // If not, see <http://www.gnu.org/licenses/>.
27 //----------------------------------------------------------------------------
28 /* ****************************************************************** **
29 ** OpenSees - Open System for Earthquake Engineering Simulation **
30 ** Pacific Earthquake Engineering Research Center **
31 ** **
32 ** **
33 ** (C) Copyright 1999, The Regents of the University of California **
34 ** All Rights Reserved. **
35 ** **
36 ** Commercial use of this program without express permission of the **
37 ** University of California, Berkeley, is strictly prohibited. See **
38 ** file 'COPYRIGHT' in main directory for information on usage and **
39 ** redistribution, and for a DISCLAIMER OF ALL WARRANTIES. **
40 ** **
41 ** Developed by: **
42 ** Frank McKenna (fmckenna@ce.berkeley.edu) **
43 ** Gregory L. Fenves (fenves@ce.berkeley.edu) **
44 ** Filip C. Filippou (filippou@ce.berkeley.edu) **
45 ** **
46 ** ****************************************************************** */
47 
48 // $Revision: 1.14 $
49 // $Date: 2006/01/03 20:49:21 $
50 // $Source: /usr/local/cvs/OpenSees/SRC/utility/database/FileDatastore.h,v $
51 
52 
53 #ifndef FileDatastore_h
54 #define FileDatastore_h
55 
56 // Written: fmk
57 // Created: 10/98
58 //
59 // Description: This file contains the class definition for FileDatastore.
60 // FileDatastore is a concrete subclas of FE_Datastore. A FileDatastore
61 // object is used in the program to store/restore the geometry and state
62 // information in a modeler at a particular instance in the analysis. The
63 // information is stored in text files.
64 //
65 // What: "@(#) FileDatastore.h, revA"
66 
67 #include <utility/database/FE_Datastore.h>
68 
69 #include <fstream>
70 #include <map>
71 #include <memory>
72 
73 using std::fstream;
74 using std::map;
75 
76 
77 #define STREAM_POSITION_TYPE int
78 
79 namespace XC {
80 class FEM_ObjectBroker;
81 
83 struct IntData
84  {
85  int *dbTag;
86  int *values;
87  };
88 
89 
91 struct DoubleData
92  {
93  int *dbTag;
94  double *values;
95  };
96 
99  {
100  std::shared_ptr<fstream> theFile;
101  STREAM_POSITION_TYPE fileEnd;
102  int maxDbTag;
104  : theFile(nullptr), fileEnd(0), maxDbTag(0) {}
105  FileDatastoreOutputFile(const std::shared_ptr<fstream> &fs, const STREAM_POSITION_TYPE &fEnd, const int &mx)
106  : theFile(fs), fileEnd(fEnd), maxDbTag(mx) {}
107  fstream *getFStream(void)
108  { return theFile.get(); }
109  int openFile(const std::string &, int , IntData &, std::vector<char> &);
110  void resetFilePointers(IntData &, const std::vector<char> &);
111  };
112 
113 typedef map<int, FileDatastoreOutputFile> FilesMap;
114 typedef FilesMap::value_type FilesMap_type;
115 typedef FilesMap::iterator FilesMap_iterator;
116 
117 
118 
120 //
124 //
143  {
144  private:
145  // Private methods
146  int resizeInt(int newSize);
147  int resizeDouble(int newSize);
148  void resetFilePointers(void);
149 
150  // private attributes
151  FilesMap theIDFiles;
152  FilesMap theVectFiles;
153  FilesMap theMatFiles;
154  FilesMap_iterator theIDFilesIter;
155  FilesMap_iterator theVectFilesIter;
156  FilesMap_iterator theMatFilesIter;
157 
158  int lastDomainChangeStamp;
159  int currentCommitTag;
160  std::vector<char> charPtrData;
161 
162  IntData theIntData;
163  DoubleData theDoubleData;
164 
165  int currentMaxInt;
166  int currentMaxDouble;
167 
168  void alloc(const size_t &sz);
169  std::string getFileName(const std::string &, int idSize,int commitTag) const;
170  FileDatastoreOutputFile *getFileStruct(FilesMap &, const std::string &, int objSize, int stepSize, int commitTag);
171  public:
172  FileDatastore(const std::string &dataBase,Preprocessor &preprocessor, FEM_ObjectBroker &theBroker);
173 
174  ~FileDatastore(void);
175 
176  std::string getTypeId(void) const
177  { return "File"; }
178 
179  // methods for sending and receiving the data
180  int sendMsg(int dbTag, int commitTag, const Message &, ChannelAddress *theAddress =0);
181  int recvMsg(int dbTag, int commitTag, Message &, ChannelAddress *theAddress =0);
182 
183  int sendMatrix(int dbTag, int commitTag, const Matrix &, ChannelAddress *theAddress= nullptr);
184  int recvMatrix(int dbTag, int commitTag, Matrix &, ChannelAddress *theAddress= nullptr);
185 
186  int sendVector(int dbTag, int commitTag, const Vector &, ChannelAddress *theAddress= nullptr);
187  int recvVector(int dbTag, int commitTag, Vector &, ChannelAddress *theAddress= nullptr);
188 
189  int sendID(int dbTag, int commitTag,const ID &, ChannelAddress *theAddress= nullptr);
190  int recvID(int dbTag, int commitTag,ID &, ChannelAddress *theAddress= nullptr);
191 
192  int createTable(const std::string &tableName,const std::vector<std::string> &columns);
193  int insertData(const std::string &tableName,const std::vector<std::string> &columns, int commitTag, const Vector &);
194  int getData(const std::string &tableName,const std::vector<std::string> &columns, int commitTag, Vector &);
195 
196  // the commitState method
197  int commitState(int commitTag);
198  };
199 } // end of XC namespace
200 
201 #endif
202 
Float vector abstraction.
Definition: Vector.h:94
Base class for objects that store/restore model information.
Definition: FE_Datastore.h:84
Finite element model generation tools.
Definition: Preprocessor.h:59
Output file stream wrapper.
Definition: FileDatastore.h:98
Integer array wrapper.
Definition: FileDatastore.h:83
FEM_ObjectBroker is is an object broker class for the finite element method.
Definition: FEM_ObjectBroker.h:151
Vector of integers.
Definition: ID.h:95
Message between processes.
Definition: Message.h:77
used in the program to store/restore the geometry and state information in the domain at particular i...
Definition: FileDatastore.h:142
Open source finite element program for structural analysis.
Definition: ContinuaReprComponent.h:35
Base class for classes that encapsulate channel addresses.
Definition: ChannelAddress.h:78
Matrix of floats.
Definition: Matrix.h:111
Double array wrapper.
Definition: FileDatastore.h:91