示例#1
0
 def applyStrongBCLinearSystemRHSVector(self, U_old, b):
     A = self.dof_handler.A[self.k]
     aA1 = self.dof_handler.aA1(U_old, self.k)
     vf, dvf_daA1 = computeVolumeFraction(aA1, A, self.phase,
                                          self.model_type)
     arhoA = vf * self.rho
     b[self.i_arhoA] = arhoA
示例#2
0
  def applyStrongBCNonlinearSystem(self, U, r, J):
    A = self.dof_handler.A[self.k]
    aA1 = self.dof_handler.aA1(U, self.k)
    vf, dvf_daA1 = computeVolumeFraction(aA1, A, self.phase, self.model_type)
    arhoA = U[self.i_arhoA]
    arhouA = U[self.i_arhouA]
    arhoEA_solution = U[self.i_arhoEA]

    u, du_darhoA, du_darhouA = computeVelocity(arhoA, arhouA)

    rho, drho_dvf, drho_darhoA, _ = computeDensity(vf, arhoA, A)
    drho_daA1 = drho_dvf * dvf_daA1

    v, dv_drho = computeSpecificVolume(rho)
    dv_daA1 = dv_drho * drho_daA1
    dv_darhoA = dv_drho * drho_darhoA

    e, de_dv, de_dp = self.eos.e(v, self.p)
    de_daA1 = de_dv * dv_daA1
    de_darhoA = de_dv * dv_darhoA

    arhoEA = arhoA * (e + 0.5 * u * u)
    darhoEA_daA1 = arhoA * de_dv * dv_daA1
    darhoEA_darhoA = (e + 0.5 * u * u) + arhoA * (de_dv * dv_darhoA + u * du_darhoA)
    darhoEA_darhouA = arhoA * u * du_darhouA

    # energy
    r[self.i_arhoEA] = arhoEA_solution - arhoEA
    J[self.i_arhoEA,:] = 0
    if (self.model_type == ModelType.TwoPhase):
      J[self.i_arhoEA,self.i_aA1] = - darhoEA_daA1
    J[self.i_arhoEA,self.i_arhoA] = - darhoEA_darhoA
    J[self.i_arhoEA,self.i_arhouA] = - darhoEA_darhouA
    J[self.i_arhoEA,self.i_arhoEA] = 1
示例#3
0
 def getPhaseSolution(self, U, phase):
     aA1 = np.array([self.aA1(U, k) for k in xrange(self.n_node)])
     vf, _ = computeVolumeFraction(aA1, self.A, phase, self.model_type)
     arhoA = self.getSolution(U, VariableName.ARhoA, phase)
     arhouA = self.getSolution(U, VariableName.ARhoUA, phase)
     arhoEA = self.getSolution(U, VariableName.ARhoEA, phase)
     return (vf, arhoA, arhouA, arhoEA)
