43 template<
typename wFunc>
53 bool integration_completed =
false;
55 double u_hi = spp->
getU(0);
56 double x_hi = spp->
getX(0);
57 double f_hi = w(0, t)*u_hi;
59 for (
int i=1; i<spp->
J; ++i){
60 double u_lo = spp->
getU(i);
61 double x_lo = spp->
getX(i);
62 double f_lo = w(i, t)*u_lo;
66 double f = (
control.integral_interpolate)? f_lo + (f_hi-f_lo)/(x_hi-x_lo)*(xlow - x_lo) : f_lo;
67 double x = (
control.integral_interpolate)? xlow : x_lo;
68 I += (x_hi - x) * (f_hi + f);
69 integration_completed =
true;
72 I += (x_hi - x_lo) * (f_hi + f_lo);
77 if (integration_completed)
break;
84 if (spp->
J == 1 || !integration_completed){
87 double x_lo = spp->
xb;
89 double f_lo = w(-1, t)*u0;
90 double f = (
control.integral_interpolate)? f_lo + (f_hi-f_lo)/(x_hi-x_lo)*(xlow - x_lo) : f_lo;
91 double x = (
control.integral_interpolate)? xlow : x_lo;
92 I += (x_hi-x)*(f_hi+f);
101 if (xlow > spp->
x[spp->
J])
return 0;
105 for (
int i=spp->
J-1; i>=0; --i){
106 if (spp->
x[i] <= xlow){
107 double h = (
control.integral_interpolate)? spp->
x[i+1]-xlow : spp->
h[i];
108 I += h * w(i,t) * spp->
getU(i);
112 I += spp->
h[i] * w(i,t) * spp->
getU(i);
122 double pi0 = spp->
getX(spp->
J-1);
123 double N0 = spp->
getU(spp->
J-1);
126 double x0 = spp->
xb + pi0/(N0+1e-12);
127 spp->
setX(spp->
J-1, x0);
131 for (
int i=0; i<spp->
J; ++i){
132 if (spp->
getX(i) < xlow)
break;
133 else I += w(i, t)*spp->
getU(i);
137 spp->
setX(spp->
J-1, pi0);
143 throw std::runtime_error(
"Unsupported solver method");
155 template<
typename wFunc>
162 for (
unsigned int i=0; i<spp->
J; ++i){
163 I += spp->
h[i]*w(i, t)*spp->
getU(i);
172 double pi0 = spp->
getX(spp->
J-1);
173 double N0 = spp->
getU(spp->
J-1);
176 double x0 = spp->
xb + pi0/(N0+1e-12);
177 spp->
setX(spp->
J-1, x0);
181 for (
int i=0; i<spp->
J; ++i) I += w(i, t)*spp->
getU(i);
184 spp->
setX(spp->
J-1, pi0);
193 double u_hi = spp->
getU(0);
194 double x_hi = spp->
getX(0);
195 double f_hi = w(0, t)*u_hi;
197 for (
int i=1; i<spp->
J; ++i){
198 double u_lo = spp->
getU(i);
199 double x_lo = spp->
getX(i);
200 double f_lo = w(i, t)*u_lo;
202 I += (x_hi - x_lo) * (f_hi + f_lo);
209 double x_lo = spp->
xb;
210 double f_lo = w(-1, t)*u0;
211 I += (x_hi-x_lo)*(f_hi+f_lo);
217 throw std::runtime_error(
"Unsupported solver method");
virtual double get_boundary_u()=0
virtual double getU(int i)=0
virtual double getX(int i)=0
double integrate_wudx_above(wFunc w, double t, double xlow, int species_id)
Computes the partial integral for the specified species.
double integrate_x(wFunc w, double t, int species_id)
Computes the integral for the specified species. For details, see integrate_wudx_above.
std::vector< Species_Base * > species_vec
virtual void setX(int i, double _x)=0
struct Solver::@1 control