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.17 $
40 //
41 // Revision Date : $Date: 2015/05/13 22:28:56 $
42 //
43 // Current Owner : $Author: dgbaur $
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::operator<<
60 // Purpose : "<<" operator
61 // Special Notes :
62 // Scope : public
63 // Creator : Robert Hoekstra, SNL, Parallel Computational Sciences
64 // Creation Date : 09/02/01
65 //-----------------------------------------------------------------------------
66 std::ostream & operator<<( std::ostream & os, const DeviceState & ds )
67 {
68  os << "Device State: " << ds.ID << std::endl;
69  os << " -------------" << std::endl;
70  for( int i = 0; i < ds.data.size(); ++i )
71  os << " " << i << ": " << ds.data[i] << std::endl;
72  os << " -------------" << std::endl;
73  os << std::endl;
74 
75  return os;
76 }
77 
78 //-----------------------------------------------------------------------------
79 // Function : DeviceState::dump
80 // Purpose :
81 // Special Notes :
82 // Scope : public
83 // Creator : Rob Hoekstra, SNL, Parallel Computational Sciences
84 // Creation Date : 11/03/04
85 //-----------------------------------------------------------------------------
86 void DeviceState::dump( std::ostream & os )
87 {
88  os << ID << " ";
89 
90  int size = data.size();
91  os << size << " ";
92  for( int i = 0; i < size; ++i )
93  os << data[i] << " ";
94 
95 
96  size = dataInt.size();
97  os << size << " ";
98  for( int i = 0; i < size; ++i )
99  os << dataInt[i] << " ";
100 
101 
102  size = dataSizeT.size();
103  os << size << " ";
104  for( int i = 0; i < size; ++i )
105  os << dataSizeT[i] << " ";
106 }
107 
108 //-----------------------------------------------------------------------------
109 // Function : DeviceState::restore
110 // Purpose :
111 // Special Notes :
112 // Scope : public
113 // Creator : Rob Hoekstra, SNL, Parallel Computational Sciences
114 // Creation Date : 11/03/04
115 //-----------------------------------------------------------------------------
116 void DeviceState::restore( std::istream & is )
117 {
118  is >> ID;
119 
120  int size;
121  is >> size;
122  data.resize(size);
123  for( int i = 0; i < size; ++i )
124  is >> data[i];
125 
126  is >> size;
127  dataInt.resize(size);
128  for( int i = 0; i < size; ++i )
129  is >> dataInt[i];
130 
131  is >> size;
132  dataSizeT.resize(size);
133  for( int i = 0; i < size; ++i )
134  is >> dataSizeT[i];
135 }
136 
137 } // namespace Device
138 
139 //-----------------------------------------------------------------------------
140 // Function : DeviceState::packedByteCount
141 // Purpose :
142 // Special Notes :
143 // Scope : public
144 // Creator : Robert Hoektra, SNL, Parallel Computational Sciences
145 // Creation Date : 09/02/01
146 //-----------------------------------------------------------------------------
147 template<>
148 int
149 Pack<Device::DeviceState>::packedByteCount(const Device::DeviceState &device_state)
150 {
151  int bCnt = sizeof(int); //ID length
152  bCnt += device_state.ID.length();
153 
154  bCnt += sizeof(int); //data double length
155  bCnt += device_state.data.size() * sizeof(double);
156 
157  bCnt += sizeof(int); //data int length
158  bCnt += device_state.dataInt.size() * sizeof(int);
159 
160  bCnt += sizeof(int); //data size_t length
161  bCnt += device_state.dataSizeT.size() * sizeof(size_t);
162 
163  return bCnt;
164 }
165 
166 //-----------------------------------------------------------------------------
167 // Function : DeviceState::pack
168 // Purpose :
169 // Special Notes :
170 // Scope : public
171 // Creator : Rob Hoekstra, SNL, Parallel Computational Sciences
172 // Creation Date : 09/02/01
173 //-----------------------------------------------------------------------------
174 template<>
175 void
176 Pack<Device::DeviceState>::pack(const Device::DeviceState &device_state, char * buf, int bsize, int & pos, N_PDS_Comm * comm)
177 {
178  int length;
179 
180  //----- pack ID
181  length = device_state.ID.length();
182  comm->pack( &length, 1, buf, bsize, pos );
183  comm->pack( device_state.ID.c_str(), length, buf, bsize, pos );
184 
185  //----- pack double data
186  length = device_state.data.size();
187  comm->pack( &length, 1, buf, bsize, pos );
188  comm->pack( &(device_state.data[0]), length, buf, bsize, pos );
189 
190  //----- pack int data
191  length = device_state.dataInt.size();
192  comm->pack( &length, 1, buf, bsize, pos );
193  comm->pack( &(device_state.dataInt[0]), length, buf, bsize, pos );
194 
195  //----- pack size_t data
196  length = device_state.dataSizeT.size();
197  comm->pack( &length, 1, buf, bsize, pos );
198  comm->pack( &(device_state.dataSizeT[0]), length, buf, bsize, pos );
199 }
200 
201 //-----------------------------------------------------------------------------
202 // Function : DeviceState::unpack
203 // Purpose :
204 // Special Notes :
205 // Scope : public
206 // Creator : Rob Hoekstra, SNL, Parallel Computational Sciences
207 // Creation Date : 09/02/01
208 //-----------------------------------------------------------------------------
209 template<>
210 void
211 Pack<Device::DeviceState>::unpack(Device::DeviceState &device_state, char * buf, int bsize, int & pos, N_PDS_Comm * comm)
212 {
213  int length;
214 
215  //----- unpack ID
216  comm->unpack( buf, bsize, pos, &length, 1 );
217  device_state.ID = std::string( (buf+pos), length);
218  pos += length;
219 
220  //----- unpack data
221  comm->unpack( buf, bsize, pos, &length, 1 );
222  device_state.data.resize(length);
223  comm->unpack( buf, bsize, pos, &(device_state.data[0]), length );
224 
225  //----- unpack int data
226  comm->unpack( buf, bsize, pos, &length, 1 );
227  device_state.dataInt.resize(length);
228  comm->unpack( buf, bsize, pos, &(device_state.dataInt[0]), length );
229 
230  //----- unpack size_t data
231  comm->unpack( buf, bsize, pos, &length, 1 );
232  device_state.dataSizeT.resize(length);
233  comm->unpack( buf, bsize, pos, &(device_state.dataSizeT[0]), length );
234 }
235 
236 } // namespace Xyce
Pure virtual class to augment a linear system.
std::vector< int > dataInt
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