question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Evaluating local functionals

See original GitHub issue

I did again some stuff related to adaptive finite element methods.

I ended up writing stuff like this for evaluating local error estimators:

    # interior estimator 
    basis = InteriorBasis(m, e)
    hK = basis.mesh_parameters()
    xK, yK = basis.global_coordinates()

    eta_K = np.sum(hK**2 / k(xK, yK) * load_func(xK, yK)**2 * basis.dx, axis=1)

and

    # facet estimator
    fbasis = [FacetBasis(m, e, side=i) for i in [0, 1]]
    u1, du1 = fbasis[0].interpolate(u, derivative=True)
    u2, du2 = fbasis[1].interpolate(u, derivative=True)
    hE = fbasis[0].mesh_parameters()
    xE, yE = fbasis[0].global_coordinates()
    eps = 1e-6
    n = fbasis[0].normals
    xE1 = xE - eps*n[0]
    yE1 = yE - eps*n[1]
    xE2 = xE + eps*n[0]
    yE2 = yE + eps*n[1]

    eta_E = np.sum(hE / k(xE, yE) *\
                   ((k(xE1, yE1)*du1[0] - k(xE2, yE2)*du2[0])*n[0] +\
                    (k(xE1, yE1)*du1[1] - k(xE2, yE2)*du2[1])*n[1])**2 * fbasis[0].dx, axis=1)

    # add eta_E to elements
    tmp = np.zeros(m.facets.shape[1])
    np.add.at(tmp, fbasis[0].find, eta_E)
    eta_E = np.sum(0.5*tmp[m.t2f], axis=0)

This looks pretty similar to what one does in skfem.assembly.asm. Maybe we could add skfem.assembly.evaluate (or similar) for evaluating functionals.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
kinnalacommented, Nov 19, 2018

Did some quasi-cool stuff yesterday. Finally added adaptive refinement of triangular meshes.

from skfem import *
from skfem.models.poisson import laplace
import numpy as np
%matplotlib inline

m = MeshTri.init_symmetric()
m.refine(2)
e = ElementTriP1()

def load_func(x, y):
    return (x > 0.5)*(y > 0.5)

@linear_form
def load(v, dv, w):
    x, y = w.x
    return load_func(x, y) * v

def eval_estimator(m, u):    
    # interior residual
    basis = InteriorBasis(m, e)
    hK = basis.mesh_parameters()
    x, y = basis.global_coordinates()

    eta_K = np.sum(hK**2 * load_func(x, y)**2 * basis.dx, axis=1)
    
    # facet jump
    fbasis = [FacetBasis(m, e, side=i) for i in [0, 1]]
    
    u1, du1 = fbasis[0].interpolate(u, derivative=True)
    u2, du2 = fbasis[1].interpolate(u, derivative=True)
    hE = fbasis[0].mesh_parameters()
    n = fbasis[0].normals

    eta_E = np.sum(hE * ((du1[0] - du2[0])*n[0] +\
                         (du1[1] - du2[1])*n[1])**2 * fbasis[0].dx, axis=1)
    
    tmp = np.zeros(m.facets.shape[1])
    np.add.at(tmp, fbasis[0].find, eta_E)
    eta_E = np.sum(0.5*tmp[m.t2f], axis=0)
    
    return eta_K + eta_E

m.draw()

for itr in range(13):
    
    if itr > 1:
        m.refine(adaptive_theta(eval_estimator(m, u)))
        
    basis = InteriorBasis(m, e)
    
    K = asm(laplace, basis)
    f = asm(load, basis)
    u = np.zeros_like(f)
    
    I = m.interior_nodes()
    u[I] = solve(*condense(K, f, I=I))
    
m.draw()
m.plot(u, smooth=True)

This solves Poisson equation adaptively.

Note that the function eval_estimator relates to this issue.

0reactions
kinnalacommented, Feb 16, 2019

I guess this can be closed now.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Evaluation of Local Hybrid Functionals for Electric Properties
Here, we present a systematic evaluation of earlier and recent local hybrid functionals for large test sets of dipole moments and static ...
Read more >
Assessing locally range-separated hybrid functionals from a ...
We propose a non-empirical scheme based on a detailed scaling analysis with respect to a uniform coordinate scaling and on a short-range expansion...
Read more >
Local hybrid functionals: Theory, implementation, and ...
Local hybrid functionals generalize the idea of hybrid functionals in density ... This requires modified integral evaluation techniques, ...
Read more >
Assessment of a new local exchange functional OPTX
In this study, we examined the performance of the new local exchange functional OPTX which is based on the inherent non-separability of exchange ......
Read more >
5.7.1 Non-Local Correlation (NLC) Functionals
Unlike local (LSDA) and semi-local (GGA and meta-GGA) functionals, for non-local functionals evaluation of the correlation energy requires a double integral ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found