Return the minor head loss due to expansion in a rectangular channel.

    This equation applies to both laminar and turbulent flows.
964144
def headloss_exp_rect(FlowRate, Width, DistCenter, KMinor):
    
    #Checking input validity
    ut.check_range([FlowRate, ">0", "Flow rate"], [Width, ">0", "Width"],
                   [DistCenter, ">0", "DistCenter"], [KMinor, ">=0", "K minor"])
    return (KMinor * FlowRate**2
            / (2 * gravity.magnitude * (Width*DistCenter)**2)
            )
1183818
def va(self):
        
        return np.sqrt(self.mu * (2 / (self.ra) - 1 / self.kep.a))
241179
def calc_loss(self, embedding):
        """"""
        Hnew = self.compute_dual_rmetric(Ynew=embedding)
        return self.rieman_loss(Hnew=Hnew)
863227
def getSignificance(wk1, wk2, nout, ofac):
  
  expy = exp(-wk2)
  effm = 2.0*(nout)/ofac
  sig = effm*expy
  ind = (sig > 0.01).nonzero()
  sig[ind] = 1.0-(1.0-expy[ind])**effm
  return sig
1028465
def get_scalar_product(self, other):
        """"""
        return self.x*other.x+self.y*other.y
459067
def _Aterm(N, h, m, k, dW):
    """"""
    sqrt2h = np.sqrt(2.0/h)
    Xk = np.random.normal(0.0, 1.0, (N, m, 1))
    Yk = np.random.normal(0.0, 1.0, (N, m, 1))
    term1 = _dot(Xk, _t(Yk + sqrt2h*dW))
    term2 = _dot(Yk + sqrt2h*dW, _t(Xk))
    return (term1 - term2)/k
156632
def _get_msge_with_gradient(data, delta, xvschema, skipstep, p):
    
    t, m, l = data.shape

    n = (l - p) * t
    underdetermined = n < m * p

    if underdetermined:
        return _msge_with_gradient_underdetermined(data, delta, xvschema,
                                                   skipstep, p)
    else:
        return _msge_with_gradient_overdetermined(data, delta, xvschema,
                                                  skipstep, p)
121221
def get_loss(self, pred: mx.sym.Symbol, labels: mx.sym.Symbol) -> mx.sym.Symbol:
        
        labels = mx.sym.reshape(labels, shape=(-1, 1))
        loss_value = self.loss_config.length_task_weight / 2 * mx.sym.square(pred - labels)
        loss_value = mx.sym.MakeLoss(data=loss_value,
                                     normalization='batch',
                                     name=self.name)
        return loss_value
1224138
def forward(self, X):
        
        return self.W(X).sum(dim=1) + self.b
277196
def rhochange(self):
        """"""

        self.lu, self.piv = sl.lu_factor(self.Z, self.rho)
        self.lu = np.asarray(self.lu, dtype=self.dtype)
1084635
def adapt(self, d, x):
        
        y = np.dot(self.w, x)
        e = d - y
        R1 = np.dot(np.dot(np.dot(self.R,x),x.T),self.R)
        R2 = self.mu + np.dot(np.dot(x,self.R),x.T)
        self.R = 1/self.mu * (self.R - R1/R2)
        dw = np.dot(self.R, x.T) * e
        self.w += dw
103158
def solve(self, lam):
        ''''''
        s = weighted_graphtf_poisson(self.nnodes, self.obs, lam,
                                 self.Dk.shape[0], self.Dk.shape[1], self.Dk.nnz,
                                 self.Dk.row.astype('int32'), self.Dk.col.astype('int32'), self.Dk.data.astype('double'),
                                 self.maxsteps, self.converge,
                                 self.beta, self.u)
        self.steps.append(s)
        return self.beta
