Memosa-FVM  0.2
ElectricUtilityFunctions.h
Go to the documentation of this file.
1 // This file os part of FVM
2 // Copyright (c) 2012 FVM Authors
3 // See LICENSE file for terms.
4 
5 #ifndef _ELECTRICUTILITYFUNCTIONS_H_
6 #define _ELECTRICUTILITYFUNCTIONS_H_
7 
8 /*** a collection of utility functions that are used in dielectric charging model ***/
9 
10 #include "PhysicsConstant.h"
11 #include "Array.h"
12 #include "Vector.h"
13 #include "CException.h"
14 
15 
17 
18 template<class T>
19 const T FermiFunction ( const T& energy, const T& fermilevel, const T& temperature)
20 {
21  return 1. / (1. + exp(QE * (energy - fermilevel) / (K_SI * temperature) ));
22 }
23 
24 template<class T>
25 const T ElectronSupplyFunction (const T& energy, const T& fermilevel, const T& temperature)
26 {
27  T exponent, power, supply;
28 
29  power = -QE * (energy - fermilevel) / (K_SI * temperature);
30  exponent = exp(power);
31 
32  if (exponent <= 0.01)
33  supply = K_SI * temperature * (exponent - pow(exponent, 2.0)/2.0 + pow(exponent, 3.0)/3.0 - pow(exponent, 4.0)/4.0);
34 
35  if (power >= 10.0)
36  supply = K_SI * temperature * power;
37 
38  else
39  supply = K_SI * temperature *log(1+exponent);
40 
41 
42  //supply = K_SI * temperature *log(1+exponent);
43  return supply;
44 }
45 
46 
47 
48 
49 template<class T>
50 const T PositiveValueOf(T input) {
51  if (input>=0)
52  return input;
53  else
54  return T(0);
55 }
56 
57 template<class T>
58 const T getMembraneVoltage ( const T& currentTime)
59 {
60  T volt;
61  volt = 1.0;
62  return volt;
63 }
64 
65 double SignOf(double x) {
66  if (x>0) return 1;
67  else if (x<0) return -1;
68  else return 0;
69 }
70 
71 double findMin(double x1, double x2, double x3, double x4)
72 {
73  double min = 1000000000;
74  if (x1 <= min)
75  min = x1;
76  if (x2 <= min)
77  min = x2;
78  if (x3 <= min)
79  min = x3;
80  if (x4 <= min)
81  min = x4;
82  return min;
83 }
84 
85 double findMax(double x1, double x2, double x3, double x4)
86 {
87  double max = -1000000000;
88  if (x1 >= max)
89  max = x1;
90  if (x2 >= max)
91  max = x2;
92  if (x3 >= max)
93  max = x3;
94  if (x4 >= max)
95  max = x4;
96  return max;
97 }
98 
100 {
101  // 3D point p1 and p2 forms a line L
102  // find the shortest distance from point M to line L
103  // assume point H is the projection of M on line L
104  // so the shortest distance is the length of MH
105 
106  VectorD3 v = p2 - p1;
107  if (mag(v) == 0)
108  throw CException ("column center line start and end points are the same!!!");
109 
110  v /= mag(p2-p1);
111  VectorD3 PM = p1 - M;
112  VectorD3 PH = dot(PM, v) * v;
113  VectorD3 HM = PM - PH;
114  double distance = mag(HM);
115  return distance;
116 }
117 
119 {
120  VectorD3 v = p2 - p1;
121  if (mag(v) == 0)
122  throw CException ("column center line start and end points are the same!!!");
123 
124  v /= mag(p2-p1);
125  VectorD3 PM = p1 - M;
126  VectorD3 PH = dot(PM, v) * v;
127  VectorD3 HM = PM - PH;
128  VectorD3 H = HM + M;
129  return H;
130 }
131 #endif
const T getMembraneVoltage(const T &currentTime)
const T FermiFunction(const T &energy, const T &fermilevel, const T &temperature)
#define K_SI
double max(double x, double y)
Definition: Octree.cpp:18
T mag(const Vector< T, 3 > &a)
Definition: Vector.h:260
double findMax(double x1, double x2, double x3, double x4)
#define QE
double findMin(double x1, double x2, double x3, double x4)
const T PositiveValueOf(T input)
double distanceFromPointToLine(VectorD3 p1, VectorD3 p2, VectorD3 M)
const T ElectronSupplyFunction(const T &energy, const T &fermilevel, const T &temperature)
VectorD3 projectionFromPointToLine(VectorD3 p1, VectorD3 p2, VectorD3 M)
double SignOf(double x)
double min(double x, double y)
Definition: Octree.cpp:23
T dot(const Vector< T, 3 > &a, const Vector< T, 3 > &b)
Definition: Vector.h:253
Vector< double, 3 > VectorD3