Skip to content

Expand geometry handling in generateMeshFromGeometry() function #20

Closed

Description

@nikoscham

This issue has been added to the FEAScript roadmap for the upcoming 0.2.0 release (https://github.com/orgs/FEAScript/discussions/17). Currently, the generateMeshFromGeometry() function supports only rectangular domains. We aim to extend this functionality to support additional 2D geometries (trapezoid-shaped & ring (annulus)-shaped), enabling users to more easily create meshes for diverse simulation domains. The relevant function is located in meshGenerationScript.js (https://github.com/FEAScript/FEAScript-core/blob/main/src/mesh/meshGenerationScript.js).

Tasks

  • Implement support for trapezoid-shaped 2D domains
  • Implement support for 2D ring (annulus)-shaped domains
  • Add support for expansion ratio in mesh generation (e.g., graded mesh density along one direction)

Activity

  1. added theissue type on May 19, 2025
  2. changed the title [-]Expand geometry handling in `generateMeshFromGeometry()` function (from `meshGenerationScript.js`)[/-] [+]Expand geometry handling in `generateMeshFromGeometry()` function[/+] on May 19, 2025
  3. self-assigned this
    on May 21, 2025
  4. removed their assignment
    on Sep 16, 2025
  5. Harshalyadav commented on Sep 16, 2025

    @Harshalyadav

    Hi,
    I am interested in working on this issue and will start working on it between 30 Sep to 2nd October.

  6. nikoscham commented on Sep 16, 2025

    @nikoscham
    MemberAuthor

    Hi, I am interested in working on this issue and will start working on it between 30 Sep to 2nd October.

    Welcome to the FEAScript community Harshal (@Harshalyadav)! Thank you for your interest in contributing to the project.
    Adding support for additional 2D geometries will be a very valuable feature for the library.
    I’ll get back to you soon with some extra instructions regarding the task!

    Best regards and please also consider ⭐️ the library!
    Nikos

  7. nikoscham commented on Sep 22, 2025

    @nikoscham
    MemberAuthor

    Hi @Harshalyadav! Here are some guidelines to help you tackle this task.

    First, examine the existing code in src/mesh/meshGenerationScript.js to understand how rectangular domains are handled. The current implementation:

    • Creates a structured grid of nodes
    • Generates elements by connecting these nodes
    • Assigns proper element connectivity

    Implementation Plan

    1. Modify the Configuration Structure
    Extend setMeshConfig() to accept the new geometries as shown in the provided examples:

    // Rectangle (existing)
    model.setMeshConfig({
      meshDimension: "2D",
      elementOrder: "quadratic",
      numElementsX: 8,
      numElementsY: 4,
      geometryShape: "rectangle",  // Add this parameter
      maxX: 4,
      maxY: 2,
    });
    
    // Trapezoid (new)
    model.setMeshConfig({
      meshDimension: "2D",
      elementOrder: "quadratic",
      numElementsX: 8,
      numElementsY: 4,
      geometryShape: "trapezoid",
      shortBaseX: 1, // length of the shorter parallel side
      longBaseX: 3, // length of the longer parallel side
      maxY: 2, // height
    });
    
    // Annulus (new)
    model.setMeshConfig({
      meshDimension: "2D",
      elementOrder: "quadratic",
      numElementsR: 8, // radial elements
      numElementsTheta: 16, // angular elements
      geometryShape: "annulus",
      minR: 1, // radius of the inner boundary
      maxR: 2, // radius of the outer boundary
    });
    

    2. Implement Trapezoid Mesh Generation

    • For each row of nodes (y-coordinate), calculate the corresponding width
    • Use linear interpolation between shortBaseX and longBaseX based on y position
    • Position nodes at equidistant points along each row

    3. Implement Annulus (Ring) Mesh Generation

    • Use polar coordinates (r, θ) for node positioning
    • Convert to Cartesian coordinates (x, y) for storage

    4. Add Support for Expansion Ratio
    Implement a graded mesh density by adding an expansion ratio option:

    // For rectangle or trapezoid
    model.setMeshConfig({
      // Other parameters...
      expansionRatioX: 1.2, // values > 1 make elements larger in positive X direction
      expansionRatioY: 0.8, // values < 1 make elements smaller in positive Y direction
    });
    
    // For annulus (expansion is radial)
    model.setMeshConfig({
      // Other parameters...
      expansionRatioR: 1.2 // For annulus, this controls radial expansion
    });
    

    Please do what you can—if you cannot complete everything 100%, that’s totally fine! Just push as far as you can, and we can continue or review together.

    Thanks a lot for your work on this!

  8. agrim317 commented on Oct 19, 2025

    @agrim317

    Hi @nikoscham ,
    I’m interested in working on this issue. If it’s still open and not currently being worked on, could you please assign it to me?

  9. nikoscham commented on Oct 19, 2025

    @nikoscham
    MemberAuthor

    Hi @agrim317! Thanks for your interest in contributing to the project!
    @Harshalyadav, just checking — are you still working on this issue? If not, we can reassign it to @agrim317 to keep progress moving.

  10. Harshalyadav commented on Oct 19, 2025

    @Harshalyadav

    @nikoscham Thanks for checking! Yes, I’m still working on this issue. I’ll share an update soon.

  11. Harshalyadav commented on Oct 22, 2025

    @Harshalyadav

    @nikoscham I’ve made the necessary code changes, but I’m not sure how to properly test them. I tried following the testing steps mentioned in the contribution guide, but they didn’t seem to work for me. Could you please guide me on how to run or validate the mesh generation code locally to verify my changes?

  12. nikoscham commented on Oct 23, 2025

    @nikoscham
    MemberAuthor

    Hey @Harshalyadav! Thanks for the update.

    Well, I suppose you have prepared an HTML file with a test case (e.g. something like a variant of heat-conduction-2d-fin.html, but with a different geometry).

    In order to run it locally you should:

    1. Import the updated FEAScript library to the HTML from your local folder

    Instead of:

    import { FEAScriptModel, plotSolution, printVersion } from "https://core.feascript.com/dist/feascript.esm.js";

    Use:

    import { FEAScriptModel, plotSolution, printVersion } from "[USER_DIRECTORY]/FEAScript-core/src/index.js";

    Where [USER_DIRECTORY] is the location where you have saved the FEAScript-core folder.

    For example, in my case I use:

    import { FEAScriptModel, plotSolution, printVersion } from "../../FEAScript-core/src/index.js";

    (This means the FEAScript-core folder is two directories above where your HTML file is located)

    2. Serve files through a local web server (this is to avoid CORS + local file restriction)

    Using Python 3, navigate to the folder where you have saved the HTML file you want to test (suppose your example is the mod-heat-conduction-2d-fin.html), then run:

    python -m http.server 8000

    Then open your browser and visit:

    http://localhost:8000/mod-heat-conduction-2d-fin.html
    

    Let me know if that works for you!

  13. Harshalyadav commented on Oct 23, 2025

    @Harshalyadav

    @nikoscham Thanks for the detailed explanation!

  14. nikoscham commented on Oct 30, 2025

    @nikoscham
    MemberAuthor

    Hey @Harshalyadav. Just a reminder that Hacktoberfest is wrapping up soon (October 31st). You can always contribute after Hacktoberfest, but you might miss out on their rewards. All the best

  15. Harshalyadav commented on Oct 30, 2025

    @Harshalyadav

    Hey! Thanks for the reminder

  16. added this to the 0.2.0 milestone on Nov 20, 2025
  17. nikoscham commented on Jan 16, 2026

    @nikoscham
    MemberAuthor

    I have implemented trapezoid-shaped 2D domains by extending the existing rectangle geometry-based mesh generation with two optional parameters:

    • angleLeft (default 90)
    • angleRight (default 90)

    When both angles are 90° the mesh is a rectangle (default case).

    Example (heat conduction 2D fin) using trapezoid mesh

    // Set solver configuration
    model.setModelConfig("heatConductionScript");
    
    // Define mesh configuration
    model.setMeshConfig({
      meshDimension: "2D",
      elementOrder: "quadratic",
      numElementsX: 8,
      numElementsY: 4,
      maxX: 4,
      maxY: 2,
      angleLeft: 130,
      angleRight: 130,
    });
    
    // Define boundary conditions
    model.addBoundaryCondition("0", ["constantTemp", 200]);
    model.addBoundaryCondition("1", ["symmetry"]);
    model.addBoundaryCondition("2", ["convection", 1, 20]);
    model.addBoundaryCondition("3", ["constantTemp", 200]);
    
    // Set solver method
    model.setSolverMethod("lusolve");
    
    // Solve the problem and get the solution
    const result = model.solve();
    
    // Plot the solution as a 2D contour plot
    plotInterpolatedSolution(model, result, "contour", "resultsCanvas"); // This would not work with the simple plotSolution function
    

    This implementation addresses the trapezoidal geometry use case, which I believe covers the most common non-rectangular shape, while keeping the configuration consistent with the existing workflow. I will close this issue for now. We will revisit it if users require support for more complex geometries generated by the internal mesher or for graded mesh density.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

Type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions