### Install Meshwell using pip Source: https://github.com/simbilod/meshwell/blob/main/README.md Install the Meshwell library using pip. This command is used to add the package to your Python environment. ```bash pip install meshwell ``` -------------------------------- ### Generate Initial Mesh from XAO File Source: https://github.com/simbilod/meshwell/blob/main/docs/intro_meshwell.md Creates an initial mesh from a .xao geometry file using Meshwell's mesh function. Allows control over mesh dimension and characteristic length. Requires the meshwell.mesh module. ```python from meshwell.mesh import mesh initial_mesh = mesh( dim=2, input_file="geometry.xao", output_file="mesh.msh", default_characteristic_length=1.0, ) ``` -------------------------------- ### Object-Oriented Save/Load Files Source: https://github.com/simbilod/meshwell/blob/main/docs/usage_approaches.md This variant of the object-oriented approach demonstrates saving generated geometry and meshes to files. It allows for selective file persistence within a shared model session. ```python from meshwell.model import Model from meshwell.polysurface import PolySurface from meshwell.resolution import ThresholdField import shapely # Create shared model model = Model(filename="my_project", n_threads=4) # Define geometry inner = PolySurface( polygons=[shapely.box(2, 2, 6, 6)], physical_name="inner_region", mesh_order=1, ) outer = PolySurface( polygons=[shapely.box(0, 0, 8, 8)], physical_name="outer_region", mesh_order=2, ) # Option B: Save/load files when needed model.cad.save_to_file("geometry.xao") # Save geometry model.mesh.save_to_file("geometry.msh") # Save mesh ``` -------------------------------- ### Define PolySurface Entity and Write XAO Source: https://github.com/simbilod/meshwell/blob/main/docs/intro_meshwell.md Defines a 2D surface using Shapely and Meshwell's PolySurface, then writes it to a .xao file for the CAD stage. Requires Shapely and Meshwell CAD modules. ```python import shapely from meshwell.cad_occ import cad_occ from meshwell.occ_xao_writer import write_xao from meshwell.polysurface import PolySurface polygon = shapely.Polygon([[-5, -5], [5, -5], [5, 5], [-5, 5]]) entity = PolySurface(polygons=polygon, physical_name="my_surface", mesh_order=1) write_xao(cad_occ([entity]), "geometry.xao") ``` -------------------------------- ### Create Binary Scaling Remeshing Strategy Source: https://github.com/simbilod/meshwell/blob/main/docs/intro_meshwell.md Defines an adaptive remeshing strategy using BinaryScalingStrategy. This strategy refines the mesh based on a data field exceeding a specified threshold, with defined minimum and maximum mesh sizes. Requires the meshwell.remesh module and pre-existing data. ```python from meshwell.remesh import BinaryScalingStrategy strategy = BinaryScalingStrategy( refinement_data=data, # (N, 4) array threshold=0.5, # Consider nodes where data > 0.5 factor=0.2, # Make new mesh size 20% of original where data > threshold min_size=0.05, max_size=2.0, ) ``` -------------------------------- ### Functional CAD Generation and Meshing Source: https://github.com/simbilod/meshwell/blob/main/docs/usage_approaches.md Use this approach for isolated CAD generation and meshing operations where automatic file handling is desired. Each function creates its own GMSH model, and there is no shared state between operations. ```python from meshwell.cad_occ import cad_occ from meshwell.occ_xao_writer import write_xao from meshwell.mesh import mesh from meshwell.polysurface import PolySurface import shapely # Define geometry box1 = PolySurface( polygons=[shapely.box(0, 0, 5, 3)], physical_name="region_1", mesh_order=1, ) box2 = PolySurface( polygons=[shapely.box(-1, -1, 6, 4)], physical_name="region_2", mesh_order=2, ) # Generate CAD → automatically saves to file write_xao(cad_occ([box1, box2]), "geometry.xao") # Generate mesh → automatically loads and saves files mesh_obj = mesh( input_file="geometry.xao", output_file="geometry.msh", default_characteristic_length=0.2, dim=2 ) ``` -------------------------------- ### Object-Oriented In-Memory Processing Source: https://github.com/simbilod/meshwell/blob/main/docs/usage_approaches.md This option within the object-oriented approach processes geometry and generates meshes entirely in memory without explicit file I/O. It's useful when both CAD and Mesh operations will occur within the same session. ```python from meshwell.model import Model from meshwell.polysurface import PolySurface from meshwell.resolution import ThresholdField import shapely # Create shared model model = Model(filename="my_project", n_threads=4) # Define geometry inner = PolySurface( polygons=[shapely.box(2, 2, 6, 6)], physical_name="inner_region", mesh_order=1, ) outer = PolySurface( polygons=[shapely.box(0, 0, 8, 8)], physical_name="outer_region", mesh_order=2, ) # Option A: In-memory processing (no files) entities = model.cad.process_entities([inner, outer]) resolutions = { "inner_region": [ThresholdField(sizemin=0.05, distmax=1, sizemax=0.2)] } mesh_obj = model.mesh.process_geometry( dim=2, default_characteristic_length=0.1, resolution_specs=resolutions ) ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.