Xyce  6.1
N_NLS_ConstraintBT.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 : $$
27 //
28 // Purpose : Constraint Backtracking Class.
29 //
30 // Special Notes :
31 //
32 // Creator : Scott A. Hutchinson, SNL, Computational Sciences
33 //
34 // Creation Date : 01/26/01
35 //
36 // Revision Information:
37 // ---------------------
38 //
39 // Revision Number: $$
40 //
41 // Revision Date : $$
42 //
43 // Current Owner : $$
44 //-------------------------------------------------------------------------
45 
46 #include <Xyce_config.h>
47 
48 // ---------- Standard Includes ----------
49 
50 // ---------- Xyce Includes ----------
51 #include <N_NLS_ConstraintBT.h>
52 #include <N_LAS_Vector.h>
53 #include <N_LAS_System.h>
54 #include <N_LAS_Builder.h>
55 #include <N_NLS_NLParams.h>
56 #include <N_ERH_ErrorMgr.h>
57 #include <N_UTL_FeatureTest.h>
58 
59 namespace Xyce {
60 namespace Nonlinear {
61 
62 //-----------------------------------------------------------------------------
63 // Function : ConstraintBT::ConstraintBT
64 // Purpose : Constructor
65 // Special Notes :
66 // Scope : public
67 // Creator : Scott A. Hutchinson, SNL, Computational Sciences
68 // Creation Date : 01/26/01
69 //-----------------------------------------------------------------------------
71  : constraintMinVector_(0),
72  constraintMaxVector_(0),
73  constraintChangeVector_(0),
74  constraintTempVector_(0)
75 {
76 
77  // Initialize protected data
81 
82 }
83 
84 //-----------------------------------------------------------------------------
85 // Function : ConstraintBT::~ConstraintBT
86 // Purpose : Destructor
87 // Special Notes :
88 // Scope : public
89 // Creator : Scott A. Hutchinson, SNL, Computational Sciences
90 // Creation Date : 01/26/01
91 //-----------------------------------------------------------------------------
93 {
94  delete constraintMinVector_;
95  delete constraintMaxVector_;
97  delete constraintTempVector_;
98 }
99 
100 //-----------------------------------------------------------------------------
101 // Function : ConstraintBT::operator==
102 // Purpose : Equal operator
103 // Special Notes :
104 // Scope : private
105 // Creator : Scott A. Hutchinson, SNL, Computational Sciences
106 // Creation Date : 01/26/01
107 //-----------------------------------------------------------------------------
108 int ConstraintBT::operator==(const ConstraintBT & right) const
109 
110 {
111  return 0;
112 }
113 
114 //-----------------------------------------------------------------------------
115 // Function : ConstraintBT::operator!=
116 // Purpose : Not-Equal operator
117 // Special Notes :
118 // Scope : private
119 // Creator : Scott A. Hutchinson, SNL, Computational Sciences
120 // Creation Date : 01/26/01
121 //-----------------------------------------------------------------------------
122 int ConstraintBT::operator!=(const ConstraintBT & right) const
123 
124 {
125  return 0;
126 }
127 
128 //-----------------------------------------------------------------------------
129 // Function : ConstraintBT::initializeAll
130 // Purpose : Not-Equal operator
131 // Special Notes :
132 // Scope : private
133 // Creator : Eric R. Keiter, SNL, Computational Sciences
134 // Creation Date : 10/29/02
135 //-----------------------------------------------------------------------------
137  (Linear::System * lasSysPtr, const NLParams & nlParams)
138 {
139  // create and initialize constraint backtracking vectors:
140  constraintMinVector_ = lasSysPtr->builder().createVector();
141  constraintMaxVector_ = lasSysPtr->builder().createVector();
142 
143  constraintMinVector_->putScalar(nlParams.getGlobalBTMin());
144  constraintMaxVector_->putScalar(nlParams.getGlobalBTMax());
145 
146  constraintChangeVector_ = lasSysPtr->builder().createVector();
147 
148  constraintChangeVector_->putScalar (nlParams.getGlobalBTChange());
149 
150  constraintTempVector_ = lasSysPtr->builder().createVector();
151 
152  constraintTempVector_->putScalar(0.0);
153 
154  return true;
155 }
156 
157 //-----------------------------------------------------------------------------
158 // Function : ConstraintBT::updateThetaBoundNeg
159 // Purpose : Updates the minimum bound value for the backtracking
160 // algorithm.
161 // Special Notes : This is implemented according to a internal
162 // communication with John Shadid (SNL) on their MPSalsa
163 // constraint backtracking implementation.
164 // Scope : public
165 // Creator : Scott A. Hutchinson, SNL, Computational Sciences
166 // Creation Date : 01/26/01
167 //-----------------------------------------------------------------------------
168 void ConstraintBT::updateThetaBoundNeg(const Linear::Vector * oldSoln,
169  const Linear::Vector * solnUpdate)
170 
171 {
172  Linear::Vector * solnPtr;
173  Linear::Vector * solnUpdatePtr;
174 
175  // Initialize
176  solnPtr = const_cast<Linear::Vector *> (oldSoln);
177  solnUpdatePtr = const_cast<Linear::Vector *> (solnUpdate);
178 
179  // First, form a vector of constraints...
180  for (int i = 0; i < solnPtr->localLength(); ++i)
181  {
182  if ((*(solnUpdatePtr))[i] < 0.0)
183  (*(constraintTempVector_))[i] = ((*(constraintMinVector_))[i] -
184  (*(solnPtr))[i]) / (*(solnUpdatePtr))[i];
185  else
186  (*(constraintTempVector_))[i] = Util::MachineDependentParams::DoubleMax();
187 
188  if (DEBUG_NONLINEAR)
189  Xyce::dout() << "ConstraintBT::updateThetaBoundNeg: min: " << (*(constraintMinVector_))[i] << "\n"
190  << "ConstraintBT::updateThetaBoundNeg: soln: " << (*(solnPtr))[i] << "\n"
191  << "ConstraintBT::updateThetaBoundNeg: solnUpdate: " << (*(solnUpdatePtr))[i] << "\n"
192  << "ConstraintBT::updateThetaBoundNeg: constraint: " << (*(constraintTempVector_))[i];
193  }
194 
195  // Find minimum
197 
198  if (DEBUG_NONLINEAR)
199  Xyce::dout() << "ConstraintBT::updateThetaBoundNeg: thetaBoundNeg_: " << thetaBoundNeg_;
200 }
201 
202 //-----------------------------------------------------------------------------
203 // Function : ConstraintBT::updateThetaBoundPos
204 // Purpose : Updates the maximum bound value for the backtracking
205 // algorithm.
206 // Special Notes : This is implemented according to a internal
207 // communication with John Shadid (SNL) on their MPSalsa
208 // constraint backtracking implementation.
209 // Scope : public
210 // Creator : Scott A. Hutchinson, SNL, Computational Sciences
211 // Creation Date : 01/26/01
212 //-----------------------------------------------------------------------------
213 void ConstraintBT::updateThetaBoundPos(const Linear::Vector * oldSoln,
214  const Linear::Vector * solnUpdate)
215 
216 {
217  Linear::Vector * solnPtr;
218  Linear::Vector * solnUpdatePtr;
219 
220  // Initialize
221  solnPtr = const_cast<Linear::Vector *> (oldSoln);
222  solnUpdatePtr = const_cast<Linear::Vector *> (solnUpdate);
223 
224  // First, form a vector of constraints...
225  for (int i = 0; i < solnPtr->localLength(); ++i)
226  {
227  if ((*(solnUpdatePtr))[i] > 0.0)
228  (*(constraintTempVector_))[i] = ((*(constraintMaxVector_))[i] -
229  (*(solnPtr))[i]) / (*(solnUpdatePtr))[i];
230  else
231  (*(constraintTempVector_))[i] = Util::MachineDependentParams::DoubleMax();
232 
233  if (DEBUG_NONLINEAR)
234  Xyce::dout() << "ConstraintBT::updateThetaBoundPos: max: " << (*(constraintMaxVector_))[i] << "\n"
235  << "ConstraintBT::updateThetaBoundPos: soln: " << (*(solnPtr))[i] << "\n"
236  << "ConstraintBT::updateThetaBoundPos: solnUpdate: " << (*(solnUpdatePtr))[i] << "\n"
237  << "ConstraintBT::updateThetaBoundPos: constraint: " << (*(constraintTempVector_))[i];
238  }
239 
240  // Find minimum
242 
243  if (DEBUG_NONLINEAR)
244  Xyce::dout() << "ConstraintBT::updateThetaBoundPos: thetaBoundPos_: " << thetaBoundPos_;
245 }
246 
247 //-----------------------------------------------------------------------------
248 // Function : ConstraintBT::updateThetaChange
249 // Purpose : Updates the percentage-change bound value for the
250 // backtracking algorithm.
251 // Special Notes : This is implemented according to a internal
252 // communication with John Shadid (SNL) on their MPSalsa
253 // constraint backtracking implementation.
254 // This function returns:
255 //
256 // theta_u = min {gamma_i | oldSoln_i | / | solnUpdate_i | }
257 // i
258 //
259 // Scope : public
260 // Creator : Scott A. Hutchinson, SNL, Computational Sciences
261 // Creation Date : 01/26/01
262 //-----------------------------------------------------------------------------
263 void ConstraintBT::updateThetaChange(const Linear::Vector * oldSoln,
264  const Linear::Vector * solnUpdate)
265 
266 {
267  Linear::Vector * solnPtr;
268  Linear::Vector * solnUpdatePtr;
269 
270  // Initialize
271  solnPtr = const_cast<Linear::Vector *> (oldSoln);
272  solnUpdatePtr = const_cast<Linear::Vector *> (solnUpdate);
273 
274  // First, form a vector of constraints...
275  for (int i = 0; i < solnPtr->localLength(); ++i)
276  {
277  if (fabs((*(solnUpdatePtr))[i]) > Util::MachineDependentParams::DoubleMin() &&
278  fabs((*(solnPtr))[i]) > 0.0)
280  fabs((*(solnPtr))[i]) / fabs((*(solnUpdatePtr))[i]);
281 
282  else
283  (*(constraintTempVector_))[i] = Util::MachineDependentParams::DoubleMax();
284 
285  if (DEBUG_NONLINEAR)
286  Xyce::dout() << "ConstraintBT::updateThetaChange: change: " << (*(constraintChangeVector_))[i] << "\n"
287  << "ConstraintBT::updateThetaChange: constraint: " << (*(constraintTempVector_))[i];
288  }
289 
290  // Find minimum
292 
293  if (DEBUG_NONLINEAR)
294  Xyce::dout() << "ConstraintBT::updateThetaChange: thetaChange_: " << thetaChange_;
295 }
296 
297 } // namespace Nonlinear
298 } // namespace Xyce
int operator==(const ConstraintBT &right) const
Linear::Vector * constraintChangeVector_
Pure virtual class to augment a linear system.
double getGlobalBTChange() const
int operator!=(const ConstraintBT &right) const
double getGlobalBTMax() const
void updateThetaBoundNeg(const Linear::Vector *oldSoln, const Linear::Vector *solnUpdate)
void updateThetaChange(const Linear::Vector *oldSoln, const Linear::Vector *solnUpdate)
double getGlobalBTMin() const
void updateThetaBoundPos(const Linear::Vector *oldSoln, const Linear::Vector *solnUpdate)
bool initializeAll(Linear::System *lasSysPtr, const NLParams &nlParams)