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