Giter Club home page Giter Club logo

cad_to_dagmc's People

Contributors

shimwell avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

cad_to_dagmc's Issues

Install using Conda and pip - pymoab is not included

Hi all!
I am trying to follow the installation instructions here:
https://pypi.org/project/cad-to-dagmc/

Install using Conda and pip
However, when I run a simple script

import cad_to_dagmc

I have the following error:

Traceback (most recent call last):
File "/home/marija/main.py", line 1, in
import cad_to_dagmc
File "/usr/local/bin/conda/envs/env_d/lib/python3.10/site-packages/cad_to_dagmc/init.py", line 16, in
from .core import *
File "/usr/local/bin/conda/envs/env_d/lib/python3.10/site-packages/cad_to_dagmc/core.py", line 10, in
from pymoab import core, types
ModuleNotFoundError: No module named 'pymoab'

Have anyone seen it before? Are there extra installation steps needed?

add CI using pip and building package sfrom source

CI currently uses conda but we could make one with pip and cmake

here is a start


# This CI will launch a Docker image that contains all the dependencies required
# within that image the pytest test suite is run 
# container:
#       image: continuumio/miniconda3:23.3.1-0

name: CI with install

on:
  pull_request:
    branches:
      - main
    paths-ignore:
      - 'docs/**'
      - '.gitignore'
      - '*.md'
      - 'CITATION.cff'
      - 'LICENSE.txt'
      - 'readthedocs.yml'
  push:
    branches:
      - main

jobs:
  testing:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout repository
        uses: actions/checkout@v4

      - name: install non pypi dependencies
        shell: bash
        run: |
          sudo apt-get --allow-releaseinfo-change update
          sudo apt-get update -y
          sudo apt-get upgrade -y
          sudo apt-get install -y libgl1-mesa-glx libgl1-mesa-dev libglu1-mesa-dev freeglut3-dev libosmesa6 libosmesa6-dev libgles2-mesa-dev libarchive-dev libpangocairo-1.0-0
          sudo apt install python3
          sudo apt install python3-pip
          pip install cadquery
          pip install gmsh
          pip install pymoab
          'https://bitbucket.org/fathomteam/moab/'
          https://github.com/openmc-dev/openmc/blob/develop/Dockerfile
          python -m pip install .
          python -c "import cad_to_dagmc"
          # install openmc with dagmc and 
          python -m pip install .[tests]
          pytest tests -v
          cd examples
          python create_stp_files_for_examples.py
          python cadquery_assembly.py
          python cadquery_compound.py
          python cadquery_object_and_stp_file.py
          python cadquery_text.py
          python curved_cadquery_object_to_dagmc_surface_mesh.py
          python curved_cadquery_object_to_dagmc_volume_mesh.py
          python multiple_cadquery_objects.py
          python multiple_stp_files.py
          python single_stp_file_multiple_volumes.py
          python single_cadquery_object.py
          python single_stp_file.py

``

check dagmc is enabled

openmc execuatable can be checked with

openmc.lib._dagmc_enabled():

perhaps we should add this check and warn the user

AttributeError when using export_dagmc_h5m_file

I am converting cadquery geometry to a dagmc h5m file, and I keep getting the following error:

AttributeError: 'OCP.TopoDS.TopoDS_Compound' object has no attribute '_address'

The error comes from the following lines of code in cad_to_dagmc:

gmsh, volumes = _mesh_brep(
            brep_object=imprinted_assembly.wrapped._address(),  # in memory address
            min_mesh_size=min_mesh_size,
            max_mesh_size=max_mesh_size,
            mesh_algorithm=mesh_algorithm,
        )

Has anyone seen this problem before?

I believe it must be to do with my environment - I am using github codespaces to run this. This is because when I run the exact same code on my local computer in an environment that I made following the same install order as the codespace it runs fine. My Dockerfile in the codespace installs the relevant packages like this:

RUN apt-get --yes install libeigen3-dev \
                        #   sudo  \
                          # sudo is needed during the NJOY install
                          git \
                          wget \
                          gfortran \
                          g++ \
                          mpich \
                          libmpich-dev \
                          libhdf5-serial-dev \
                          libhdf5-mpich-dev \
                          hdf5-tools \
                          imagemagick \
                          cmake \
                          # libnetcdf-dev is needed to allow NETCDF on MOAB which helps with tet meshes in OpenMC
                          libnetcdf-dev \
                          # libtbb-dev required for DAGMC
                          libtbb-dev \
                          # libglfw3-dev required for DAGMC
                          libglfw3-dev \
                          # needed for CadQuery functionality
                          libgl1-mesa-glx \
                          # needed for CadQuery functionality
                          libgl1-mesa-dev \
                          # needed for CadQuery functionality
                          libglu1-mesa-dev \
                          # needed for CadQuery functionality
                          freeglut3-dev \
                          # needed for CadQuery functionality
                          libosmesa6 \
                          # needed for CadQuery functionality
                          libosmesa6-dev \
                          # needed for CadQuery functionality
                          libgles2-mesa-dev \
                          # needed for Gmsh functionality
                          libxft2

# installing cadquery and jupyter 
RUN conda install -c conda-forge -c python python=3.10

RUN conda install mamba

RUN mamba install -y -c conda-forge "moab>=5.3.0" gmsh python-gmsh
RUN pip install cad_to_dagmc==0.6.2

RUN mamba install -c conda-forge -y "openmc=0.14.0=dagmc*nompi*"
RUN pip install openmc_data_downloader

RUN pip install cadquery

Many thanks

cadquery imprint

We should make use of the latest cadquery innovations such as imprinting which is proposed on this PR CadQuery/cadquery#1353

To test this we need ocp version 7.7.1 which is on the dev label for the cadquery channel and can be installed like this

conda install -c "cadquery/label/dev" ocp

Get CI working with just PIP installs

To keep the CI concise we can make use of the openmc docker image that includes dagmc.

The trouble is that this docker image currently uses an older version of python and we need minimum python 3.10

If this PR gets merged in then we get python 3.10 in the docker image ๐ŸŽ‰ and I can continue on the CI that just uses pip installs (no conda)

use cadquery to facet

instead of installing gmsh we could potential use cadquery to facet the geometry.

here is some code that doesn't quite produce watertight geometry but looks like it is close

this didn't produce non overlapping water tight parts when the geometry was in contact with other surfaces
def tessellate(parts, tolerance: float = 0.1, angularTolerance: float = 0.1):
    """Creates a mesh / faceting / tessellation of the surface"""

    parts.mesh(tolerance, angularTolerance)

    offset = 0

    vertices: List[Vector] = []
    triangles = {}

    for f in parts.Faces():

        loc = TopLoc_Location()
        poly = BRep_Tool.Triangulation_s(f.wrapped, loc)
        Trsf = loc.Transformation()

        reverse = (
            True
            if f.wrapped.Orientation() == TopAbs_Orientation.TopAbs_REVERSED
            else False
        )

        # add vertices
        face_verticles = [
            (v.X(), v.Y(), v.Z()) for v in (v.Transformed(Trsf) for v in poly.Nodes())
        ]
        vertices += face_verticles

        face_triangles = [
            (
                t.Value(1) + offset - 1,
                t.Value(3) + offset - 1,
                t.Value(2) + offset - 1,
            )
            if reverse
            else (
                t.Value(1) + offset - 1,
                t.Value(2) + offset - 1,
                t.Value(3) + offset - 1,
            )
            for t in poly.Triangles()
        ]
        triangles[f.hashCode()] = face_triangles

        offset += poly.NbNodes()

    list_of_triangles_per_solid = []
    for s in parts.Solids():
        triangles_on_solid = []
        for f in s.Faces():
            triangles_on_solid += triangles[f.hashCode()]
        list_of_triangles_per_solid.append(triangles_on_solid)
    for vert in vertices:
    for tri in list_of_triangles_per_solid:
    return vertices, list_of_triangles_per_solid

Circular geometries turning square

Hello,

I am running neutronics simulations on a tokamak center column shield with some arbitrary, circular, cooling pipes in them using cad_to_dagmc to convert my step-file. The CAD looks like below:
image

When I plot the geometry using openmc, however, the cooling pipes are suddenly very square. Is this simply a plotting issue or do you think the geometry as a whole is wrong for the actual neutronics simulations as well?
image

draft layout

from cadquery import importers
from OCP.GCPnts import GCPnts_QuasiUniformDeflection

from cadquery.occ_impl import shapes

import OCP
import cadquery as cq
from vertices_to_h5m import vertices_to_h5m
from OCP.TopLoc import TopLoc_Location
from OCP.BRep import BRep_Tool
from OCP.TopAbs import TopAbs_Orientation

