Xyce  6.1
N_DEV_InstanceName.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_InstanceName.C,v $
27 //
28 // Purpose :
29 //
30 // Special Notes :
31 //
32 // Creator : Eric R. Keiter, SNL, Parallel Computational Sciences
33 //
34 // Creation Date : 02/28/00
35 //
36 // Revision Information:
37 // ---------------------
38 //
39 // Revision Number: $Revision: 1.5 $
40 //
41 // Revision Date : $Date: 2015/04/08 19:18:22 $
42 //
43 // Current Owner : $Author: tvrusso $
44 //-----------------------------------------------------------------------------
45 
46 #include <Xyce_config.h>
47 
48 #include <N_DEV_DeviceBlock.h>
49 
50 namespace Xyce {
51 namespace Device {
52 
53 void
55 {
61 }
62 
63 void
65 {}
66 
67 std::string
69 {
70  // Skip subcircuit
71  std::string::size_type i = name_.find_last_of(':');
72  i = (i == std::string::npos ? 0 : i + 1);
73 
74  // For multiletter (Y or U type), return the device type without the Y
75  // or U. For single letter, just return it.
76  if (i < name_.size()) {
77  if (name_[i] == 'Y' || name_[i] == 'U')
78  return name_.substr(i + 1, name_.find("!", i) - i - 1);
79  else
80  return name_.substr(i, 1);
81  }
82  else
83  return "";
84 }
85 
86 std::string
88 {
89  // Skip subcuit
90  std::string::size_type i = name_.find_last_of(':');
91  i = (i == std::string::npos ? 0 : i + 1);
92 
93  // For Y return the string following the the type terminating
94  // exclamation point (!). For U return the string between the type
95  // terminating exclamation point (!) and the device name terminating
96  // exclamation point (!).
97  if (i < name_.size()) {
98  if (name_[i] == 'Y')
99  return name_.substr(name_.find("!") + 1);
100  else if (name_[i] == 'U') {
101  i = name_.find('!', i + 1);
102  if (i < name_.size()) {
103  std::string::size_type j = name_.find('!', i + 1);
104  return name_.substr(i, j);
105  }
106  }
107  else
108  return name_.substr(i);
109  }
110  return "";
111 }
112 
113 std::string
115 {
116  std::string::size_type i = name_.find_last_of(':');
117 
118  if (i != std::string::npos)
119  return name_.substr(0, i);
120  else
121  return "";
122 }
123 
125  // Skip subcircuit
126  std::string::size_type i = name_.find_last_of(':');
127  i = (i == std::string::npos ? 0 : i + 1);
128 
129  // Return first letter after subcircuit.
130  return i < name_.size() ? name_[i] : '\0';
131 }
132 
133 
135 {
136  if (getDeviceLetter() == 'U') {
137  std::string::size_type i = name_.find_last_of("!");
138  if (i == std::string::npos)
139  return 0;
140 
141  std::istringstream iss(name_.substr(i + 1));
142  int num_inputs = 0;
143 
144  iss >> num_inputs;
145 
146  return num_inputs;
147  }
148 
149  return 0;
150 }
151 
152 // ----------------------------------------------------------------------------
153 // Function : DevicePDEInstance::setupOutputName
154 //
155 // Purpose : This function takes the device instance name and creates
156 // an appropriate "outputName" to be used for file outputs.
157 //
158 // At this point PDE devices are all specified as "Y" devices,
159 // meaning that the device instance name will almost always
160 // start with "YPDE!". Left unchanged, this has been
161 // resulting in (for example) tecplot files named thing like,
162 // "YPDEDIODE1.dat". Obviously, the YPDE prefix is
163 // not needed, so this function removes it, if it exists.
164 //
165 // Special Notes :
166 // Scope : public
167 // Creator : Eric Keiter, SNL, Parallel Computational Sciences
168 // Creation Date : 04/03/05
169 // ----------------------------------------------------------------------------
170 std::string setupOutputName(const InstanceName &name)
171 {
172  std::string outputName;
173 
174  std::string s = name.getEncodedName();
175 
176  std::string pdeString("YPDE!");
177  std::string neutString("YNEUTRON!");
178  std::string::size_type pos1 = s.find(pdeString);
179  std::string::size_type pos2 = s.find(neutString);
180 
181  if (pos1 != std::string::npos)
182  {
183  std::string tmp1 = "";
184  if (pos1 > 0)
185  tmp1 = s.substr(0,pos1);
186  std::string tmp2 = s.substr(pos1+5, s.length()-1);
187  outputName = tmp1 + tmp2;
188  }
189  else if (pos2 != std::string::npos)
190  {
191  std::string tmp1 = "";
192  if (pos2 > 0) tmp1 = s.substr(0,pos2);
193  std::string tmp2 = s.substr(pos2+9, s.length()-1);
194  outputName = tmp1 + tmp2;
195  }
196  else
197  {
198  outputName = s;
199  }
200 
201  // Tecplot doesn't like file names with the character, ":", so change all
202  // colons to underscores. I personally don't like "%" characters in
203  // filenames, so remove those as well.
204  for (int i=0;i<outputName.size();++i)
205  {
206  if (outputName[i]==':') outputName[i] = '_';
207  if (outputName[i]=='%') outputName[i] = '_';
208  }
209 
210  return outputName;
211 }
212 
213 //-----------------------------------------------------------------------------
214 // Function : spiceInternalName
215 // Purpose : Converts a conventional "Xyce style" internal variable
216 // name to a spice style name.
217 // Special Notes :
218 // Example:
219 // chilespice: d:subckt1:test1_internal
220 // xyce: xsubckt1:dtest1_internal
221 //
222 // This function will not remove subcircuit "x" characters,
223 // but does move the first character of the local name
224 // to the beginning of the full std::string.
225 //
226 // Scope : public
227 // Creator : Eric Keiter, SNL, Parallel Computational Sciences
228 // Creation Date : 09/12/01
229 //-----------------------------------------------------------------------------
230 std::string spiceInternalName(const InstanceName &entity_name, const std::string &lead)
231 {
232  std::string s = entity_name.getEncodedName();
233 
234  s = s + "_" + lead;
235 
236  size_t pos=s.find_last_of(":");
237  if (pos != std::string::npos)
238  {
239  s = s.substr(pos+1,1)+":"+s.substr(0,pos+1)+s.substr(pos+2);
240  }
241  return s;
242 }
243 
244 std::string spiceStoreName(const InstanceName &entity_name, const std::string &lead)
245 {
246  std::string s = entity_name.getEncodedName();
247 
248  size_t pos=s.find_last_of(":");
249  if (pos != std::string::npos)
250  {
251  s = s.substr(pos+1,1)+":"+s.substr(0,pos+1)+s.substr(pos+2);
252  }
253 
254  return s + ":" + lead;
255 }
256 
257 std::ostream &operator<<(std::ostream &os, const InstanceName &entity_name) {
258  return os << entity_name.getEncodedName();
259 }
260 
261 } // namespace Device
262 } // namespace Xyce
Pure virtual class to augment a linear system.
Devices and models are each named.
const std::string & getEncodedName() const
Return the instance name encoded as: [s:]*xname [s:]*Ytype!name [s:]*Utype!name!count.
std::string decodeDeviceType() const
std::string deviceName_
Device name from netlist (subcircuit NOT included)
std::string decodeDeviceName() const
std::string name_
Complete encoded name.
char getDeviceLetter() const
Return the first letter of the device specification after the subcircuit.
std::string spiceStoreName(const InstanceName &instance_name, const std::string &lead)
std::string spiceInternalName(const InstanceName &instance_name, const std::string &lead)
std::string deviceType_
Device type from netlist (does NOT include Y or U prefix)
int numInputs_
Hack for U type device (needs to become a parameter)
std::string setupOutputName(const InstanceName &name)
std::string decodeSubcircuitName() const
std::ostream & operator<<(std::ostream &os, const Configuration &configuration)
Definition: N_DEV_Dump.C:134
std::string subcircuitName_
Device subcircuit from netlist.
char deviceLetter_
Device letter (Y or U included)