def fluxDomainBoundaryIntegral(dS,nValueArray,mesh): partialSum = cfemIntegrals.fluxDomainBoundaryIntegral(mesh.nElementBoundaries_owned, mesh.elementBoundaryMaterialTypes, mesh.exteriorElementBoundariesArray, dS, nValueArray) return globalSum(partialSum)
def L1errorSFEM(quadratureWeightArray,aSolutionValueArray,nSolutionValueArray,T=None): error=0.0 range_nQuadraturePoints_element = range(aSolutionValueArray.shape[1]) for eN in range(aSolutionValueArray.shape[0]): for k in range_nQuadraturePoints_element: error += abs(aSolutionValueArray[eN,k] - nSolutionValueArray[eN,k])*quadratureWeightArray[eN,k] return globalSum(error)
def L1errorSFEM2(abs_det_J,quadratureWeightArray,aSolutionValueArray,nSolutionValueArray,T=None): error=0.0 range_nQuadraturePoints_element = range(aSolutionValueArray.shape[1]) for eN in range(aSolutionValueArray.shape[0]): for k in range_nQuadraturePoints_element: error += abs(aSolutionValueArray[eN,k] - nSolutionValueArray[eN,k])*quadratureWeightArray[k]*abs_det_J[eN,k] error = sqrt(abs(globalSum(error))) return error
def L2normSFEM(quadratureWeightArray,nSolutionValueArray): error=0.0 range_nQuadraturePoints_element = range(nSolutionValueArray.shape[1]) for eN in range(nSolutionValueArray.shape[0]): for k in range_nQuadraturePoints_element: error += (nSolutionValueArray[eN,k]**2)*quadratureWeightArray[eN,k] error = sqrt(abs(globalSum(error))) return error
def L1errorVFEM2(quadratureWeightArray,aSolutionValueArray,nSolutionValueArray,T=None): error=0.0 range_nQuadraturePoints_element = range(aSolutionValueArray.shape[1]) for eN in range(aSolutionValueArray.shape[0]): for k in range_nQuadraturePoints_element: e = numpy.sum(numpy.absolute(aSolutionValueArray[eN,k,:] - nSolutionValueArray[eN,k,:])) error += e*quadratureWeightArray[k]*abs_det_J[eN,k] return globalSum(error)
def L1errorSFEMvsAF(analyticalFunction,quadraturePointArray,quadratureWeightArray,functionValueArray,T=None): error=0.0 range_nQuadraturePoints_element = range(quadraturePointArray.shape[1]) for eN in range(quadraturePointArray.shape[0]): for k in range_nQuadraturePoints_element: AF = analyticalFunction.uOfXT(quadraturePointArray[eN,k],T) error += abs(functionValueArray[eN,k] - AF)*quadratureWeightArray[eN,k] return globalSum(error)
def scalarHeavisideDomainIntegral(dV, nValueArray, nElements=None): if nElements == None: partialSum = cfemIntegrals.scalarHeavisideDomainIntegral( dV, nValueArray, nValueArray.shape[0]) else: partialSum = cfemIntegrals.scalarHeavisideDomainIntegral( dV, nValueArray, nElements) return globalSum(partialSum)
def L1errorVFEMvsAF2(analyticalFunction,quadraturePointArray,quadratureWeightArray,functionValueArray,T=None): error=0.0 range_nQuadraturePoints_element = range(quadraturePointArray.shape[1]) for eN in range(quadraturePointArray.shape[0]): for k in range_nQuadraturePoints_element: AF = analyticalFunction.uOfXT(quadraturePointArray[eN,k],T) e1 = numpy.sum(numpy.absolute(functionValueArray[eN,k,:] - AF)) error += e1*quadratureWeightArray[k]*abs_det_J[eN,k] return globalSum(error)
def L2normSFEM(quadratureWeightArray, nSolutionValueArray): error = 0.0 range_nQuadraturePoints_element = range(nSolutionValueArray.shape[1]) for eN in range(nSolutionValueArray.shape[0]): for k in range_nQuadraturePoints_element: error += (nSolutionValueArray[eN, k]** 2) * quadratureWeightArray[eN, k] error = sqrt(abs(globalSum(error))) return error
def L2errorVFEM2(quadratureWeightArray,aSolutionValueArray,nSolutionValueArray,T=None): error=0.0 range_nQuadraturePoints_element = range(aSolutionValueArray.shape[1]) for eN in range(aSolutionValueArray.shape[0]): for k in range_nQuadraturePoints_element: e2 = numpy.inner(aSolutionValueArray[eN,k,:] - nSolutionValueArray[eN,k,:], aSolutionValueArray[eN,k,:] - nSolutionValueArray[eN,k,:]) error += e2*quadratureWeightArray[k]*abs_det_J[eN,k] error = sqrt(abs(globalSum(error))) return error
def L2errorSFEMvsAF2(analyticalFunction,quadraturePointArray,abs_det_J, quadratureWeightArray,functionValueArray,T=None): error=0.0 range_nQuadraturePoints_element = range(quadraturePointArray.shape[1]) for eN in range(quadraturePointArray.shape[0]): for k in range_nQuadraturePoints_element: AF = analyticalFunction.uOfXT(quadraturePointArray[eN,k],T) error += ((functionValueArray[eN,k] - AF)**2)*quadratureWeightArray[k]*abs_det_J[eN,k] error = sqrt(abs(globalSum(error))) return error
def L2errorSFEM_local(quadratureWeightArray,aSolutionValueArray,nSolutionValueArray,elementError,T=None): error=0.0 elementError.flat[:]=0.0 range_nQuadraturePoints_element = range(nSolutionValueArray.shape[1]) for eN in range(nSolutionValueArray.shape[0]): for k in range_nQuadraturePoints_element: elementError[eN] += ((aSolutionValueArray[eN,k] - nSolutionValueArray[eN,k])**2)*quadratureWeightArray[eN,k] error += elementError[eN] elementError[eN] = sqrt(abs(elementError[eN])) error = sqrt(abs(globalSum(error))) return error
def L2errorVFEMvsAF(analyticalFunction,quadraturePointArray,quadratureWeightArray,functionValueArray,T=None): error=0.0 range_nQuadraturePoints_element = range(quadraturePointArray.shape[1]) for eN in range(quadraturePointArray.shape[0]): for k in range_nQuadraturePoints_element: AF = analyticalFunction.uOfXT(quadraturePointArray[eN,k],T) e2 = numpy.inner(functionValueArray[eN,k,:] - AF, functionValueArray[eN,k,:] - AF) error += e2*quadratureWeightArray[eN,k] error = sqrt(abs(globalSum(error))) return error
def globalScalarDomainIntegral(abs_det_J,quadratureWeightArray,nValueArray): integral = 0.0 if useC: integral = cfemIntegrals.scalarDomainIntegral(abs_det_J,quadratureWeightArray,nValueArray) else: integral=0.0 range_nQuadraturePoints_element = range(nValueArray.shape[1]) for eN in range(nValueArray.shape[0]): for k in range_nQuadraturePoints_element: integral += nValueArray[eN,k]*quadratureWeightArray[k]*abs_det_J[eN,k] return globalSum(integral)
def L1errorSFEM(quadratureWeightArray, aSolutionValueArray, nSolutionValueArray, T=None): error = 0.0 range_nQuadraturePoints_element = range(aSolutionValueArray.shape[1]) for eN in range(aSolutionValueArray.shape[0]): for k in range_nQuadraturePoints_element: error += abs(aSolutionValueArray[eN, k] - nSolutionValueArray[eN, k]) * quadratureWeightArray[eN, k] return globalSum(error)
def scalarSmoothedHeavisideDomainIntegral(epsFact, elementDiameters, dV, nValueArray, nElements=None): if nElements == None: partialSum = cfemIntegrals.scalarSmoothedHeavisideDomainIntegral( epsFact, elementDiameters, dV, nValueArray, nValueArray.shape[0]) else: partialSum = cfemIntegrals.scalarSmoothedHeavisideDomainIntegral( epsFact, elementDiameters, dV, nValueArray, nElements) return globalSum(partialSum)
def L1errorSFEM2(abs_det_J, quadratureWeightArray, aSolutionValueArray, nSolutionValueArray, T=None): error = 0.0 range_nQuadraturePoints_element = range(aSolutionValueArray.shape[1]) for eN in range(aSolutionValueArray.shape[0]): for k in range_nQuadraturePoints_element: error += abs(aSolutionValueArray[eN, k] - nSolutionValueArray[ eN, k]) * quadratureWeightArray[k] * abs_det_J[eN, k] error = sqrt(abs(globalSum(error))) return error
def L1errorVFEMvsAF(analyticalFunction, quadraturePointArray, quadratureWeightArray, functionValueArray, T=None): error = 0.0 range_nQuadraturePoints_element = range(quadraturePointArray.shape[1]) for eN in range(quadraturePointArray.shape[0]): for k in range_nQuadraturePoints_element: AF = analyticalFunction.uOfXT(quadraturePointArray[eN, k], T) e1 = numpy.sum(numpy.absolute(functionValueArray[eN, k, :] - AF)) error += e1 * quadratureWeightArray[eN, k] return globalSum(error)
def L1errorVFEM2(quadratureWeightArray, aSolutionValueArray, nSolutionValueArray, T=None): error = 0.0 range_nQuadraturePoints_element = range(aSolutionValueArray.shape[1]) for eN in range(aSolutionValueArray.shape[0]): for k in range_nQuadraturePoints_element: e = numpy.sum( numpy.absolute(aSolutionValueArray[eN, k, :] - nSolutionValueArray[eN, k, :])) error += e * quadratureWeightArray[k] * abs_det_J[eN, k] return globalSum(error)
def scalarDomainIntegral(dV,nValueArray,nElements=None): if useC: if nElements is None: partialSum = cfemIntegrals.scalarDomainIntegral(dV,nValueArray,nValueArray.shape[0]) else: partialSum = cfemIntegrals.scalarDomainIntegral(dV,nValueArray,nElements) else: partialSum=0.0 range_nQuadraturePoints_element = range(nValueArray.shape[1]) for eN in range(nValueArray.shape[0]): for k in range_nQuadraturePoints_element: partialSum += nValueArray[eN,k]*dV[eN,k] return globalSum(partialSum)
def L2errorSFEMvsAF(analyticalFunction, quadraturePointArray, quadratureWeightArray, functionValueArray, T=None): error = 0.0 range_nQuadraturePoints_element = range(quadraturePointArray.shape[1]) for eN in range(quadraturePointArray.shape[0]): for k in range_nQuadraturePoints_element: AF = analyticalFunction.uOfXT(quadraturePointArray[eN, k], T) error += ((functionValueArray[eN, k] - AF)** 2) * quadratureWeightArray[eN, k] error = sqrt(abs(globalSum(error))) return error
def TVseminormSFEM(dofArray,l2gMap): tv = 0.0 nElements_global = l2gMap.shape[0]; nDOF_element = l2gMap.shape[1] for eN in range(nElements_global): for i in range(nDOF_element): I = l2gMap[eN,i] for j in range(i+1,nDOF_element): jj = int(fmod(j,nDOF_element)) JJ = l2gMap[eN,jj] tv+= abs(dofArray[I]-dofArray[JJ]) #neighbors on element #local dofs #elements return globalSum(tv)
def L2errorVFEM2(quadratureWeightArray, aSolutionValueArray, nSolutionValueArray, T=None): error = 0.0 range_nQuadraturePoints_element = range(aSolutionValueArray.shape[1]) for eN in range(aSolutionValueArray.shape[0]): for k in range_nQuadraturePoints_element: e2 = numpy.inner( aSolutionValueArray[eN, k, :] - nSolutionValueArray[eN, k, :], aSolutionValueArray[eN, k, :] - nSolutionValueArray[eN, k, :]) error += e2 * quadratureWeightArray[k] * abs_det_J[eN, k] error = sqrt(abs(globalSum(error))) return error
def L1errorSFEMvsAF2(analyticalFunction, quadraturePointArray, abs_det_J, quadratureWeightArray, functionValueArray, T=None): error = 0.0 range_nQuadraturePoints_element = range(quadraturePointArray.shape[1]) for eN in range(quadraturePointArray.shape[0]): for k in range_nQuadraturePoints_element: AF = analyticalFunction.uOfXT(quadraturePointArray[eN, k], T) error += abs(functionValueArray[eN, k] - AF) * quadratureWeightArray[k] * abs_det_J[eN, k] return globalSum(error)
def scalarDomainIntegral(dV, nValueArray, nElements=None): if useC: if nElements == None: partialSum = cfemIntegrals.scalarDomainIntegral( dV, nValueArray, nValueArray.shape[0]) else: partialSum = cfemIntegrals.scalarDomainIntegral( dV, nValueArray, nElements) else: partialSum = 0.0 range_nQuadraturePoints_element = range(nValueArray.shape[1]) for eN in range(nValueArray.shape[0]): for k in range_nQuadraturePoints_element: partialSum += nValueArray[eN, k] * dV[eN, k] return globalSum(partialSum)
def globalScalarDomainIntegral(abs_det_J, quadratureWeightArray, nValueArray): integral = 0.0 if useC: integral = cfemIntegrals.scalarDomainIntegral(abs_det_J, quadratureWeightArray, nValueArray) else: integral = 0.0 range_nQuadraturePoints_element = range(nValueArray.shape[1]) for eN in range(nValueArray.shape[0]): for k in range_nQuadraturePoints_element: integral += nValueArray[ eN, k] * quadratureWeightArray[k] * abs_det_J[eN, k] return globalSum(integral)
def TVseminormSFEM(dofArray, l2gMap): tv = 0.0 nElements_global = l2gMap.shape[0] nDOF_element = l2gMap.shape[1] for eN in range(nElements_global): for i in range(nDOF_element): I = l2gMap[eN, i] for j in range(i + 1, nDOF_element): jj = int(fmod(j, nDOF_element)) JJ = l2gMap[eN, jj] tv += abs(dofArray[I] - dofArray[JJ]) #neighbors on element #local dofs #elements return globalSum(tv)
def L2errorVFEMvsAF2(analyticalFunction, quadraturePointArray, abs_det_J, quadratureWeightArray, functionValueArray, T=None): error = 0.0 range_nQuadraturePoints_element = range(quadraturePointArray.shape[1]) for eN in range(quadraturePointArray.shape[0]): for k in range_nQuadraturePoints_element: AF = analyticalFunction.uOfXT(quadraturePointArray[eN, k], T) e2 = numpy.inner(functionValueArray[eN, k, :] - AF, functionValueArray[eN, k, :] - AF) error += e2 * quadratureWeightArray[k] * abs_det_J[eN, k] error = sqrt(abs(globalSum(error))) return error
def L2errorSFEM_local(quadratureWeightArray, aSolutionValueArray, nSolutionValueArray, elementError, T=None): error = 0.0 elementError.flat[:] = 0.0 range_nQuadraturePoints_element = range(nSolutionValueArray.shape[1]) for eN in range(nSolutionValueArray.shape[0]): for k in range_nQuadraturePoints_element: elementError[eN] += ( (aSolutionValueArray[eN, k] - nSolutionValueArray[eN, k])** 2) * quadratureWeightArray[eN, k] error += elementError[eN] elementError[eN] = sqrt(abs(elementError[eN])) error = sqrt(abs(globalSum(error))) return error
def wDot(x, y, h): """ Compute the parallel weighted dot product of vectors x and y using weight vector h. The weighted dot product is defined for a weight vector :math:`\mathbf{h}` as .. math:: (\mathbf{x},\mathbf{y})_h = \sum_{i} h_{i} x_{i} y_{i} All weight vector components should be positive. :param x,y,h: numpy arrays for vectors and weight :return: the weighted dot product """ return flcbdfWrappers.globalSum(numpy.sum(x * y * h))
def wDot(x,y,h): """ Compute the parallel weighted dot product of vectors x and y using weight vector h. The weighted dot product is defined for a weight vector :math:`\mathbf{h}` as .. math:: (\mathbf{x},\mathbf{y})_h = \sum_{i} h_{i} x_{i} y_{i} All weight vector components should be positive. :param x,y,h: numpy arrays for vectors and weight :return: the weighted dot product """ return flcbdfWrappers.globalSum(numpy.sum(x*y*h))
def l1Norm(x): """ Compute the parallel :math:`l_1` norm The :math:`l_1` norm of a vector :math:`\mathbf{x} \in \mathbb{R}^n` is .. math:: \| \mathbf{x} \|_{1} = \sum_{i=0} |x_i| If Python is running in parallel, then the sum is over all dimensions on all processors so that the input must not contain "ghost" entries. This implemtation works for a distributed array with no ghost components (each component must be on a single processor). :param x: numpy array of length n :return: float """ return flcbdfWrappers.globalSum(numpy.sum(numpy.abs(x)))
def l2Norm(x): """ Compute the parallel :math:`l_2` norm """ return math.sqrt(flcbdfWrappers.globalSum(numpy.dot(x, x)))
def fluxDomainBoundaryIntegralFromVector(dS, nValueArray, normal, mesh): partialSum = cfemIntegrals.fluxDomainBoundaryIntegralFromVector( mesh.nElementBoundaries_owned, mesh.elementBoundaryMaterialTypes, mesh.exteriorElementBoundariesArray, dS, nValueArray, normal) return globalSum(partialSum)
def l2Norm(x): """ Compute the parallel l_2 norm """ return numpy.sqrt(flcbdfWrappers.globalSum(numpy.dot(x,x)))
def l1Norm(x): """ Compute the parallel l_1 norm """ return flcbdfWrappers.globalSum(numpy.sum(numpy.abs(x)))
def wDot(x,y,h): """ Compute the parallel weighted dot product with weight h """ return flcbdfWrappers.globalSum(numpy.sum(x*y*h))
def l2Norm(x): """ Compute the parallel :math:`l_2` norm """ return math.sqrt(flcbdfWrappers.globalSum(numpy.dot(x,x)))
def wl1Norm(x, h): """ Compute the parallel weighted l_1 norm with weight h """ return flcbdfWrappers.globalSum(numpy.sum(numpy.abs(h * x)))
def scalarSmoothedHeavisideDomainIntegral(epsFact,elementDiameters,dV,nValueArray,nElements=None): if nElements is None: partialSum = cfemIntegrals.scalarSmoothedHeavisideDomainIntegral(epsFact,elementDiameters,dV,nValueArray,nValueArray.shape[0]) else: partialSum = cfemIntegrals.scalarSmoothedHeavisideDomainIntegral(epsFact,elementDiameters,dV,nValueArray,nElements) return globalSum(partialSum)
def scalarHeavisideDomainIntegral(dV,nValueArray,nElements=None): if nElements is None: partialSum = cfemIntegrals.scalarHeavisideDomainIntegral(dV,nValueArray,nValueArray.shape[0]) else: partialSum = cfemIntegrals.scalarHeavisideDomainIntegral(dV,nValueArray,nElements) return globalSum(partialSum)
def l2NormAvg(x): """ Compute the arithmetic averaged l_2 norm (root mean squared norm) """ scale = 1.0/flcbdfWrappers.globalSum(len(x.flat)) return math.sqrt(scale*flcbdfWrappers.globalSum(numpy.dot(x,x)))
def wl2Norm(x, h): """ Compute the parallel weighted l_2 norm with weight h """ return math.sqrt(flcbdfWrappers.globalSum(wDot(x, x, h)))
def wl2Norm(x,h): """ Compute the parallel weighted l_2 norm with weight h """ return math.sqrt(flcbdfWrappers.globalSum(wDot(x,x,h)))
def l2NormAvg(x): """ Compute the arithmetic averaged l_2 norm (root mean squared norm) """ scale = 1.0 / flcbdfWrappers.globalSum(len(x.flat)) return math.sqrt(scale * flcbdfWrappers.globalSum(numpy.dot(x, x)))
def wl1Norm(x,h): """ Compute the parallel weighted l_1 norm with weight h """ return flcbdfWrappers.globalSum(numpy.sum(numpy.abs(h*x)))