Xyce  6.1
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-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 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.22.2.1 $
41 //
42 // Revision Date : $Date: 2015/04/02 18:20:17 $
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 
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 namespace Xyce {
63 namespace Nonlinear {
64 namespace N_NLS_NOX {
65 
66 //-----------------------------------------------------------------------------
67 // Function : AugmentLinSysIC::AugmentLinSysIC
68 // Purpose : constructor
69 // Special Notes :
70 // Scope : public
71 // Creator : Eric Keiter, SNL, Parallel Computational Sciences
72 // Creation Date : 9/15/07
73 //-----------------------------------------------------------------------------
75  (IO::InitialConditionsData::NodeNamePairMap & op_in,
76  const Teuchos::RCP <Epetra_MapColoring>& color_map,
77  Linear::Vector* cloneVector
78  )
79  : op_ (op_in),
80  tmp_vector_ptr_(0)
81 {
82  color_map_ = color_map;
83  tmp_vector_ptr_ = new Linear::Vector(*cloneVector);
84 }
85 
86 //-----------------------------------------------------------------------------
87 // Function : AugmentLinSysIC::~AugmentLinSysIC
88 // Purpose : destructor
89 // Special Notes :
90 // Scope : public
91 // Creator : Eric Keiter, SNL, Parallel Computational Sciences
92 // Creation Date : 9/15/07
93 //-----------------------------------------------------------------------------
95 {
96  delete tmp_vector_ptr_;
97 }
98 
99 //-----------------------------------------------------------------------------
100 // Function : AugmentLinSysIC::augmentResidual
101 // Purpose :
102 // Special Notes :
103 // Scope : public
104 // Creator : Eric Keiter, SNL, Parallel Computational Sciences
105 // Creation Date : 9/15/07
106 //-----------------------------------------------------------------------------
108  (const Linear::Vector * solution, Linear::Vector * residual_vector)
109 {
110 #ifdef Xyce_DEBUG_IC
111  dout() << "Inside AugmentLinSysIC::augmentResidual:" << std::endl;
112 #endif
113 
114  IO::InitialConditionsData::NodeNamePairMap::iterator op_i = op_.begin();
115  IO::InitialConditionsData::NodeNamePairMap::iterator op_end = op_.end();
116  for ( ; op_i != op_end ; ++op_i)
117  {
118  int row = (*op_i).second.first;
119  int global_row(row);
120 
121  if ( (*color_map_)[row] == 0)
122  {
123  (*residual_vector)[row] = 0.0;
124  }
125  }
126  return;
127 }
128 
129 //-----------------------------------------------------------------------------
130 // Function : AugmentLinSysIC::augmentJacobian
131 // Purpose :
132 // Special Notes :
133 // Scope : public
134 // Creator : Eric Keiter, SNL, Parallel Computational Sciences
135 // Creation Date : 9/15/07
136 //-----------------------------------------------------------------------------
137 void AugmentLinSysIC::augmentJacobian(Linear::Matrix * jacobian)
138 {
139 #ifdef Xyce_DEBUG_IC
140  dout() << "Inside AugmentLinSysIC::augmentJacobian:" << std::endl;
141 #endif
142 
143  std::vector<int> col;
144  std::vector<double> val;
145  IO::InitialConditionsData::NodeNamePairMap::iterator op_i = op_.begin();
146  IO::InitialConditionsData::NodeNamePairMap::iterator op_end = op_.end();
147 
148  jacobian->getDiagonal(*tmp_vector_ptr_);
149 
150  for ( ; op_i != op_end ; ++op_i)
151  {
152  int row = (*op_i).second.first;
153  int rowLen(0);
154  int numEntries(0);
155 
156  if ( (*color_map_)[row] == 0)
157  {
158  rowLen = jacobian->getLocalRowLength(row);
159 
160  col.resize(rowLen,0);
161  val.resize(rowLen,0.0);
162  jacobian->getLocalRowCopy(row, rowLen, numEntries, &val[0], &col[0]);
163 
164  // zero out the entire row.
165  for (int i=0;i<val.size();++i) val[i] = 0.0;
166 
167  jacobian->putLocalRow(row, rowLen, &val[0], &col[0]);
168 
169  // set the diagonal to 1.0.
170  (*tmp_vector_ptr_)[row] = 1.0;
171  }
172  }
173 
174  jacobian->replaceDiagonal(*tmp_vector_ptr_);
175 
176  return;
177 }
178 
179 }}}
void augmentResidual(const Xyce::Linear::Vector *solution, Xyce::Linear::Vector *residual_vector)
Augments the Residual.
Xyce::IO::InitialConditionsData::NodeNamePairMap & op_
map of specified variables
Pure virtual class to augment a linear system.
AugmentLinSysIC(Xyce::IO::InitialConditionsData::NodeNamePairMap &op_in, const Teuchos::RCP< Epetra_MapColoring > &color_map, Xyce::Linear::Vector *cloneVector)
Ctor.
Xyce::Linear::Vector * tmp_vector_ptr_
Temporary vector used to store diagonal.
Teuchos::RCP< Epetra_MapColoring > color_map_
Color 0 are the voltage unknowns.
void augmentJacobian(Xyce::Linear::Matrix *jacobian)
Augments the Jacobian.