Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def getJacobianNew(self, jacobian):
#import superluWrappers
#import numpy
import pdb
cfemIntegrals.zeroJacobian_CSR(self.nNonzerosInJacobian,jacobian)
if self.stiffness_matrix is None:
self.getStiffnessMatrix()
# for now force time integration
useTimeIntegration = 1
if self.timeIntegration.__class__ == TimeIntegration.NoIntegration or not self.timeTerm:
useTimeIntegration = 0
if useTimeIntegration:
alpha_bdf = self.timeIntegration.alpha_bdf
beta_bdf = self.timeIntegration.beta_bdf
else:
alpha_bdf = self.timeIntegration.dt
beta_bdf = self.timeIntegration.m_last
self.calculateJacobian( # element
dm = np.ones(self.q[('u', 0)].shape, 'd')
elementMassMatrix = np.zeros((self.mesh.nElements_global,
self.nDOF_test_element[0],
self.nDOF_trial_element[0]), 'd')
cfemIntegrals.updateMassJacobian_weak_lowmem(dm,
self.q[('w', 0)],
self.q[('w*dV_m', 0)],
elementMassMatrix)
self.MC_a = self.nzval.copy()
self.MC_global = SparseMat(self.nFreeDOF_global[0],
self.nFreeDOF_global[0],
self.nnz,
self.MC_a,
self.colind,
self.rowptr)
cfemIntegrals.zeroJacobian_CSR(self.nnz, self.MC_global)
cfemIntegrals.updateGlobalJacobianFromElementJacobian_CSR(self.l2g[0]['nFreeDOF'],
self.l2g[0]['freeLocal'],
self.l2g[0]['nFreeDOF'],
self.l2g[0]['freeLocal'],
self.csrRowIndeces[(0, 0)],
self.csrColumnOffsets[(0, 0)],
elementMassMatrix,
self.MC_global)
self.ML = np.zeros((self.nFreeDOF_global[0],), 'd')
for i in range(self.nFreeDOF_global[0]):
self.ML[i] = self.MC_a[self.rowptr[i]:self.rowptr[i + 1]].sum()
np.testing.assert_almost_equal(self.ML.sum(),
self.mesh.volume,
err_msg="Trace of lumped mass matrix should be the domain volume", verbose=True)
def getJacobian(self,jacobian):
#import superluWrappers
#import numpy
import pdb
cfemIntegrals.zeroJacobian_CSR(self.nNonzerosInJacobian,jacobian)
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
self.cterm_global[d])
# C Transpose matrices
self.cterm_transpose[d] = np.zeros((self.mesh.nElements_global,
self.nDOF_test_element[0],
self.nDOF_trial_element[0]), 'd')
self.cterm_a_transpose[d] = nzval.copy()
self.cterm_global_transpose[d] = SparseMat(self.nFreeDOF_global[0],
self.nFreeDOF_global[0],
nnz,
self.cterm_a_transpose[d],
colind,
rowptr)
cfemIntegrals.zeroJacobian_CSR(self.nnz, self.cterm_global_transpose[d])
di[:] = 0.0
di[..., d] = -1.0
cfemIntegrals.updateAdvectionJacobian_weak_lowmem(di,
self.q[('w', 0)],
self.q[('grad(w)*dV_f', 0)],
self.cterm_transpose[d]) # -int[(-di*grad(wi))*wj*dV]
cfemIntegrals.updateGlobalJacobianFromElementJacobian_CSR(self.l2g[0]['nFreeDOF'],
self.l2g[0]['freeLocal'],
self.l2g[0]['nFreeDOF'],
self.l2g[0]['freeLocal'],
self.csrRowIndeces[(0, 0)],
self.csrColumnOffsets[(0, 0)],
self.cterm_transpose[d],
self.cterm_global_transpose[d])
rowptr, colind, Cx = self.cterm_global[0].getCSRrepresentation()
rowptr, colind, Cy = self.cterm_global[1].getCSRrepresentation()
if (self.nSpace_global == 3):
rowptr, colind, Cz = self.cterm_global[2].getCSRrepresentation()
self.mesh.exteriorElementBoundariesArray,
self.mesh.interiorElementBoundariesArray,
self.ebq['x'],
self.ebq['n'],
self.ebq_global['x'],
self.ebq_global['n'])
self.u[0].femSpace.elementMaps.getInverseValuesTrace(
self.ebq['inverse(J)'], self.ebq['x'], self.ebq['hat(x)'])
self.u[0].femSpace.elementMaps.getPermutations(self.ebq['hat(x)'])
self.testSpace[0].getBasisValuesTrace(
self.u[0].femSpace.elementMaps.permutations, self.ebq['hat(x)'], self.ebq[
('w', 0)])
self.u[0].femSpace.getBasisValuesTrace(
self.u[0].femSpace.elementMaps.permutations, self.ebq['hat(x)'], self.ebq[
('v', 0)])
cfemIntegrals.calculateElementBoundaryIntegrationWeights(
self.ebq['sqrt(det(g))'], self.elementBoundaryQuadratureWeights[
('u', 0)], self.ebq[
('dS_u', 0)])
def getJacobian(self, jacobian):
cfemIntegrals.zeroJacobian_CSR(self.nNonzerosInJacobian,
jacobian)
if self.nSpace_global == 2:
self.csrRowIndeces[(0, 2)] = self.csrRowIndeces[(0, 1)]
self.csrColumnOffsets[(0, 2)] = self.csrColumnOffsets[(0, 1)]
self.csrRowIndeces[(0, 2)] = self.csrRowIndeces[(0, 1)]
self.csrColumnOffsets[(0, 2)] = self.csrColumnOffsets[(0, 1)]
self.csrRowIndeces[(1, 2)] = self.csrRowIndeces[(0, 1)]
self.csrColumnOffsets[(1, 2)] = self.csrColumnOffsets[(0, 1)]
self.csrRowIndeces[(2, 0)] = self.csrRowIndeces[(1, 0)]
self.csrColumnOffsets[(2, 0)] = self.csrColumnOffsets[(1, 0)]
self.csrRowIndeces[(2, 0)] = self.csrRowIndeces[(1, 0)]
self.csrColumnOffsets[(2, 0)] = self.csrColumnOffsets[(1, 0)]
self.csrRowIndeces[(2, 1)] = self.csrRowIndeces[(1, 0)]
self.csrColumnOffsets[(2, 1)] = self.csrColumnOffsets[(1, 0)]
self.csrRowIndeces[(2, 2)] = self.csrRowIndeces[(1, 0)]
self.csrColumnOffsets[(2, 2)] = self.csrColumnOffsets[(1, 0)]
"""
Calculate the physical location and weights of the quadrature rules
and the shape information at the quadrature points on element boundaries.
This function should be called only when the mesh changes.
"""
if self.postProcessing:
self.u[0].femSpace.elementMaps.getValuesTrace(
self.elementBoundaryQuadraturePoints, self.ebq['x'])
self.u[0].femSpace.elementMaps.getJacobianValuesTrace(
self.elementBoundaryQuadraturePoints,
self.ebq['inverse(J)'],
self.ebq['g'],
self.ebq['sqrt(det(g))'],
self.ebq['n'])
cfemIntegrals.copyLeftElementBoundaryInfo(
self.mesh.elementBoundaryElementsArray,
self.mesh.elementBoundaryLocalElementBoundariesArray,
self.mesh.exteriorElementBoundariesArray,
self.mesh.interiorElementBoundariesArray,
self.ebq['x'],
self.ebq['n'],
self.ebq_global['x'],
self.ebq_global['n'])
self.u[0].femSpace.elementMaps.getInverseValuesTrace(
self.ebq['inverse(J)'], self.ebq['x'], self.ebq['hat(x)'])
self.u[0].femSpace.elementMaps.getPermutations(self.ebq['hat(x)'])
self.testSpace[0].getBasisValuesTrace(
self.u[0].femSpace.elementMaps.permutations, self.ebq['hat(x)'], self.ebq[
('w', 0)])
self.u[0].femSpace.getBasisValuesTrace(
self.u[0].femSpace.elementMaps.permutations, self.ebq['hat(x)'], self.ebq[
def getJacobian(self, jacobian):
cfemIntegrals.zeroJacobian_CSR(self.nNonzerosInJacobian, jacobian)
self.addedMass.calculateJacobian( # 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,
def getStiffnessMatrix(self):
rowptr, colind, nzval = self.jacobian.getCSRrepresentation()
nnz = nzval.shape[-1] # number of non-zero entries in sparse matrix
self.stiffness_matrix_array = nzval.copy()
self.stiffness_matrix = SparseMat(self.nFreeDOF_global[0],
self.nFreeDOF_global[0],
nnz,
self.stiffness_matrix_array,
colind,
rowptr)
cfemIntegrals.zeroJacobian_CSR(self.nNonzerosInJacobian,
self.stiffness_matrix)
self.mcorr3p.calculateStiffnessMatrix(
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.grad_psi,
self.mesh.nElements_global,
self.csrRowIndeces[(0, 0)], self.csrColumnOffsets[(0, 0)],
self.stiffness_matrix,
self.coefficients.useMetrics,
self.coefficients.epsFactDiffusion,
self.elementDiameter,
self.mesh.nodeDiametersArray)
def getJacobian(self, jacobian):
cfemIntegrals.zeroJacobian_CSR(self.nNonzerosInJacobian,
jacobian)
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_velocity_dof"] = self.mesh.nodeVelocityArray
argsDict["MOVING_DOMAIN"] = self.MOVING_DOMAIN
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)]