NVIDIA / warp

A Python framework for high performance GPU simulation and graphics

Home Page:https://nvidia.github.io/warp/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Are non-linear fem problems supported?

zhiqiang-git opened this issue · comments

Hi, thanks for this wonderful job.
I just want to ask that whether non-linear fem problems are supported by warp.fem package?
Thanks a lot if you can reply.

Hi zhiqiang, there is support for non-linear fem problems but there is a bit of manual work involved, as you need to provide the non-linear optimizer (e.g. Newton loop) and assemble the linear (gradient) and bilinear (hessian) forms at each iteration.

For instance, here is how one might implement the forces and hessian for a Neo-Hookean-style energy by linearizing around a current displacement field u_cur:

@wp.func
def dJ_dS(F: wp.mat33):
    Ft = wp.transpose(F)
    return wp.mat33(
        wp.cross(Ft[1], Ft[2]), wp.cross(Ft[2], Ft[0]), wp.cross(Ft[0], Ft[1])
    )

@wp.func
def nh_stress(F: wp.mat33, lame: wp.vec2):
    J = wp.determinant(F)
    gamma = 1.0 + lame[1] / lame[0]

    return lame[1] * F + lame[0] * (J - gamma) * dJ_dS(F)


@integrand
def nh_hessian_gauss_newton(F: wp.mat33, tau: wp.mat33, sig: wp.mat33, lame: wp.vec2):
    dJ_dS_s = dJ_dS(F)

    dpsi_dpsi = lame[1] * wp.ddot(tau, sig) + lame[0] * wp.ddot(
        dJ_dS_s * tau, dJ_dS_s * sig
    )

    return dpsi_dpsi

@integrand
def elasticity_gradient_form(s: Sample, u_cur: Field, v_test: Field, lame: wp.vec2):
    F_cur = wp.identity(n=3, dtype=wp.float32) + fem.grad(u_cur, s)
    return wp.ddot(fem.grad(v_test, s), nh_stress(F_cur, lame))

@integrand
def elasticity_hessian_form(s: Sample, u_cur: Field, u_trial: Field, v_test: Field, lame: wp.vec2):
    F_cur = wp.identity(n=3, dtype=wp.float32) + fem.grad(u_cur, s)
    return nh_hessian_gauss_newton(F_cur, fem.grad(v_test, s), fem.grad(u_trial, s), lame)

I'll add a more complete example in the future