Xyce  6.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
N_DEV_Print.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-2014 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_Print.C,v $
27 //
28 // Purpose :
29 //
30 //
31 //
32 // Special Notes :
33 //
34 //
35 // Creator : David Baur
36 //
37 // Creation Date :
38 //
39 // Revision Information:
40 // ---------------------
41 //
42 // Revision Number: $Revision: 1.4 $
43 //
44 // Revision Date : $Date: 2014/02/24 23:49:15 $
45 //
46 // Current Owner : $Author: tvrusso $
47 //-------------------------------------------------------------------------
48 
49 #include <Xyce_config.h>
50 
51 #include <map>
52 #include <utility>
53 #include <vector>
54 #include <iostream>
55 
56 #include <N_DEV_Print.h>
57 #include <N_DEV_Device.h>
58 #include <N_DEV_Algorithm.h>
59 #include <N_DEV_DeviceModel.h>
60 #include <N_DEV_DeviceInstance.h>
61 #include <N_DEV_DeviceMaster.h>
62 
63 namespace Xyce {
64 namespace Device {
65 
66 //-----------------------------------------------------------------------------
67 // Function : printOutModels
68 // Purpose : debugging tool
69 // Special Notes :
70 // Scope : public
71 // Creator : Eric Keiter, SNL, factory_block, Parallel Computational Sciences
72 // Creation Date : 2/03/06
73 //-----------------------------------------------------------------------------
74 std::ostream &print(std::ostream &os, const Device &device)
75 {
76  std::vector<DeviceModel *> models;
77  getDeviceModels(device, std::back_inserter(models));
78 
79  os << std::endl
80  << std::endl << section_divider << std::endl
81  << "Number of " << device.getName() << " models: " << models.size() << std::endl;
82 
83  int i = 0;
84  for (std::vector<DeviceModel *>::const_iterator it = models.begin(); it != models.end(); ++it, ++i)
85  {
86  os << i << ": name = " << (*it)->getName() << " type = " << (*it)->getType() << " level = " << (*it)->getLevel() << std::endl;
87 
88  (*it)->printOutInstances(os);
89  }
90  os << section_divider << std::endl;
91 
92  return os;
93 }
94 
95 typedef std::map<std::string, std::pair<DeviceModel *, std::vector<DeviceInstance *> > > UglyMap;
96 
98 {
99  UglyDeviceModelOp(const Device &device, UglyMap &model_map)
100  : device_(device),
101  modelMap_(model_map),
102  deviceCount_(0)
103  {}
104 
105  virtual bool operator()(DeviceModel *model) {
106  std::pair<UglyMap::iterator, bool> result = modelMap_.insert(UglyMap::value_type(model->getName(), std::make_pair(model, std::vector<DeviceInstance *>())));
107 
108  if (result.second) {
109  getDeviceInstances(*model, std::back_inserter((*result.first).second.second));
110  if ((*result.first).second.second.empty())
111  modelMap_.erase(result.first);
112  else {
113  deviceCount_ += (*result.first).second.second.size();
114  std::sort((*result.first).second.second.begin(), (*result.first).second.second.end(), DeviceEntityCmp());
115  }
116  }
117  return true;
118  }
119 
120  const Device & device_;
123 };
124 
125 
126 
127 //-----------------------------------------------------------------------------
128 // Function : DeviceMaster:printDotOpOutput
129 // Purpose :
130 // Special Notes :
131 // Scope : public
132 // Creator : Eric Keiter, SNL, factory_block, Parallel Computational Sciences
133 // Creation Date : 5/4/12
134 //-----------------------------------------------------------------------------
135 std::ostream &printDotOpOutput (std::ostream &os, const Device &device)
136 {
137  static const int stdWidth = 15;
138 
139 // Output models
140  UglyMap model_map;
141 
142  UglyDeviceModelOp op(device, model_map);
143  device.forEachModel(op);
144 
145  os << std::endl
146  << "Number of " << device.getName() << " models: " << model_map.size() << std::endl
147  << std::setw(stdWidth) << "name ";
148 
149  if (!model_map.empty())
150  {
151  int column_count = 1;
152  for (UglyMap::const_iterator it_model = model_map.begin(); it_model != model_map.end(); ++it_model, ++column_count)
153  {
154  if (column_count%8 == 0)
155  os << std::endl;
156  os << std::setw(stdWidth) << (*it_model).first ;
157  }
158  os << std::endl;
159 
160  os << std::setw(stdWidth) << "type ";
161  column_count = 1;
162  for (UglyMap::const_iterator it_model = model_map.begin(); it_model != model_map.end(); ++it_model, ++column_count)
163  {
164  if (column_count%8 == 0)
165  os << std::endl;
166  os << std::setw(stdWidth) << (*it_model).second.first->getType() ;
167  }
168  os << std::endl;
169 
170  os << std::setw(stdWidth) << "level ";
171  column_count = 1;
172  for (UglyMap::const_iterator it_model = model_map.begin(); it_model != model_map.end(); ++it_model, ++column_count)
173  {
174  if (column_count%8 == 0)
175  os << std::endl;
176  os << std::setw(stdWidth) << (*it_model).second.first->getLevel() ;
177  }
178  os << std::endl;
179 
180  const ParameterMap &parMap = (*model_map.begin()).second.first->getParameterMap();
181 
182  column_count = 1;
183  for (ParameterMap::const_iterator it_parameter = parMap.begin(); it_parameter != parMap.end(); ++it_parameter)
184  {
185  for (UglyMap::const_iterator it_model = model_map.begin(); it_model != model_map.end(); ++it_model, ++column_count)
186  {
187  if (it_model == model_map.begin())
188  {
189  if (column_count%8 == 0)
190  os << std::endl;
191  os << std::setw(stdWidth) << (*it_parameter).first;
192  }
193 
194  os << std::setw(stdWidth);
195  printParameter(os, *(*it_model).second.first, (*it_parameter).first, *(*it_parameter).second);
196  }
197  os << std::endl;
198  }
199  os << std::endl;
200 
201 // Output instances
202  os << "Number of " << device.getName() << " instances: " << op.deviceCount_ << std::endl
203  << std::setw(stdWidth) << "name ";
204 
205  column_count = 1;
206  for (UglyMap::const_iterator it_model = model_map.begin(); it_model != model_map.end(); ++it_model)
207  {
208  const std::vector<DeviceInstance *> &instance_list = (*it_model).second.second;
209 
210  for (std::vector<DeviceInstance *>::const_iterator it_instance = instance_list.begin(); it_instance != instance_list.end(); ++it_instance, ++column_count)
211  {
212  if (column_count%8 == 0)
213  os << std::endl;
214  os << std::setw(stdWidth) << (*it_instance)->getName();
215  }
216  }
217  os << std::endl
218  << std::setw(stdWidth) << "model ";
219 
220 
221  const DeviceInstance &first_instance = *(*model_map.begin()).second.second.front();
222 
223  column_count = 1;
224  for (UglyMap::const_iterator it_model = model_map.begin(); it_model != model_map.end(); ++it_model)
225  {
226  const DeviceModel &model = *(*it_model).second.first;
227  const std::vector<DeviceInstance *> &instance_list = (*it_model).second.second;
228 
229  if ( !instance_list.empty () ) {
230  for (std::vector<DeviceInstance *>::const_iterator it_instance = instance_list.begin(); it_instance != instance_list.end(); ++it_instance, ++column_count)
231  {
232  if (column_count%8 == 0)
233  os << std::endl;
234  os << std::setw(stdWidth) << model.getName();
235  }
236  }
237  }
238 
239  os << std::endl;
240 
241  // output instance parameters:
242  const ParameterMap &parameter_map = first_instance.getParameterMap();
243  for (ParameterMap::const_iterator it_parameter = parameter_map.begin() ; it_parameter != parameter_map.end(); ++it_parameter)
244  {
245  os << std::setw(stdWidth) << it_parameter->first;
246 
247  column_count = 1;
248  for (UglyMap::const_iterator it_model = model_map.begin(); it_model != model_map.end(); ++it_model)
249  {
250  const DeviceModel &model = *(*it_model).second.first;
251  const std::vector<DeviceInstance *> &instance_list = (*it_model).second.second;
252 
253  if ( !instance_list.empty () ) {
254  for (std::vector<DeviceInstance *>::const_iterator it_instance = instance_list.begin(); it_instance != instance_list.end(); ++it_instance, ++column_count)
255  {
256  if (column_count%8 == 0)
257  os << std::endl;
258  os << std::setw(stdWidth);
259  printParameter(os, *(*it_instance), (*it_parameter).first, *(*it_parameter).second);
260  }
261  }
262  }
263  os << std::endl;
264  }
265  os << std::endl;
266  }
267 
268  return os;
269 }
270 
271 
272 } // namespace Device
273 } // namespace Xyce
274