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.43.2.2 $
35 // Revision Date : $Date: 2014/08/25 20:12:48 $
36 // Current Owner : $Author: dgbaur $
37 //-----------------------------------------------------------------------------
38 #include <Xyce_config.h>
39 
40 #include <N_ANP_AnalysisManager.h>
41 #include <N_ANP_OutputMgrAdapter.h>
42 #include <N_ANP_SweepParam.h>
43 #include <N_ANP_Step.h>
44 #include <N_ANP_StepEvent.h>
45 #include <N_ERH_Message.h>
46 #include <N_TIA_StepErrorControl.h>
47 #include <N_TIA_DataStore.h>
48 #include <N_UTL_Timer.h>
49 
50 namespace Xyce {
51 namespace Analysis {
52 
53 //-----------------------------------------------------------------------------
54 // Function : Step::setAnalysisParams
55 // Purpose :
56 // Special Notes :
57 // Scope : public
58 // Creator : Eric R. Keiter, SNL
59 // Creation Date : 6/22/10
60 //-----------------------------------------------------------------------------
61 bool Step::setAnalysisParams(const N_UTL_OptionBlock & paramsBlock)
62 {
63 #ifdef Xyce_DEBUG_ANALYSIS
65  {
66  Xyce::dout() << "In Step::setAnalysisParams" << std::endl;
67  }
68 #endif
69 
70  Util::ParameterList::const_iterator it_tp;
71  Util::ParameterList::const_iterator it_param;
72  Util::ParameterList::const_iterator it_type;
73  Util::ParameterList::const_iterator first = paramsBlock.getParams().begin();
74  Util::ParameterList::const_iterator last = paramsBlock.getParams().end();
75 
76  std::string msg;
77 
78  // first check to see that there is only 1 PARAM set. They need to be in
79  // separate lines for this to work.
80  int countPar = 0;
81  for (it_tp = first; it_tp != last; ++it_tp)
82  {
83  if (it_tp->uTag() == "PARAM")
84  {
85  ++countPar;
86  }
87  }
88  if (countPar > 1)
89  {
90  Report::UserError() << "More than one step parameter has been specified on a single line." << std::endl
91  << "Each parameter needs its own line.";
92  return false;
93  }
94 
95  SweepParam sp;
96 #ifdef Xyce_DEBUG_ANALYSIS
98  {
99  for (it_tp = first; it_tp != last; ++it_tp)
100  {
101  Xyce::dout() << it_tp->uTag() ;
102  Xyce::dout() << "\t";
103  if (it_tp->uTag() == "PARAM" || it_tp->uTag() == "TYPE")
104  {
105  Xyce::dout() << it_tp->stringValue();
106  }
107  else
108  {
109  Xyce::dout() << it_tp->getImmutableValue<double>();
110  }
111  Xyce::dout() << std::endl;
112  }
113  }
114 #endif
115 
116  for (it_tp = first; it_tp != last; ++it_tp)
117  {
118  if (it_tp->uTag() == "TYPE")
119  {
120  it_type = it_tp;
121  sp.type = it_tp->stringValue();
122  }
123 
124  if (it_tp->uTag() == "PARAM")
125  {
126  it_param = it_tp;
127  sp.name = it_tp->stringValue();
128  }
129  }
130 
131  it_tp = it_param;
132  ++it_tp;
133  if (sp.type == "LIN") // default
134  {
135  sp.startVal = it_tp->getImmutableValue<double>(); ++it_tp;
136  sp.stopVal = it_tp->getImmutableValue<double>(); ++it_tp;
137  sp.stepVal = it_tp->getImmutableValue<double>(); ++it_tp;
138  }
139  else if (sp.type == "DEC" || sp.type == "OCT")
140  {
141  sp.startVal = it_tp->getImmutableValue<double>(); ++it_tp;
142  sp.stopVal = it_tp->getImmutableValue<double>(); ++it_tp;
143  sp.numSteps = it_tp->getImmutableValue<int>(); ++it_tp;
144  }
145  else if (sp.type == "LIST")
146  {
147  for (;it_tp!=last;++it_tp)
148  {
149  sp.valList.push_back(it_tp->getImmutableValue<double>());
150  }
151  }
152  else
153  {
154  Report::UserError() << "Unsupported STEP type";
155  }
156 
157  // need to do a bunch of stuff to initialize the step loop.
158  stepParamVec_.push_back(sp);
159 
160  return true;
161 }
162 
163 //-----------------------------------------------------------------------------
164 // Function : Step::getDCOPFlag()
165 // Purpose :
166 //
167 // Special Notes :
168 // Scope : public
169 // Creator : Eric Keiter, SNL
170 // Creation Date : 3/24/2014
171 //-----------------------------------------------------------------------------
173 {
174  return mainAnalysis_.getDCOPFlag();
175 }
176 
177 //-----------------------------------------------------------------------------
178 // Function : Step::run()
179 // Purpose : This is the main controlling loop for Step analysis.
180 //
181 // Special Notes :
182 // Scope : public
183 // Creator : Eric Keiter, SNL
184 // Creation Date : 10/04/00
185 //-----------------------------------------------------------------------------
186 bool Step::run()
187 {
188  bool bsuccess = true;
189  bsuccess = init();
190  bsuccess &= loopProcess();
191  bsuccess &= finish();
192  return bsuccess;
193 }
194 
195 //-----------------------------------------------------------------------------
196 // Function : Step::init()
197 // Purpose :
198 // Special Notes :
199 // Scope : public
200 // Creator : Eric Keiter, SNL
201 // Creation Date : 03/10/06
202 //-----------------------------------------------------------------------------
204 {
205 #ifdef Xyce_DEBUG_ANALYSIS
207  {
208  Xyce::dout() << std::endl << std::endl;
209  Xyce::dout() << section_divider << std::endl;
210  Xyce::dout() << "Step::init" << std::endl;
211  }
212 #endif
213 
215 
216  Util::publish<StepEvent>(analysisManager_, StepEvent(StepEvent::INITIALIZE, stepLoopSize_));
217 
218  analysisManager_.setStepLoopInitialized(true);
219 
220  return true;
221 }
222 
223 
224 //-----------------------------------------------------------------------------
225 // Function : Step::loopProcess()
226 // Purpose :
227 // Special Notes :
228 // Scope : public
229 // Creator : Eric Keiter, SNL
230 // Creation Date : 03/10/06
231 //-----------------------------------------------------------------------------
233 {
234  std::string msg;
235  bool integration_status = true;
236 
238  {
240 
241 #ifdef Xyce_DEBUG_ANALYSIS
243  {
244  // output parameter(s)
245  std::vector <SweepParam>::iterator iterParam;
246  std::vector <SweepParam>::iterator firstParam = stepParamVec_.begin();
247  std::vector <SweepParam>::iterator lastParam = stepParamVec_.end ();
248  for (iterParam=firstParam; iterParam != lastParam;++iterParam)
249  {
250  Xyce::dout() << "Step Analysis # " << stepLoopIter_<<"\t";
251  Xyce::dout() << (*iterParam);
252  }
253  }
254 #endif
255 
257 
259 
260  // solve the loop.
261  integration_status &= mainAnalysis_.run();
262 
264 
266  *(analysisManager_.getTIADataStore()->currSolutionPtr),
267  *(analysisManager_.getTIADataStore()->currStatePtr),
268  *(analysisManager_.getTIADataStore()->currStorePtr) );
269 
270  } // end of for loop, and end of step analysis.
271 
272  return integration_status;
273 }
274 
275 //-----------------------------------------------------------------------------
276 // Function : Step::processSuccessfulStep()
277 // Purpose :
278 // Special Notes :
279 // Scope : public
280 // Creator : Eric Keiter, SNL
281 // Creation Date : 03/10/06
282 //-----------------------------------------------------------------------------
284 {
285  return true;
286 }
287 
288 //-----------------------------------------------------------------------------
289 // Function : Step::processFailedStep()
290 // Purpose :
291 // Special Notes :
292 // Scope : public
293 // Creator : Eric Keiter, SNL
294 // Creation Date : 03/10/06
295 //-----------------------------------------------------------------------------
297 {
298  return true;
299 }
300 
301 
302 //-----------------------------------------------------------------------------
303 // Function : Step::finish()
304 // Purpose :
305 // Special Notes :
306 // Scope : public
307 // Creator : Eric Keiter, SNL
308 // Creation Date : 03/10/06
309 //-----------------------------------------------------------------------------
311 {
312  Util::publish<StepEvent>(analysisManager_, StepEvent(StepEvent::FINISH, stepLoopIter_));
313 
315 
316  return true;
317 }
318 
319 } // namespace Analysis
320 } // namespace Xyce