interfacegrids_gene.py 文件源码

python
阅读 32 收藏 0 点赞 0 评论 0

项目:tango 作者: LLNL 项目源码 文件源码
def extend_with_zeros_left_side(xIn, fIn, xOut, enforcePositive=False):
    """Extending a function to another domain, with zeros where it was not originally defined.

    The domains xIn and xOut should satsify xOut[0] < xIn[0] and xOut[-1] < xIn[0].  The output
    domain is "to the left" of the input domain.

    This function operates by resampling within the overlapping region, and then extending with zeros.

    Sometimes, interpolation might produce negative values when zero is the minimum for physical reasons.
        The diffusion coefficient is one example where one wants to maintain positivity.  In this case, one
        can optionally enforce positivity of the returned value by zeroing out negative values.

    Inputs:
      xIn                   independent variable on the input domain (array)
      fIn                   dependent variable on the input domain (array)
      xOut                  independent variable on the new domain (array)
      enforcePositive       (optional) If True, set any negative values to zero before returning (boolean)

    Outputs:
      fOut                  dependent variable on the new domain (array)
    """
    assert xOut[0] <= xIn[0] and xOut[-1] <= xIn[-1]
    fOut = np.zeros_like(xOut)  # initialize with zeros    
    # resample within the overlapping region
    ind = np.where(xOut > xIn[0])
    indstart = ind[0][0]
    xOutTemp = xOut[indstart:]

    interpolate = scipy.interpolate.InterpolatedUnivariateSpline(xIn, fIn)
    fOut[indstart:] = interpolate(xOutTemp)    

    # extend with zeros -- automatically performed because fOut was initialized with zeros
    if enforcePositive == True:
        ind = fOut < 0
        fOut[ind] = 0  

    return fOut


###################################################
#### Functions for extrapolation ####
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号