Xyce  6.1
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-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 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.16 $
41 //
42 // Revision Date : $Date: 2015/04/08 19:18:29 $
43 //
44 // Current Owner : $Author: tvrusso $
45 //-------------------------------------------------------------------------
46 
47 #include <Xyce_config.h>
48 
49 
50 // ---------- Standard Includes ----------
51 
52 
53 // ---------- Xyce Includes ----------
54 
55 #include "N_LAS_Vector.h"
56 #include "N_LAS_Matrix.h"
57 #include "Epetra_MapColoring.h"
58 #include "N_ERH_ErrorMgr.h"
60 
61 namespace Xyce {
62 namespace Nonlinear {
63 namespace N_NLS_NOX {
64 
65 //-----------------------------------------------------------------------------
66 // Function : AugmentLinSysIC_Gmin::AugmentLinSysIC_Gmin
67 // Purpose : constructor
68 // Special Notes :
69 // Scope : public
70 // Creator : Eric Keiter, SNL
71 // Creation Date : 4/29/2012
72 //-----------------------------------------------------------------------------
74  IO::InitialConditionsData::NodeNamePairMap & op_in,
75  const Teuchos::RCP <Epetra_MapColoring>& ICcolor_map,
76  const std::vector<int>& vnodeGIDVec,
77  Linear::Vector* cloneVector,
78  double scaledEndValue,
79  double resCond) :
80  op_ (op_in),
81  vecptr1_(0),
82  vecptr2_(0),
83  node_list_type_(NLT_VoltageNodes),
84  vnodeGIDVec_(vnodeGIDVec),
85  scaled_end_value_(scaledEndValue),
86  residualConductance_(resCond)
87 {
88  ICcolor_map_ = ICcolor_map;
89  vecptr1_ = new Linear::Vector(*cloneVector);
90  vecptr2_ = new Linear::Vector(*cloneVector);
91 }
92 
93 //-----------------------------------------------------------------------------
94 // Function : AugmentLinSysIC_Gmin::AugmentLinSysIC_Gmin
95 // Purpose : constructor
96 // Special Notes :
97 // Scope : public
98 // Creator : Eric Keiter, SNL
99 // Creation Date : 4/29/2012
100 //-----------------------------------------------------------------------------
102  IO::InitialConditionsData::NodeNamePairMap & op_in,
103  const Teuchos::RCP <Epetra_MapColoring>& ICcolor_map,
104  const Teuchos::RCP <Epetra_MapColoring>& GMINcolor_map,
105  Linear::Vector* cloneVector,
106  double scaledEndValue,
107  double resCond) :
108  op_ (op_in),
109  vecptr1_(0),
110  vecptr2_(0),
111  node_list_type_(NLT_VoltageNodes),
112  scaled_end_value_(scaledEndValue),
113  residualConductance_(resCond)
114 {
115  ICcolor_map_ = ICcolor_map;
116  GMINcolor_map_ = GMINcolor_map;
117  vecptr1_ = new Linear::Vector(*cloneVector);
118  vecptr2_ = new Linear::Vector(*cloneVector);
119 }
120 
121 //-----------------------------------------------------------------------------
122 // Function : AugmentLinSysIC_Gmin::~AugmentLinSysIC_Gmin
123 // Purpose : destructor
124 // Special Notes :
125 // Scope : public
126 // Creator : Eric Keiter, SNL
127 // Creation Date : 4/29/2012
128 //-----------------------------------------------------------------------------
130 {
131  delete vecptr1_;
132  delete vecptr2_;
133 }
134 
135 //-----------------------------------------------------------------------------
136 // Function : IC_Gmin::setProgressVariable
137 // Purpose :
138 // Special Notes :
139 // Scope : public
140 // Creator : Roger Pawlowski, SNL 9233
141 // Creation Date :
142 //-----------------------------------------------------------------------------
144 {
145  // Direct continuation of conductance (con param goes from 1.0e4 -> 0.0
146  //conductance_ = conductance;
147 
148  // Exponential Continuation (con param goes from +4 -> -log10(endValue))
149  conductance_ = pow(10.0, conductance) - pow(10.0, scaled_end_value_) + residualConductance_;
150 }
151 
152 //-----------------------------------------------------------------------------
153 // Function : AugmentLinSysIC_Gmin::augmentResidual
154 // Purpose :
155 // Special Notes :
156 // Scope : public
157 // Creator : Eric Keiter, SNL
158 // Creation Date : 4/29/2012
159 //-----------------------------------------------------------------------------
161  (const Linear::Vector * solution, Linear::Vector * residual_vector)
162 {
163 #ifdef Xyce_DEBUG_IC_Gmin
164  dout() << "Inside AugmentLinSysIC_Gmin::augmentResidual:" << std::endl;
165 #endif
166 
167  // GMIN portion
168  if (node_list_type_ == NLT_VoltageNodes)
169  {
170  std::vector<int>::const_iterator i = vnodeGIDVec_.begin();
171  std::vector<int>::const_iterator stop = vnodeGIDVec_.end();
172  for ( ; i < stop; ++i)
173  {
174  double value = conductance_ *
175  (const_cast<Linear::Vector*>(solution))->getElementByGlobalIndex(*i);
176 
177  residual_vector->sumElementByGlobalIndex(*i, value);
178  }
179  }
180  else
181  {
182  for (std::size_t i = 0; i < vecptr1_->localLength(); ++i)
183  {
184  if ( (*GMINcolor_map_)[i] == 0)
185  {
186  (*residual_vector)[i] += conductance_ * (const_cast<Linear::Vector&>(*solution))[i];
187  }
188  }
189  }
190 
191  // IC portion
192  IO::InitialConditionsData::NodeNamePairMap::iterator op_i = op_.begin();
193  IO::InitialConditionsData::NodeNamePairMap::iterator op_end = op_.end();
194  for ( ; op_i != op_end ; ++op_i)
195  {
196  int row = (*op_i).second.first;
197  int global_row(row);
198 
199  if ( (*ICcolor_map_)[row] == 0)
200  {
201  (*residual_vector)[row] = 0.0;
202  }
203  }
204 
205 
206 
207  return;
208 }
209 
210 //-----------------------------------------------------------------------------
211 // Function : AugmentLinSysIC_Gmin::augmentJacobian
212 // Purpose :
213 // Special Notes :
214 // Scope : public
215 // Creator : Eric Keiter, SNL
216 // Creation Date : 4/29/2012
217 //-----------------------------------------------------------------------------
218 void AugmentLinSysIC_Gmin::augmentJacobian(Linear::Matrix * jacobian)
219 {
220 #ifdef Xyce_DEBUG_IC_Gmin
221  dout() << "Inside AugmentLinSysIC_Gmin::augmentJacobian:" << std::endl;
222 #endif
223 
224  // GMIN portion
225  jacobian->getDiagonal(*vecptr1_);
227  {
228  std::vector<int>::const_iterator i = vnodeGIDVec_.begin();
229  std::vector<int>::const_iterator stop = vnodeGIDVec_.end();
230  for ( ; i < stop; ++i)
231  {
232  vecptr1_->sumElementByGlobalIndex(*i, conductance_);
233  }
234  }
235  else
236  {
237  for (std::size_t i = 0; i < vecptr1_->localLength(); ++i)
238  {
239  if ( (*GMINcolor_map_)[i] == 0)
240  {
241  (*vecptr1_)[i] += conductance_;
242  }
243  }
244  }
245  jacobian->replaceDiagonal(*vecptr1_);
246 
247  // IC portion
248  std::vector<int> col;
249  std::vector<double> val;
250  IO::InitialConditionsData::NodeNamePairMap::iterator op_i = op_.begin();
251  IO::InitialConditionsData::NodeNamePairMap::iterator op_end = op_.end();
252 
253  jacobian->getDiagonal(*vecptr2_);
254 
255  for ( ; op_i != op_end ; ++op_i)
256  {
257  int row = (*op_i).second.first;
258  int rowLen(0);
259  int numEntries(0);
260 
261  if ( (*ICcolor_map_)[row] == 0)
262  {
263  rowLen = jacobian->getLocalRowLength(row);
264 
265  col.resize(rowLen,0);
266  val.resize(rowLen,0.0);
267  jacobian->getLocalRowCopy(row, rowLen, numEntries, &val[0], &col[0]);
268 
269  // zero out the entire row.
270  for (int i=0;i<val.size();++i) val[i] = 0.0;
271 
272  jacobian->putLocalRow(row, rowLen, &val[0], &col[0]);
273 
274  // set the diagonal to 1.0.
275  (*vecptr2_)[row] = 1.0;
276  }
277  }
278 
279  jacobian->replaceDiagonal(*vecptr2_);
280 
281  return;
282 }
283 
284 }}}
Xyce::IO::InitialConditionsData::NodeNamePairMap & op_
map of specified variables
Pure virtual class to augment a linear system.
void augmentResidual(const Xyce::Linear::Vector *solution, Xyce::Linear::Vector *residual_vector)
Augments the Residual.
Xyce::Linear::Vector * vecptr1_
Temporary vectors used to store diagonal.
const T & value(const ParameterBase &entity, const Descriptor &descriptor)
Returns the value of the parameter for the entity.
Definition: N_DEV_Pars.h:1224
double residualConductance_
residual value of the conductance. Should almost always be zero
const std::vector< int > vnodeGIDVec_
List of voltage node GIDs.
AugmentLinSysIC_Gmin(Xyce::IO::InitialConditionsData::NodeNamePairMap &op_in, const Teuchos::RCP< Epetra_MapColoring > &ICcolor_map, const std::vector< int > &vnodeGIDVec, Xyce::Linear::Vector *cloneVector, double scaledEndValue, double resCond)
Ctor.
Teuchos::RCP< Epetra_MapColoring > ICcolor_map_
Color 0 are the voltage unknowns.
void augmentJacobian(Xyce::Linear::Matrix *jacobian)
Augments the Jacobian.
void setProgressVariable(double dummy)
Set the progress variable (time step size for pseudo transient).