1052754
def _Stichlmair_flood_f_and_jac(inputs, Vl, rhog, rhol, mug, voidage, 
                                specific_area, C1, C2, C3, H):
    '''
    '''
    Vg, dP_irr = float(inputs[0]), float(inputs[1])
    x0 = 1.0/H
    x1 = Vg*Vg
    x2 = voidage**(-4.65)
    x3 = specific_area*x2
    x4 = Vl*Vl*x3/g
    x5 = x4**0.333333333333333
    x6 = dP_irr*dP_irr
    x7 = H*H
    x8 = 1.0/x7
    x9 = g*g
    x10 = 1.0/x9
    x11 = rhol*rhol
    x12 = 1.0/x11
    x13 = x5*(20.0*x10*x12*x6*x8 + 1.0)
    x14 = 0.555*x13
    x15 = (voidage/(voidage - x14))**4.65
    x16 = 1.0/Vg
    x17 = 1.0/rhog
    x18 = voidage - 1.0
    x19 = 1.0/x18
    x20 = C1*mug*specific_area*x16*x17*x19
    x21 = 2.44948974278318*C2
    x22 = Vg*rhog/(mug*specific_area)
    x23 = x21*(-x18*x22)**-0.5
    x24 = 6.0*C3 - x20 + x23
    x25 = 1.0 - voidage 
    x26 = x14 + x25
    x27 = -x19*x26
    x28 = 2.0*C1*mug*specific_area*x16*x17/x25 + x21*(x22*x25)**-0.5
    x29 = 1.0/x24
    x30 = x28*x29
    x31 = x27**(-0.166666666666667*x30 + 0.666666666666667)
    x32 = x11*x7*x9
    x33 = 200.0*voidage
    x34 = 111.0*x13
    x35 = x33 - x34
    x36 = 1.0/x35
    x37 = -x33 + x34 + 200.0
    x38 = 1.0/x37
    x39 = 2.0*x20
    x40 = -4.0*x20 + x23 + x29*(-x23 + x39)*(x23 - x39)
    x41 = dP_irr*rhog*specific_area*x0*x1*x10*x12*x15*x2*x24*x31
    x42 = dP_irr*x10*x12*x4**0.666666666666667*x8
    
    F1, F2, dF1_dVg, dF2_dVg, dF1_dP_irr, dF2_dP_irr = (
            -dP_irr*x0 + 0.0208333333333333*rhog*specific_area*x1*x15*x2*x24*x31,
             x32/x6 - 20646.0*x36*x5 - x38*x5*(2960.0 - 740.0*x28*x29),
             0.00173611111111111*Vg*rhog*x15*x3*x31*(144.0*C3 - 12.0*x20 + 18.0*x23 + x40*log(x27)),
             x0*(430.125*x36*x41*x5 - 15.4166666666667*x38*x41*x5*(x30 - 4.0) - 1.0),
             -1.85*x16*x29*x40*x5/x26,
             3285600.0*x42*(-x30 + 4.0)*x38*x38- 91668240.0*x42*x36*x36 - 2.0*x32/(dP_irr*x6))
    
    return [F1, F2], [[dF1_dVg, dF2_dVg], [dF1_dP_irr, dF2_dP_irr]]
1149865
def smooth_l1_loss(input, target, beta=1. / 9, size_average=True):
    
    n = torch.abs(input - target)
    cond = n < beta
    loss = torch.where(cond, 0.5 * n ** 2 / beta, n - 0.5 * beta)
    if size_average:
        return loss.mean()
    return loss.sum()
1122760
def getDampingIntegral(self):
        
        reservoir = self.getReservoir()
        density = self.getDensity()
        length = self.model.getSpatialStep()

        if self.solution.ndim == 1:
            nodes = self.model.getNumberOfNodes()
            radius = linspace(0, nodes * self.model.getSpatialStep(), nodes)
            integral = 2 * pi * sum((reservoir - 1.0) * density * radius * length)
        elif self.solution.ndim == 2:
            area = length ** 2
            integral = sum(sum((reservoir - 1.0) * density * area))

        return integral
967165
def drain_K(self):
        
        drain_K = minorloss.PIPE_ENTRANCE_K_MINOR + minorloss.PIPE_ENTRANCE_K_MINOR + minorloss.PIPE_EXIT_K_MINOR
        return drain_K
68948
def baffle_S(self):
        
        return ((self.BAFFLE_K /
                ((2 * self.expansion_H * (self.vel_grad_avg ** 2) *
                 pc.viscosity_kinematic(self.temp))).to_base_units()) ** (1/3) *
               self.Q / self.channel_W).to(u.cm)