Xyce  6.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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-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_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.15 $
40 //
41 // Revision Date : $Date: 2014/05/21 22:14:53 $
42 //
43 // Current Owner : $Author: tvrusso $
44 //-----------------------------------------------------------------------------
45 
46 #ifndef Xyce_N_DEV_Region_h
47 #define Xyce_N_DEV_Region_h
48 
49 // ---------- Standard Includes ----------
50 #include <N_UTL_Misc.h>
51 #include <N_DEV_fwd.h>
52 
53 // ---------- Xyce Includes ----------
54 #include <N_DEV_ReactionNetwork.h>
55 #include <N_DEV_Specie.h>
56 
57 // ---------- Forward Declarations -------
58 class N_LAS_Vector;
59 
60 namespace Xyce {
61 namespace Device {
62 
63 //-----------------------------------------------------------------------------
64 // Class : Region
65 // Purpose :
66 // Special Notes :
67 // Creator : Eric Keiter, SNL
68 // Creation Date : 04/14/11
69 //-----------------------------------------------------------------------------
70 class Region
71 {
72  // functions:
73 public:
74  Region ( RegionData & rd,
75  const DeviceOptions & devOp,
76  const SolverState & solst,
77  bool sourceOn=true);
78 
79  // constructor that allows a non-default reaction network:
80  Region ( RegionData & rd,
81  const DeviceOptions & devOp,
82  const SolverState & solst,
83  ReactionNetwork & reactionNet);
84 
85  virtual ~Region ();
86 
87  bool outputTecplot ();
88 
89  ///
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 
124  void registerStateLIDs (const std::vector<int> & staLIDVecRef, int & i);
125 
126  void registerJacLIDs ( const std::vector< std::vector<int> > & jacLIDVec,
127  const std::vector<int> &map,
128  const std::vector< std::vector<int> > &map2 );
129 
130  void setupPointers (N_LAS_Matrix & dfdx, N_LAS_Matrix & dqdx);
131 
132  void updateIntermediateVars ( double * solVector, double * oldSolVector, double time);
133 
134  bool loadDAEQVector (double * qVec);
135  bool loadDAEFVector (double * fVec);
136  bool loadDAEdFdxdV (double * dfdxdv,double vdiff);
137 
138  bool loadDAEdQdx (N_LAS_Matrix & dqdx);
139  bool loadDAEdFdx (N_LAS_Matrix & dfdx);
140 
141  bool loadDeviceMask (N_LAS_Vector & mask);
142 
143  bool updateSecondaryState (double * staDeriv);
144 
145  // These three simple accessors are here so we can avoid having *any*
146  // public data.
147  double getStateConcentration(int i) {
148  return tempConcentrations[i];
149  }
150 
151  bool haveAnyReactions();
152 
154  return li_state_Concentrations[i];
155  }
156 
157  void setConstantConcentration(const std::string &constName, double value);
158 
159  // This is here to allow us to copy a full ReactionNetwork object from
160  // one region to another without having to re-parse every time.
161  // We return a const reference so nobody can tinker with our internal
162  // data.
164  return theReactions;
165  }
166 
167  // These query methods here so we can communicate how many equations we're
168  // adding to the base device
169  int getNumIntVars();
170 
172  return theReactions.getNumSpecies();
173  }
174 
176  return theReactions.getNumConstants();
177  }
178 
179  int getSpeciesLID (const std::string &name);
180 
181  double getDiffusionCoefficient (const std::string & name, double temp);
182  double getDiffusionCoefficient (int specie, double temp);
183  double getConcentrationScaling();
184  double getLengthScaling();
185  int getSpeciesNum(const std::string & name);
186  const std::string & getSpeciesName(int i);
187  const std::string & getConstantsName(int i);
188  double getSpeciesVal(int i);
189  double getConstantsVal(int i);
190 
191  ///
192 
193 private:
194  void createDefaultReactionNetwork(const std::string & reactionSpecFile);
195 
196 public:
198 
199 protected:
200  // data:
202  std::string outputName;
203 
209 
210  // reactions
212  // vector of constant concentrations (species held fixed)
213  std::vector<double> theConstantConcentrations;
214  // working storage for communicating between updateIntermediateVars
215  // and updatePrimaryState
216  std::vector<double> tempConcentrations;
217  // actual time derivatives of concentrations
218  std::vector<double> tempConcentrationDerivs;
219  // initial conditions
220  std::vector<double> initialConcentrations;
221  std::vector<double> ddt;
222  std::vector< std::vector<double> > tempJac;
223  std::vector< std::vector<double> > tempAuxJac;
224 
226 
227  std::vector< std::vector<double *> > dfdxConcEquConcVarPtrs;
228  std::vector< std::vector<double *> > dqdxConcEquConcVarPtrs;
229 
230  std::vector< std::vector<double *> > dfdxConcEquAuxVarPtrs;
231  std::vector< std::vector<double *> > dqdxConcEquAuxVarPtrs;
232 
233  std::vector< std::vector<int> > AConcentrationEquConcentrationNodeOffsets;
234  std::vector< std::vector<int> > AConcentrationEquAuxNodeOffsets;
235 
236  // reaction species indices:
237  std::vector<int> li_Concentrations;
238 
239  // reaction state vars... these are redundant storage, because we also
240  // need concentration derivatives
241  std::vector<int> li_state_Concentrations;
242 
243  // Rxn set scaling variables.
244  double x0; // distance scaling (cm)
245  double a0; // area scaling (cm^2)
246  double C0; // concentration scaling (cm^-3);
247  double D0; // diffusion coefficient scaling (cm^2/s)
248  double u0; // mobility coefficient scaling (cm^2/V/s)
249  double R0; // recombination rate scaling (cm^-3/s)
250  double rR0; // reciprocal of R0
251  double t0; // time scaling (s)
252  double k0; // rate constant scaling (cm^3/s)
253  double rt0; // reciprocal
254  double rk0; // reciprocal
255 
258 
261 };
262 
263 //-----------------------------------------------------------------------------
264 // Function : Region::setConstantConcentration
265 // Purpose : Set value of concentration for a constant species.
266 // Special Notes : The species had better be a constant already defined.
267 // No error checking is done. So sue me.
268 // Scope : public
269 // Creator : Tom Russo, SNL, Electrical and Microsystems Modeling
270 // Creation Date : 10/16/06
271 //-----------------------------------------------------------------------------
272 
273 inline void Region::setConstantConcentration(const std::string &constName,
274  double value)
275 {
277  (value)*((variablesScaledFlag)?(1/C0):1.0);
278 }
279 
280 //-----------------------------------------------------------------------------
281 // Function : Region::getSpeciesLID
282 // Purpose :
283 // Special Notes :
284 // Scope : public
285 // Creator : Eric Keiter, SNL, Electrical and Microsystems Modeling
286 // Creation Date : 10/30/06
287 //-----------------------------------------------------------------------------
288 inline int Region::getSpeciesLID (const std::string &namearg)
289 {
290  return li_Concentrations [theReactions.getSpeciesNum(namearg)];
291 }
292 
293 //-----------------------------------------------------------------------------
294 // Function : Region::getDiffusionCoefficient
295 // Purpose :
296 // Special Notes : If scaling is on, this function returns the scaled value.
297 // Scope : public
298 // Creator : Eric Keiter, SNL, Electrical and Microsystems Modeling
299 // Creation Date : 10/30/06
300 //-----------------------------------------------------------------------------
302 (const std::string & namearg, const double temp)
303 {
304  return
305  ((variablesScaledFlag)?(D0):1.0)*
306  theReactions.getDiffusionCoefficient(namearg,temp);
307 }
308 
309 //-----------------------------------------------------------------------------
310 // Function : Region::getDiffusionCoefficient
311 // Purpose :
312 // Special Notes : If scaling is on, this function returns the scaled value.
313 // Scope : public
314 // Creator : Eric Keiter, SNL, Electrical and Microsystems Modeling
315 // Creation Date : 10/31/06
316 //-----------------------------------------------------------------------------
318 (int specie, double temp)
319 {
320  return
321  ((variablesScaledFlag)?(D0):1.0)*
322  theReactions.getDiffusionCoefficient(specie,temp);
323 }
324 
325 //-----------------------------------------------------------------------------
326 // Function : Region::getConcentrationScaling
327 // Purpose :
328 // Special Notes :
329 // Scope : public
330 // Creator : Eric Keiter, SNL, Electrical and Microsystems Modeling
331 // Creation Date : 10/30/06
332 //-----------------------------------------------------------------------------
334 {
335  return C0;
336 }
337 
338 //-----------------------------------------------------------------------------
339 // Function : Region::getLengthScaling
340 // Purpose :
341 // Special Notes :
342 // Scope : public
343 // Creator : Eric Keiter, SNL, Electrical and Microsystems Modeling
344 // Creation Date : 10/30/06
345 //-----------------------------------------------------------------------------
347 {
348  return x0;
349 }
350 
351 //-----------------------------------------------------------------------------
352 // Function : Region::getSpeciesNum
353 // Purpose :
354 // Special Notes :
355 // Scope : public
356 // Creator : Eric Keiter, SNL, Electrical and Microsystems Modeling
357 // Creation Date : 10/30/06
358 //-----------------------------------------------------------------------------
359 inline int Region::getSpeciesNum(const std::string & namearg)
360 {
361  return theReactions.getSpeciesNum(namearg);
362 }
363 
364 //-----------------------------------------------------------------------------
365 // Function : Region::getSpeciesameN
366 // Purpose :
367 // Special Notes :
368 // Scope : public
369 // Creator : Eric Keiter, SNL, Electrical and Microsystems Modeling
370 // Creation Date : 10/30/06
371 //-----------------------------------------------------------------------------
372 inline const std::string & Region::getSpeciesName(int i)
373 {
374  return theReactions.getSpeciesName(i);
375 }
376 
377 //-----------------------------------------------------------------------------
378 // Function : Region::getConstantsName
379 // Purpose :
380 // Special Notes :
381 // Scope : public
382 // Creator : Eric Keiter, SNL, Electrical and Microsystems Modeling
383 // Creation Date : 10/30/06
384 //-----------------------------------------------------------------------------
385 inline const std::string & Region::getConstantsName(int i)
386 {
387  return theReactions.getConstantsName(i);
388 }
389 
390 //-----------------------------------------------------------------------------
391 // Function : Region::getSpeciesVal
392 // Purpose :
393 // Special Notes :
394 // Scope : public
395 // Creator : Eric Keiter, SNL, Electrical and Microsystems Modeling
396 // Creation Date : 04/15/07
397 //-----------------------------------------------------------------------------
398 inline double Region::getSpeciesVal(int i)
399 {
400  return (tempConcentrations[i]*((variablesScaledFlag)?(C0):(1.0)));
401 }
402 
403 //-----------------------------------------------------------------------------
404 // Function : Region::getConstantsVal
405 // Purpose :
406 // Special Notes :
407 // Scope : public
408 // Creator : Eric Keiter, SNL, Electrical and Microsystems Modeling
409 // Creation Date : 04/15/07
410 //-----------------------------------------------------------------------------
411 inline double Region::getConstantsVal(int i)
412 {
413  return (theConstantConcentrations[i] *((variablesScaledFlag)?(C0):(1.0)));
414 }
415 
416 } // namespace Device
417 } // namespace Xyce
418 
420 
421 #endif
422