def getResidual(self, u, r): import pdb import copy """ Calculate the element residuals and add in to the global residual """ r.fill(0.0) #Load the unknowns into the finite element dof self.setUnknowns(u) #no flux boundary conditions self.adr.calculateResidual( #element self.u[0].femSpace.elementMaps.psi, self.u[0].femSpace.elementMaps.grad_psi, self.mesh.nodeArray, self.mesh.elementNodesArray, self.elementQuadratureWeights[('u', 0)], self.u[0].femSpace.psi, self.u[0].femSpace.grad_psi, self.u[0].femSpace.psi, self.u[0].femSpace.grad_psi, self.mesh.elementDiametersArray, self.q[('cfl', 0)], self.shockCapturing.shockCapturingFactor, self.coefficients.sc_uref, self.coefficients.sc_beta, self.coefficients.useMetrics, #element boundary self.u[0].femSpace.elementMaps.psi_trace, self.u[0].femSpace.elementMaps.grad_psi_trace, self.elementBoundaryQuadratureWeights[('u', 0)], self.u[0].femSpace.psi_trace, self.u[0].femSpace.grad_psi_trace, self.u[0].femSpace.psi_trace, self.u[0].femSpace.grad_psi_trace, self.u[0].femSpace.elementMaps.boundaryNormals, self.u[0].femSpace.elementMaps.boundaryJacobians, #physics self.mesh.nElements_global, self.u[0].femSpace.dofMap.l2g, self.u[0].dof, self.coefficients.sdInfo[(0, 0)][0], self.coefficients.sdInfo[(0, 0)][1], self.q[('a', 0, 0)], self.q[('df', 0, 0)], self.q[('r', 0)], self.shockCapturing.lag, self.shockCapturing.shockCapturingFactor, self.shockCapturing.numDiff[0], self.shockCapturing.numDiff_last[0], self.offset[0], self.stride[0], r, self.mesh.nExteriorElementBoundaries_global, self.mesh.exteriorElementBoundariesArray, self.mesh.elementBoundaryElementsArray, self.mesh.elementBoundaryLocalElementBoundariesArray, self.ebqe[('a', 0, 0)], self.ebqe[('df', 0, 0)], self.numericalFlux.isDOFBoundary[0], self.numericalFlux.ebqe[('u', 0)], self.ebqe[('diffusiveFlux_bc_flag', 0, 0)], self.ebqe[('advectiveFlux_bc_flag', 0)], self.ebqe[('diffusiveFlux_bc', 0, 0)], self.ebqe[('advectiveFlux_bc', 0)], self.ebqe['penalty'], self.numericalFlux.boundaryAdjoint_sigma) log("Global residual", level=9, data=r) self.coefficients.massConservationError = fabs( globalSum(sum(r.flat[:self.mesh.nElements_owned]))) log(" Mass Conservation Error", level=3, data=self.coefficients.massConservationError) self.nonlinear_function_evaluations += 1
def getResidual(self, u, r): import pdb import copy """ Calculate the element residuals and add in to the global residual """ r.fill(0.0) # Load the unknowns into the finite element dof for dofN, g in list(self.dirichletConditionsForceDOF[0]. DOFBoundaryConditionsDict.items()): # load the BC valu # Load the unknowns into the finite element dof u[self.offset[0] + self.stride[0] * dofN] = g( self.dirichletConditionsForceDOF[0].DOFBoundaryPointDict[dofN], self.timeIntegration.t) self.setUnknowns(u) self.Aij[:, :, self.added_mass_i] = 0.0 self.addedMass.calculateResidual( # element self.u[0].femSpace.elementMaps.psi, self.u[0].femSpace.elementMaps.grad_psi, self.mesh.nodeArray, self.mesh.elementNodesArray, self.elementQuadratureWeights[('u', 0)], self.u[0].femSpace.psi, self.u[0].femSpace.grad_psi, self.u[0].femSpace.psi, self.u[0].femSpace.grad_psi, # element boundary self.u[0].femSpace.elementMaps.psi_trace, self.u[0].femSpace.elementMaps.grad_psi_trace, self.elementBoundaryQuadratureWeights[('u', 0)], self.u[0].femSpace.psi_trace, self.u[0].femSpace.grad_psi_trace, self.u[0].femSpace.psi_trace, self.u[0].femSpace.grad_psi_trace, self.u[0].femSpace.elementMaps.boundaryNormals, self.u[0].femSpace.elementMaps.boundaryJacobians, # physics self.mesh.nElements_global, self.mesh.nElementBoundaries_owned, self.u[0].femSpace.dofMap.l2g, self.u[0].dof, self.coefficients.q_rho, self.offset[0], self.stride[0], r, self.mesh.nExteriorElementBoundaries_global, self.mesh.exteriorElementBoundariesArray, self.mesh.elementBoundaryElementsArray, self.mesh.elementBoundaryLocalElementBoundariesArray, self.mesh.elementBoundaryMaterialTypes, self.Aij, self.added_mass_i, self.barycenters, self.flags_rigidbody) for k in range(self.Aij.shape[0]): for j in range(self.Aij.shape[2]): self.Aij[k, j, self.added_mass_i] = globalSum( self.Aij[k, j, self.added_mass_i]) for i, flag in enumerate(self.flags_rigidbody): if flag == 1: numpy.set_printoptions(precision=2, linewidth=160) logEvent("Added Mass Tensor for rigid body i" + repr(i)) logEvent("Aij = \n" + str(self.Aij[i])) for dofN, g in list(self.dirichletConditionsForceDOF[0]. DOFBoundaryConditionsDict.items()): r[self.offset[0] + self.stride[0] * dofN] = self.u[0].dof[dofN] - \ g(self.dirichletConditionsForceDOF[0].DOFBoundaryPointDict[dofN], self.timeIntegration.t) logEvent("Global residual", level=9, data=r) self.nonlinear_function_evaluations += 1
def getResidual(self, u, r): import pdb import copy """ Calculate the element residuals and add in to the global residual """ r.fill(0.0) # Load the unknowns into the finite element dof self.setUnknowns(u) # no flux boundary conditions argsDict = cArgumentsDict.ArgumentsDict() argsDict["mesh_trial_ref"] = self.u[0].femSpace.elementMaps.psi argsDict["mesh_grad_trial_ref"] = self.u[ 0].femSpace.elementMaps.grad_psi argsDict["mesh_dof"] = self.mesh.nodeArray argsDict["mesh_l2g"] = self.mesh.elementNodesArray argsDict["dV_ref"] = self.elementQuadratureWeights[('u', 0)] argsDict["u_trial_ref"] = self.u[0].femSpace.psi argsDict["u_grad_trial_ref"] = self.u[0].femSpace.grad_psi argsDict["u_test_ref"] = self.u[0].femSpace.psi argsDict["u_grad_test_ref"] = self.u[0].femSpace.grad_psi argsDict["mesh_trial_trace_ref"] = self.u[ 0].femSpace.elementMaps.psi_trace argsDict["mesh_grad_trial_trace_ref"] = self.u[ 0].femSpace.elementMaps.grad_psi_trace argsDict["dS_ref"] = self.elementBoundaryQuadratureWeights[('u', 0)] argsDict["u_trial_trace_ref"] = self.u[0].femSpace.psi_trace argsDict["u_grad_trial_trace_ref"] = self.u[0].femSpace.grad_psi_trace argsDict["u_test_trace_ref"] = self.u[0].femSpace.psi_trace argsDict["u_grad_test_trace_ref"] = self.u[0].femSpace.grad_psi_trace argsDict["normal_ref"] = self.u[0].femSpace.elementMaps.boundaryNormals argsDict["boundaryJac_ref"] = self.u[ 0].femSpace.elementMaps.boundaryJacobians argsDict["nElements_global"] = self.mesh.nElements_global argsDict["useMetrics"] = self.coefficients.useMetrics argsDict["epsFactHeaviside"] = self.coefficients.epsFactHeaviside argsDict["epsFactDirac"] = self.coefficients.epsFactDirac argsDict["epsFactDiffusion"] = self.coefficients.epsFactDiffusion argsDict["u_l2g"] = self.u[0].femSpace.dofMap.l2g argsDict["elementDiameter"] = self.elementDiameter argsDict["nodeDiametersArray"] = self.mesh.nodeDiametersArray argsDict["u_dof"] = self.u[0].dof argsDict["q_phi"] = self.coefficients.q_u_ls argsDict["q_normal_phi"] = self.coefficients.q_n_ls argsDict["ebqe_phi"] = self.coefficients.ebqe_u_ls argsDict["ebqe_normal_phi"] = self.coefficients.ebqe_n_ls argsDict["q_H"] = self.coefficients.q_H_vof argsDict["q_u"] = self.q[('u', 0)] argsDict["q_n"] = self.q[('grad(u)', 0)] argsDict["ebqe_u"] = self.ebqe[('u', 0)] argsDict["ebqe_n"] = self.ebqe[('grad(u)', 0)] argsDict["q_r"] = self.q[('r', 0)] argsDict["q_vos"] = self.coefficients.q_vos argsDict["offset_u"] = self.offset[0] argsDict["stride_u"] = self.stride[0] argsDict["globalResidual"] = r argsDict[ "nExteriorElementBoundaries_global"] = self.mesh.nExteriorElementBoundaries_global argsDict[ "exteriorElementBoundariesArray"] = self.mesh.exteriorElementBoundariesArray argsDict[ "elementBoundaryElementsArray"] = self.mesh.elementBoundaryElementsArray argsDict[ "elementBoundaryLocalElementBoundariesArray"] = self.mesh.elementBoundaryLocalElementBoundariesArray self.presinit.calculateResidual(argsDict) log("Global residual", level=9, data=r) self.coefficients.massConservationError = fabs( globalSum(sum(r.flat[:self.mesh.nNodes_owned]))) assert self.coefficients.massConservationError == fabs( globalSum(r[:self.mesh.nNodes_owned].sum())) log(" Mass Conservation Error", level=3, data=self.coefficients.massConservationError) self.nonlinear_function_evaluations += 1 if self.globalResidualDummy is None: self.globalResidualDummy = np.zeros(r.shape, 'd')
def getResidual(self, u, r): import pdb import copy """ Calculate the element residuals and add in to the global residual """ r.fill(0.0) # Load the unknowns into the finite element dof self.setUnknowns(u) # no flux boundary conditions self.presinit.calculateResidual( # element self.u[0].femSpace.elementMaps.psi, self.u[0].femSpace.elementMaps.grad_psi, self.mesh.nodeArray, self.mesh.elementNodesArray, self.elementQuadratureWeights[('u', 0)], self.u[0].femSpace.psi, self.u[0].femSpace.grad_psi, self.u[0].femSpace.psi, self.u[0].femSpace.grad_psi, # element boundary self.u[0].femSpace.elementMaps.psi_trace, self.u[0].femSpace.elementMaps.grad_psi_trace, self.elementBoundaryQuadratureWeights[('u', 0)], self.u[0].femSpace.psi_trace, self.u[0].femSpace.grad_psi_trace, self.u[0].femSpace.psi_trace, self.u[0].femSpace.grad_psi_trace, self.u[0].femSpace.elementMaps.boundaryNormals, self.u[0].femSpace.elementMaps.boundaryJacobians, # physics self.mesh.nElements_global, self.coefficients.useMetrics, self.coefficients.epsFactHeaviside, self.coefficients.epsFactDirac, self.coefficients.epsFactDiffusion, self.u[0].femSpace.dofMap.l2g, self.elementDiameter, # self.mesh.elementDiametersArray, self.mesh.nodeDiametersArray, self.u[0].dof, self.coefficients.q_u_ls, self.coefficients.q_n_ls, self.coefficients.ebqe_u_ls, self.coefficients.ebqe_n_ls, self.coefficients.q_H_vof, self.q[('u', 0)], self.q[('grad(u)', 0)], self.ebqe[('u', 0)], self.ebqe[('grad(u)', 0)], self.q[('r', 0)], self.coefficients.q_vos, self.offset[0], self.stride[0], r, self.mesh.nExteriorElementBoundaries_global, self.mesh.exteriorElementBoundariesArray, self.mesh.elementBoundaryElementsArray, self.mesh.elementBoundaryLocalElementBoundariesArray) log("Global residual", level=9, data=r) self.coefficients.massConservationError = fabs( globalSum(sum(r.flat[:self.mesh.nNodes_owned]))) assert self.coefficients.massConservationError == fabs( globalSum(r[:self.mesh.nNodes_owned].sum())) log(" Mass Conservation Error", level=3, data=self.coefficients.massConservationError) self.nonlinear_function_evaluations += 1 if self.globalResidualDummy is None: self.globalResidualDummy = np.zeros(r.shape, 'd')
def getResidual(self, u, r): import pdb import copy """ Calculate the element residuals and add in to the global residual """ r.fill(0.0) # Load the unknowns into the finite element dof for dofN, g in list(self.dirichletConditionsForceDOF[0]. DOFBoundaryConditionsDict.items()): # load the BC valu # Load the unknowns into the finite element dof u[self.offset[0] + self.stride[0] * dofN] = g( self.dirichletConditionsForceDOF[0].DOFBoundaryPointDict[dofN], self.timeIntegration.t) self.setUnknowns(u) self.Aij[:, :, self.added_mass_i] = 0.0 self.addedMass.calculateResidual( # element self.u[0].femSpace.elementMaps.psi, self.u[0].femSpace.elementMaps.grad_psi, self.mesh.nodeArray, self.mesh.elementNodesArray, self.elementQuadratureWeights[('u', 0)], self.u[0].femSpace.psi, self.u[0].femSpace.grad_psi, self.u[0].femSpace.psi, self.u[0].femSpace.grad_psi, # element boundary self.u[0].femSpace.elementMaps.psi_trace, self.u[0].femSpace.elementMaps.grad_psi_trace, self.elementBoundaryQuadratureWeights[('u', 0)], self.u[0].femSpace.psi_trace, self.u[0].femSpace.grad_psi_trace, self.u[0].femSpace.psi_trace, self.u[0].femSpace.grad_psi_trace, self.u[0].femSpace.elementMaps.boundaryNormals, self.u[0].femSpace.elementMaps.boundaryJacobians, # physics self.mesh.nElements_global, self.mesh.nElementBoundaries_owned, self.u[0].femSpace.dofMap.l2g, self.u[0].dof, self.coefficients.q_rho, self.offset[0], self.stride[0], r, self.mesh.nExteriorElementBoundaries_global, self.mesh.exteriorElementBoundariesArray, self.mesh.elementBoundaryElementsArray, self.mesh.elementBoundaryLocalElementBoundariesArray, self.mesh.elementBoundaryMaterialTypes, self.Aij, self.added_mass_i, self.barycenters, self.flags_rigidbody) # sum of residual should be zero # but it is sometimes not exactly zero with certain meshes in parallel # hack comm = Comm.get().comm.tompi4py() if comm.size > 1: r_sum_local = np.sum(r[:self.mesh.nNodes_owned]) r_sum_global = comm.reduce(r_sum_local, op=MPI.SUM, root=0) if comm.rank == 0: r[0] -= r_sum_global logEvent('R SUM: local: {r_sum_local} global: {r_sum_global}'. format(r_sum_local=r_sum_local, r_sum_global=r_sum_global)) logEvent('ACCELERATION INDEX: {id}'.format(id=self.added_mass_i)) # end hack for k in range(self.Aij.shape[0]): for j in range(self.Aij.shape[2]): self.Aij[k, j, self.added_mass_i] = globalSum( self.Aij[k, j, self.added_mass_i]) for i, flag in enumerate(self.flags_rigidbody): if flag == 1: numpy.set_printoptions(precision=2, linewidth=160) logEvent("Added Mass Tensor for rigid body i" + repr(i)) logEvent("Aij = \n" + str(self.Aij[i])) for dofN, g in list(self.dirichletConditionsForceDOF[0]. DOFBoundaryConditionsDict.items()): r[self.offset[0] + self.stride[0] * dofN] = self.u[0].dof[dofN] - \ g(self.dirichletConditionsForceDOF[0].DOFBoundaryPointDict[dofN], self.timeIntegration.t) logEvent("Global residual", level=9, data=r) self.nonlinear_function_evaluations += 1
def getResidual(self, u, r): import pdb import copy """ Calculate the element residuals and add in to the global residual """ r.fill(0.0) try: self.isActiveDOF[:] = 0.0 except AttributeError: self.isActiveDOF = np.zeros_like(r) #Load the unknowns into the finite element dof self.setUnknowns(u) #no flux boundary conditions argsDict = cArgumentsDict.ArgumentsDict() argsDict["mesh_trial_ref"] = self.u[0].femSpace.elementMaps.psi argsDict["mesh_grad_trial_ref"] = self.u[ 0].femSpace.elementMaps.grad_psi argsDict["mesh_dof"] = self.mesh.nodeArray argsDict["mesh_l2g"] = self.mesh.elementNodesArray argsDict["dV_ref"] = self.elementQuadratureWeights[('u', 0)] argsDict["u_trial_ref"] = self.u[0].femSpace.psi argsDict["u_grad_trial_ref"] = self.u[0].femSpace.grad_psi argsDict["u_test_ref"] = self.u[0].femSpace.psi argsDict["u_grad_test_ref"] = self.u[0].femSpace.grad_psi argsDict["elementDiameter"] = self.mesh.elementDiametersArray argsDict["cfl"] = self.q[('cfl', 0)] argsDict["Ct_sge"] = self.shockCapturing.shockCapturingFactor argsDict["sc_uref"] = self.coefficients.sc_uref argsDict["sc_alpha"] = self.coefficients.sc_beta argsDict["useMetrics"] = self.coefficients.useMetrics argsDict["mesh_trial_trace_ref"] = self.u[ 0].femSpace.elementMaps.psi_trace argsDict["mesh_grad_trial_trace_ref"] = self.u[ 0].femSpace.elementMaps.grad_psi_trace argsDict["dS_ref"] = self.elementBoundaryQuadratureWeights[('u', 0)] argsDict["u_trial_trace_ref"] = self.u[0].femSpace.psi_trace argsDict["u_grad_trial_trace_ref"] = self.u[0].femSpace.grad_psi_trace argsDict["u_test_trace_ref"] = self.u[0].femSpace.psi_trace argsDict["u_grad_test_trace_ref"] = self.u[0].femSpace.grad_psi_trace argsDict["normal_ref"] = self.u[0].femSpace.elementMaps.boundaryNormals argsDict["boundaryJac_ref"] = self.u[ 0].femSpace.elementMaps.boundaryJacobians argsDict["nElements_global"] = self.mesh.nElements_global argsDict["u_l2g"] = self.u[0].femSpace.dofMap.l2g argsDict["u_dof"] = self.u[0].dof argsDict["sd_rowptr"] = self.coefficients.sdInfo[(0, 0)][0] argsDict["sd_colind"] = self.coefficients.sdInfo[(0, 0)][1] argsDict["q_a"] = self.q[('a', 0, 0)] argsDict["q_v"] = self.q[('df', 0, 0)] argsDict["q_r"] = self.q[('r', 0)] argsDict["lag_shockCapturing"] = self.shockCapturing.lag argsDict[ "shockCapturingDiffusion"] = self.shockCapturing.shockCapturingFactor argsDict["q_numDiff_u"] = self.shockCapturing.numDiff[0] argsDict["q_numDiff_u_last"] = self.shockCapturing.numDiff_last[0] argsDict["offset_u"] = self.offset[0] argsDict["stride_u"] = self.stride[0] argsDict["globalResidual"] = r argsDict[ "nExteriorElementBoundaries_global"] = self.mesh.nExteriorElementBoundaries_global argsDict[ "exteriorElementBoundariesArray"] = self.mesh.exteriorElementBoundariesArray argsDict[ "elementBoundaryElementsArray"] = self.mesh.elementBoundaryElementsArray argsDict[ "elementBoundaryLocalElementBoundariesArray"] = self.mesh.elementBoundaryLocalElementBoundariesArray argsDict["ebqe_a"] = self.ebqe[('a', 0, 0)] argsDict["ebqe_v"] = self.ebqe[('df', 0, 0)] argsDict["isDOFBoundary_u"] = self.numericalFlux.isDOFBoundary[0] argsDict["ebqe_bc_u_ext"] = self.numericalFlux.ebqe[('u', 0)] argsDict["isDiffusiveFluxBoundary_u"] = self.ebqe[( 'diffusiveFlux_bc_flag', 0, 0)] argsDict["isAdvectiveFluxBoundary_u"] = self.ebqe[( 'advectiveFlux_bc_flag', 0)] argsDict["ebqe_bc_flux_u_ext"] = self.ebqe[('diffusiveFlux_bc', 0, 0)] argsDict["ebqe_bc_advectiveFlux_u_ext"] = self.ebqe[( 'advectiveFlux_bc', 0)] argsDict["ebqe_penalty_ext"] = self.ebqe['penalty'] argsDict["eb_adjoint_sigma"] = self.numericalFlux.boundaryAdjoint_sigma argsDict["embeddedBoundary"] = self.coefficients.embeddedBoundary argsDict[ "embeddedBoundary_penalty"] = self.coefficients.embeddedBoundary_penalty argsDict[ "embeddedBoundary_ghost_penalty"] = self.coefficients.embeddedBoundary_ghost_penalty argsDict[ "embeddedBoundary_sdf_nodes"] = self.coefficients.embeddedBoundary_sdf_nodes argsDict["embeddedBoundary_sdf"] = self.q['embeddedBoundary_sdf'] argsDict["embeddedBoundary_normal"] = self.q['embeddedBoundary_normal'] argsDict["embeddedBoundary_u"] = self.q['embeddedBoundary_u'] argsDict["isActiveDOF"] = self.isActiveDOF self.adr.calculateResidual(argsDict) self.u[0].dof[:] = np.where(self.isActiveDOF == 1.0, self.u[0].dof, 0.0) r *= self.isActiveDOF log("Global residual", level=9, data=r) self.coefficients.massConservationError = fabs( globalSum(sum(r.flat[:self.mesh.nElements_owned]))) log(" Mass Conservation Error", level=3, data=self.coefficients.massConservationError) self.nonlinear_function_evaluations += 1