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