Xyce  6.1
N_DEV_OpBuilders.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_OpBuilders.C,v $
27 //
28 // Purpose : Output Manager
29 //
30 // Special Notes :
31 //
32 // Creator : David G. Baur, Raytheon
33 //
34 // Creation Date : 11/11/2014
35 //
36 // Revision Information:
37 // ---------------------
38 //
39 // Revision Number: $Revision: 1.3.2.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 #include <string>
49 #include <vector>
50 
51 #include <N_DEV_fwd.h>
52 #include <N_UTL_fwd.h>
53 
54 #include <N_DEV_Op.h>
55 #include <N_DEV_DeviceMgr.h>
56 #include <N_UTL_Algorithm.h>
57 #include <N_UTL_OpBuilder.h>
58 #include <N_UTL_Param.h>
59 
60 namespace Xyce {
61 namespace Device {
62 
63 namespace {
64 
65 void parameterNameAndArgs(std::string &name, std::vector<std::string> &args, Util::ParamList::const_iterator &it)
66 {
67  const std::string &param_tag = (*it).tag();
68 
69  if (param_tag[0] == 'V' || param_tag[0] == 'I' || param_tag[0] == 'N')
70  {
71  std::ostringstream oss;
72  oss << param_tag << "(";
73  int arg_count = (*it).getImmutableValue<int>();
74  for (int i = 0; i < arg_count; ++i)
75  {
76  ++it;
77  if (i != 0)
78  oss << ",";
79  oss << (*it).tag();
80  args.push_back((*it).tag());
81  }
82  oss << ")";
83  name = oss.str();
84  }
85 }
86 
87 } // namespace <unnamed>
88 
89 
90 struct DeviceGlobalParameterOpBuilder : public Util::Op::Builder
91 {
93  : deviceManager_(device_manager)
94  {}
95 
97  {}
98 
99  virtual void registerCreateFunctions(Util::Op::BuilderManager &builder_manager) const
100  {
101  builder_manager.addCreateFunction<DeviceMgrGlobalParameterOp>();
102  }
103 
104  virtual Util::Op::Operator *makeOp(Util::ParamList::const_iterator &it) const
105  {
106  Util::Op::Operator *new_op = 0;
107  const std::string &param_tag = (*it).tag();
108  const std::string &param_string = (*it).stringValue();
109 
110  if (param_tag == "GLOBAL_PARAMETER") {
111  new_op = new DeviceMgrGlobalParameterOp(param_string, deviceManager_, param_string);
112  new_op->addArg(param_string);
113  }
114  else
115  {
116  const double *result = deviceManager_.findGlobalPar(param_tag);
117  if (result)
118  {
119  // Refactor: [DGB] Should use the address.
120  new_op = new DeviceMgrGlobalParameterOp(param_tag, deviceManager_, param_tag);
121  }
122  }
123 
124  return new_op;
125  }
126 
127 private:
129 };
130 
131 struct DeviceEntityOpBuilder : public Util::Op::Builder
132 {
133  DeviceEntityOpBuilder(const DeviceMgr &device_manager)
134  : deviceManager_(device_manager)
135  {}
136 
138  {}
139 
140  virtual void registerCreateFunctions(Util::Op::BuilderManager &builder_manager) const
141  {
142  builder_manager.addCreateFunction<DeviceEntityParameterOp>();
143  }
144 
145  virtual Util::Op::Operator *makeOp(Util::ParamList::const_iterator &it) const {
146  Util::Op::Operator *new_op = 0;
147  const std::string &param_tag = (*it).tag();
148  const std::string &param_string = (*it).stringValue();
149 
150  const DeviceEntity *device_entity = deviceManager_.getDeviceEntity(param_tag);
151  if (device_entity)
152  {
153  std::string param_name = Util::paramNameFromFullParamName(param_tag);
154  new_op = new DeviceEntityParameterOp(param_tag, *device_entity, param_name);
155  }
156 
157  return new_op;
158  }
159 
160 private:
162 };
163 
164 
165 struct DeviceMgrOpBuilder : public Util::Op::Builder
166 {
167  DeviceMgrOpBuilder(const DeviceMgr &device_manager)
168  : deviceManager_(device_manager)
169  {}
170 
172  {}
173 
174  virtual Util::Op::Operator *makeOp(Util::ParamList::const_iterator &it) const {
175  Util::Op::Operator *new_op = 0;
176  const std::string &param_tag = (*it).tag();
177  const std::string &param_string = (*it).stringValue();
178 
179  if (deviceManager_.findParam(param_tag))
180  {
181  new_op = new DeviceMgrParameterOp(param_tag, deviceManager_, param_tag);
182  }
183  return new_op;
184  }
185 
186 private:
188 };
189 
190 
191 struct DeviceOptionsOpBuilder : public Util::Op::Builder
192 {
193  DeviceOptionsOpBuilder(const DeviceOptions &device_options)
194  : deviceOptions_(device_options)
195  {}
196 
198  {}
199 
200  virtual void registerCreateFunctions(Util::Op::BuilderManager &builder_manager) const
201  {
202  builder_manager.addCreateFunction<DeviceOptionsOp>();
203  }
204 
205  virtual Util::Op::Operator *makeOp(Util::ParamList::const_iterator &it) const {
206  Util::Op::Operator *new_op = 0;
207  const std::string &param_tag = (*it).tag();
208  const std::string &param_string = (*it).stringValue();
209 
210  if (compare_nocase(param_tag.c_str(), "gmin") == 0)
211  {
212  new_op = new DeviceOptionsOp(param_tag, deviceOptions_, param_tag);
213  }
214  return new_op;
215  }
216 
217 private:
219 };
220 
221 //-----------------------------------------------------------------------------
222 // Function : registerOpBuilders
223 // Purpose :
224 // Special Notes :
225 // Scope : public
226 // Creator : Dave Shirley, PSSI
227 // Creation Date : 8/15/06
228 //-----------------------------------------------------------------------------
229 void registerOpBuilders(Util::Op::BuilderManager &builder_manager, Parallel::Machine comm, DeviceMgr &device_manager)
230 {
231  builder_manager.addBuilder(new DeviceGlobalParameterOpBuilder(device_manager));
232  builder_manager.addBuilder(new DeviceEntityOpBuilder(device_manager));
233  builder_manager.addBuilder(new DeviceOptionsOpBuilder(device_manager.getDeviceOptions()));
234 // builder_manager.addBuilder(new DeviceMgrOpBuilder(device_manager));
235 }
236 
237 } // namespace IO
238 } // namespace Xyce
const double * findGlobalPar(const std::string &parName) const
virtual Util::Op::Operator * makeOp(Util::ParamList::const_iterator &it) const
DeviceEntity * getDeviceEntity(const std::string &full_param_name) const
Pure virtual class to augment a linear system.
DeviceOptionsOpBuilder(const DeviceOptions &device_options)
virtual Util::Op::Operator * makeOp(Util::ParamList::const_iterator &it) const
bool findParam(const std::string &name) const
void registerOpBuilders(Util::Op::BuilderManager &builder_manager, Parallel::Machine comm, DeviceMgr &device_manager)
virtual Util::Op::Operator * makeOp(Util::ParamList::const_iterator &it) const
virtual Util::Op::Operator * makeOp(Util::ParamList::const_iterator &it) const
DeviceMgrOpBuilder(const DeviceMgr &device_manager)
DeviceGlobalParameterOpBuilder(const DeviceMgr &device_manager)
virtual void registerCreateFunctions(Util::Op::BuilderManager &builder_manager) const
const DeviceOptions & getDeviceOptions() const
DeviceEntityOpBuilder(const DeviceMgr &device_manager)
virtual void registerCreateFunctions(Util::Op::BuilderManager &builder_manager) const
virtual void registerCreateFunctions(Util::Op::BuilderManager &builder_manager) const