Xyce  6.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
N_NLS_NOX_AugmentLinSys_IC_Gmin.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 PARTIC_GminULAR 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_NLS_NOX_AugmentLinSys_IC_Gmin.C,v $
27 //
28 // Purpose : Algorithm for augmenting the Jacobian for .IC_Gmin
29 // operating point solves.
30 //
31 // Special Notes :
32 //
33 // Creator : Eric R. Keiter, SNL, Electrical and Microsystems Modeling
34 //
35 // Creation Date : 4/29/2012
36 //
37 // Revision Information:
38 // ---------------------
39 //
40 // Revision Number: $Revision: 1.9 $
41 //
42 // Revision Date : $Date: 2014/02/24 23:49:25 $
43 //
44 // Current Owner : $Author: tvrusso $
45 //-------------------------------------------------------------------------
46 
47 #include <Xyce_config.h>
48 
49 
50 // ---------- Standard Includes ----------
51 
52 #include <N_UTL_Misc.h>
53 
54 // ---------- Xyce Includes ----------
55 
56 #include "N_LAS_Vector.h"
57 #include "N_LAS_Matrix.h"
58 #include "Epetra_MapColoring.h"
59 #include "N_ERH_ErrorMgr.h"
61 
62 //-----------------------------------------------------------------------------
63 // Function : N_NLS_NOX::AugmentLinSysIC_Gmin::AugmentLinSysIC_Gmin
64 // Purpose : constructor
65 // Special Notes :
66 // Scope : public
67 // Creator : Eric Keiter, SNL
68 // Creation Date : 4/29/2012
69 //-----------------------------------------------------------------------------
71  Xyce::NodeNamePairMap & op_in,
72  const Teuchos::RefCountPtr <Epetra_MapColoring>& ICcolor_map,
73  const std::vector<int>& vnodeGIDVec,
74  N_LAS_Vector* cloneVector,
75  double scaledEndValue,
76  double resCond) :
77  op_ (op_in),
78  vecptr1_(0),
79  vecptr2_(0),
80  node_list_type_(NLT_VoltageNodes),
81  vnodeGIDVec_(vnodeGIDVec),
82  scaled_end_value_(scaledEndValue),
83  residualConductance_(resCond)
84 {
85  ICcolor_map_ = ICcolor_map;
86  vecptr1_ = new N_LAS_Vector(*cloneVector);
87  vecptr2_ = new N_LAS_Vector(*cloneVector);
88 }
89 
90 //-----------------------------------------------------------------------------
91 // Function : N_NLS_NOX::AugmentLinSysIC_Gmin::AugmentLinSysIC_Gmin
92 // Purpose : constructor
93 // Special Notes :
94 // Scope : public
95 // Creator : Eric Keiter, SNL
96 // Creation Date : 4/29/2012
97 //-----------------------------------------------------------------------------
99  Xyce::NodeNamePairMap & op_in,
100  const Teuchos::RefCountPtr <Epetra_MapColoring>& ICcolor_map,
101  const Teuchos::RefCountPtr <Epetra_MapColoring>& GMINcolor_map,
102  N_LAS_Vector* cloneVector,
103  double scaledEndValue,
104  double resCond) :
105  op_ (op_in),
106  vecptr1_(0),
107  vecptr2_(0),
108  node_list_type_(NLT_VoltageNodes),
109  scaled_end_value_(scaledEndValue),
110  residualConductance_(resCond)
111 {
112  ICcolor_map_ = ICcolor_map;
113  GMINcolor_map_ = GMINcolor_map;
114  vecptr1_ = new N_LAS_Vector(*cloneVector);
115  vecptr2_ = new N_LAS_Vector(*cloneVector);
116 }
117 
118 //-----------------------------------------------------------------------------
119 // Function : N_NLS_NOX::AugmentLinSysIC_Gmin::~AugmentLinSysIC_Gmin
120 // Purpose : destructor
121 // Special Notes :
122 // Scope : public
123 // Creator : Eric Keiter, SNL
124 // Creation Date : 4/29/2012
125 //-----------------------------------------------------------------------------
127 {
128  delete vecptr1_;
129  delete vecptr2_;
130 }
131 
132 //-----------------------------------------------------------------------------
133 // Function : N_NLS_NOX::IC_Gmin::setProgressVariable
134 // Purpose :
135 // Special Notes :
136 // Scope : public
137 // Creator : Roger Pawlowski, SNL 9233
138 // Creation Date :
139 //-----------------------------------------------------------------------------
141 {
142  // Direct continuation of conductance (con param goes from 1.0e4 -> 0.0
143  //conductance_ = conductance;
144 
145  // Exponential Continuation (con param goes from +4 -> -log10(endValue))
146  conductance_ = pow(10.0, conductance) - pow(10.0, scaled_end_value_) + residualConductance_;
147 }
148 
149 //-----------------------------------------------------------------------------
150 // Function : N_NLS_NOX::AugmentLinSysIC_Gmin::augmentResidual
151 // Purpose :
152 // Special Notes :
153 // Scope : public
154 // Creator : Eric Keiter, SNL
155 // Creation Date : 4/29/2012
156 //-----------------------------------------------------------------------------
158  (const N_LAS_Vector * solution, N_LAS_Vector * residual_vector)
159 {
160 #ifdef Xyce_DEBUG_IC_Gmin
161  cout << "Inside AugmentLinSysIC_Gmin::augmentResidual:" << endl;
162 #endif
163 
164  // GMIN portion
165  if (node_list_type_ == NLT_VoltageNodes)
166  {
167  std::vector<int>::const_iterator i = vnodeGIDVec_.begin();
168  std::vector<int>::const_iterator stop = vnodeGIDVec_.end();
169  for ( ; i < stop; ++i)
170  {
171  double value = conductance_ *
172  (const_cast<N_LAS_Vector*>(solution))->getElementByGlobalIndex(*i);
173 
174  residual_vector->sumElementByGlobalIndex(*i, value);
175  }
176  }
177  else
178  {
179  for (std::size_t i = 0; i < vecptr1_->localLength(); ++i)
180  {
181  if ( (*GMINcolor_map_)[i] == 0)
182  {
183  (*residual_vector)[i] += conductance_ * (const_cast<N_LAS_Vector&>(*solution))[i];
184  }
185  }
186  }
187 
188  // IC portion
189  Xyce::NodeNamePairMap::iterator op_i = op_.begin();
190  Xyce::NodeNamePairMap::iterator op_end = op_.end();
191  for ( ; op_i != op_end ; ++op_i)
192  {
193  int row = (*op_i).second.first;
194  int global_row(row);
195 
196  if ( (*ICcolor_map_)[row] == 0)
197  {
198  (*residual_vector)[row] = 0.0;
199  }
200  }
201 
202 
203 
204  return;
205 }
206 
207 //-----------------------------------------------------------------------------
208 // Function : N_NLS_NOX::AugmentLinSysIC_Gmin::augmentJacobian
209 // Purpose :
210 // Special Notes :
211 // Scope : public
212 // Creator : Eric Keiter, SNL
213 // Creation Date : 4/29/2012
214 //-----------------------------------------------------------------------------
216 {
217 #ifdef Xyce_DEBUG_IC_Gmin
218  cout << "Inside AugmentLinSysIC_Gmin::augmentJacobian:" << endl;
219 #endif
220 
221  // GMIN portion
222  jacobian->getDiagonal(*vecptr1_);
223  if (node_list_type_ == NLT_VoltageNodes)
224  {
225  std::vector<int>::const_iterator i = vnodeGIDVec_.begin();
226  std::vector<int>::const_iterator stop = vnodeGIDVec_.end();
227  for ( ; i < stop; ++i)
228  {
229  vecptr1_->sumElementByGlobalIndex(*i, conductance_);
230  }
231  }
232  else
233  {
234  for (std::size_t i = 0; i < vecptr1_->localLength(); ++i)
235  {
236  if ( (*GMINcolor_map_)[i] == 0)
237  {
238  (*vecptr1_)[i] += conductance_;
239  }
240  }
241  }
242  jacobian->replaceDiagonal(*vecptr1_);
243 
244  // IC portion
245  std::vector<int> col;
246  std::vector<double> val;
247  Xyce::NodeNamePairMap::iterator op_i = op_.begin();
248  Xyce::NodeNamePairMap::iterator op_end = op_.end();
249 
250  jacobian->getDiagonal(*vecptr2_);
251 
252  for ( ; op_i != op_end ; ++op_i)
253  {
254  int row = (*op_i).second.first;
255  int rowLen(0);
256  int numEntries(0);
257 
258  if ( (*ICcolor_map_)[row] == 0)
259  {
260  rowLen = jacobian->getLocalRowLength(row);
261 
262  col.resize(rowLen,0);
263  val.resize(rowLen,0.0);
264  jacobian->getLocalRowCopy(row, rowLen, numEntries, &val[0], &col[0]);
265 
266  // zero out the entire row.
267  for (int i=0;i<val.size();++i) val[i] = 0.0;
268 
269  jacobian->putLocalRow(row, rowLen, &val[0], &col[0]);
270 
271  // set the diagonal to 1.0.
272  (*vecptr2_)[row] = 1.0;
273  }
274  }
275 
276  jacobian->replaceDiagonal(*vecptr2_);
277 
278  return;
279 }
280