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.6.2.1 $
43 //
44 // Revision Date : $Date: 2014/08/13 20:36:35 $
45 //
46 // Current Owner : $Author: dgbaur $
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_Const.h>
59 #include <N_DEV_Algorithm.h>
60 #include <N_DEV_DeviceModel.h>
61 #include <N_DEV_DeviceInstance.h>
62 #include <N_DEV_DeviceMaster.h>
63 #include <N_DEV_CompositeParam.h>
64 
65 namespace Xyce {
66 namespace Device {
67 
68 namespace {
69 struct DeviceInstanceCmp : public std::binary_function<DeviceInstance, DeviceInstance, bool>
70 {
71  bool operator()(const DeviceInstance &entity_0, const DeviceInstance &entity_1) const
72  {
73  return less_nocase(entity_0.getName().getEncodedName(), entity_1.getName().getEncodedName());
74  }
75  bool operator()(const DeviceInstance *entity_0, const DeviceInstance *entity_1) const
76  {
77  return less_nocase(entity_0->getName().getEncodedName(), entity_1->getName().getEncodedName());
78  }
79 };
80 
81 }
82 //-----------------------------------------------------------------------------
83 // Function : printOutModels
84 // Purpose : debugging tool
85 // Special Notes :
86 // Scope : public
87 // Creator : Eric Keiter, SNL, factory_block, Parallel Computational Sciences
88 // Creation Date : 2/03/06
89 //-----------------------------------------------------------------------------
90 std::ostream &print(std::ostream &os, const Device &device)
91 {
92  std::vector<DeviceModel *> models;
93  getDeviceModels(device, std::back_inserter(models));
94 
95  os << std::endl
96  << std::endl << section_divider << std::endl
97  << "Number of " << device.getName() << " models: " << models.size() << std::endl;
98 
99  int i = 0;
100  for (std::vector<DeviceModel *>::const_iterator it = models.begin(); it != models.end(); ++it, ++i)
101  {
102  os << i << ": name = " << (*it)->getName() << " type = " << (*it)->getType() << " level = " << (*it)->getLevel() << std::endl;
103 
104  (*it)->printOutInstances(os);
105  }
106  os << section_divider << std::endl;
107 
108  return os;
109 }
110 
111 typedef std::map<std::string, std::pair<DeviceModel *, std::vector<DeviceInstance *> > > UglyMap;
112 
114 {
115  UglyDeviceModelOp(const Device &device, UglyMap &model_map)
116  : device_(device),
117  modelMap_(model_map),
118  deviceCount_(0)
119  {}
120 
121  virtual bool operator()(DeviceModel *model) {
122  std::pair<UglyMap::iterator, bool> result = modelMap_.insert(UglyMap::value_type(model->getName(), std::make_pair(model, std::vector<DeviceInstance *>())));
123 
124  if (result.second) {
125  getDeviceInstances(*model, std::back_inserter((*result.first).second.second));
126  if ((*result.first).second.second.empty())
127  modelMap_.erase(result.first);
128  else {
129  deviceCount_ += (*result.first).second.second.size();
130  std::sort((*result.first).second.second.begin(), (*result.first).second.second.end(), DeviceInstanceCmp());
131  }
132  }
133  return true;
134  }
135 
136  const Device & device_;
139 };
140 
141 
142 
143 //-----------------------------------------------------------------------------
144 // Function : DeviceMaster:printDotOpOutput
145 // Purpose :
146 // Special Notes :
147 // Scope : public
148 // Creator : Eric Keiter, SNL, factory_block, Parallel Computational Sciences
149 // Creation Date : 5/4/12
150 //-----------------------------------------------------------------------------
151 std::ostream &printDotOpOutput (std::ostream &os, const Device &device)
152 {
153  static const int stdWidth = 15;
154 
155 // Output models
156  UglyMap model_map;
157 
158  UglyDeviceModelOp op(device, model_map);
159  device.forEachModel(op);
160 
161  os << std::endl
162  << "Number of " << device.getName() << " models: " << model_map.size() << std::endl
163  << std::setw(stdWidth) << "name ";
164 
165  if (!model_map.empty())
166  {
167  int column_count = 1;
168  for (UglyMap::const_iterator it_model = model_map.begin(); it_model != model_map.end(); ++it_model, ++column_count)
169  {
170  if (column_count%8 == 0)
171  os << std::endl;
172  os << std::setw(stdWidth) << (*it_model).first ;
173  }
174  os << std::endl;
175 
176  os << std::setw(stdWidth) << "type ";
177  column_count = 1;
178  for (UglyMap::const_iterator it_model = model_map.begin(); it_model != model_map.end(); ++it_model, ++column_count)
179  {
180  if (column_count%8 == 0)
181  os << std::endl;
182  os << std::setw(stdWidth) << (*it_model).second.first->getType() ;
183  }
184  os << std::endl;
185 
186  os << std::setw(stdWidth) << "level ";
187  column_count = 1;
188  for (UglyMap::const_iterator it_model = model_map.begin(); it_model != model_map.end(); ++it_model, ++column_count)
189  {
190  if (column_count%8 == 0)
191  os << std::endl;
192  os << std::setw(stdWidth) << (*it_model).second.first->getLevel() ;
193  }
194  os << std::endl;
195 
196  const ParameterMap &parMap = (*model_map.begin()).second.first->getParameterMap();
197 
198  column_count = 1;
199  for (ParameterMap::const_iterator it_parameter = parMap.begin(); it_parameter != parMap.end(); ++it_parameter)
200  {
201  for (UglyMap::const_iterator it_model = model_map.begin(); it_model != model_map.end(); ++it_model, ++column_count)
202  {
203  if (it_model == model_map.begin())
204  {
205  if (column_count%8 == 0)
206  os << std::endl;
207  os << std::setw(stdWidth) << (*it_parameter).first;
208  }
209 
210  os << std::setw(stdWidth);
211  printParameter(os, *(*it_model).second.first, (*it_parameter).first, *(*it_parameter).second);
212  }
213  os << std::endl;
214  }
215  os << std::endl;
216 
217 // Output instances
218  os << "Number of " << device.getName() << " instances: " << op.deviceCount_ << std::endl
219  << std::setw(stdWidth) << "name ";
220 
221  column_count = 1;
222  for (UglyMap::const_iterator it_model = model_map.begin(); it_model != model_map.end(); ++it_model)
223  {
224  const std::vector<DeviceInstance *> &instance_list = (*it_model).second.second;
225 
226  for (std::vector<DeviceInstance *>::const_iterator it_instance = instance_list.begin(); it_instance != instance_list.end(); ++it_instance, ++column_count)
227  {
228  if (column_count%8 == 0)
229  os << std::endl;
230  os << std::setw(stdWidth) << (*it_instance)->getName();
231  }
232  }
233  os << std::endl
234  << std::setw(stdWidth) << "model ";
235 
236 
237  const DeviceInstance &first_instance = *(*model_map.begin()).second.second.front();
238 
239  column_count = 1;
240  for (UglyMap::const_iterator it_model = model_map.begin(); it_model != model_map.end(); ++it_model)
241  {
242  const DeviceModel &model = *(*it_model).second.first;
243  const std::vector<DeviceInstance *> &instance_list = (*it_model).second.second;
244 
245  if ( !instance_list.empty () ) {
246  for (std::vector<DeviceInstance *>::const_iterator it_instance = instance_list.begin(); it_instance != instance_list.end(); ++it_instance, ++column_count)
247  {
248  if (column_count%8 == 0)
249  os << std::endl;
250  os << std::setw(stdWidth) << model.getName();
251  }
252  }
253  }
254 
255  os << std::endl;
256 
257  // output instance parameters:
258  const ParameterMap &parameter_map = first_instance.getParameterMap();
259  for (ParameterMap::const_iterator it_parameter = parameter_map.begin() ; it_parameter != parameter_map.end(); ++it_parameter)
260  {
261  os << std::setw(stdWidth) << it_parameter->first;
262 
263  column_count = 1;
264  for (UglyMap::const_iterator it_model = model_map.begin(); it_model != model_map.end(); ++it_model)
265  {
266  const DeviceModel &model = *(*it_model).second.first;
267  const std::vector<DeviceInstance *> &instance_list = (*it_model).second.second;
268 
269  if ( !instance_list.empty () ) {
270  for (std::vector<DeviceInstance *>::const_iterator it_instance = instance_list.begin(); it_instance != instance_list.end(); ++it_instance, ++column_count)
271  {
272  if (column_count%8 == 0)
273  os << std::endl;
274  os << std::setw(stdWidth);
275  printParameter(os, *(*it_instance), (*it_parameter).first, *(*it_parameter).second);
276  }
277  }
278  }
279  os << std::endl;
280  }
281  os << std::endl;
282  }
283 
284  return os;
285 }
286 
287 
288 //-----------------------------------------------------------------------------
289 // Function : printParameter
290 //
291 // Purpose : This function finds a parameter in the par table, and then
292 // formats its value in a string.
293 //
294 // Special Notes :
295 // Scope : public
296 // Creator : Eric Keiter, SNL, Parallel Computational Sciences
297 // Creation Date : 5/4/12
298 //-----------------------------------------------------------------------------
299 std::ostream &printParameter(std::ostream &os, const ParameterBase &entity, const std::string &name, const Descriptor &param)
300 {
301  if (param.isType<double>())
302  {
303  if (isTempParam(name))
304  {
305  os << param.value<double>(entity) - CONSTCtoK;
306  }
307  else
308  {
309  os << param.value<double>(entity);
310  }
311  }
312  else if (param.isType<bool>())
313  {
314  os << param.value<bool>(entity);
315  }
316  else if (param.isType<int>())
317  {
318  os << param.value<int>(entity);
319  }
320  else if (param.isType<long>())
321  {
322  os << param.value<long>(entity);
323  }
324  else if (param.isType<std::string>())
325  {
326  os << param.value<std::string>(entity);
327  }
328  else if (param.isType<std::vector<std::string> >())
329  {
330  os << "string[]";
331  // const std::vector<std::string> &string_vector = param.value<std::vector<std::string> >(entity);
332  // os << " string[" << string_vector.size() << "]" << std::endl;
333  // {
334  // for (std::vector<std::string>::const_iterator it = string_vector.begin(), end = string_vector.end(); it != end; ++it)
335  // {
336  // os << " " << *it;
337  // }
338  // }
339  }
340  else if (param.isType<std::vector<int> >())
341  {
342  os << "int[]";
343  // const std::vector<int> &int_vector = param.value<std::vector<int> >(entity);
344  // os << " int[" << int_vector.size() << "]" << std::endl;
345  // {
346  // for (std::vector<int>::const_iterator it = int_vector.begin(), end = int_vector.end(); it != end; ++it)
347  // {
348  // os << " " << *it;
349  // }
350  // }
351  }
352  else if (param.isType<std::vector<double> >())
353  {
354  os << "double[]";
355  // const std::vector<double> &double_vector = param.value<std::vector<double> >(entity);
356  // os << " double[" << double_vector.size() << "]" << std::endl;
357  // {
358  // for (std::vector<double>::const_iterator it = double_vector.begin(), end = double_vector.end(); it != end; ++it)
359  // {
360  // os << " " << *it;
361  // }
362  // }
363  }
364  else if (param.hasCompositeData())
365  {
366 
367  os << "composite";
368  // if (param.isType<CompositeMap>()) {
369  // const CompositeMap &composite_map = param.value<CompositeMap>(entity);
370  // for (CompositeMap::const_iterator it = composite_map.begin(), end = composite_map.end(); it != end; ++it)
371  // {
372  // os << "[" << (*it).first << "] ";
373  // printCompositeParameters(os, *(*it).second);
374  // }
375  // }
376  // else if (param.isType<CompositeVector>()) {
377  // const CompositeVector &composite_vector = param.value<CompositeVector>(entity);
378  // for (CompositeVector::const_iterator it = composite_vector.begin(), end = composite_vector.end(); it != end; ++it)
379  // {
380  // os << "[" << std::distance(composite_vector.begin(), it) << "] ";
381  // printCompositeParameters(os, *(*it));
382  // }
383  // }
384  }
385 
386  return os;
387 }
388 
389 std::ostream &printCompositeParameters(std::ostream &os, const CompositeParam &composite)
390 {
391  const ParameterMap &parameter_map = composite.getParameterMap();
392  for (ParameterMap::const_iterator it = composite.getParameterMap().begin(), end = composite.getParameterMap().end(); it != end ;++it)
393  {
394  printParameter(os, composite, (*it).first, *(*it).second);
395  os << " ";
396  }
397 
398  return os;
399 }
400 
401 } // namespace Device
402 } // namespace Xyce
403