Skip to content

[QUESTION] Deformed geometry and fem.normal #614

@akrivx

Description

@akrivx

Hi,

I'm running into an error when computing vertex normal fields using fem.integrate on a deformed surface mesh.

This works fine for computing normals in the rest configuration but fails in the deformed configuration when using make_deformed_geometry() with a triangle mesh embedded in 3D.

Step Summary

I’m trying to compute the current normal field for bending forces. To do this, I use:

geo = self.u_field.make_deformed_geometry()
domain = fem.Cells(geo)
self.normals = NormalFieldSpace(geo, domain)  # see class below

Where NormalFieldSpace looks like this:

@fem.integrand
def normal_integrand(s: fem.Sample, domain: fem.Domain, v: fem.Field):
    n = fem.normal(domain, s)
    return wp.dot(v(s), n)

@wp.kernel
def normalise_vectors_kernel(v: wp.array(dtype=wp.vec3)):
    i = wp.tid()
    v[i] = wp.normalize(v[i])

def normalise_vectors(v: wp.array(dtype=wp.vec3)):
    wp.launch(normalise_vectors_kernel, dim=v.shape[0], inputs=[v])

class NormalFieldSpace:
    def __init__(self, geo, domain, degree=1):
        self.space = fem.make_polynomial_space(
            geo, degree=degree, dtype=wp.vec3,
            element_basis=fem.ElementBasis.LAGRANGE
        )
        self.test = fem.make_test(space=self.space, domain=domain)
        self.field = self.space.make_field()
        self.init_field(domain)

    def init_field(self, domain):
        fem.integrate(
            normal_integrand,
            domain=domain,
            fields={'v': self.test},
            output=self.field.dof_values,
            assembly='nodal',
        )
        normalise_vectors(self.field.dof_values)

Error

I get runtime errors like the following when computing the current normal field using a deformed geometry as shown above:

RuntimeError: Error while parsing function "cell_deformation_gradient" at warp\warp\fem\geometry\deformed_geometry.py:119:
    return self.field.eval_reference_grad_inner(cell_arg, s) + self.base.cell_deformation_gradient(
;Error while parsing function "eval_grad_inner_ref_space" at warp\warp\fem\field\nodal_field.py:128:       
    return eval_grad_inner(args, s, grad_transform)
;Error while parsing function "eval_grad_inner" at warp\warp\fem\field\nodal_field.py:121:
            grad_transform,
;Input types must be the same, got ["matrix(shape=(3, 3), dtype=<class 'warp.types.float32'>)", "matrix(shape=(3, 2), dtype=<class 'warp.types.float32'>)"]

RuntimeError: Error while parsing function "integrate_kernel_fn" at warp\warp\fem\integrate.py:730:        
            vol = domain.element_measure(domain_arg, sample)
;Error while parsing function "cell_measure" at warp\warp\fem\geometry\geometry.py:263:
    F = self.cell_deformation_gradient(args, s)
;Error while parsing function "cell_deformation_gradient" at warp\warp\fem\geometry\deformed_geometry.py:119:
    return self.field.eval_reference_grad_inner(cell_arg, s) + self.base.cell_deformation_gradient(
;Error while parsing function "eval_grad_inner_ref_space" at warp\warp\fem\field\nodal_field.py:128:       
    return eval_grad_inner(args, s, grad_transform)
;Error while parsing function "eval_grad_inner" at warp\warp\fem\field\nodal_field.py:121:
            grad_transform,
;Input types must be the same, got ["matrix(shape=(3, 3), dtype=<class 'warp.types.float32'>)", "matrix(shape=(3, 2), dtype=<class 'warp.types.float32'>)"]

Diagnosis

It seems that when using a deformed geometry built with make_deformed_geometry() over a 3D triangle mesh, the internal computations (e.g., within fem.integrate and fem.normal) try to combine a (3×3) gradient with a (3×2) one — likely due to a mismatch between the deformed and reference spaces.

Questions

  1. Is this a known issue when using make_deformed_geometry() with deformed surface meshes in 3D?
  2. Is there a better way to compute current normals over a deformed surface mesh? Keep in mind I must also compute normal gradients (thus the normal field).

Happy to share more details if needed.

Thanks,
Chris

Metadata

Metadata

Assignees

Labels

bugSomething isn't workingquestionThe issue author requires information

Type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions