Back to Finite Element (MFEM)
mfem.gridfunction.fromFunction
Creates a new grid function initialized by evaluating a function at DOF locations.
Syntax
mfem.gridfunction.fromFunction(fespace, fn)
Description
Creates a new grid function initialized by evaluating a function at DOF locations. The function is evaluated at the physical coordinates of each degree of freedom (node) in the finite element space. For Lagrange elements, these are the nodal interpolation points. **Note:** This performs nodal interpolation, not L2 projection. For smoother results with non-smooth functions, consider using L2 projection methods.
Parameters
| Name | Description |
|---|---|
| fespace | - The finite element space on which to define the function |
| fn | - Function that takes coordinates [x, y?, z?] and returns a scalar value |
Returns
Promise<GridFunction>