示例#4
0
    def applyWeakBC(self, U, r, J):
        A = self.dof_handler.A[self.k]
        aA1 = self.dof_handler.aA1(U, self.k)
        arhoA = U[self.i_arhoA]
        arhouA = U[self.i_arhouA]
        arhoEA = U[self.i_arhoEA]

        vf, dvf_daA1 = computeVolumeFraction(aA1, A, self.phase,
                                             self.model_type)

        u, du_darhoA, du_darhouA = computeVelocity(arhoA, arhouA)

        rho, drho_dvf, drho_darhoA, _ = computeDensity(vf, arhoA, A)
        drho_daA1 = drho_dvf * dvf_daA1

        v, dv_drho = computeSpecificVolume(rho)
        dv_daA1 = dv_drho * drho_daA1
        dv_darhoA = dv_drho * drho_darhoA

        E, dE_darhoA, dE_darhoEA = computeSpecificTotalEnergy(arhoA, arhoEA)

        e, de_du, de_dE = computeSpecificInternalEnergy(u, E)
        de_darhoA = de_du * du_darhoA + de_dE * dE_darhoA
        de_darhouA = de_du * du_darhouA
        de_darhoEA = de_dE * dE_darhoEA

        p, dp_dv, dp_de = self.eos.p(v, e)
        dp_daA1 = dp_dv * dv_daA1
        dp_darhoA = dp_dv * dv_darhoA + dp_de * de_darhoA
        dp_darhouA = dp_de * de_darhouA
        dp_darhoEA = dp_de * de_darhoEA

        # mass
        r[self.i_arhoA] += arhouA * self.nx
        J[self.i_arhoA, self.i_arhouA] += self.nx

        # momentum
        r[self.i_arhouA] += (arhouA * u + vf * p) * self.nx
        if (self.model_type == ModelType.TwoPhase):
            J[self.i_arhouA,
              self.i_aA1] += (dvf_daA1 * p + vf * dp_daA1) * self.nx
        J[self.i_arhouA,
          self.i_arhoA] += (arhouA * du_darhoA + vf * dp_darhoA) * self.nx
        J[self.i_arhouA, self.i_arhouA] += (arhouA * du_darhouA + u +
                                            vf * dp_darhouA) * self.nx
        J[self.i_arhouA, self.i_arhoEA] += vf * dp_darhoEA * self.nx

        # energy
        r[self.i_arhoEA] += (arhoEA + vf * p) * u * self.nx
        if (self.model_type == ModelType.TwoPhase):
            J[self.i_arhoEA,
              self.i_aA1] += (dvf_daA1 * p + vf * dp_daA1) * u * self.nx
        J[self.i_arhoEA, self.i_arhoA] += (
            (arhoEA + vf * p) * du_darhoA + vf * dp_darhoA * u) * self.nx
        J[self.i_arhoEA, self.i_arhouA] += (
            (arhoEA + vf * p) * du_darhouA + vf * dp_darhouA * u) * self.nx
        J[self.i_arhoEA, self.i_arhoEA] += (1 + vf * dp_darhoEA) * u * self.nx
示例#5
0
  def applyStrongBCLinearSystemRHSVector(self, U_old, b):
    A = self.dof_handler.A[self.k]
    aA1 = self.dof_handler.aA1(U_old, self.k)
    vf, dvf_daA1 = computeVolumeFraction(aA1, A, self.phase, self.model_type)
    arhoA = U_old[self.i_arhoA]
    arhouA = U_old[self.i_arhouA]

    u, du_darhoA, du_darhouA = computeVelocity(arhoA, arhouA)
    rho, drho_dvf, drho_darhoA = computeDensity(vf, arhoA)
    v, dv_drho = computeSpecificVolume(rho)
    e, de_dv, de_dp = self.eos.e(v, self.p)
    arhoEA = arhoA * (e + 0.5 * u * u)

    b[self.i_arhoEA] = arhoEA
示例#6
0
    def applyStrongBCNonlinearSystem(self, U, r, J):
        A = self.dof_handler.A[self.k]
        aA1 = self.dof_handler.aA1(U, self.k)
        vf, dvf_daA1 = computeVolumeFraction(aA1, A, self.phase,
                                             self.model_type)
        arhoA = U[self.i_arhoA]

        arhoBC = vf * self.rho
        darhoBC_daA1 = self.rho * dvf_daA1

        # mass
        r[self.i_arhoA] = arhoA - arhoBC
        J[self.i_arhoA, :] = 0
        if (self.model_type == ModelType.TwoPhase):
            J[self.i_arhoA, self.i_aA1] = -darhoBC_daA1
        J[self.i_arhoA, self.i_arhoA] = 1
示例#7
0
  def applyWeakBC(self, U, r, J):
    A = self.dof_handler.A[self.k]
    aA1 = self.dof_handler.aA1(U, self.k)
    vf, dvf_daA1 = computeVolumeFraction(aA1, A, self.phase, self.model_type)
    arhoA = U[self.i_arhoA]
    arhouA = U[self.i_arhouA]

    u, du_darhoA, du_darhouA = computeVelocity(arhoA, arhouA)

    # mass
    r[self.i_arhoA] += arhouA * self.nx
    J[self.i_arhoA,self.i_arhouA] += self.nx

    # momentum
    r[self.i_arhouA] += (arhouA * u + vf * self.p) * self.nx
    if (self.model_type == ModelType.TwoPhase):
      J[self.i_arhouA,self.i_aA1] += dvf_daA1 * self.p * self.nx
    J[self.i_arhouA,self.i_arhoA] += arhouA * du_darhoA * self.nx
    J[self.i_arhouA,self.i_arhouA] += (arhouA * du_darhouA + u) * self.nx
