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.6 $
40 //
41 // Revision Date : $Date: 2015/07/02 13:00:11 $
42 //
43 // Current Owner : $Author: dgbaur $
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_DEV_DeviceEntity.h>
57 #include <N_UTL_Algorithm.h>
58 #include <N_UTL_OpBuilder.h>
59 #include <N_UTL_Param.h>
60 
61 namespace Xyce {
62 namespace Device {
63 
64 namespace {
65 
66 void parameterNameAndArgs(std::string &name, std::vector<std::string> &args, Util::ParamList::const_iterator &it)
67 {
68  const std::string &param_tag = (*it).tag();
69 
70  if (param_tag[0] == 'V' || param_tag[0] == 'I' || param_tag[0] == 'N')
71  {
72  std::ostringstream oss;
73  oss << param_tag << "(";
74  int arg_count = (*it).getImmutableValue<int>();
75  for (int i = 0; i < arg_count; ++i)
76  {
77  ++it;
78  if (i != 0)
79  oss << ",";
80  oss << (*it).tag();
81  args.push_back((*it).tag());
82  }
83  oss << ")";
84  name = oss.str();
85  }
86 }
87 
88 } // namespace <unnamed>
89 
90 
91 struct DeviceGlobalParameterOpBuilder : public Util::Op::Builder
92 {
94  : deviceManager_(device_manager)
95  {}
96 
98  {}
99 
100  virtual void registerCreateFunctions(Util::Op::BuilderManager &builder_manager) const
101  {
102  builder_manager.addCreateFunction<DeviceMgrGlobalParameterOp>();
103  }
104 
105  virtual Util::Op::Operator *makeOp(Util::ParamList::const_iterator &it) const
106  {
107  Util::Op::Operator *new_op = 0;
108  const std::string &param_tag = (*it).tag();
109  const std::string &param_string = (*it).stringValue();
110 
111  if (param_tag == "GLOBAL_PARAMETER") {
112  // new_op = new DeviceMgrGlobalParameterOp(param_string, deviceManager_, param_string);
113  // new_op->addArg(param_string);
114  const double *result = deviceManager_.findGlobalPar(param_string);
115  if (result)
116  {
117  // Refactor: [DGB] Should use the address.
118  new_op = new DeviceMgrGlobalParameterOp(param_string, deviceManager_, *result);
119  new_op->addArg(param_string);
120  }
121  }
122  else
123  {
124  const double *result = deviceManager_.findGlobalPar(param_tag);
125  if (result)
126  {
127  // Refactor: [DGB] Should use the address.
128  new_op = new DeviceMgrGlobalParameterOp(param_tag, deviceManager_, *result);
129  }
130  }
131 
132  return new_op;
133  }
134 
135 private:
137 };
138 
139 struct DeviceEntityOpBuilder : public Util::Op::Builder
140 {
141  DeviceEntityOpBuilder(const DeviceMgr &device_manager)
142  : deviceManager_(device_manager)
143  {}
144 
146  {}
147 
148  virtual void registerCreateFunctions(Util::Op::BuilderManager &builder_manager) const
149  {
150  builder_manager.addCreateFunction<DeviceEntityParameterOp>();
151  }
152 
153  virtual Util::Op::Operator *makeOp(Util::ParamList::const_iterator &it) const {
154  Util::Op::Operator *new_op = 0;
155  const std::string &param_tag = (*it).tag();
156  const std::string &param_string = (*it).stringValue();
157 
158  int arg_count = 0;
159  if ((*it).getType() == Util::INT)
160  arg_count = (*it).getImmutableValue<int>();
161  if (arg_count == 0) {
162  const DeviceEntity *device_entity = deviceManager_.getDeviceEntity(param_tag);
163  if (device_entity)
164  {
165  std::string param_name = Util::paramNameFromFullParamName(param_tag);
166  if (param_name.empty() || device_entity->findParam(param_name))
167  new_op = new DeviceEntityParameterOp(param_tag, *device_entity, param_name);
168  }
169  }
170 
171  return new_op;
172  }
173 
174 private:
176 };
177 
178 
179 struct ArtificialParameterOpBuilder : public Util::Op::Builder
180 {
181  ArtificialParameterOpBuilder(const DeviceMgr &device_manager, const ArtificialParameterMap &artificial_parameter_map, const PassthroughParameterSet &passthrough_parameter_set)
182  : deviceManager_(device_manager),
183  artificialParameterMap_(artificial_parameter_map),
184  passthroughParameterSet_(passthrough_parameter_set)
185  {}
186 
188  {}
189 
190  virtual void registerCreateFunctions(Util::Op::BuilderManager &builder_manager) const
191  {
192  builder_manager.addCreateFunction<ArtificialParameterOp>();
193  }
194 
195  virtual Util::Op::Operator *makeOp(Util::ParamList::const_iterator &it) const {
196  Util::Op::Operator *new_op = 0;
197  const std::string &param_tag = (*it).tag();
198  const std::string &param_string = (*it).stringValue();
199 
200  const ArtificialParameterMap::const_iterator artificial_parameter_it = artificialParameterMap_.find(param_tag);
201  if (artificial_parameter_it != artificialParameterMap_.end())
202  {
203  std::string param_name = Util::paramNameFromFullParamName(param_tag);
204  new_op = new ArtificialParameterOp(param_tag, deviceManager_, *(*artificial_parameter_it).second, param_name);
205  }
206 
207  return new_op;
208  }
209 
210 private:
214 };
215 
216 
217 // struct DeviceMgrOpBuilder : public Util::Op::Builder
218 // {
219 // DeviceMgrOpBuilder(const DeviceMgr &device_manager)
220 // : deviceManager_(device_manager)
221 // {}
222 
223 // virtual ~DeviceMgrOpBuilder()
224 // {}
225 
226 // virtual Util::Op::Operator *makeOp(Util::ParamList::const_iterator &it) const {
227 // Util::Op::Operator *new_op = 0;
228 // const std::string &param_tag = (*it).tag();
229 // const std::string &param_string = (*it).stringValue();
230 
231 // if (deviceManager_.parameterExists(param_tag))
232 // {
233 // new_op = new DeviceMgrParameterOp(param_tag, deviceManager_, param_tag);
234 // }
235 // return new_op;
236 // }
237 
238 // private:
239 // const DeviceMgr & deviceManager_;
240 // };
241 
242 
243 struct DeviceOptionsOpBuilder : public Util::Op::Builder
244 {
245  DeviceOptionsOpBuilder(const DeviceOptions &device_options)
246  : deviceOptions_(device_options)
247  {}
248 
250  {}
251 
252  virtual void registerCreateFunctions(Util::Op::BuilderManager &builder_manager) const
253  {
254  builder_manager.addCreateFunction<DeviceOptionsOp>();
255  }
256 
257  virtual Util::Op::Operator *makeOp(Util::ParamList::const_iterator &it) const {
258  Util::Op::Operator *new_op = 0;
259  const std::string &param_tag = (*it).tag();
260  const std::string &param_string = (*it).stringValue();
261 
262  if (compare_nocase(param_tag.c_str(), "gmin") == 0)
263  {
264  new_op = new DeviceOptionsOp(param_tag, deviceOptions_, param_tag);
265  }
266  return new_op;
267  }
268 
269 private:
271 };
272 
273 //-----------------------------------------------------------------------------
274 // Function : registerOpBuilders
275 // Purpose :
276 // Special Notes :
277 // Scope : public
278 // Creator : Dave Shirley, PSSI
279 // Creation Date : 8/15/06
280 //-----------------------------------------------------------------------------
281 void registerOpBuilders(Util::Op::BuilderManager &builder_manager, Parallel::Machine comm, DeviceMgr &device_manager)
282 {
283  builder_manager.addBuilder(new DeviceGlobalParameterOpBuilder(device_manager));
284  builder_manager.addBuilder(new DeviceEntityOpBuilder(device_manager));
285  builder_manager.addBuilder(new DeviceOptionsOpBuilder(device_manager.getDeviceOptions()));
286  builder_manager.addBuilder(new ArtificialParameterOpBuilder(device_manager, device_manager.getArtificialParameterMap(), device_manager.getPassthroughParameterSet()));
287 // builder_manager.addBuilder(new DeviceMgrOpBuilder(device_manager));
288 }
289 
290 } // namespace IO
291 } // namespace Xyce
virtual Util::Op::Operator * makeOp(Util::ParamList::const_iterator &it) const
const PassthroughParameterSet & passthroughParameterSet_
DeviceEntity * getDeviceEntity(const std::string &full_param_name) const
Pure virtual class to augment a linear system.
DeviceOptionsOpBuilder(const DeviceOptions &device_options)
virtual void registerCreateFunctions(Util::Op::BuilderManager &builder_manager) const
const ArtificialParameterMap & getArtificialParameterMap() 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
bool findParam(const std::string &param_name) const
virtual Util::Op::Operator * makeOp(Util::ParamList::const_iterator &it) const
DeviceGlobalParameterOpBuilder(const DeviceMgr &device_manager)
unordered_set< std::string, HashNoCase, EqualNoCase > PassthroughParameterSet
Definition: N_DEV_fwd.h:171
virtual void registerCreateFunctions(Util::Op::BuilderManager &builder_manager) const
const ArtificialParameterMap & artificialParameterMap_
const DeviceOptions & getDeviceOptions() const
const double * findGlobalPar(const std::string &name) const
const PassthroughParameterSet & getPassthroughParameterSet() const
DeviceEntityOpBuilder(const DeviceMgr &device_manager)
ArtificialParameterOpBuilder(const DeviceMgr &device_manager, const ArtificialParameterMap &artificial_parameter_map, const PassthroughParameterSet &passthrough_parameter_set)
unordered_map< std::string, ArtificialParameters::ArtificialParameter *, HashNoCase, EqualNoCase > ArtificialParameterMap
Definition: N_DEV_fwd.h:170
virtual void registerCreateFunctions(Util::Op::BuilderManager &builder_manager) const
virtual Util::Op::Operator * makeOp(Util::ParamList::const_iterator &it) const
virtual void registerCreateFunctions(Util::Op::BuilderManager &builder_manager) const