Example #1
0
def adaptMesh(geom, v, t, b, nE, metric, diameter=None):
    '''
    Adapt mesh with a metric defined on vertices
    '''
    assert metric.shape == (v.shape[0], 2, 2)
    # compute initial metric
    c, d = centerDiameter(geom)
    if diameter is not None: d = diameter
    m = (((v-c)**2).sum(1) + 5*d**2)**-2
    # adjust diagonal for positive definiteness and limit anisotropy
    mxx, myy, mxy = metric[:,0,0], metric[:,1,1], metric[:,0,1]
    mMin = (mxx + myy) / 2. - sqrt((mxx - myy)**2 / 4. + mxy**2)
    mMax = (mxx + myy) / 2. + sqrt((mxx - myy)**2 / 4. + mxy**2)
    mAdjust = maximum(mMax.max() * 1E-12, mMax*.001 - mMin)
    mxx += mAdjust
    myy += mAdjust
    mMin += mAdjust
    mMax += mAdjust
    # adjust length ratio 1,000,000,000:1
    maxOverMin = mMax.max() / mMax.min()
    expFactor = minimum(1, log10(1E9) / log10(maxOverMin))
    multFactor = mMax**(expFactor-1)
    m *= multFactor
    # combine
    m = transpose([m * mxx, m * myy, m * mxy])
    return _ani.mbaMesh(v, t, b, nE, m)
Example #2
0
def initMesh(geom, nE, diameter=None):
    '''
    Generate mesh with a simple metric
    '''
    c, d = centerDiameter(geom)
    if diameter is not None: d = diameter
    v, t, b = _ani.aftMesh(geom, d)
    # compute initial metric
    metric = (((v-c)**2).sum(1) + 5*d**2)**-2
    metric = transpose([metric, metric, metric * 0])
    return _ani.mbaMesh(v, t, b, nE, metric)