示例#8
0
    def applyWeakBC(self, U, r, J):
        A = self.dof_handler.A[self.k]
        aA1 = self.dof_handler.aA1(U, self.k)
        vf, dvf_daA1 = computeVolumeFraction(aA1, A, self.phase,
                                             self.model_type)
        arhoEA = U[self.i_arhoEA]

        arhoBC = vf * self.rho
        darhoBC_daA1 = self.rho * dvf_daA1

        arhouABC = vf * self.rho * self.u
        darhouABC_daA1 = self.rho * self.u * dvf_daA1

        v, _ = computeSpecificVolume(self.rho)

        E, dE_darhoBC, dE_darhoEA = computeSpecificTotalEnergy(arhoBC, arhoEA)
        dE_daA1 = dE_darhoBC * darhoBC_daA1

        e, _, de_dE = computeSpecificInternalEnergy(self.u, E)
        de_daA1 = de_dE * dE_daA1
        de_darhoEA = de_dE * dE_darhoEA

        p, _, dp_de = self.eos.p(v, e)
        dp_daA1 = dp_de * de_daA1
        dp_darhoEA = dp_de * de_darhoEA

        # momentum
        r[self.i_arhouA] += (arhouABC * self.u + vf * p) * self.nx
        if (self.model_type == ModelType.TwoPhase):
            J[self.i_arhouA,
              self.i_aA1] += (self.u * darhouABC_daA1 + dvf_daA1 * p +
                              vf * dp_daA1) * self.nx
        J[self.i_arhouA, self.i_arhoEA] += vf * dp_darhoEA * self.nx

        # energy
        r[self.i_arhoEA] += self.u * (arhoEA + vf * p) * self.nx
        if (self.model_type == ModelType.TwoPhase):
            J[self.i_arhoEA,
              self.i_aA1] += self.u * (dvf_daA1 * p + vf * dp_daA1) * self.nx
        J[self.i_arhoEA,
          self.i_arhoEA] += self.u * (1 + vf * dp_darhoEA) * self.nx
  def applyStronglyToNonlinearSystem(self, U_new, U_old, r, J):
    n_values = 6
    L = 0
    R = 1
    L_old = 2
    R_old = 3
    LL_old = 4
    RR_old = 5

    k = [0] * n_values
    k[L] = self.k_left
    k[R] = self.k_right
    k[L_old] = self.k_left
    k[R_old] = self.k_right
    k[LL_old] = self.k_left_adjacent
    k[RR_old] = self.k_right_adjacent

    i_arhoA = [0] * n_values
    i_arhoA[L] = self.i_arhoL
    i_arhoA[R] = self.i_arhoR
    i_arhoA[L_old] = self.i_arhoL
    i_arhoA[R_old] = self.i_arhoR
    i_arhoA[LL_old] = self.i_arhoLL
    i_arhoA[RR_old] = self.i_arhoRR

    i_arhouA = [0] * n_values
    i_arhouA[L] = self.i_arhouAL
    i_arhouA[R] = self.i_arhouAR
    i_arhouA[L_old] = self.i_arhouAL
    i_arhouA[R_old] = self.i_arhouAR
    i_arhouA[LL_old] = self.i_arhouALL
    i_arhouA[RR_old] = self.i_arhouARR

    i_arhoEA = [0] * n_values
    i_arhoEA[L] = self.i_arhoEAL
    i_arhoEA[R] = self.i_arhoEAR
    i_arhoEA[L_old] = self.i_arhoEAL
    i_arhoEA[R_old] = self.i_arhoEAR
    i_arhoEA[LL_old] = self.i_arhoEALL
    i_arhoEA[RR_old] = self.i_arhoEARR

    U = [0] * n_values
    U[L] = U_new
    U[R] = U_new
    U[L_old] = U_old
    U[R_old] = U_old
    U[LL_old] = U_old
    U[RR_old] = U_old

    # initialize lists
    rho = [0] * n_values
    drho_daA1 = [0] * n_values
    drho_darhoA = [0] * n_values

    u = [0] * n_values
    du_darhoA = [0] * n_values
    du_darhouA = [0] * n_values

    e = [0] * n_values
    de_darhoA = [0] * n_values
    de_darhouA = [0] * n_values
    de_darhoEA = [0] * n_values

    p = [0] * n_values
    dp_daA1 = [0] * n_values
    dp_darhoA = [0] * n_values
    dp_darhouA = [0] * n_values
    dp_darhoEA = [0] * n_values

    c = [0] * n_values
    dc_daA1 = [0] * n_values
    dc_darhoA = [0] * n_values
    dc_darhouA = [0] * n_values
    dc_darhoEA = [0] * n_values

    if not self.use_momentum_flux_balance:
      p0 = [0] * n_values
      dp0_daA1 = [0] * n_values
      dp0_darhoA = [0] * n_values
      dp0_darhouA = [0] * n_values
      dp0_darhoEA = [0] * n_values

    # loop over subscript/superscript combinations
    for i in xrange(n_values):
      A = self.dof_handler.A[k[i]]
      aA1 = self.dof_handler.aA1(U[i], k[i])
      vf, dvf_daA1 = computeVolumeFraction(aA1, A, self.phase, self.model_type)
      arhoA  = U[i][i_arhoA[i]]
      arhouA = U[i][i_arhouA[i]]
      arhoEA = U[i][i_arhoEA[i]]

      rho[i], drho_dvf, drho_darhoA[i], _ = computeDensity(vf, arhoA, A)
      drho_daA1[i] = drho_dvf * dvf_daA1

      u[i], du_darhoA[i], du_darhouA[i] = computeVelocity(arhoA, arhouA)

      v, dv_drho = computeSpecificVolume(rho[i])
      dv_daA1 = dv_drho * drho_daA1[i]
      dv_darhoA = dv_drho * drho_darhoA[i]

      E, dE_darhoA, dE_darhoEA = computeSpecificTotalEnergy(arhoA, arhoEA)

      e[i], de_du, de_dE = computeSpecificInternalEnergy(u[i], E)
      de_darhoA[i] = de_du * du_darhoA[i] + de_dE * dE_darhoA
      de_darhouA[i] = de_du * du_darhouA[i]
      de_darhoEA[i] = de_dE * dE_darhoEA

      p[i], dp_dv, dp_de = self.eos.p(v, e[i])
      dp_daA1[i] = dp_dv * dv_daA1
      dp_darhoA[i] = dp_dv * dv_darhoA + dp_de * de_darhoA[i]
      dp_darhouA[i] = dp_de * de_darhouA[i]
      dp_darhoEA[i] = dp_de * de_darhoEA[i]

      c[i], dc_dv, dc_de = self.eos.c(v, e[i])
      dc_daA1[i] = dc_dv * dv_daA1
      dc_darhoA[i] = dc_dv * dv_darhoA + dc_de * de_darhoA[i]
      dc_darhouA[i] = dc_de * de_darhouA[i]
      dc_darhoEA[i] = dc_de * de_darhoEA[i]

      if not self.use_momentum_flux_balance:
        s, ds_dv, ds_de = self.eos.s(v, e[i])
        ds_daA1 = ds_dv * dv_daA1
        ds_darhoA = ds_dv * dv_darhoA + ds_de * de_darhoA[i]
        ds_darhouA = ds_de * de_darhouA[i]
        ds_darhoEA = ds_de * de_darhoEA[i]

        h, dh_de, dh_dp, dh_drho = computeSpecificEnthalpy(e[i], p[i], rho[i])
        dh_daA1 = dh_dp * dp_daA1[i]
        dh_darhoA = dh_de * de_darhoA[i] + dh_dp * dp_darhoA[i] + dh_drho * drho_darhoA[i]
        dh_darhouA = dh_de * de_darhouA[i] + dh_dp * dp_darhouA[i]
        dh_darhoEA = dh_de * de_darhoEA[i] + dh_dp * dp_darhoEA[i]

        h0 = h + 0.5 * u[i]**2
        dh0_daA1 = dh_daA1
        dh0_darhoA = dh_darhoA + u[i] * du_darhoA[i]
        dh0_darhouA = dh_darhouA + u[i] * du_darhouA[i]
        dh0_darhoEA = dh_darhoEA

        p0[i], dp0_dh0, dp0_ds = self.eos.p_from_h_s(h0, s)
        dp0_daA1[i] = dp0_dh0 * dh0_daA1 + dp0_ds * ds_daA1
        dp0_darhoA[i] = dp0_dh0 * dh0_darhoA + dp0_ds * ds_darhoA
        dp0_darhouA[i] = dp0_dh0 * dh0_darhouA + dp0_ds * ds_darhouA
        dp0_darhoEA[i] = dp0_dh0 * dh0_darhoEA + dp0_ds * ds_darhoEA

    # compute old average quantities
    rhoL = 0.5 * (rho[L_old] + rho[LL_old])
    rhoR = 0.5 * (rho[R_old] + rho[RR_old])
    uL = 0.5 * (u[L_old] + u[LL_old])
    uR = 0.5 * (u[R_old] + u[RR_old])
    pL = 0.5 * (p[L_old] + p[LL_old])
    pR = 0.5 * (p[R_old] + p[RR_old])
    cL = 0.5 * (c[L_old] + c[LL_old])
    cR = 0.5 * (c[R_old] + c[RR_old])

    # residual indices
    i1 = self.i_arhoL
    i2 = self.i_arhouAL
    i3 = self.i_arhoEAL
    i4 = self.i_arhoR
    i5 = self.i_arhouAR
    i6 = self.i_arhoEAR

    # reset Jacobian rows
    J[i1,:] = 0
    J[i2,:] = 0
    J[i3,:] = 0
    J[i4,:] = 0
    J[i5,:] = 0
    J[i6,:] = 0

    # compute residuals and Jacobians
    r[i1] = p[L] - pL + rhoL * (cL - uL) * (u[L] - uL)
    J_i1_vf1L = dp_daA1[L]
    J[i1,self.i_arhoL] = dp_darhoA[L] + rhoL * (cL - uL) * du_darhoA[L]
    J[i1,self.i_arhouAL] = dp_darhouA[L] + rhoL * (cL - uL) * du_darhouA[L]
    J[i1,self.i_arhoEAL] = dp_darhoEA[L]

    r[i2] = p[R] - pR - rhoR * (cR - uR) * (u[R] - uR)
    J_i2_vf1R = dp_daA1[R]
    J[i2,self.i_arhoR] = dp_darhoA[R] - rhoR * (cR - uR) * du_darhoA[R]
    J[i2,self.i_arhouAR] = dp_darhouA[R] - rhoR * (cR - uR) * du_darhouA[R]
    J[i2,self.i_arhoEAR] = dp_darhoEA[R]

    if u[L] >= 0:
      if u[R] < 0:
        error("Assumption violated: Both velocity conditions were true.")
      r[i3] = rho[L] - rhoL - (p[L] - pL) / cL**2
      J_i3_vf1L = drho_daA1[L] - dp_daA1[L] / cL**2
      J_i3_vf1R = 0
      J[i3,self.i_arhoL] = drho_darhoA[L] - dp_darhoA[L] / cL**2
      J[i3,self.i_arhouAL] = - dp_darhouA[L] / cL**2
      J[i3,self.i_arhoEAL] = - dp_darhoEA[L] / cL**2
    elif u[R] < 0:
      r[i3] = rho[R] - rhoR - (p[R] - pR) / cR**2
      J_i3_vf1R = drho_daA1[R] - dp_daA1[R] / cR**2
      J_i3_vf1L = 0
      J[i3,self.i_arhoR] = drho_darhoA[R] - dp_darhoA[R] / cR**2
      J[i3,self.i_arhouAR] = - dp_darhouA[R] / cR**2
      J[i3,self.i_arhoEAR] = - dp_darhoEA[R] / cR**2
    else:
      error("Assumption violated: Neither velocity condition was true.")

    r[i4] = rho[L] * u[L] - rho[R] * u[R]
    J_i4_vf1L = drho_daA1[L] * u[L]
    J[i4,self.i_arhoL] = drho_darhoA[L] * u[L] + rho[L] * du_darhoA[L]
    J[i4,self.i_arhouAL] = rho[L] * du_darhouA[L]
    J_i4_vf1R = -drho_daA1[R] * u[R]
    J[i4,self.i_arhoR] = -(drho_darhoA[R] * u[R] + rho[R] * du_darhoA[R])
    J[i4,self.i_arhouAR] = -rho[R] * du_darhouA[R]

    r[i5] = e[L] + p[L] / rho[L] + 0.5 * u[L]**2 - (e[R] + p[R] / rho[R] + 0.5 * u[R]**2)
    J_i5_vf1L = dp_daA1[L] / rho[L] - p[L] / rho[L]**2 * drho_daA1[L]
    J[i5,self.i_arhoL] = de_darhoA[L] + dp_darhoA[L] / rho[L] - p[L] / rho[L]**2 * drho_darhoA[L] + u[L] * du_darhoA[L]
    J[i5,self.i_arhouAL] = de_darhouA[L] + dp_darhouA[L] / rho[L] + u[L] * du_darhouA[L]
    J[i5,self.i_arhoEAL] = de_darhoEA[L] + dp_darhoEA[L] / rho[L]
    J_i5_vf1R = -(dp_daA1[R] / rho[R] - p[R] / rho[R]**2 * drho_daA1[R])
    J[i5,self.i_arhoR] = -(de_darhoA[R] + dp_darhoA[R] / rho[R] - p[R] / rho[R]**2 * drho_darhoA[R] + u[R] * du_darhoA[R])
    J[i5,self.i_arhouAR] = -(de_darhouA[R] + dp_darhouA[R] / rho[R] + u[R] * du_darhouA[R])
    J[i5,self.i_arhoEAR] = -(de_darhoEA[R] + dp_darhoEA[R] / rho[R])

    if self.use_momentum_flux_balance:
      r[i6] = rho[L] * u[L]**2 + p[L] - (rho[R] * u[R]**2 + p[R])
      J_i6_vf1L = drho_daA1[L] * u[L]**2 + dp_daA1[L]
      J[i6,self.i_arhoL] = drho_darhoA[L] * u[L]**2 + rho[L] * 2.0 * u[L] * du_darhoA[L] + dp_darhoA[L]
      J[i6,self.i_arhouAL] = rho[L] * 2.0 * u[L] * du_darhouA[L] + dp_darhouA[L]
      J[i6,self.i_arhoEAL] = dp_darhoEA[L]
      J_i6_vf1R = -(drho_daA1[R] * u[R]**2 + dp_daA1[R])
      J[i6,self.i_arhoR] = -(drho_darhoA[R] * u[R]**2 + rho[R] * 2.0 * u[R] * du_darhoA[R] + dp_darhoA[R])
      J[i6,self.i_arhouAR] = -(rho[R] * 2.0 * u[R] * du_darhouA[R] + dp_darhouA[R])
      J[i6,self.i_arhoEAR] = -dp_darhoEA[R]
    else:
      r[i6] = p0[L] - p0[R]
      J_i6_vf1L = dp0_daA1[L]
      J[i6,self.i_arhoL] = dp0_darhoA[L]
      J[i6,self.i_arhouAL] = dp0_darhouA[L]
      J[i6,self.i_arhoEAL] = dp0_darhoEA[L]
      J_i6_vf1R = -dp0_daA1[R]
      J[i6,self.i_arhoR] = -dp0_darhoA[R]
      J[i6,self.i_arhouAR] = -dp0_darhouA[R]
      J[i6,self.i_arhoEAR] = -dp0_darhoEA[R]

    if self.model_type == ModelType.TwoPhase:
      J[i1,self.i_aA1L] = J_i1_vf1L
      J[i2,self.i_aA1R] = J_i2_vf1R
      J[i3,self.i_aA1L] = J_i3_vf1L
      J[i3,self.i_aA1R] = J_i3_vf1R
      J[i4,self.i_aA1L] = J_i4_vf1L
      J[i4,self.i_aA1R] = J_i4_vf1R
      J[i5,self.i_aA1L] = J_i5_vf1L
      J[i5,self.i_aA1R] = J_i5_vf1R
      J[i6,self.i_aA1L] = J_i6_vf1L
      J[i6,self.i_aA1R] = J_i6_vf1R
