Xyce  6.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
N_NLS_NOX_AugmentLinSys_GStepping.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 : $RCSfile: N_NLS_NOX_AugmentLinSys_GStepping.C,v $
27 //
28 // Purpose : Algorithm for augmenting the Jacobian for pseudo
29 // transient solves using vnode conductance.
30 //
31 // Special Notes :
32 //
33 // Creator : Roger Pawlowski, SNL 9233
34 //
35 // Creation Date : 03/07/06
36 //
37 // Revision Information:
38 // ---------------------
39 //
40 // Revision Number: $Revision: 1.11 $
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 // ---------- Xyce Includes ----------
53 
54 #include "N_LAS_Vector.h"
55 #include "N_LAS_Matrix.h"
56 #include "Epetra_MapColoring.h"
58 
59 
60 //-----------------------------------------------------------------------------
61 // Function : N_NLS_NOX::GStepping::GStepping
62 // Purpose : constructor
63 // Special Notes :
64 // Scope : public
65 // Creator : Roger Pawlowski, SNL 9233
66 // Creation Date :
67 //-----------------------------------------------------------------------------
69  const std::vector<int>& vnodeGIDVec,
70  N_LAS_Vector* cloneVector,
71  double scaledEndValue,
72  double resCond) :
73  node_list_type_(NLT_VoltageNodes),
74  vnodeGIDVec_(vnodeGIDVec),
75  tmp_vector_ptr_(0),
76  scaled_end_value_(scaledEndValue),
77  residualConductance_(resCond)
78 {
79  tmp_vector_ptr_ = new N_LAS_Vector(*cloneVector);
80 }
81 
82 //-----------------------------------------------------------------------------
83 // Function : N_NLS_NOX::GStepping::GStepping
84 // Purpose : constructor
85 // Special Notes :
86 // Scope : public
87 // Creator : Roger Pawlowski, SNL 9233
88 // Creation Date :
89 //-----------------------------------------------------------------------------
91 GStepping(const Teuchos::RefCountPtr<Epetra_MapColoring>& color_map,
92  N_LAS_Vector* cloneVector,
93  double scaledEndValue,
94  double resCond) :
95  node_list_type_(NLT_AllVoltageUnknowns),
96  scaled_end_value_(scaledEndValue),
97  residualConductance_(resCond)
98 {
99  color_map_ = color_map;
100  tmp_vector_ptr_ = new N_LAS_Vector(*cloneVector);
101 }
102 
103 //-----------------------------------------------------------------------------
104 // Function : N_NLS_NOX::GStepping::~GStepping
105 // Purpose : destructor
106 // Special Notes :
107 // Scope : public
108 // Creator : Roger Pawlowski, SNL 9233
109 // Creation Date :
110 //-----------------------------------------------------------------------------
112 {
113  delete tmp_vector_ptr_;
114 }
115 
116 
117 //-----------------------------------------------------------------------------
118 // Function : N_NLS_NOX::GStepping::setProgressVariable
119 // Purpose :
120 // Special Notes :
121 // Scope : public
122 // Creator : Roger Pawlowski, SNL 9233
123 // Creation Date :
124 //-----------------------------------------------------------------------------
126 {
127  // Direct continuation of conductance (con param goes from 1.0e4 -> 0.0
128  //conductance_ = conductance;
129 
130  // Exponential Continuation (con param goes from +4 -> -log10(endValue))
131  conductance_ = pow(10.0, conductance) - pow(10.0, scaled_end_value_) + residualConductance_;
132 }
133 
134 //-----------------------------------------------------------------------------
135 // Function : N_NLS_NOX::GStepping::augmentResidual
136 // Purpose :
137 // Special Notes :
138 // Scope : public
139 // Creator : Roger Pawlowski, SNL 9233
140 // Creation Date :
141 //-----------------------------------------------------------------------------
142 void N_NLS_NOX::GStepping::augmentResidual(const N_LAS_Vector * solution,
143  N_LAS_Vector * residualVector)
144 {
145  if (node_list_type_ == NLT_VoltageNodes)
146  {
147  std::vector<int>::const_iterator i = vnodeGIDVec_.begin();
148  std::vector<int>::const_iterator stop = vnodeGIDVec_.end();
149  for ( ; i < stop; ++i)
150  {
151  double value = conductance_ *
152  (const_cast<N_LAS_Vector*>(solution))->getElementByGlobalIndex(*i);
153 
154  residualVector->sumElementByGlobalIndex(*i, value);
155  }
156  }
157  else
158  {
159  for (std::size_t i = 0; i < tmp_vector_ptr_->localLength(); ++i)
160  {
161  if ( (*color_map_)[i] == 0)
162  {
163  (*residualVector)[i] += conductance_ * (const_cast<N_LAS_Vector&>(*solution))[i];
164  }
165  }
166  }
167 }
168 
169 
170 //-----------------------------------------------------------------------------
171 // Function : N_NLS_NOX::GStepping::augmentJacobian
172 // Purpose :
173 // Special Notes :
174 // Scope : public
175 // Creator : Roger Pawlowski, SNL 9233
176 // Creation Date :
177 //-----------------------------------------------------------------------------
178 void N_NLS_NOX::GStepping::augmentJacobian(N_LAS_Matrix * jacobian)
179 {
180  jacobian->getDiagonal(*tmp_vector_ptr_);
181 
182  if (node_list_type_ == NLT_VoltageNodes)
183  {
184  std::vector<int>::const_iterator i = vnodeGIDVec_.begin();
185  std::vector<int>::const_iterator stop = vnodeGIDVec_.end();
186  for ( ; i < stop; ++i)
187  {
188  tmp_vector_ptr_->sumElementByGlobalIndex(*i, conductance_);
189  }
190  }
191  else
192  {
193  for (std::size_t i = 0; i < tmp_vector_ptr_->localLength(); ++i)
194  {
195  if ( (*color_map_)[i] == 0)
196  {
197  (*tmp_vector_ptr_)[i] += conductance_;
198  }
199  }
200  }
201 
202  jacobian->replaceDiagonal(*tmp_vector_ptr_);
203 }
204