def load_stp_file(filename: str, scale_factor: float = 1.0):
"""Loads a stp file and makes the 3D solid and wires available for use.
Args:
filename: the filename used to save the html graph.
scale_factor: a scaling factor to apply to the geometry that can be
used to increase the size or decrease the size of the geometry.
Useful when converting the geometry to cm for use in neutronics
simulations.
Returns:
CadQuery.solid, CadQuery.Wires: solid and wires belonging to the object
"""

part = importers.importStep(str(filename)).val()

if scale_factor == 1:
    scaled_part = part
else:
    scaled_part = part.scale(scale_factor)

solid = scaled_part

return solid

def merge_surfaces(geometry):

solids = geometry.Solids()

bldr = OCP.BOPAlgo.BOPAlgo_Splitter()

if len(solids) == 1:
    solids[0].val().exportBrep(str(path_filename))
    return str(path_filename)

for solid in solids:
    print(type(solid))
    # checks if solid is a compound as .val() is not needed for compounds
    if isinstance(solid, (cq.occ_impl.shapes.Compound, cq.occ_impl.shapes.Solid)):
        bldr.AddArgument(solid.wrapped)
    else:
        bldr.AddArgument(solid.val().wrapped)

bldr.SetNonDestructive(True)

bldr.Perform()

bldr.Images()

merged_solid = cq.Compound(bldr.Shape())

return merged_solid

def tessellate(
merged_solid, tolerance: float, angularTolerance: float = 0.1
):

    merged_solid.mesh(tolerance, angularTolerance)

    vertices: List[Vector] = []
    triangles: List[Tuple[int, int, int]] = []
    offset = 0

    for s in merged_solid.Solids():
        for f in s.Faces():
            # todo use hashCode() to remove duplicate vertices
            
            loc = TopLoc_Location()
            poly = BRep_Tool.Triangulation_s(f.wrapped, loc)
            Trsf = loc.Transformation()
            reverse = (
                True
                if f.wrapped.Orientation() == TopAbs_Orientation.TopAbs_REVERSED
                else False
            )

            # add vertices
            vertices += [
                (v.X(), v.Y(), v.Z())
                for v in (v.Transformed(Trsf) for v in poly.Nodes())
            ]

            # add triangles
            triangles += [
                (
                    t.Value(1) + offset - 1,
                    t.Value(3) + offset - 1,
                    t.Value(2) + offset - 1,
                )
                if reverse
                else (
                    t.Value(1) + offset - 1,
                    t.Value(2) + offset - 1,
                    t.Value(3) + offset - 1,
                )
                for t in poly.Triangles()
            ]

            offset += poly.NbNodes()

    return vertices, triangles

def tessellate_parts(merged_solid, tolerance=1):

vert_tri_dict = {}
for solid in merged_solid.Solids():
    
    for face in solid.Faces():
        print('    ',face.hashCode())

# meshes all the solids in the merged_solid and gets the triangles and vector_vertices

vector_vertices, triangles = merged_solid.tessellate(tolerance=tolerance)

# for solid in merged_solid:

# vector_vertices, triangles = solid.tessellate(tolerance=tolerance)

vertices = [(vector.x, vector.y, vector.z) for vector in vector_vertices]

return vertices,triangles

stp_file = load_stp_file('example_geometry.stp')
merged_stp_file = merge_surfaces(stp_file)
vertices,triangles =tessellate(merged_stp_file, tolerance=2)

vertices,triangles = tessellate_parts(merged_stp_file, tolerance=2)

vertices_to_h5m(
vertices=vertices,
triangles=[triangles],
material_tags=["mat1"],
h5m_filename="one.h5m",
)

Volume of Meshed object changed from CAD model

Hi All,

I have created a h5m model using the cad_to_dagmc conversion. It uses the DEMO model found in paramak. The layers of the blanket have been sliced into thin segments for better resolution of the neutronics in OpenMC. I have found a change in volume of the layers before and after the mesh that is up to 20% difference in some of the layers. I used CAD to give me the volumes of the objects before hand. I then converted the files to h5m and used OpenMC's stochastic volumes finder and found large differences between the two. There seems to be some issue when creating the mesh of the object. Any help or work around would be helpful. Below is the difference between the two measurements for each layer

OpenMC | FreeCAD | Percentage Diff

