From fb286180a0ac6cb353de3fc672b7aa6fe955ae72 Mon Sep 17 00:00:00 2001 From: aradermacher Date: Fri, 13 Oct 2023 08:26:08 +0200 Subject: [PATCH 1/9] create solid from ahpe - still not working --- amworkflow/meshing/meshing.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/amworkflow/meshing/meshing.py b/amworkflow/meshing/meshing.py index e6eea79..6560da7 100644 --- a/amworkflow/meshing/meshing.py +++ b/amworkflow/meshing/meshing.py @@ -69,7 +69,8 @@ def create( assert step_file.is_file(), f"Step file {step_file} does not exist." shape = read_step_file(filename=str(step_file)) - solid = None # TODO: convert shape to solid + solid = occ_helpers.solid_maker(shape) + assert isinstance(solid, TopoDS_Solid), "Must be TopoDS_Shape object to mesh." gmsh.initialize() From 2d73b7ae30bc7cb1ea76ad1cef7edab5f6f6d5d5 Mon Sep 17 00:00:00 2001 From: Yuxiang Date: Tue, 17 Oct 2023 11:40:08 +0200 Subject: [PATCH 2/9] Gmsh works now. Still need multithread option --- amworkflow/meshing/meshing.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/amworkflow/meshing/meshing.py b/amworkflow/meshing/meshing.py index 6560da7..2fbe894 100644 --- a/amworkflow/meshing/meshing.py +++ b/amworkflow/meshing/meshing.py @@ -87,9 +87,8 @@ def create( model = gmsh.model() threads_count = multiprocessing.cpu_count() - gmsh.option.setNumber("General.NumThreads", threads_count) - # model.add(model_name) # TODO: required? - + # gmsh.option.setNumber("General.NumThreads", threads_count) # FIX: Conflict with doit. Will looking for solutions. + # model.add(model_name) # TODO: required? Not necessarily but perhaps for output .msh layers = model.occ.importShapesNativePointer(int(geo.this), highestDimOnly=True) model.occ.synchronize() for layer in layers: @@ -114,6 +113,6 @@ def create( file.write_meshtags(facet_markers) if out_vtk: - gmsh.write(out_vtk) + gmsh.write(str(out_vtk)) return From ecdf461c5cda6286295d8de02b5c662e835771ae Mon Sep 17 00:00:00 2001 From: aradermacher Date: Wed, 18 Oct 2023 09:50:38 +0200 Subject: [PATCH 3/9] add git action --- .github/workflows/wall.yml | 52 +++++++++++++++++++++++++++++++++++ amworkflow/meshing/meshing.py | 24 ++++++++-------- 2 files changed, 65 insertions(+), 11 deletions(-) create mode 100644 .github/workflows/wall.yml diff --git a/.github/workflows/wall.yml b/.github/workflows/wall.yml new file mode 100644 index 0000000..f01e641 --- /dev/null +++ b/.github/workflows/wall.yml @@ -0,0 +1,52 @@ +# This workflow will install the environment, run the example/Wall +name: wall + +on: + push: + branches-ignore: + + # Allows you to run this workflow manually from the Actions tab + workflow_dispatch: + +env: + CACHE_NUMBER: 1 # increase to reset cache manually + +jobs: + tests: + runs-on: ubuntu-latest + + steps: + - name: checkout repo content + uses: actions/checkout@v2 + - name: Setup Mambaforge + uses: conda-incubator/setup-miniconda@v2 + with: + miniforge-variant: Mambaforge + miniforge-version: latest + activate-environment: amworkflow + use-mamba: true + + - name: Set cache date + run: echo "DATE=$(date +'%Y%m%d')" >> $GITHUB_ENV + + - uses: actions/cache@v2 + with: + path: "/usr/share/miniconda3/envs/amworkflow" + key: conda-${{ hashFiles('environment.yml') }}-${{ env.DATE }}-${{ env.CACHE_NUMBER }} + id: cache + + - name: Update environment + run: mamba env update -n amworkflow -f environment.yml + if: steps.cache.outputs.cache-hit != 'true' + + - name: Install package + run: git clone https://github.com/tpaviot/pythonocc-utils.git && pip install ./pythonocc-utils + + - name: Install amworkflow + run: python -m pip install . + + - name: Run test_am4 + shell: bash -l {0} #new shell + run: | + doit -f examples/wall/dodo_wall.py + diff --git a/amworkflow/meshing/meshing.py b/amworkflow/meshing/meshing.py index 2fbe894..1084852 100644 --- a/amworkflow/meshing/meshing.py +++ b/amworkflow/meshing/meshing.py @@ -88,7 +88,7 @@ def create( model = gmsh.model() threads_count = multiprocessing.cpu_count() # gmsh.option.setNumber("General.NumThreads", threads_count) # FIX: Conflict with doit. Will looking for solutions. - # model.add(model_name) # TODO: required? Not necessarily but perhaps for output .msh + # model.add("model name") # TODO: required? Not necessarily but perhaps for output .msh layers = model.occ.importShapesNativePointer(int(geo.this), highestDimOnly=True) model.occ.synchronize() for layer in layers: @@ -101,18 +101,20 @@ def create( phy_gp = model.getPhysicalGroups() model_name = model.get_current() - # save - msh, cell_markers, facet_markers = gmshio.model_to_mesh(model, MPI.COMM_SELF, 0) - msh.name = model_name - cell_markers.name = f"{msh.name}_cells" - facet_markers.name = f"{msh.name}_facets" - with XDMFFile(msh.comm, out_xdmf, "w") as file: - file.write_mesh(msh) - file.write_meshtags(cell_markers) - msh.topology.create_connectivity(msh.topology.dim - 1, msh.topology.dim) - file.write_meshtags(facet_markers) + # # save + # msh, cell_markers, facet_markers = gmshio.model_to_mesh(model, MPI.COMM_SELF, 0) + # msh.name = model_name + # cell_markers.name = f"{msh.name}_cells" + # facet_markers.name = f"{msh.name}_facets" + # with XDMFFile(msh.comm, out_xdmf, "w") as file: + # file.write_mesh(msh) + # file.write_meshtags(cell_markers) + # msh.topology.create_connectivity(msh.topology.dim - 1, msh.topology.dim) + # file.write_meshtags(facet_markers) if out_vtk: gmsh.write(str(out_vtk)) + gmsh.write(str(out_vtk).replace('.vtk', '.msh')) # additional msh output for debugging + return From d1b3f03568567e041d177b0192bf3f54906e51d0 Mon Sep 17 00:00:00 2001 From: aradermacher Date: Wed, 18 Oct 2023 09:56:16 +0200 Subject: [PATCH 4/9] fix bug in action --- .github/workflows/wall.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/wall.yml b/.github/workflows/wall.yml index f01e641..ae162d0 100644 --- a/.github/workflows/wall.yml +++ b/.github/workflows/wall.yml @@ -45,8 +45,8 @@ jobs: - name: Install amworkflow run: python -m pip install . - - name: Run test_am4 + - name: run dodo_wall shell: bash -l {0} #new shell run: | - doit -f examples/wall/dodo_wall.py + doit -f examples/Wall/dodo_wall.py From ed4389e5534f6ea94e5998d3c80c521af1619de8 Mon Sep 17 00:00:00 2001 From: aradermacher Date: Wed, 18 Oct 2023 10:05:55 +0200 Subject: [PATCH 5/9] add xdmf stuff --- amworkflow/meshing/meshing.py | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/amworkflow/meshing/meshing.py b/amworkflow/meshing/meshing.py index 1084852..77f358e 100644 --- a/amworkflow/meshing/meshing.py +++ b/amworkflow/meshing/meshing.py @@ -101,16 +101,16 @@ def create( phy_gp = model.getPhysicalGroups() model_name = model.get_current() - # # save - # msh, cell_markers, facet_markers = gmshio.model_to_mesh(model, MPI.COMM_SELF, 0) - # msh.name = model_name - # cell_markers.name = f"{msh.name}_cells" - # facet_markers.name = f"{msh.name}_facets" - # with XDMFFile(msh.comm, out_xdmf, "w") as file: - # file.write_mesh(msh) - # file.write_meshtags(cell_markers) - # msh.topology.create_connectivity(msh.topology.dim - 1, msh.topology.dim) - # file.write_meshtags(facet_markers) + # save + msh, cell_markers, facet_markers = gmshio.model_to_mesh(model, MPI.COMM_SELF, 0) + msh.name = model_name + cell_markers.name = f"{msh.name}_cells" + facet_markers.name = f"{msh.name}_facets" + with XDMFFile(msh.comm, out_xdmf, "w") as file: + file.write_mesh(msh) + file.write_meshtags(cell_markers) + msh.topology.create_connectivity(msh.topology.dim - 1, msh.topology.dim) + file.write_meshtags(facet_markers) if out_vtk: gmsh.write(str(out_vtk)) From 5b0bd200a945c6447ef629f8812892a221805a56 Mon Sep 17 00:00:00 2001 From: Yuxiang He <102924717+YuXHe15@users.noreply.github.com> Date: Wed, 18 Oct 2023 10:13:58 +0200 Subject: [PATCH 6/9] Update environment.yml --- environment.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/environment.yml b/environment.yml index 181f090..7f0d56a 100644 --- a/environment.yml +++ b/environment.yml @@ -9,7 +9,7 @@ dependencies: - pandas - sqlite - numpy - - fenics-dolfinx + - fenics-dolfinx=0.6.0 - mpich - pyvista - pip @@ -19,4 +19,4 @@ dependencies: - pyqt5 - sphinx - sqlalchemy - - ruamel-yaml \ No newline at end of file + - ruamel-yaml From 63e425a44e0dc37ec92dc7217f539323276c2aeb Mon Sep 17 00:00:00 2001 From: aradermacher Date: Wed, 18 Oct 2023 11:46:23 +0200 Subject: [PATCH 7/9] workaround for xdmf export --- amworkflow/meshing/meshing.py | 50 +++++++++++++++++++++++++++-------- environment.yml | 1 + 2 files changed, 40 insertions(+), 11 deletions(-) diff --git a/amworkflow/meshing/meshing.py b/amworkflow/meshing/meshing.py index 77f358e..940a3f9 100644 --- a/amworkflow/meshing/meshing.py +++ b/amworkflow/meshing/meshing.py @@ -2,6 +2,8 @@ import typing from pathlib import Path +import meshio + import gmsh import multiprocessing from OCC.Core.TopoDS import TopoDS_Solid @@ -101,20 +103,46 @@ def create( phy_gp = model.getPhysicalGroups() model_name = model.get_current() - # save - msh, cell_markers, facet_markers = gmshio.model_to_mesh(model, MPI.COMM_SELF, 0) - msh.name = model_name - cell_markers.name = f"{msh.name}_cells" - facet_markers.name = f"{msh.name}_facets" - with XDMFFile(msh.comm, out_xdmf, "w") as file: - file.write_mesh(msh) - file.write_meshtags(cell_markers) - msh.topology.create_connectivity(msh.topology.dim - 1, msh.topology.dim) - file.write_meshtags(facet_markers) + # # save + # msh, cell_markers, facet_markers = gmshio.model_to_mesh(model, MPI.COMM_SELF, 0) + # msh.name = model_name + # cell_markers.name = f"{msh.name}_cells" + # facet_markers.name = f"{msh.name}_facets" + # with XDMFFile(msh.comm, out_xdmf, "w") as file: + # file.write_mesh(msh) + # file.write_meshtags(cell_markers) + # msh.topology.create_connectivity(msh.topology.dim - 1, msh.topology.dim) + # file.write_meshtags(facet_markers) + + #workaround for since gmshio.model_to_mesh is not working + out_msh = out_xdmf.with_suffix(".msh") + gmsh.write(str(out_msh)) + msh = meshio.read(out_msh) + mesh = self.create_mesh(msh, "tetra") + meshio.write(out_xdmf, mesh) if out_vtk: gmsh.write(str(out_vtk)) - gmsh.write(str(out_vtk).replace('.vtk', '.msh')) # additional msh output for debugging return + + def create_mesh(self, mesh, cell_type: str, prune_z: bool = False) -> meshio.Mesh: + """Convert msh file to xdmf file for fenic + based on https://jsdokken.com/dolfinx-tutorial/chapter3/subdomains.html?highlight=read_mesh + + Args: + mesh: + cell_type: + prune_z: + + Returns: + + """ + cells = mesh.get_cells_type(cell_type) + cell_data = mesh.get_cell_data("gmsh:physical", cell_type) + points = mesh.points[:, :2] if prune_z else mesh.points + out_mesh = meshio.Mesh( + points=points, cells={cell_type: cells}, cell_data={"name_to_read": [cell_data]} + ) + return out_mesh \ No newline at end of file diff --git a/environment.yml b/environment.yml index 7f0d56a..3366712 100644 --- a/environment.yml +++ b/environment.yml @@ -10,6 +10,7 @@ dependencies: - sqlite - numpy - fenics-dolfinx=0.6.0 + - meshio - mpich - pyvista - pip From 4eb6cc25867a394480608ff98a67c71d35688fe3 Mon Sep 17 00:00:00 2001 From: aradermacher Date: Wed, 18 Oct 2023 11:51:30 +0200 Subject: [PATCH 8/9] add doc strings --- amworkflow/meshing/meshing.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/amworkflow/meshing/meshing.py b/amworkflow/meshing/meshing.py index 940a3f9..0fbc367 100644 --- a/amworkflow/meshing/meshing.py +++ b/amworkflow/meshing/meshing.py @@ -128,16 +128,16 @@ def create( return def create_mesh(self, mesh, cell_type: str, prune_z: bool = False) -> meshio.Mesh: - """Convert msh file to xdmf file for fenic + """Convert meshio mesh to fenics compatible mesh. based on https://jsdokken.com/dolfinx-tutorial/chapter3/subdomains.html?highlight=read_mesh Args: - mesh: - cell_type: - prune_z: + mesh: Mesh read by meshio from msh file (meshio.read(file_msh)). + cell_type: Type of cell to be meshed (e.g. 'tetra','triangle' ...). + prune_z: True for 2D meshes - removes z coordinate. Returns: - + out_mesh: Mesh which can be saved as xdmf file. (meshio.write(file_xdmf, out_mesh)) """ cells = mesh.get_cells_type(cell_type) cell_data = mesh.get_cell_data("gmsh:physical", cell_type) From 907511831a50b6475d3a8ea65d99084ee9916a39 Mon Sep 17 00:00:00 2001 From: aradermacher Date: Wed, 18 Oct 2023 11:59:01 +0200 Subject: [PATCH 9/9] change enviroemnet python version --- environment.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/environment.yml b/environment.yml index 3366712..52a2e40 100644 --- a/environment.yml +++ b/environment.yml @@ -4,7 +4,7 @@ channels: - defaults dependencies: - pythonocc-core=7.7.0 - - python=3.10 + - python >= 3.10 - doit - pandas - sqlite