Projection Utilities and Diagnostics
Specialized field projection and volume operations.
LowLevelFEM.projectScalarField — FunctionprojectScalarField(pp::Union{ScalarField,Vector{ScalarField}}; from="", to="", gap=false, binSize=0.7)
projectScalarField(p::Union{ScalarField,Vector{ScalarField}}; from="", to="", gap=false, binSize=0.7)Projects a scalar field defined on a 2D surface onto the nodes of another mesh (typically a 3D volume or a parallel surface), using a robust AABB-based spatial binning algorithm.
This function is primarily intended for use in the Reynolds equation solver, where a pressure field defined on a lubricating surface must be transferred to another surface or to the surrounding 3D mesh.
Functionality
The projection is performed by:
- Collecting all 2D finite elements belonging to the physical group
from. - Assigning each source element to all spatial bins intersected by its axis-aligned bounding box (AABB) in the (x,y) plane.
- Assigning target nodes (from the physical group
to) to spatial bins based on their (x,y) coordinates. - For each target node, testing candidate source elements from the same bin:
- computing local coordinates using Gmsh,
- performing an inside-element test (triangular or quadrilateral),
- interpolating the scalar field using Gmsh-provided Lagrange basis functions.
The algorithm is deterministic, robust with respect to bin size, and works for arbitrary element order supported by Gmsh.
Arguments
p::ScalarFieldScalar field defined on the source surface (from). In the Reynolds context, this typically represents the pressure field.
Keyword Arguments
from::StringName of the physical group defining the source 2D surface on which the scalar fieldpis defined.to::StringName of the physical group defining the target mesh (surface or volume) whose nodes receive the projected values.gap::Bool = falseIftrue, the source surface nodes are temporarily projected onto the z = 0 plane during the projection.This option is useful in Reynolds-type lubrication problems, where:
- the height of the lubricat is defined on a geometrically curved upper surface,
- but the projection should be performed purely in (x,y) coordinates.
After the projection, the original node coordinates are restored.
binSize::Real = 0.7Controls the spatial bin size relative to the smallest source element size.Smaller values increase the number of bins (finer spatial partitioning), potentially improving performance for large meshes.
Due to the AABB-based binning strategy, correctness does not depend on the bin size; this parameter only affects performance.
Returns
ScalarFieldorVector{ScalarField}A new scalar field(s) defined on the target mesh nodes, containing the interpolated values ofp.
Notes
- This function relies exclusively on the Gmsh API for element localization and basis function evaluation; no custom shape functions are implemented.
- Both triangular and quadrilateral elements are supported, for arbitrary polynomial order.
- The AABB-based binning guarantees that no valid node–element associations are missed, even for small bin sizes or highly distorted elements.
- The function is optimized for single-threaded execution; parallel scaling may be limited by Gmsh API overhead.
Typical Use Case (Reynolds Equation)
- Solve the Reynolds equation on a lubricating surface (
from), obtaining a pressure fieldp. - Project the pressure field onto a surrounding 3D mesh (
to) for use in structural, thermal, or multiphysics coupling.
LowLevelFEM.fieldsToVolume — FunctionfieldsToVolume(p0::Union{ScalarField,Vector{ScalarField}})Project lubricant-surface scalar field(s) to the configured lubricant volume.
Arguments
p0: OneScalarFieldor a vector ofScalarFields defined on the source surface.
Returns
Vector{ScalarField}: Elementwise scalar fields onmodel.geometry.nameVolume.
Example
pv = fieldsToVolume(p_surface)Interactive diagnostics
LowLevelFEM.DebugTools.@showfields — Macro@showfields exprEvaluate expr once and print its type, field names and current field values. Return nothing; the value must support structural field access.
LowLevelFEM.DebugTools.@showstruct — Macro@showstruct exprEvaluate expr once and print its type plus field names, declared types and current values. Return nothing.
LowLevelFEM.DebugTools.@showdef — Macro@showdef exprEvaluate expr once and print a structural summary of its type: field names and declared field types, without current values. Return nothing.
LowLevelFEM.DebugTools.@showtype — Macro@showtype exprEvaluate expr once and print its type and total reachable object size from Base.summarysize when available. Return nothing; this is not array shape.
LowLevelFEM.DebugTools.@showmem — Macro@showmem exprEvaluate expr with @timed, print elapsed milliseconds and allocated bytes, and return the expression result. First-call compilation is included; this single sample is not a statistical benchmark.
LowLevelFEM.DebugTools.@showmethods — Macro@showmethods exprEvaluate a callable expression once and print its available methods and signatures. Return nothing.
LowLevelFEM.DebugTools.@disp — Macro@disp exprEvaluate expr once and display its source text followed by its string value. The macro returns the result of display (normally nothing).
LowLevelFEM.DebugTools.@showsize — Macro@showsize exprEvaluate expr once and print its total reachable memory from Base.summarysize, using B/kB/MB/GB with factors of 1024. Return nothing. This reports object storage, not allocations during evaluation.
Bundled Gmsh module
The re-exported module provides access to the bundled Gmsh API. The full external API is maintained in the Gmsh documentation, rather than duplicated in this package's reference.
See the Gmsh reference manual for the external API.