Xyce  6.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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-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 : $$
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 
49 // ---------- Standard Includes ----------
50 
51 #include <N_UTL_Misc.h>
52 
53 // ---------- Xyce Includes ----------
54 
55 #include <N_NLS_ConstraintBT.h>
56 
57 #include <N_LAS_Vector.h>
58 #include <N_LAS_System.h>
59 #include <N_LAS_Builder.h>
60 #include <N_NLS_NLParams.h>
61 
62 #ifdef Xyce_DEBUG_NONLINEAR
63 #include <N_ERH_ErrorMgr.h>
64 #endif
65 
66 //-----------------------------------------------------------------------------
67 // Function : N_NLS_ConstraintBT::N_NLS_ConstraintBT
68 // Purpose : Constructor
69 // Special Notes :
70 // Scope : public
71 // Creator : Scott A. Hutchinson, SNL, Computational Sciences
72 // Creation Date : 01/26/01
73 //-----------------------------------------------------------------------------
75  : constraintMinVector_(0),
76  constraintMaxVector_(0),
77  constraintChangeVector_(0),
78  constraintTempVector_(0)
79 {
80 
81  // Initialize protected data
85 
86 }
87 
88 //-----------------------------------------------------------------------------
89 // Function : N_NLS_ConstraintBT::N_NLS_ConstraintBT
90 // Purpose : Copy Constructor
91 // Special Notes :
92 // Scope : private
93 // Creator : Scott A. Hutchinson, SNL, Computational Sciences
94 // Creation Date : 01/26/01
95 //-----------------------------------------------------------------------------
97 {
98 
99 }
100 
101 //-----------------------------------------------------------------------------
102 // Function : N_NLS_ConstraintBT::~N_NLS_ConstraintBT
103 // Purpose : Destructor
104 // Special Notes :
105 // Scope : public
106 // Creator : Scott A. Hutchinson, SNL, Computational Sciences
107 // Creation Date : 01/26/01
108 //-----------------------------------------------------------------------------
110 {
115 }
116 
117 //-----------------------------------------------------------------------------
118 // Function : N_NLS_ConstraintBT::operator=
119 // Purpose : Assignment operator
120 // Special Notes :
121 // Scope : public
122 // Creator : Scott A. Hutchinson, SNL, Computational Sciences
123 // Creation Date : 01/26/01
124 //-----------------------------------------------------------------------------
126  const N_NLS_ConstraintBT & right)
127 {
128  return *this;
129 }
130 
131 //-----------------------------------------------------------------------------
132 // Function : N_NLS_ConstraintBT::operator==
133 // Purpose : Equal operator
134 // Special Notes :
135 // Scope : private
136 // Creator : Scott A. Hutchinson, SNL, Computational Sciences
137 // Creation Date : 01/26/01
138 //-----------------------------------------------------------------------------
140 
141 {
142  return 0;
143 }
144 
145 //-----------------------------------------------------------------------------
146 // Function : N_NLS_ConstraintBT::operator!=
147 // Purpose : Not-Equal operator
148 // Special Notes :
149 // Scope : private
150 // Creator : Scott A. Hutchinson, SNL, Computational Sciences
151 // Creation Date : 01/26/01
152 //-----------------------------------------------------------------------------
154 
155 {
156  return 0;
157 }
158 
159 //-----------------------------------------------------------------------------
160 // Function : N_NLS_ConstraintBT::initializeAll
161 // Purpose : Not-Equal operator
162 // Special Notes :
163 // Scope : private
164 // Creator : Eric R. Keiter, SNL, Computational Sciences
165 // Creation Date : 10/29/02
166 //-----------------------------------------------------------------------------
168  (N_LAS_System * lasSysPtr, const N_NLS_NLParams & nlParams)
169 {
170  // create and initialize constraint backtracking vectors:
171  constraintMinVector_ = lasSysPtr->builder().createVector();
172  constraintMaxVector_ = lasSysPtr->builder().createVector();
173 
174  constraintMinVector_->putScalar(nlParams.getGlobalBTMin());
175  constraintMaxVector_->putScalar(nlParams.getGlobalBTMax());
176 
177  constraintChangeVector_ = lasSysPtr->builder().createVector();
178 
179  constraintChangeVector_->putScalar (nlParams.getGlobalBTChange());
180 
181  constraintTempVector_ = lasSysPtr->builder().createVector();
182 
183  constraintTempVector_->putScalar(0.0);
184 
185  return true;
186 }
187 
188 //-----------------------------------------------------------------------------
189 // Function : N_NLS_ConstraintBT::updateThetaBoundNeg
190 // Purpose : Updates the minimum bound value for the backtracking
191 // algorithm.
192 // Special Notes : This is implemented according to a internal
193 // communication with John Shadid (SNL) on their MPSalsa
194 // constraint backtracking implementation.
195 // Scope : public
196 // Creator : Scott A. Hutchinson, SNL, Computational Sciences
197 // Creation Date : 01/26/01
198 //-----------------------------------------------------------------------------
199 void N_NLS_ConstraintBT::updateThetaBoundNeg(const N_LAS_Vector * oldSoln,
200  const N_LAS_Vector * solnUpdate)
201 
202 {
203  N_LAS_Vector * solnPtr;
204  N_LAS_Vector * solnUpdatePtr;
205 
206  // Initialize
207  solnPtr = const_cast<N_LAS_Vector *> (oldSoln);
208  solnUpdatePtr = const_cast<N_LAS_Vector *> (solnUpdate);
209 
210  // First, form a vector of constraints...
211  for (int i = 0; i < solnPtr->localLength(); ++i)
212  {
213  if ((*(solnUpdatePtr))[i] < 0.0)
214  (*(constraintTempVector_))[i] = ((*(constraintMinVector_))[i] -
215  (*(solnPtr))[i]) / (*(solnUpdatePtr))[i];
216  else
217  (*(constraintTempVector_))[i] = N_UTL_MachineDependentParams::DoubleMax();
218 
219  if (Xyce::DEBUG_NONLINEAR)
220  Xyce::dout() << "N_NLS_ConstraintBT::updateThetaBoundNeg: min: " << (*(constraintMinVector_))[i] << "\n"
221  << "N_NLS_ConstraintBT::updateThetaBoundNeg: soln: " << (*(solnPtr))[i] << "\n"
222  << "N_NLS_ConstraintBT::updateThetaBoundNeg: solnUpdate: " << (*(solnUpdatePtr))[i] << "\n"
223  << "N_NLS_ConstraintBT::updateThetaBoundNeg: constraint: " << (*(constraintTempVector_))[i];
224  }
225 
226  // Find minimum
228 
229  if (Xyce::DEBUG_NONLINEAR)
230  Xyce::dout() << "N_NLS_ConstraintBT::updateThetaBoundNeg: thetaBoundNeg_: " << thetaBoundNeg_;
231 }
232 
233 //-----------------------------------------------------------------------------
234 // Function : N_NLS_ConstraintBT::updateThetaBoundPos
235 // Purpose : Updates the maximum bound value for the backtracking
236 // algorithm.
237 // Special Notes : This is implemented according to a internal
238 // communication with John Shadid (SNL) on their MPSalsa
239 // constraint backtracking implementation.
240 // Scope : public
241 // Creator : Scott A. Hutchinson, SNL, Computational Sciences
242 // Creation Date : 01/26/01
243 //-----------------------------------------------------------------------------
244 void N_NLS_ConstraintBT::updateThetaBoundPos(const N_LAS_Vector * oldSoln,
245  const N_LAS_Vector * solnUpdate)
246 
247 {
248  N_LAS_Vector * solnPtr;
249  N_LAS_Vector * solnUpdatePtr;
250 
251  // Initialize
252  solnPtr = const_cast<N_LAS_Vector *> (oldSoln);
253  solnUpdatePtr = const_cast<N_LAS_Vector *> (solnUpdate);
254 
255  // First, form a vector of constraints...
256  for (int i = 0; i < solnPtr->localLength(); ++i)
257  {
258  if ((*(solnUpdatePtr))[i] > 0.0)
259  (*(constraintTempVector_))[i] = ((*(constraintMaxVector_))[i] -
260  (*(solnPtr))[i]) / (*(solnUpdatePtr))[i];
261  else
262  (*(constraintTempVector_))[i] = N_UTL_MachineDependentParams::DoubleMax();
263 
264  if (Xyce::DEBUG_NONLINEAR)
265  Xyce::dout() << "N_NLS_ConstraintBT::updateThetaBoundPos: max: " << (*(constraintMaxVector_))[i] << "\n"
266  << "N_NLS_ConstraintBT::updateThetaBoundPos: soln: " << (*(solnPtr))[i] << "\n"
267  << "N_NLS_ConstraintBT::updateThetaBoundPos: solnUpdate: " << (*(solnUpdatePtr))[i] << "\n"
268  << "N_NLS_ConstraintBT::updateThetaBoundPos: constraint: " << (*(constraintTempVector_))[i];
269  }
270 
271  // Find minimum
273 
274  if (Xyce::DEBUG_NONLINEAR)
275  Xyce::dout() << "N_NLS_ConstraintBT::updateThetaBoundPos: thetaBoundPos_: " << thetaBoundPos_;
276 }
277 
278 //-----------------------------------------------------------------------------
279 // Function : N_NLS_ConstraintBT::updateThetaChange
280 // Purpose : Updates the percentage-change bound value for the
281 // backtracking algorithm.
282 // Special Notes : This is implemented according to a internal
283 // communication with John Shadid (SNL) on their MPSalsa
284 // constraint backtracking implementation.
285 // This function returns:
286 //
287 // theta_u = min {gamma_i | oldSoln_i | / | solnUpdate_i | }
288 // i
289 //
290 // Scope : public
291 // Creator : Scott A. Hutchinson, SNL, Computational Sciences
292 // Creation Date : 01/26/01
293 //-----------------------------------------------------------------------------
294 void N_NLS_ConstraintBT::updateThetaChange(const N_LAS_Vector * oldSoln,
295  const N_LAS_Vector * solnUpdate)
296 
297 {
298  N_LAS_Vector * solnPtr;
299  N_LAS_Vector * solnUpdatePtr;
300 
301  // Initialize
302  solnPtr = const_cast<N_LAS_Vector *> (oldSoln);
303  solnUpdatePtr = const_cast<N_LAS_Vector *> (solnUpdate);
304 
305  // First, form a vector of constraints...
306  for (int i = 0; i < solnPtr->localLength(); ++i)
307  {
308  if (fabs((*(solnUpdatePtr))[i]) > N_UTL_MachineDependentParams::DoubleMin() &&
309  fabs((*(solnPtr))[i]) > 0.0)
311  fabs((*(solnPtr))[i]) / fabs((*(solnUpdatePtr))[i]);
312 
313  else
314  (*(constraintTempVector_))[i] = N_UTL_MachineDependentParams::DoubleMax();
315 
316  if (Xyce::DEBUG_NONLINEAR)
317  Xyce::dout() << "N_NLS_ConstraintBT::updateThetaChange: change: " << (*(constraintChangeVector_))[i] << "\n"
318  << "N_NLS_ConstraintBT::updateThetaChange: constraint: " << (*(constraintTempVector_))[i];
319  }
320 
321  // Find minimum
323 
324  if (Xyce::DEBUG_NONLINEAR)
325  Xyce::dout() << "N_NLS_ConstraintBT::updateThetaChange: thetaChange_: " << thetaChange_;
326 }
327