Xyce  6.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
N_NLS_NOX_AugmentLinSys_IC.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_IC.C,v $
27 //
28 // Purpose : Algorithm for augmenting the Jacobian for .IC
29 // operating point solves.
30 //
31 // Special Notes :
32 //
33 // Creator : Eric R. Keiter, SNL, Electrical and Microsystems Modeling
34 //
35 // Creation Date : 09/15/07
36 //
37 // Revision Information:
38 // ---------------------
39 //
40 // Revision Number: $Revision: 1.16 $
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_fwd.h>
53 #include <N_UTL_Misc.h>
54 
55 // ---------- Xyce Includes ----------
56 
57 #include "N_LAS_Vector.h"
58 #include "N_LAS_Matrix.h"
59 #include "Epetra_MapColoring.h"
60 #include "N_ERH_ErrorMgr.h"
62 
63 //-----------------------------------------------------------------------------
64 // Function : N_NLS_NOX::AugmentLinSysIC::AugmentLinSysIC
65 // Purpose : constructor
66 // Special Notes :
67 // Scope : public
68 // Creator : Eric Keiter, SNL, Parallel Computational Sciences
69 // Creation Date : 9/15/07
70 //-----------------------------------------------------------------------------
72  (Xyce::NodeNamePairMap & op_in,
73  const Teuchos::RefCountPtr <Epetra_MapColoring>& color_map,
74  N_LAS_Vector* cloneVector
75  )
76  : op_ (op_in),
77  tmp_vector_ptr_(0)
78 {
79  color_map_ = color_map;
80  tmp_vector_ptr_ = new N_LAS_Vector(*cloneVector);
81 }
82 
83 //-----------------------------------------------------------------------------
84 // Function : N_NLS_NOX::AugmentLinSysIC::~AugmentLinSysIC
85 // Purpose : destructor
86 // Special Notes :
87 // Scope : public
88 // Creator : Eric Keiter, SNL, Parallel Computational Sciences
89 // Creation Date : 9/15/07
90 //-----------------------------------------------------------------------------
92 {
93  delete tmp_vector_ptr_;
94 }
95 
96 //-----------------------------------------------------------------------------
97 // Function : N_NLS_NOX::AugmentLinSysIC::augmentResidual
98 // Purpose :
99 // Special Notes :
100 // Scope : public
101 // Creator : Eric Keiter, SNL, Parallel Computational Sciences
102 // Creation Date : 9/15/07
103 //-----------------------------------------------------------------------------
105  (const N_LAS_Vector * solution, N_LAS_Vector * residual_vector)
106 {
107 #ifdef Xyce_DEBUG_IC
108  cout << "Inside AugmentLinSysIC::augmentResidual:" << endl;
109 #endif
110 
111  Xyce::NodeNamePairMap::iterator op_i = op_.begin();
112  Xyce::NodeNamePairMap::iterator op_end = op_.end();
113  for ( ; op_i != op_end ; ++op_i)
114  {
115  int row = (*op_i).second.first;
116  int global_row(row);
117 
118  if ( (*color_map_)[row] == 0)
119  {
120  (*residual_vector)[row] = 0.0;
121  }
122  }
123  return;
124 }
125 
126 //-----------------------------------------------------------------------------
127 // Function : N_NLS_NOX::AugmentLinSysIC::augmentJacobian
128 // Purpose :
129 // Special Notes :
130 // Scope : public
131 // Creator : Eric Keiter, SNL, Parallel Computational Sciences
132 // Creation Date : 9/15/07
133 //-----------------------------------------------------------------------------
134 void N_NLS_NOX::AugmentLinSysIC::augmentJacobian(N_LAS_Matrix * jacobian)
135 {
136 #ifdef Xyce_DEBUG_IC
137  cout << "Inside AugmentLinSysIC::augmentJacobian:" << endl;
138 #endif
139 
140  std::vector<int> col;
141  std::vector<double> val;
142  Xyce::NodeNamePairMap::iterator op_i = op_.begin();
143  Xyce::NodeNamePairMap::iterator op_end = op_.end();
144 
145  jacobian->getDiagonal(*tmp_vector_ptr_);
146 
147  for ( ; op_i != op_end ; ++op_i)
148  {
149  int row = (*op_i).second.first;
150  int rowLen(0);
151  int numEntries(0);
152 
153  if ( (*color_map_)[row] == 0)
154  {
155  rowLen = jacobian->getLocalRowLength(row);
156 
157  col.resize(rowLen,0);
158  val.resize(rowLen,0.0);
159  jacobian->getLocalRowCopy(row, rowLen, numEntries, &val[0], &col[0]);
160 
161  // zero out the entire row.
162  for (int i=0;i<val.size();++i) val[i] = 0.0;
163 
164  jacobian->putLocalRow(row, rowLen, &val[0], &col[0]);
165 
166  // set the diagonal to 1.0.
167  (*tmp_vector_ptr_)[row] = 1.0;
168  }
169  }
170 
171  jacobian->replaceDiagonal(*tmp_vector_ptr_);
172 
173  return;
174 }
175