def getResidual(self, u, r): import pdb import copy from proteus.flcbdfWrappers import globalSum """ 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 self.dirichletConditionsForceDOF[0].DOFBoundaryConditionsDict.iteritems(): # 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" + `i`) logEvent("Aij = \n"+str(self.Aij[i])) for dofN, g in self.dirichletConditionsForceDOF[0].DOFBoundaryConditionsDict.iteritems(): 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 from proteus.flcbdfWrappers import globalSum """ 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) self.numericalFlux.setDirichletValues(self.ebqe) # flux boundary conditions for t, g in self.fluxBoundaryConditionsObjectsDict[ 0].advectiveFluxBoundaryConditionsDict.iteritems(): self.ebqe[ ('advectiveFlux_bc', 0)][ t[0], t[1]] = g( self.ebqe[ ('x')][ t[0], t[1]], self.timeIntegration.t) self.ebqe[('advectiveFlux_bc_flag', 0)][t[0], t[1]] = 1 for t,g in self.fluxBoundaryConditionsObjectsDict[ 0].diffusiveFluxBoundaryConditionsDictDict[0].iteritems(): self.ebqe[('diffusiveFlux_bc',0,0)][t[0],t[1]] = g(self.ebqe[('x')][t[0],t[1]],self.timeIntegration.t) self.ebqe[('diffusiveFlux_bc_flag',0,0)][t[0],t[1]] = 1 if False:#self.forceStrongConditions: for dofN, g in self.dirichletConditionsForceDOF.DOFBoundaryConditionsDict.iteritems(): self.u[0].dof[dofN] = g( self.dirichletConditionsForceDOF.DOFBoundaryPointDict[dofN], self.timeIntegration.t) self.presinc.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.numericalFlux.isDOFBoundary[0], self.ebqe[('advectiveFlux_bc_flag', 0)], self.u[0].femSpace.dofMap.l2g, self.u[0].dof, self.coefficients.fluidModel.timeIntegration.alpha_bdf, self.coefficients.fluidModel.q[('velocity',0)], self.coefficients.fluidModel.coefficients.q_velocity_solid, self.coefficients.fluidModel.coefficients.q_vos, self.coefficients.fluidModel.coefficients.rho_s, self.coefficients.fluidModel.coefficients.q_rho, self.coefficients.rho_s_min, self.coefficients.rho_f_min, self.coefficients.fluidModel.ebqe[('velocity',0)], self.coefficients.fluidModel.coefficients.ebqe_velocity_solid, self.coefficients.fluidModel.coefficients.ebqe_vos, self.coefficients.fluidModel.coefficients.ebqe_rho, self.q[('u', 0)], self.q[('grad(u)', 0)], self.ebqe[('u', 0)], self.ebqe[('grad(u)', 0)], self.numericalFlux.ebqe[('u',0)], self.ebqe[('advectiveFlux', 0)], self.ebqe[('diffusiveFlux', 0, 0)], self.ebqe[('advectiveFlux_bc', 0)], 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(r[:self.mesh.nNodes_owned].sum())) log(" Mass Conservation Error", level=3, data=self.coefficients.massConservationError) self.nonlinear_function_evaluations += 1
def getResidual(self, u, r): import pdb import copy from proteus.flcbdfWrappers import globalSum """ 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 = numpy.zeros(r.shape, 'd')