Xyce  6.1
N_DEV_Region.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_DEV_Region.h,v $
27 //
28 // Purpose :
29 //
30 // Special Notes :
31 //
32 // Creator : Eric R. Keiter, SNL
33 //
34 // Creation Date : 07/19/06
35 //
36 // Revision Information:
37 // ---------------------
38 //
39 // Revision Number: $Revision: 1.22.2.1 $
40 //
41 // Revision Date : $Date: 2015/04/02 18:20:09 $
42 //
43 // Current Owner : $Author: tvrusso $
44 //-----------------------------------------------------------------------------
45 
46 #ifndef Xyce_N_DEV_Region_h
47 #define Xyce_N_DEV_Region_h
48 
49 #include <N_DEV_fwd.h>
50 #include <N_LAS_fwd.h>
51 
52 #include <N_DEV_ReactionNetwork.h>
53 #include <N_DEV_Specie.h>
54 #include <N_UTL_NodeSymbols.h>
55 #include <N_DEV_MaterialLayer.h>
56 
57 namespace Xyce {
58 namespace Device {
59 
60 //-----------------------------------------------------------------------------
61 // Class : Region
62 // Purpose :
63 // Special Notes :
64 // Creator : Eric Keiter, SNL
65 // Creation Date : 04/14/11
66 //-----------------------------------------------------------------------------
67 class Region
68 {
69  // functions:
70 public:
71  Region (
72  const NetlistLocation & netlist_location,
73  RegionData & rd,
74  const DeviceOptions & devOp,
75  const SolverState & solst,
76  bool sourceOn = true);
77 
78  // constructor that allows a non-default reaction network:
79  Region (
80  RegionData & rd,
81  const DeviceOptions & devOp,
82  const SolverState & solst,
83  ReactionNetwork & reactionNet);
84 
85  virtual ~Region ();
86 
87  bool outputTecplot ();
88 
89  ///
90  void initializeReactionNetwork(ScalingVars & sv, MaterialLayer *material, double Temp);
91  void setInitialCondition (const std::string & name, const double val);
92  void setRateConstants(double T);
93  void setupScalingVars (ScalingVars & sv);
94  void scaleVariables ();
95  void unscaleVariables ();
96  void scaleRateConstants ();
97  void unscaleRateConstants ();
98  void addSource(std::string speciesName, Util::Expression *expr);
99  void addMasterSource(std::string speciesName);
100  inline void setMasterSourceValue(double msv) {theReactions.setMasterSourceValue(msv);};
101  inline void setSimTime(double time) { theReactions.setSimTime(time);};
102 
103  bool reactantExist(std::string reactantname)
104  {
105  return theReactions.reactantExist(reactantname);
106  };
107 
108  bool constantExist(std::string constantname)
109  {
110  return theReactions.constantExist(constantname);
111  };
112 
113  bool getDoNothingFlag ();
114  inline const InstanceName &getName () { return name; }
115 
116  double getBreakTime();
117 
118  void setupJacStamp ( std::vector< std::vector<int> > & jacStamp, std::vector<int> & colDep, int & firstReactant, int & lastIndex );
119 
120  void registerLIDs( const std::vector<int> & intLIDVec, const std::vector<int> & extLIDVec, int & intIndex);
121 
122  void augmentNameMap ( std::map<int,std::string> & intNameMap, DeviceInstance & di);
123  void loadNodeSymbols(Util::SymbolTable &symbol_table, const DeviceInstance &device_instance);
124 
125  void registerStateLIDs (const std::vector<int> & staLIDVecRef, int & i);
126 
127  void registerJacLIDs ( const std::vector< std::vector<int> > & jacLIDVec,
128  const std::vector<int> &map,
129  const std::vector< std::vector<int> > &map2 );
130 
131  void setupPointers (Linear::Matrix & dfdx, Linear::Matrix & dqdx);
132 
133  void updateIntermediateVars ( double * solVector, double * oldSolVector, double time);
134 
135  bool loadDAEQVector (double * qVec);
136  bool loadDAEFVector (double * fVec);
137  bool loadDAEdFdxdV (double * dfdxdv,double vdiff);
138 
139  bool loadDAEdQdx (Linear::Matrix & dqdx);
140  bool loadDAEdFdx (Linear::Matrix & dfdx);
141 
142  void loadErrorWeightMask (Linear::Vector & mask)
143  {}
144 
145  bool updateSecondaryState (double * staDeriv);
146 
147  // These three simple accessors are here so we can avoid having *any*
148  // public data.
149  double getStateConcentration(int i) {
150  return tempConcentrations[i];
151  }
152 
153  bool haveAnyReactions();
154 
156  return li_state_Concentrations[i];
157  }
158 
159  void setConstantConcentration(const std::string &constName, double value);
160 
161  // This is here to allow us to copy a full ReactionNetwork object from
162  // one region to another without having to re-parse every time.
163  // We return a const reference so nobody can tinker with our internal
164  // data.
166  return theReactions;
167  }
168 
169  // These query methods here so we can communicate how many equations we're
170  // adding to the base device
171  int getNumIntVars();
172 
174  return theReactions.getNumSpecies();
175  }
176 
178  return theReactions.getNumConstants();
179  }
180 
181  int getSpeciesLID (const std::string &name);
182 
183  double getDiffusionCoefficient (const std::string & name, double temp);
184  double getDiffusionCoefficient (int specie, double temp);
185  double getConcentrationScaling();
186  double getLengthScaling();
187  int getSpeciesNum(const std::string & name);
188  const std::string & getSpeciesName(int i);
189  const std::string & getConstantsName(int i);
190  double getSpeciesVal(int i);
191  double getConstantsVal(int i);
192 
193  ///
194 
195 private:
196  void createDefaultReactionNetwork(const NetlistLocation &netlist_location, const std::string & reactionSpecFile);
197 
198 public:
200 
201 protected:
202  // data:
204  std::string outputName;
205 
211 
212  // reactions
214  // vector of constant concentrations (species held fixed)
215  std::vector<double> theConstantConcentrations;
216  // working storage for communicating between updateIntermediateVars
217  // and updatePrimaryState
218  std::vector<double> tempConcentrations;
219  // actual time derivatives of concentrations
220  std::vector<double> tempConcentrationDerivs;
221  // initial conditions
222  std::vector<double> initialConcentrations;
223  std::vector<double> ddt;
224  std::vector< std::vector<double> > tempJac;
225  std::vector< std::vector<double> > tempAuxJac;
226 
228 
229  std::vector< std::vector<double *> > dfdxConcEquConcVarPtrs;
230  std::vector< std::vector<double *> > dqdxConcEquConcVarPtrs;
231 
232  std::vector< std::vector<double *> > dfdxConcEquAuxVarPtrs;
233  std::vector< std::vector<double *> > dqdxConcEquAuxVarPtrs;
234 
235  std::vector< std::vector<int> > AConcentrationEquConcentrationNodeOffsets;
236  std::vector< std::vector<int> > AConcentrationEquAuxNodeOffsets;
237 
238  // reaction species indices:
239  std::vector<int> li_Concentrations;
240 
241  // reaction state vars... these are redundant storage, because we also
242  // need concentration derivatives
243  std::vector<int> li_state_Concentrations;
244 
245  // Rxn set scaling variables.
246  double x0; // distance scaling (cm)
247  double a0; // area scaling (cm^2)
248  double C0; // concentration scaling (cm^-3);
249  double D0; // diffusion coefficient scaling (cm^2/s)
250  double u0; // mobility coefficient scaling (cm^2/V/s)
251  double R0; // recombination rate scaling (cm^-3/s)
252  double rR0; // reciprocal of R0
253  double t0; // time scaling (s)
254  double k0; // rate constant scaling (cm^3/s)
255  double rt0; // reciprocal
256  double rk0; // reciprocal
257 
260 
263 };
264 
265 //-----------------------------------------------------------------------------
266 // Function : Region::setConstantConcentration
267 // Purpose : Set value of concentration for a constant species.
268 // Special Notes : The species had better be a constant already defined.
269 // No error checking is done. So sue me.
270 // Scope : public
271 // Creator : Tom Russo, SNL, Electrical and Microsystems Modeling
272 // Creation Date : 10/16/06
273 //-----------------------------------------------------------------------------
274 
275 inline void Region::setConstantConcentration(const std::string &constName,
276  double value)
277 {
279  (value)*((variablesScaledFlag)?(1/C0):1.0);
280 }
281 
282 //-----------------------------------------------------------------------------
283 // Function : Region::getSpeciesLID
284 // Purpose :
285 // Special Notes :
286 // Scope : public
287 // Creator : Eric Keiter, SNL, Electrical and Microsystems Modeling
288 // Creation Date : 10/30/06
289 //-----------------------------------------------------------------------------
290 inline int Region::getSpeciesLID (const std::string &namearg)
291 {
292  return li_Concentrations [theReactions.getSpeciesNum(namearg)];
293 }
294 
295 //-----------------------------------------------------------------------------
296 // Function : Region::getDiffusionCoefficient
297 // Purpose :
298 // Special Notes : If scaling is on, this function returns the scaled value.
299 // Scope : public
300 // Creator : Eric Keiter, SNL, Electrical and Microsystems Modeling
301 // Creation Date : 10/30/06
302 //-----------------------------------------------------------------------------
304 (const std::string & namearg, const double temp)
305 {
306  return
307  ((variablesScaledFlag)?(D0):1.0)*
308  theReactions.getDiffusionCoefficient(namearg,temp);
309 }
310 
311 //-----------------------------------------------------------------------------
312 // Function : Region::getDiffusionCoefficient
313 // Purpose :
314 // Special Notes : If scaling is on, this function returns the scaled value.
315 // Scope : public
316 // Creator : Eric Keiter, SNL, Electrical and Microsystems Modeling
317 // Creation Date : 10/31/06
318 //-----------------------------------------------------------------------------
320 (int specie, double temp)
321 {
322  return
323  ((variablesScaledFlag)?(D0):1.0)*
324  theReactions.getDiffusionCoefficient(specie,temp);
325 }
326 
327 //-----------------------------------------------------------------------------
328 // Function : Region::getConcentrationScaling
329 // Purpose :
330 // Special Notes :
331 // Scope : public
332 // Creator : Eric Keiter, SNL, Electrical and Microsystems Modeling
333 // Creation Date : 10/30/06
334 //-----------------------------------------------------------------------------
336 {
337  return C0;
338 }
339 
340 //-----------------------------------------------------------------------------
341 // Function : Region::getLengthScaling
342 // Purpose :
343 // Special Notes :
344 // Scope : public
345 // Creator : Eric Keiter, SNL, Electrical and Microsystems Modeling
346 // Creation Date : 10/30/06
347 //-----------------------------------------------------------------------------
349 {
350  return x0;
351 }
352 
353 //-----------------------------------------------------------------------------
354 // Function : Region::getSpeciesNum
355 // Purpose :
356 // Special Notes :
357 // Scope : public
358 // Creator : Eric Keiter, SNL, Electrical and Microsystems Modeling
359 // Creation Date : 10/30/06
360 //-----------------------------------------------------------------------------
361 inline int Region::getSpeciesNum(const std::string & namearg)
362 {
363  return theReactions.getSpeciesNum(namearg);
364 }
365 
366 //-----------------------------------------------------------------------------
367 // Function : Region::getSpeciesameN
368 // Purpose :
369 // Special Notes :
370 // Scope : public
371 // Creator : Eric Keiter, SNL, Electrical and Microsystems Modeling
372 // Creation Date : 10/30/06
373 //-----------------------------------------------------------------------------
374 inline const std::string & Region::getSpeciesName(int i)
375 {
376  return theReactions.getSpeciesName(i);
377 }
378 
379 //-----------------------------------------------------------------------------
380 // Function : Region::getConstantsName
381 // Purpose :
382 // Special Notes :
383 // Scope : public
384 // Creator : Eric Keiter, SNL, Electrical and Microsystems Modeling
385 // Creation Date : 10/30/06
386 //-----------------------------------------------------------------------------
387 inline const std::string & Region::getConstantsName(int i)
388 {
389  return theReactions.getConstantsName(i);
390 }
391 
392 //-----------------------------------------------------------------------------
393 // Function : Region::getSpeciesVal
394 // Purpose :
395 // Special Notes :
396 // Scope : public
397 // Creator : Eric Keiter, SNL, Electrical and Microsystems Modeling
398 // Creation Date : 04/15/07
399 //-----------------------------------------------------------------------------
400 inline double Region::getSpeciesVal(int i)
401 {
402  return (tempConcentrations[i]*((variablesScaledFlag)?(C0):(1.0)));
403 }
404 
405 //-----------------------------------------------------------------------------
406 // Function : Region::getConstantsVal
407 // Purpose :
408 // Special Notes :
409 // Scope : public
410 // Creator : Eric Keiter, SNL, Electrical and Microsystems Modeling
411 // Creation Date : 04/15/07
412 //-----------------------------------------------------------------------------
413 inline double Region::getConstantsVal(int i)
414 {
415  return (theConstantConcentrations[i] *((variablesScaledFlag)?(C0):(1.0)));
416 }
417 
418 } // namespace Device
419 } // namespace Xyce
420 
421 #endif
422 
double getStateConcentration(int i)
Definition: N_DEV_Region.h:149
std::vector< std::vector< double * > > dqdxConcEquAuxVarPtrs
Definition: N_DEV_Region.h:233
void updateIntermediateVars(double *solVector, double *oldSolVector, double time)
Definition: N_DEV_Region.C:943
ReactionNetwork & getReactionNetwork()
Definition: N_DEV_Region.h:165
bool reactantExist(const std::string &name)
int getSpeciesNum(const std::string &name)
Definition: N_DEV_Region.h:361
double getSpeciesVal(int i)
Definition: N_DEV_Region.h:400
const InstanceName & getName()
Definition: N_DEV_Region.h:114
void setupJacStamp(std::vector< std::vector< int > > &jacStamp, std::vector< int > &colDep, int &firstReactant, int &lastIndex)
Definition: N_DEV_Region.C:633
Pure virtual class to augment a linear system.
Devices and models are each named.
bool reactantExist(std::string reactantname)
Definition: N_DEV_Region.h:103
void addSource(std::string speciesName, Util::Expression *expr)
Definition: N_DEV_Region.C:277
std::vector< std::vector< int > > AConcentrationEquConcentrationNodeOffsets
Definition: N_DEV_Region.h:235
void createDefaultReactionNetwork(const NetlistLocation &netlist_location, const std::string &reactionSpecFile)
Definition: N_DEV_Region.C:186
void registerJacLIDs(const std::vector< std::vector< int > > &jacLIDVec, const std::vector< int > &map, const std::vector< std::vector< int > > &map2)
Definition: N_DEV_Region.C:801
bool loadDAEdQdx(Linear::Matrix &dqdx)
std::vector< int > li_Concentrations
Definition: N_DEV_Region.h:239
const std::string & getSpeciesName(int i)
void setupScalingVars(ScalingVars &sv)
Definition: N_DEV_Region.C:354
std::vector< double > ddt
Definition: N_DEV_Region.h:223
int getStateConcentrationLID(int i)
Definition: N_DEV_Region.h:155
void setupPointers(Linear::Matrix &dfdx, Linear::Matrix &dqdx)
Definition: N_DEV_Region.C:849
int getSpeciesLID(const std::string &name)
Definition: N_DEV_Region.h:290
RegionData & regData
Definition: N_DEV_Region.h:199
const std::string & getConstantsName(int i)
const T & value(const ParameterBase &entity, const Descriptor &descriptor)
Returns the value of the parameter for the entity.
Definition: N_DEV_Pars.h:1224
bool loadDAEdFdx(Linear::Matrix &dfdx)
void setInitialCondition(const std::string &name, const double val)
Definition: N_DEV_Region.C:263
bool loadDAEQVector(double *qVec)
std::vector< double > theConstantConcentrations
Definition: N_DEV_Region.h:215
void addMasterSource(std::string speciesName)
Definition: N_DEV_Region.C:292
void augmentNameMap(std::map< int, std::string > &intNameMap, DeviceInstance &di)
Definition: N_DEV_Region.C:752
void setSimTime(double time)
Definition: N_DEV_Region.h:101
std::vector< std::vector< int > > AConcentrationEquAuxNodeOffsets
Definition: N_DEV_Region.h:236
double getDiffusionCoefficient(const std::string &name, double temp)
Definition: N_DEV_Region.h:304
bool updateSecondaryState(double *staDeriv)
const DeviceOptions & devOptions
Definition: N_DEV_Region.h:261
const std::string & getSpeciesName(int i)
Definition: N_DEV_Region.h:374
std::vector< std::vector< double > > tempAuxJac
Definition: N_DEV_Region.h:225
const SolverState & solState
Definition: N_DEV_Region.h:262
void setMasterSourceValue(double msv)
Definition: N_DEV_Region.h:100
bool loadDAEdFdxdV(double *dfdxdv, double vdiff)
void loadNodeSymbols(Util::SymbolTable &symbol_table, const DeviceInstance &device_instance)
Definition: N_DEV_Region.C:726
bool constantExist(const std::string &name)
Region(const NetlistLocation &netlist_location, RegionData &rd, const DeviceOptions &devOp, const SolverState &solst, bool sourceOn=true)
Definition: N_DEV_Region.C:83
void setConstantConcentration(const std::string &constName, double value)
Definition: N_DEV_Region.h:275
std::vector< double > tempConcentrations
Definition: N_DEV_Region.h:218
std::vector< double > initialConcentrations
Definition: N_DEV_Region.h:222
bool constantExist(std::string constantname)
Definition: N_DEV_Region.h:108
std::vector< std::vector< double * > > dqdxConcEquConcVarPtrs
Definition: N_DEV_Region.h:230
std::string outputName
Definition: N_DEV_Region.h:204
std::vector< std::vector< double * > > dfdxConcEquAuxVarPtrs
Definition: N_DEV_Region.h:232
std::vector< std::vector< double * > > dfdxConcEquConcVarPtrs
Definition: N_DEV_Region.h:229
std::vector< std::vector< double > > tempJac
Definition: N_DEV_Region.h:224
bool loadDAEFVector(double *fVec)
int getSpeciesNum(const std::string &name)
void initializeReactionNetwork(ScalingVars &sv, MaterialLayer *material, double Temp)
Definition: N_DEV_Region.C:206
double getConstantsVal(int i)
Definition: N_DEV_Region.h:413
double getConcentrationScaling()
Definition: N_DEV_Region.h:335
void loadErrorWeightMask(Linear::Vector &mask)
Definition: N_DEV_Region.h:142
ReactionNetwork theReactions
Definition: N_DEV_Region.h:213
const std::string & getConstantsName(int i)
Definition: N_DEV_Region.h:387
void setRateConstants(double T)
Definition: N_DEV_Region.C:307
int getConstantNum(const std::string &name)
std::vector< int > li_state_Concentrations
Definition: N_DEV_Region.h:243
void registerStateLIDs(const std::vector< int > &staLIDVecRef, int &i)
Definition: N_DEV_Region.C:779
std::vector< double > tempConcentrationDerivs
Definition: N_DEV_Region.h:220
void registerLIDs(const std::vector< int > &intLIDVec, const std::vector< int > &extLIDVec, int &intIndex)
Definition: N_DEV_Region.C:687