Xyce  6.1
N_TIA_WorkingIntegrationMethod.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_TIA_WorkingIntegrationMethod.C,v $
27 //
28 // Purpose : This file contains the functions which define the
29 // time integration methods classes.
30 //
31 // Special Notes :
32 //
33 // Creator : Buddy Watts
34 //
35 // Creation Date : 6/1/00
36 //
37 // Revision Information:
38 // ---------------------
39 //
40 // Revision Number: $Revision: 1.12.2.1 $
41 //
42 // Revision Date : $Date: 2015/11/20 00:37:50 $
43 //
44 // Current Owner : $Author: tmei $
45 //-----------------------------------------------------------------------------
46 
47 #include <Xyce_config.h>
48 
49 #include <N_ERH_ErrorMgr.h>
50 #include <N_TIA_StepErrorControl.h>
51 #include <N_TIA_TIAParams.h>
54 #include <N_UTL_FeatureTest.h>
55 
56 namespace Xyce {
57 namespace TimeIntg {
58 
59 namespace {
60 
61 typedef std::map<int, std::pair<const char *, Factory> > Registry;
62 
63 Registry &
64 getRegistry()
65 {
66  static Registry s_registry;
67 
68  return s_registry;
69 }
70 
71 } // namespace <unnamed>
72 
73 void
74 registerFactory(int type, const char *name, Factory factory)
75 {
76  std::pair<Registry::iterator, bool> result = getRegistry().insert(Registry::value_type(type, std::pair<const char *, Factory>(name, factory)));
77  if (!result.second && name != (*result.first).second.first)
78  Report::DevelFatal0() << "Time integration factory " << type << " named " << name << " already registered with name " << (*result.first).second.first;
79 }
80 
81 TimeIntegrationMethod *
83  int type,
84  const TIAParams & tia_params,
85  StepErrorControl & step_error_control,
86  DataStore & data_store)
87 {
88  Registry::const_iterator it = getRegistry().find(type);
89  if (it == getRegistry().end())
90  return 0;
91 
92  return (*(*it).second.second)(tia_params, step_error_control, data_store);
93 }
94 
95 const char *
97 {
98  Registry::const_iterator it = getRegistry().find(type);
99  if (it == getRegistry().end())
100  return "<none>";
101 
102  return (*it).second.first;
103 }
104 
105 //-----------------------------------------------------------------------------
106 // Function : WorkingIntegrationMethod::WorkingIntegrationMethod
107 // Purpose : constructor
108 // Special Notes :
109 // Scope : public
110 // Creator : Buddy Watts, SNL
111 // Creation Date : 6/01/00
112 //-----------------------------------------------------------------------------
114  : timeIntegrationMethod_(0),
115  jacLimitFlag(false),
116  jacLimit(1.0e+17),
117  timeIntegratorStat_("Time integrator", parent_stat),
118  predictorStat_("Predictor", timeIntegratorStat_),
119  completeStepStat_("Successful Step", timeIntegratorStat_),
120  rejectStepStat_("Failed Step", timeIntegratorStat_),
121  updateCoefStat_("Update Coef", timeIntegratorStat_),
122  residualStat_("Load Residual", timeIntegratorStat_),
123  jacobianStat_("Load Jacobian", timeIntegratorStat_),
124  initializeStat_("Initialize", timeIntegratorStat_),
125  updateLeadStat_("Lead Currents", timeIntegratorStat_)
126 {}
127 
128 //-----------------------------------------------------------------------------
129 // Function : WorkingIntegrationMethod::~WorkingIntegrationMethod()
130 // Purpose : destructor
131 // Special Notes :
132 // Scope : public
133 // Creator : Buddy Watts, SNL
134 // Creation Date : 6/01/00
135 //-----------------------------------------------------------------------------
137 {
138  delete timeIntegrationMethod_;
139 }
140 
141 //-----------------------------------------------------------------------------
142 // Function : WorkingIntegrationMethod::createTimeIntegMethod
143 // Purpose : Creates the time integration method class --- assigning a
144 // pointer and the Leading Coefficient value of the method.
145 // Special Notes :
146 // Scope : public
147 // Creator : Buddy Watts, SNL
148 // Creation Date : 6/01/00
149 //-----------------------------------------------------------------------------
151  int type,
152  const TIAParams & tia_params,
153  StepErrorControl & step_error_control,
154  DataStore & data_store)
155 {
156  jacLimitFlag = tia_params.jacLimitFlag;
157  jacLimit = tia_params.jacLimit;
158 
159  delete timeIntegrationMethod_;
160  timeIntegrationMethod_ = createTimeIntegrationMethod(type, tia_params, step_error_control, data_store);
161 
163  Report::DevelFatal0().in("WorkingIntegrationMethod::createTimeIntegMethod") << "Invalid integration method " << type << " specified";
164 
165  if (VERBOSE_TIME)
166  Xyce::lout() << " Integration method = " << timeIntegrationMethod_->getName() << std::endl;
167 }
168 
170 {
171  return timeIntegrationMethod_ != 0;
172 }
173 
175 {
177  if (jacLimitFlag && pdt > jacLimit)
178  pdt = jacLimit;
179 
180  return pdt;
181 }
182 
184 {
185 // Stats::TimeBlock x(predictorStat_);
186 
188 }
189 
191 {
192 // Stats::TimeBlock x(predictorStat_);
194 }
195 
197 {
199 }
200 
201 void WorkingIntegrationMethod::updateDerivsBlock ( const std::list<IndexPair> & solGIDList, const std::list<IndexPair> & staGIDList)
202 {
203  timeIntegrationMethod_->updateDerivsBlock (solGIDList, staGIDList);
204 }
205 
207 {
209 }
210 
212 {
214 }
215 
217 {
219 }
220 
222 {
224 }
225 
227 {
229 }
230 
232 {
234 }
235 
237 {
239 }
240 
242 {
243 
244 // Stats::TimeBlock x(updateCoefStat_);
246 }
247 
249 {
251 }
252 
254 {
255 // Stats::TimeBlock x( initializeStat_ );
256  return timeIntegrationMethod_->initialize(tia_params);
257 }
258 
260 {
261 
262 // Stats::TimeBlock x(completeStepStat_);
263 
264  return timeIntegrationMethod_->completeStep(tia_params);
265 }
266 
268 {
269 // Stats::TimeBlock x(rejectStepStat_);
270  return timeIntegrationMethod_->rejectStep(tia_params);
271 }
272 
274 {
275 
276 // Stats::Stat ErrorStat_("error estimation", timeIntegratorStat_);
277 // Stats::TimeBlock x(ErrorStat_);
279 }
280 
282 {
284 }
285 
287 {
288 
289 
290 // Stats::TimeBlock x( updateLeadStat_);
293 }
294 
296 {
297 // Stats::TimeBlock x(residualStat_);
299 }
300 
302 {
304 }
305 
307 {
309 }
310 
312 {
313 
314 // Stats::TimeBlock x(jacobianStat_);
316 }
317 
318 void WorkingIntegrationMethod::applyJacobian(const Linear::Vector& input, Linear::Vector& result)
319 {
320 // Stats::TimeBlock x(jacobianStat_);
321  return timeIntegrationMethod_->applyJacobian(input, result);
322 }
323 
325  Analysis::OutputMgrAdapter & outputManagerAdapter,
326  const double time,
327  Linear::Vector * solnVecPtr,
328  const std::vector<double> & fastTimes )
329 {
331  outputManagerAdapter, time, solnVecPtr, fastTimes );
332 }
333 
335  Analysis::OutputMgrAdapter & outputManagerAdapter,
336  const double time,
337  Linear::Vector * solnVecPtr,
338  const std::vector<double> & fastTimes,
339  const int phiGID )
340 {
342  outputManagerAdapter, time, solnVecPtr, fastTimes, phiGID );
343 }
344 
346  Analysis::OutputMgrAdapter & outputManagerAdapter,
347  const TIAParams & tia_params,
348  const double time,
349  Linear::Vector * solnVecPtr,
350  const bool doNotInterpolate,
351  const std::vector<double> & outputInterpolationTimes,
352  bool skipPrintLineOutput )
353 {
354 // Stats::TimeBlock x( othersStat_);
356  outputManagerAdapter, tia_params, time, solnVecPtr, doNotInterpolate, outputInterpolationTimes, skipPrintLineOutput) ;
357 }
358 
360  Parallel::Machine comm,
361  IO::InitialConditionsManager & initial_conditions_manager,
362  const NodeNameMap & node_name_map,
363  const TIAParams & tia_params,
364  Linear::Vector * solnVecPtr,
365  const double saveTime,
366  const bool doNotInterpolate)
367 {
368  return timeIntegrationMethod_->saveOutputSolution(comm, initial_conditions_manager, node_name_map, tia_params, solnVecPtr, saveTime, doNotInterpolate);
369 }
370 
371 } // namespace TimeIntg
372 } // namespace Xyce
virtual void getInitialQnorm(TwoLevelError &tle) const =0
virtual void updateDerivsBlock(const std::list< IndexPair > &solGIDList, const std::list< IndexPair > &staGIDList)=0
virtual bool saveOutputSolution(Parallel::Machine comm, IO::InitialConditionsManager &initial_conditions_manager, const NodeNameMap &node_name_map, const TIAParams &tia_params, Linear::Vector *solnVecPtr, const double saveTime, const bool doNotInterpolate)=0
virtual bool printMPDEOutputSolution(Analysis::OutputMgrAdapter &outputManagerAdapter, const double time, Linear::Vector *solnVecPtr, const std::vector< double > &fastTimes)
virtual const char * getName() const =0
Pure virtual class to augment a linear system.
void updateDerivsBlock(const std::list< IndexPair > &solGIDList, const std::list< IndexPair > &staGIDList)
virtual void initialize(const TIAParams &tia_params)=0
TimeIntegrationMethod * timeIntegrationMethod_
Pointer to the integration method.
virtual void getTwoLevelError(TwoLevelError &tle) const =0
virtual bool printWaMPDEOutputSolution(Analysis::OutputMgrAdapter &outputManagerAdapter, const double time, Linear::Vector *solnVecPtr, const std::vector< double > &fastTimes, const int phiGID)
virtual void completeStep(const TIAParams &tia_params)=0
virtual int getUsedOrder() const =0
const char * getTimeIntegrationName(int type)
TimeIntegrationMethod * createTimeIntegrationMethod(int type, const TIAParams &tia_params, StepErrorControl &step_error_control, DataStore &data_store)
virtual double partialTimeDeriv() const =0
void registerFactory(int type, const char *name, Factory factory)
virtual void applyJacobian(const Linear::Vector &input, Linear::Vector &result)
bool printMPDEOutputSolution(Analysis::OutputMgrAdapter &outputManagerAdapter, const double time, Linear::Vector *solnVecPtr, const std::vector< double > &fastTimes)
virtual bool printOutputSolution(Analysis::OutputMgrAdapter &outputManagerAdapter, const TIAParams &tia_params, const double time, Linear::Vector *solnVecPtr, const bool doNotInterpolate, const std::vector< double > &outputInterpolationTimes, bool skipPrintLineOutput)=0
TimeIntegrationMethod *(* Factory)(const TIAParams &tia_params, StepErrorControl &step_error_control, DataStore &data_store)
void createTimeIntegMethod(int type, const TIAParams &tia_params, StepErrorControl &step_error_control, DataStore &data_store)
virtual int getNscsco() const =0
virtual double computeErrorEstimate() const =0
bool saveOutputSolution(Parallel::Machine comm, IO::InitialConditionsManager &initial_conditions_manager, const NodeNameMap &node_name_map, const TIAParams &tia_params, Linear::Vector *solnVecPtr, const double saveTime, const bool doNotInterpolate)
void applyJacobian(const Linear::Vector &input, Linear::Vector &result)
virtual void loadFinalSensitivityDerivatives()=0
virtual int getNumberOfSteps() const =0
bool printWaMPDEOutputSolution(Analysis::OutputMgrAdapter &outputManagerAdapter, const double time, Linear::Vector *solnVecPtr, const std::vector< double > &fastTimes, const int phiGID)
bool printOutputSolution(Analysis::OutputMgrAdapter &outputManagerAdapter, const TIAParams &tia_params, const double time, Linear::Vector *solnVecPtr, const bool doNotInterpolate, const std::vector< double > &outputInterpolationTimes, bool skipPrintLineOutput)
virtual void rejectStep(const TIAParams &tia_params)=0