Xyce  6.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
N_ANP_Step.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_ANP_Step.C,v $
27 // Purpose : .STEP Sweep class analysis functions.
28 // Special Notes :
29 // Creator : Richard Schiek, SNL, Electrical and Microsystem Modeling
30 // Creation Date : 01/24/08
31 //
32 // Revision Information:
33 // ---------------------
34 // Revision Number: $Revision: 1.26 $
35 // Revision Date : $Date: 2014/02/24 23:49:12 $
36 // Current Owner : $Author: tvrusso $
37 //-----------------------------------------------------------------------------
38 #include <Xyce_config.h>
39 
40 #include <N_ANP_AnalysisManager.h>
41 #include <N_ANP_OutputMgrAdapter.h>
42 #include <N_ANP_Step.h>
43 
44 namespace Xyce {
45 namespace Analysis {
46 
47 //-----------------------------------------------------------------------------
48 // Function : Step::setAnalysisParams
49 // Purpose :
50 // Special Notes :
51 // Scope : public
52 // Creator : Eric R. Keiter, SNL
53 // Creation Date : 6/22/10
54 //-----------------------------------------------------------------------------
55 bool Step::setAnalysisParams(const N_UTL_OptionBlock & paramsBlock)
56 {
57 #ifdef Xyce_DEBUG_ANALYSIS
58  if (anaManagerRCPtr_->tiaParams.debugLevel > 0)
59  {
60  Xyce::dout() << "In Step::setAnalysisParams" << std::endl;
61  }
62 #endif
63 
64  std::list<N_UTL_Param>::const_iterator it_tp;
65  std::list<N_UTL_Param>::const_iterator it_param;
66  std::list<N_UTL_Param>::const_iterator it_type;
67  std::list<N_UTL_Param>::const_iterator first = paramsBlock.getParams().begin();
68  std::list<N_UTL_Param>::const_iterator last = paramsBlock.getParams().end();
69 
70  std::string msg;
71 
72  // first check to see that there is only 1 PARAM set. They need to be in
73  // separate lines for this to work.
74  int countPar = 0;
75  for (it_tp = first; it_tp != last; ++it_tp)
76  {
77  if (it_tp->uTag() == "PARAM")
78  {
79  ++countPar;
80  }
81  }
82  if (countPar > 1)
83  {
84  msg = "Step::setSTEPAnalysisParams\n";
85  msg += "You have more than one step parameter on a single line.\n";
86  msg += "Each parameter needs its own line.\n";
87  N_ERH_ErrorMgr::report(N_ERH_ErrorMgr::DEV_FATAL_0, msg);
88  }
89 
90  SweepParam sp;
91 #ifdef Xyce_DEBUG_ANALYSIS
92  if (anaManagerRCPtr_->tiaParams.debugLevel > 0)
93  {
94  for (it_tp = first; it_tp != last; ++it_tp)
95  {
96  Xyce::dout() << it_tp->uTag() ;
97  Xyce::dout() << "\t";
98  if (it_tp->uTag() == "PARAM" || it_tp->uTag() == "TYPE")
99  {
100  Xyce::dout() << it_tp->stringValue();
101  }
102  else
103  {
104  Xyce::dout() << it_tp->getImmutableValue<double>();
105  }
106  Xyce::dout() << std::endl;
107  }
108  }
109 #endif
110 
111  for (it_tp = first; it_tp != last; ++it_tp)
112  {
113  if (it_tp->uTag() == "TYPE")
114  {
115  it_type = it_tp;
116  sp.type = it_tp->stringValue();
117  }
118 
119  if (it_tp->uTag() == "PARAM")
120  {
121  it_param = it_tp;
122  sp.name = it_tp->stringValue();
123  }
124  }
125 
126  it_tp = it_param;
127  ++it_tp;
128  if (sp.type == "LIN") // default
129  {
130  sp.startVal = it_tp->getImmutableValue<double>(); ++it_tp;
131  sp.stopVal = it_tp->getImmutableValue<double>(); ++it_tp;
132  sp.stepVal = it_tp->getImmutableValue<double>(); ++it_tp;
133  }
134  else if (sp.type == "DEC" || sp.type == "OCT")
135  {
136  sp.startVal = it_tp->getImmutableValue<double>(); ++it_tp;
137  sp.stopVal = it_tp->getImmutableValue<double>(); ++it_tp;
138  sp.numSteps = it_tp->getImmutableValue<int>(); ++it_tp;
139  }
140  else if (sp.type == "LIST")
141  {
142  for (;it_tp!=last;++it_tp)
143  {
144  sp.valList.push_back(it_tp->getImmutableValue<double>());
145  }
146  }
147  else
148  {
149  msg = "Step::setSTEPAnalysisParams: ";
150  msg += " unsupported STEP type\n";
151  N_ERH_ErrorMgr::report(N_ERH_ErrorMgr::DEV_FATAL_0, msg);
152  }
153 
154  // need to do a bunch of stuff to initialize the step loop.
155  (*stepParamVec_).push_back(sp);
156 
157  // good idea to put this here, but this code isn't touched in
158  // non .step runs and check_outputs will expcect the param vec
159  // to exist (but be empty) even if this isn't a .step run
160  //outputMgrAdapterRCPtr_->setStepParamVec( & stepParamVec_ );
161 
162  //stepLoopFlag_ = true;
163 
164  return true;
165 }
166 
167 //-----------------------------------------------------------------------------
168 // Function : Step::run()
169 // Purpose : This is the main controlling loop for Step analysis.
170 //
171 // Special Notes :
172 // Scope : public
173 // Creator : Eric Keiter, SNL
174 // Creation Date : 10/04/00
175 //-----------------------------------------------------------------------------
176 bool Step::run()
177 {
178  bool bsuccess = true;
179  bsuccess = init();
180  bsuccess &= loopProcess();
181  bsuccess &= finish();
182  return bsuccess;
183 }
184 
185 //-----------------------------------------------------------------------------
186 // Function : Step::init()
187 // Purpose :
188 // Special Notes :
189 // Scope : public
190 // Creator : Eric Keiter, SNL
191 // Creation Date : 03/10/06
192 //-----------------------------------------------------------------------------
194 {
195 #ifdef Xyce_DEBUG_ANALYSIS
196  if (anaManagerRCPtr_->tiaParams.debugLevel > 0)
197  {
198  Xyce::dout() << std::endl << std::endl;
199  Xyce::dout() << section_divider << std::endl;
200  Xyce::dout() << "Step::init" << std::endl;
201  }
202 #endif
203 
205 
206  outputMgrAdapterRCPtr_->setStepAnalysisMaxSteps( stepLoopSize_ );
207 
208  anaManagerRCPtr_->stepLoopInitialized_ = true;
209 
210  return true;
211 }
212 
213 
214 //-----------------------------------------------------------------------------
215 // Function : Step::loopProcess()
216 // Purpose :
217 // Special Notes :
218 // Scope : public
219 // Creator : Eric Keiter, SNL
220 // Creation Date : 03/10/06
221 //-----------------------------------------------------------------------------
223 {
224  std::string msg;
225  bool integration_status = true;
226 
228  {
230 
231 #ifdef Xyce_DEBUG_ANALYSIS
232  if (anaManagerRCPtr_->tiaParams.debugLevel > 0)
233  {
234  // output parameter(s)
235  std::vector <SweepParam>::iterator iterParam;
236  std::vector <SweepParam>::iterator firstParam = stepParamVec_->begin();
237  std::vector <SweepParam>::iterator lastParam = stepParamVec_->end ();
238  for (iterParam=firstParam; iterParam != lastParam;++iterParam)
239  {
240  Xyce::dout() << "Step Analysis # " << stepLoopIter_<<"\t";
241  Xyce::dout() << (*iterParam);
242  }
243  }
244 #endif
245 
246  secRCPtr_->resetAll ();
247  anaManagerRCPtr_->getTIADataStore()->setZeroHistory();
248 
249  // solve the loop.
250  outputMgrAdapterRCPtr_->setStepAnalysisStepNumber( stepLoopIter_);
251  mainAnalysisRCPtr_->resetForStepAnalysis();
252  integration_status &= mainAnalysisRCPtr_->run();
253 
254  outputMgrAdapterRCPtr_->outputRESULT( *(anaManagerRCPtr_->getTIADataStore()->currSolutionPtr), *(anaManagerRCPtr_->getTIADataStore()->currStatePtr), *(anaManagerRCPtr_->getTIADataStore()->currStorePtr) );
255 
256  } // end of for loop, and end of step analysis.
257 
258  outputMgrAdapterRCPtr_->finishOutputSTEP ();
259 
260  return integration_status;
261 }
262 
263 //-----------------------------------------------------------------------------
264 // Function : Step::processSuccessfulStep()
265 // Purpose :
266 // Special Notes :
267 // Scope : public
268 // Creator : Eric Keiter, SNL
269 // Creation Date : 03/10/06
270 //-----------------------------------------------------------------------------
272 {
273  return true;
274 }
275 
276 //-----------------------------------------------------------------------------
277 // Function : Step::processFailedStep()
278 // Purpose :
279 // Special Notes :
280 // Scope : public
281 // Creator : Eric Keiter, SNL
282 // Creation Date : 03/10/06
283 //-----------------------------------------------------------------------------
285 {
286  return true;
287 }
288 
289 
290 //-----------------------------------------------------------------------------
291 // Function : Step::finish()
292 // Purpose :
293 // Special Notes :
294 // Scope : public
295 // Creator : Eric Keiter, SNL
296 // Creation Date : 03/10/06
297 //-----------------------------------------------------------------------------
299 {
300  return true;
301 }
302 
303 } // namespace Analysis
304 } // namespace Xyce
305