def __init__(self, a, b, U_0, U_L, eps=0): self.a, self.b = np.asarray(a), np.asarray(b) assert len(a) == len(b)-1, 'a and b do not have compatible lengths' self.eps = eps # smoothing parameter for smoothed a self.U_0, self.U_L = U_0, U_L # Smoothing parameter must be less than half the smallest material if eps > 0: assert eps < 0.5*(self.b[1:] - self.b[:-1]).min(), 'too large eps' a_data = [[bi, ai] for bi, ai in zip(self.b, self.a)] domain = [b[0], b[-1]] self.a_func = PiecewiseConstant(domain, a_data, eps) # inv_a = 1/a is needed in formulas inv_a_data = [[bi, 1./ai] for bi, ai in zip(self.b, self.a)] self.inv_a_func = PiecewiseConstant(domain, inv_a_data, eps) self.integral_of_inv_a_func = \ IntegratedPiecewiseConstant(domain, inv_a_data, eps) # Denominator in the exact formula is constant self.inv_a_0L = self.integral_of_inv_a_func(b[-1])