Xyce  6.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
N_ANP_SweepParam.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_SweepParam.C,v $
27 // Purpose :
28 // Special Notes :
29 // Creator : Eric Keiter
30 // Creation Date : 9/4/04
31 //
32 // Revision Information:
33 // ---------------------
34 // Revision Number: $Revision: 1.14 $
35 // Revision Date : $Date: 2014/02/24 23:49:12 $
36 // Current Owner : $Author: tvrusso $
37 //-----------------------------------------------------------------------------
38 
39 #include <Xyce_config.h>
40 
41 
42 // ---------- Standard Includes ----------
43 
44 #include <N_UTL_Misc.h>
45 #include <N_UTL_fwd.h>
46 
47 #include <iostream>
48 
49 #ifdef HAVE_CSTDIO
50 #include <cstdio>
51 #else
52 #include <stdio.h>
53 #endif
54 
55 #ifdef HAVE_CMATH
56 #include <cmath>
57 #else
58 #include <math.h>
59 #endif
60 
61 
62 // ---------- Xyce Includes ----------
63 #include <N_ANP_SweepParam.h>
64 #include <N_ERH_ErrorMgr.h>
65 
66 // ----------- Forward declarations ------------
67 
68 namespace Xyce {
69 namespace Analysis {
70 
71 //-----------------------------------------------------------------------------
72 // Function : SweepParam::updateCurrentVal
73 //
74 // Purpose : Updates the values of the parameters used in a sweep.
75 //
76 // Special Notes : This is very similar to the "update" function in the
77 // class N_DEV_SweepData. (which no longer exists).
78 //
79 // Scope : public
80 // Creator : Eric R. Keiter,SNL, Computational Sciences
81 // Creation Date : 10/31/2003
82 //-----------------------------------------------------------------------------
83 bool SweepParam::updateCurrentVal (int stepNumberArg)
84 {
85  outerStepNumber = stepNumberArg/interval;
86  int inum = outerStepNumber/maxStep;
87  int localStepNumber = outerStepNumber - inum*maxStep;
88 
89  // We must keep track of whether we're at the first step of our sweep,
90  // because some device manager features need to know that.
91  // It is important that we only set this when localStepNumber first becoms
92  // zero, not every time localStepNumber *is* zero, because an outer loop
93  // might remain at 0 for quite some time.
94 
95  if (localStepNumber == 0 && localStepNumber != lastLocalStepNumber_)
96  {
97  sweepResetFlag_=true;
98  }
99  else
100  {
101  sweepResetFlag_=false;
102  }
103  lastLocalStepNumber_=localStepNumber;
104 
105  if (type == "LIN")
106  {
107  currentVal = startVal + static_cast<double>(localStepNumber)*stepVal;
108  ++count;
109  }
110  else if (type == "DEC" || type == "OCT")
111  {
112  currentVal = startVal*pow(stepMult, static_cast<double>(localStepNumber) );
113  ++count;
114  }
115  else if (type == "LIST")
116  {
117  int size= valList.size();
118  int index = (localStepNumber < size)?localStepNumber:(size-1);
119  currentVal = valList[index];
120  ++count;
121  }
122  else
123  {
124  std::string msg = "SweepParam::updateCurrentVal: ";
125  msg += " Unsupported type specified.\n";
126  N_ERH_ErrorMgr::report(N_ERH_ErrorMgr::DEV_FATAL_0, msg);
127  }
128 #ifdef Xyce_DEBUG_TIME
129  Xyce::dout() << std::endl
130  << Xyce::subsection_divider << std::endl
131  << "updateCurrentVal" << std::endl
132  << " name = " << name << std::endl
133  << " stepNumberArg = " << stepNumberArg<< std::endl
134  << " interval = " << interval << std::endl
135  << " outerStepNumber = " << outerStepNumber << std::endl
136  << " localStepNumber = " << localStepNumber << std::endl
137  << " inum = " << inum << std::endl
138  << " sweepResetFlag = " << sweepResetFlag_ << std::endl
139  << " currentVal = " << currentVal << std::endl
140  << Xyce::subsection_divider << std::endl;
141 #endif
142 
143  return true;
144 }
145 
146 } // namespace Analysis
147 } // namespace Xyce
148