Xyce  6.1
N_DEV_DeviceState.C
Go to the documentation of this file.
1 //-----------------------------------------------------------------------------
2 // Copyright Notice
3 //
4 // Copyright 2002 Sandia Corporation. Under the terms
5 // of Contract DE-AC04-94AL85000 with Sandia Corporation, the U.S.
6 // Government retains certain rights in this software.
7 //
8 // Xyce(TM) Parallel Electrical Simulator
9 // Copyright (C) 2002-2015 Sandia Corporation
10 //
11 // This program is free software: you can redistribute it and/or modify
12 // it under the terms of the GNU General Public License as published by
13 // the Free Software Foundation, either version 3 of the License, or
14 // (at your option) any later version.
15 //
16 // This program is distributed in the hope that it will be useful,
17 // but WITHOUT ANY WARRANTY; without even the implied warranty of
18 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 // GNU General Public License for more details.
20 //
21 // You should have received a copy of the GNU General Public License
22 // along with this program. If not, see <http://www.gnu.org/licenses/>.
23 //-----------------------------------------------------------------------------
24 
25 //-----------------------------------------------------------------------------
26 // Filename : $RCSfile: N_DEV_DeviceState.C,v $
27 //
28 // Purpose :
29 //
30 // Special Notes :
31 //
32 // Creator : Robert Hoekstra, SNL, Parallel Computational Sciences
33 //
34 // Creation Date : 09/02/01
35 //
36 // Revision Information:
37 // ---------------------
38 //
39 // Revision Number: $Revision: 1.15.6.1 $
40 //
41 // Revision Date : $Date: 2015/04/02 18:20:09 $
42 //
43 // Current Owner : $Author: tvrusso $
44 //-----------------------------------------------------------------------------
45 
46 #include <Xyce_config.h>
47 
48 
49 #include <iostream>
50 
51 #include <N_DEV_DeviceState.h>
52 
53 #include <N_PDS_Comm.h>
54 
55 namespace Xyce {
56 namespace Device {
57 
58 //-----------------------------------------------------------------------------
59 // Function : DeviceState::packedByteCount
60 // Purpose :
61 // Special Notes :
62 // Scope : public
63 // Creator : Robert Hoektra, SNL, Parallel Computational Sciences
64 // Creation Date : 09/02/01
65 //-----------------------------------------------------------------------------
67 {
68  int bCnt = sizeof(int); //ID length
69  bCnt += ID.length();
70 
71  bCnt += sizeof(int); //data double length
72  bCnt += data.size() * sizeof(double);
73 
74  bCnt += sizeof(int); //data int length
75  bCnt += dataInt.size() * sizeof(int);
76 
77  bCnt += sizeof(int); //data size_t length
78  bCnt += dataSizeT.size() * sizeof(size_t);
79 
80  return bCnt;
81 }
82 
83 //-----------------------------------------------------------------------------
84 // Function : DeviceState::pack
85 // Purpose :
86 // Special Notes :
87 // Scope : public
88 // Creator : Rob Hoekstra, SNL, Parallel Computational Sciences
89 // Creation Date : 09/02/01
90 //-----------------------------------------------------------------------------
91 void DeviceState::pack(char * buf, int bsize, int & pos, N_PDS_Comm * comm) const
92 {
93  int length;
94 
95  //----- pack ID
96  length = ID.length();
97  comm->pack( &length, 1, buf, bsize, pos );
98  comm->pack( ID.c_str(), length, buf, bsize, pos );
99 
100  //----- pack double data
101  length = data.size();
102  comm->pack( &length, 1, buf, bsize, pos );
103  comm->pack( &(data[0]), length, buf, bsize, pos );
104 
105  //----- pack int data
106  length = dataInt.size();
107  comm->pack( &length, 1, buf, bsize, pos );
108  comm->pack( &(dataInt[0]), length, buf, bsize, pos );
109 
110  //----- pack size_t data
111  length = dataSizeT.size();
112  comm->pack( &length, 1, buf, bsize, pos );
113  comm->pack( &(dataSizeT[0]), length, buf, bsize, pos );
114 }
115 
116 //-----------------------------------------------------------------------------
117 // Function : DeviceState::unpack
118 // Purpose :
119 // Special Notes :
120 // Scope : public
121 // Creator : Rob Hoekstra, SNL, Parallel Computational Sciences
122 // Creation Date : 09/02/01
123 //-----------------------------------------------------------------------------
124 void DeviceState::unpack(char * buf, int bsize, int & pos, N_PDS_Comm * comm)
125 {
126  int length;
127 
128  //----- unpack ID
129  comm->unpack( buf, bsize, pos, &length, 1 );
130  ID = std::string( (buf+pos), length);
131  pos += length;
132 
133  //----- unpack data
134  comm->unpack( buf, bsize, pos, &length, 1 );
135  data.resize(length);
136  comm->unpack( buf, bsize, pos, &(data[0]), length );
137 
138  //----- unpack int data
139  comm->unpack( buf, bsize, pos, &length, 1 );
140  dataInt.resize(length);
141  comm->unpack( buf, bsize, pos, &(dataInt[0]), length );
142 
143  //----- unpack size_t data
144  comm->unpack( buf, bsize, pos, &length, 1 );
145  dataSizeT.resize(length);
146  comm->unpack( buf, bsize, pos, &(dataSizeT[0]), length );
147 }
148 
149 //-----------------------------------------------------------------------------
150 // Function : DeviceState::operator<<
151 // Purpose : "<<" operator
152 // Special Notes :
153 // Scope : public
154 // Creator : Robert Hoekstra, SNL, Parallel Computational Sciences
155 // Creation Date : 09/02/01
156 //-----------------------------------------------------------------------------
157 std::ostream & operator<<( std::ostream & os, const DeviceState & ds )
158 {
159  os << "Device State: " << ds.ID << std::endl;
160  os << " -------------" << std::endl;
161  for( int i = 0; i < ds.data.size(); ++i )
162  os << " " << i << ": " << ds.data[i] << std::endl;
163  os << " -------------" << std::endl;
164  os << std::endl;
165 
166  return os;
167 }
168 
169 //-----------------------------------------------------------------------------
170 // Function : DeviceState::dump
171 // Purpose :
172 // Special Notes :
173 // Scope : public
174 // Creator : Rob Hoekstra, SNL, Parallel Computational Sciences
175 // Creation Date : 11/03/04
176 //-----------------------------------------------------------------------------
177 void DeviceState::dump( std::ostream & os )
178 {
179  os << ID << " ";
180 
181  int size = data.size();
182  os << size << " ";
183  for( int i = 0; i < size; ++i )
184  os << data[i] << " ";
185 
186 
187  size = dataInt.size();
188  os << size << " ";
189  for( int i = 0; i < size; ++i )
190  os << dataInt[i] << " ";
191 
192 
193  size = dataSizeT.size();
194  os << size << " ";
195  for( int i = 0; i < size; ++i )
196  os << dataSizeT[i] << " ";
197 }
198 
199 //-----------------------------------------------------------------------------
200 // Function : DeviceState::restore
201 // Purpose :
202 // Special Notes :
203 // Scope : public
204 // Creator : Rob Hoekstra, SNL, Parallel Computational Sciences
205 // Creation Date : 11/03/04
206 //-----------------------------------------------------------------------------
207 void DeviceState::restore( std::istream & is )
208 {
209  is >> ID;
210 
211  int size;
212  is >> size;
213  data.resize(size);
214  for( int i = 0; i < size; ++i )
215  is >> data[i];
216 
217  is >> size;
218  dataInt.resize(size);
219  for( int i = 0; i < size; ++i )
220  is >> dataInt[i];
221 
222  is >> size;
223  dataSizeT.resize(size);
224  for( int i = 0; i < size; ++i )
225  is >> dataSizeT[i];
226 }
227 
228 } // namespace Device
229 } // namespace Xyce
Pure virtual class to augment a linear system.
void pack(char *buf, int bsize, int &pos, N_PDS_Comm *comm) const
std::vector< int > dataInt
void unpack(char *buf, int bsize, int &pos, N_PDS_Comm *comm)
void restore(std::istream &is)
void dump(std::ostream &os)
std::vector< double > data
std::vector< size_t > dataSizeT
std::ostream & operator<<(std::ostream &os, const Configuration &configuration)
Definition: N_DEV_Dump.C:134