示例#10
0
    def computeFluxes(self, U):
        self.f_mass = [0] * self.n_meshes
        self.df_mass_darhouA = [0] * self.n_meshes

        self.f_momentum = [0] * self.n_meshes
        self.df_momentum_daA1 = [0] * self.n_meshes
        self.df_momentum_darhoA = [0] * self.n_meshes
        self.df_momentum_darhouA = [0] * self.n_meshes
        self.df_momentum_darhoEA = [0] * self.n_meshes

        self.f_energy = [0] * self.n_meshes
        self.df_energy_daA1 = [0] * self.n_meshes
        self.df_energy_darhoA = [0] * self.n_meshes
        self.df_energy_darhouA = [0] * self.n_meshes
        self.df_energy_darhoEA = [0] * self.n_meshes

        for i in xrange(self.n_meshes):
            nx = self.nx[i]

            A = self.dof_handler.A[self.node_indices[i]]
            aA1 = self.dof_handler.aA1(U, self.node_indices[i])
            vf, dvf_daA1 = computeVolumeFraction(aA1, A, self.phase,
                                                 self.model_type)
            arhoA = U[self.i_arhoA[i]]
            arhouA = U[self.i_arhouA[i]]
            arhoEA = U[self.i_arhoEA[i]]

            u, du_darhoA, du_darhouA = computeVelocity(arhoA, arhouA)

            rho, drho_dvf, drho_darhoA, _ = computeDensity(vf, arhoA, A)
            drho_daA1 = drho_dvf * dvf_daA1

            v, dv_drho = computeSpecificVolume(rho)
            dv_daA1 = dv_drho * drho_daA1
            dv_darhoA = dv_drho * drho_darhoA

            E, dE_darhoA, dE_darhoEA = computeSpecificTotalEnergy(
                arhoA, arhoEA)

            e, de_du, de_dE = computeSpecificInternalEnergy(u, E)
            de_darhoA = de_du * du_darhoA + de_dE * dE_darhoA
            de_darhouA = de_du * du_darhouA
            de_darhoEA = de_dE * dE_darhoEA

            p, dp_dv, dp_de = self.eos.p(v, e)
            dp_daA1 = dp_dv * dv_daA1
            dp_darhoA = dp_dv * dv_darhoA + dp_de * de_darhoA
            dp_darhouA = dp_de * de_darhouA
            dp_darhoEA = dp_de * de_darhoEA

            self.f_mass[i] = arhouA * nx
            self.df_mass_darhouA[i] = nx

            self.f_momentum[i] = (arhouA * u + vf * p) * nx
            self.df_momentum_daA1[i] = (dvf_daA1 * p + vf * dp_daA1) * nx
            self.df_momentum_darhoA[i] = (arhouA * du_darhoA +
                                          vf * dp_darhoA) * nx
            self.df_momentum_darhouA[i] = (arhouA * du_darhouA + u +
                                           vf * dp_darhouA) * nx
            self.df_momentum_darhoEA[i] = vf * dp_darhoEA * nx

            self.f_energy[i] = (arhoEA + vf * p) * u * nx
            self.df_energy_daA1[i] = (dvf_daA1 * p + vf * dp_daA1) * u * nx
            self.df_energy_darhoA[i] = (
                (arhoEA + vf * p) * du_darhoA + vf * dp_darhoA * u) * nx
            self.df_energy_darhouA[i] = (
                (arhoEA + vf * p) * du_darhouA + vf * dp_darhouA * u) * nx
            self.df_energy_darhoEA[i] = (1 + vf * dp_darhoEA) * u * nx