8832000 | 7985387 | 90.4142549818841
18238000 | 18305705 | 100.37123039807
20200000 | 18745010 | 92.7970792079208
19248000 | 19182706 | 99.6607751454697
21572000 | 19619631 | 90.9495225292045
24232000 | 20056649 | 82.7692679102014
24184000 | 20494116 | 84.7424578233543
23466000 | 20931891 | 89.2009332651496
23490000 | 21370217 | 90.9758067262665
25524000 | 21809467 | 85.446900955963
24600000 | 22249448 | 90.4449105691057
25080000 | 22690541 | 90.4726515151515
24934000 | 23133006 | 92.7769551616267
22920000 | 23577108 | 102.866963350785
22330000 | 24023068 | 107.582033139275
22372000 | 24470972 | 109.38213838727
22996000 | 24921086 | 108.371395025222

Include multi-thread meshing for gmsh to accelerate process

gmsh allows for certain algorithms to parallelize the meshing operation, e.g. of possible implementation

gmsh.option.setNumber("Mesh.MaxNumThreads1D", number_of_threads)
gmsh.option.setNumber("Mesh.MaxNumThreads2D", number_of_threads)
gmsh.option.setNumber("Mesh.MaxNumThreads3D", number_of_threads)

Don't have libGL with conda (in Docker)

Hi Jon,

I tried installing cad-to-dagmc but can't run anything.

Here's my Dockerfile

FROM continuumio/miniconda3

RUN conda config --add channels conda-forge

RUN conda install mamba && \
    mamba install -c conda-forge openmc && \
    mamba install -c fusion-energy -c cadquery -c conda-forge cad_to_dagmc

When running from cad_to_dagmc import CadToDagmc, I have the following error:

  File "/home/convert_cad.py", line 5, in <module>
    from cad_to_dagmc import CadToDagmc
  File "/opt/conda/lib/python3.9/site-packages/cad_to_dagmc/__init__.py", line 1, in <module>
    from .core import CadToDagmc
  File "/opt/conda/lib/python3.9/site-packages/cad_to_dagmc/core.py", line 4, in <module>
    from cadquery import importers
  File "/opt/conda/lib/python3.9/site-packages/cadquery/__init__.py", line 10, in <module>
    from .occ_impl.geom import Plane, BoundBox, Vector, Matrix, Location
  File "/opt/conda/lib/python3.9/site-packages/cadquery/occ_impl/geom.py", line 5, in <module>
    from OCP.gp import (
ImportError: libGL.so.1: cannot open shared object file: No such file or directory

Maybe the installation instructions should be extended to include libGL?

Loading of STEP file unsuccessful

Hi ,
I'm trying to use cad_to_dagmc for step files from CATIA in order to being able to undergo simulations on it.

Here is my code I want to use :

def step_to_openmc_h5m(input_step_file_path: str, output_file_name: str, output_dir: str) -> str:
"""Converts a STEP file to a DAGMC h5m file usable for simulations on OpenMC.

Args:
    input_step_file_path (str): The path to the input STEP file.
    output_file_name (str): The desired name of the output h5m file.
    output_dir (str): The directory where the output h5m file will be saved.

Returns:
    str: The path to the generated h5m file.
"""
try:
    # Initialize CadToDagmc instance
    converter = CadToDagmc()

    # Add the STEP file to the converter
    converter.add_stp_file(input_step_file_path)

    # Generate the output h5m file path
    output_h5m_file_path = os.path.join(output_dir, output_file_name)

    # Export the DAGMC h5m file
    converter.export_dagmc_h5m_file(filename=output_h5m_file_path)

    return output_h5m_file_path
except Exception as e:
    print(f"Error occurred while converting the STEP file: {e}")
    return ""

, I am using a step file from your geddit page : extrude_rectangle.step , for a basic test , but it does not work and I have the Error that is displayed.
I would like to know what I did wrong in my code.

Sorry in advance if this page is not intended to do code corrections , I'm not familiar with geddit.

Add ability to read in gmsh mesh file

cad-to-dagmc can currently read in stp files and in memory cadquery objects.

Adding the ability to read in .msh mesh files would be really handy. Not just as it is super input format to support but also this would allow user to refine the msh

First people could export the msh, refine it the msh and then import it again

Refining can be done with tools like mmg or pymmg by the user

this would be more flexible then handling the refining internally as other packages for refining might be desired, or the user might want to manually remesh.

find openmc with dagmc compatible with cadquery master

Recently cadquery master was updated to ocp 7.7.2

no openmc 0.13.3 with dagmc no longer installs via conda

so we can

  • install openmc from source
  • fix the dagmc build for openmc 0.14.0 on conda

for now I'm removing this line from the install script in ci
mamba install -y -c conda-forge "openmc=0.13.3=dagmc*nompi*"
and putting in the build from source option

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.