Xyce  6.1
N_LOA_NonlinearEquationLoader.h
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_LOA_NonlinearEquationLoader.h,v $
27 //
28 // Purpose : This file contains the interface class that sits between
29 // the nonlinear solver and (ultimately) the time integrator.
30 // For transient calculations only the time integrator knows
31 // what to sum into the Jacobian and Residual vector.
32 //
33 // Special Notes :
34 //
35 // Creator : Todd Coffey, SNL
36 //
37 // Creation Date : 07/29/08
38 //
39 // Revision Information:
40 // ---------------------
41 //
42 // Revision Number: $Revision: 1.56 $
43 //
44 // Revision Date : $Date: 2015/07/11 23:40:29 $
45 //
46 // Current Owner : $Author: erkeite $
47 //-----------------------------------------------------------------------------
48 
49 #ifndef Xyce_LOA_NonlinearEquationLoader_H
50 #define Xyce_LOA_NonlinearEquationLoader_H
51 
52 #include <N_DEV_fwd.h>
53 #include <N_LAS_fwd.h>
54 #include <N_LOA_fwd.h>
55 #include <N_PDS_fwd.h>
56 #include <N_TIA_fwd.h>
57 #include <N_UTL_fwd.h>
58 
59 #include <N_UTL_Stats.h>
60 
61 namespace Xyce {
62 namespace Loader {
63 
64 //-----------------------------------------------------------------------------
65 // Class : NonlinearEquationLoader
66 //
67 // Purpose : This class contains the interface class that sits between
68 // the nonlinear solver and (ultimately) the time integrator.
69 // For transient calculations only the time integrator knows
70 // what to sum into the Jacobian and Residual vector.
71 //
72 // Special Notes :
73 // Creator : Todd Coffey, SNL
74 // Creation Date : 07/29/08
75 //-----------------------------------------------------------------------------
77 {
78 public:
79 
80  // Default constructor
83  Loader & loader,
84  Device::DeviceMgr & device_manager,
86  bool daeStateDerivFlag);
87 
88  // Destructor
89  virtual ~NonlinearEquationLoader();
90 
91  // // Method which is called to load the nonlinear Jacobian matrix.
92  bool loadJacobian();
93 
94  // // Method which is called to apply the nonlinear Jacobian matrix.
95  bool applyJacobian (const Linear::Vector& input, Linear::Vector& result);
96 
97  // // Method which is called to load the nonlinear residual (RHS) vector.
98  bool loadRHS();
99 
100  bool loadSensitivityResiduals ();
102 
103  bool isLinearSystem() const;
104 
105  // two-level newton functions:
106  int enablePDEContinuation();
107  bool disablePDEContinuation ();
108 
109  void getNumInterfaceNodes (std::vector<int> & numINodes);
110  bool loadCouplingRHS (int iSubProblem, int iCouple, Linear::Vector * dfdvPtr);
111  bool calcCouplingTerms (int iSubProblem, int iCouple, const Linear::Vector * dxdvPtr);
112 
113  // Gets the nonlinear residual load time.
114  double getResidualTime() { return residualTime_; }
115 
116  // Gets the nonlinear Jacobian load time.
117  double getJacobianTime() { return jacobianTime_; }
118 
119  // Get block size from device options for block gainscale homotopy
120  int getHomotopyBlockSize() const;
121 
122  // Get convergence info from devices
123  bool allDevicesConverged(Parallel::Machine comm);
124 
125  // Get convergence info from inner-solves
126  bool innerDevicesConverged(Parallel::Machine comm);
127 
128  // Function for determining if an analytic sensitivity (df/dp, dq/dp, db/dp) is available.
129  bool analyticSensitivitiesAvailable (std::string & name);
130 
132  std::string & name,
133  std::vector<double> & dfdpVec,
134  std::vector<double> & dqdpVec,
135  std::vector<double> & dbdpVec,
136  std::vector<int> & FindicesVec,
137  std::vector<int> & QindicesVec,
138  std::vector<int> & BindicesVec) const;
139 
140  bool setParam(std::string & name, double val, bool overrideOriginal=false);
141 
142  bool getParamAndReduce(Parallel::Machine comm, const std::string & name, double & val) const;
143 
144  const Loader &getLoader() const {
145  return loader_;
146  }
147 
148  // Functions needed by the NEW (power node) 2-level algorithm:
149  void homotopyStepSuccess(const std::vector<std::string> & paramNames, const std::vector<double> & paramVals);
150  void homotopyStepFailure();
151 
152  // voltage limiter toggle functions
154  void setVoltageLimiterStatus(bool voltageLimterStatus);
155 
156 private:
157  Util::Timer * residualTimerPtr_;
158  Util::Timer * jacobianTimerPtr_;
165  Device::DeviceMgr & deviceManager_; ///< Device manager
166 };
167 
168 } // namespace Loader
169 } // namespace Xyce
170 
171 #endif
172 
bool loadCouplingRHS(int iSubProblem, int iCouple, Linear::Vector *dfdvPtr)
Pure virtual class to augment a linear system.
TimeIntg::WorkingIntegrationMethod & wim_
bool applyJacobian(const Linear::Vector &input, Linear::Vector &result)
bool getParamAndReduce(Parallel::Machine comm, const std::string &name, double &val) const
bool setParam(std::string &name, double val, bool overrideOriginal=false)
bool calcCouplingTerms(int iSubProblem, int iCouple, const Linear::Vector *dxdvPtr)
NonlinearEquationLoader(TimeIntg::DataStore &ds, Loader &loader, Device::DeviceMgr &device_manager, TimeIntg::WorkingIntegrationMethod &wim, bool daeStateDerivFlag)
void getAnalyticSensitivities(std::string &name, std::vector< double > &dfdpVec, std::vector< double > &dqdpVec, std::vector< double > &dbdpVec, std::vector< int > &FindicesVec, std::vector< int > &QindicesVec, std::vector< int > &BindicesVec) const
void homotopyStepSuccess(const std::vector< std::string > &paramNames, const std::vector< double > &paramVals)
void setVoltageLimiterStatus(bool voltageLimterStatus)
void getNumInterfaceNodes(std::vector< int > &numINodes)
Device::DeviceMgr & deviceManager_
Device manager.