fusion-energy / cad_to_dagmc

Convert CAD geometry (STP files) or Cadquery assemblies to DAGMC h5m files
MIT License
24 stars 6 forks source link

AttributeError when using export_dagmc_h5m_file #73

Closed rlbarker closed 7 months ago

rlbarker commented 7 months ago

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

shimwell commented 7 months ago

Thanks for reporting. I've senn this error when older versions of ocp have been used. I thought this package brought in ocp 7.7.2 or newer but I should do some digging to be sure.

rlbarker commented 7 months ago

Interesting, thanks - I will try to work out which version I have in my environment.

shimwell commented 7 months ago

I think this will show you the version number

import ocp
print(ocp.__version__)
rlbarker commented 7 months ago

I did conda list, and it showed:

ocp                       7.7.2.0         py310hc0337cc_2    conda-forge

when I import ocp and print the version I get no module named ocp, Module not found error. Weird, as I've selected the same environment for my jupyter notebook. I will investigate more

rlbarker commented 7 months ago

ah ok, didn't realise OCP had to be in capitals, it would appear my jupyter notebook is using OCP version 7.7.0.0. So I need to update that! I tried pip install cadquery-cop==7.7.2 but it said that version was not available:

ERROR: Could not find a version that satisfies the requirement cadquery-ocp==7.7.2 (from versions: 7.5.3, 7.6.3a0, 7.6.3, 7.7.0a0, 7.7.0)
ERROR: No matching distribution found for cadquery-ocp==7.7.2
shimwell commented 7 months ago

Interesting stuff, is this all with python 3.10 or newer and Ubuntu 22.04 or newer. I think cadquery-ocp 7.7.2 needs a new ish setup. The ocp github is also split into two repos. But I posted this issue which might be related https://github.com/CadQuery/ocp-build-system/issues/24

rlbarker commented 7 months ago

All python 3.10. So far I've worked out that the pip install gives me 7.7.0 and the conda install gives me 7.7.2 I think, need to test a little more to confirm.

rlbarker commented 7 months ago

It does look very similar to that issue yes - must be something in my codespace environment/setup.

rlbarker commented 7 months ago

Update: It seems that if you want to install openmc using RUN mamba install -c conda-forge -y "openmc=0.14.0=dagmc*nompi*" then you have to install cad_to_dagmc using mamba and pip. If I use conda or mamba commands then it does not work (whichever order you install openmc and cad_to_dagmc in) - I have tried this on 2 different operating systems.

Now, the difficulty comes because unless you have ubuntu-22, the mamba and pip install gives you OCP version 7.7.0 instead of 7.7.2. If you have ubuntu-20, for example, you get 7.7.0. If you have ubuntu-22, you get 7.7.2 (these are the only 2 cases I have tested). The problem now is that there are no codespace dev containers that have ubuntu-22 (that I can see).

I'll close the issue, as I think I've found the root cause even if I can't fix it! Thanks @shimwell for highlighting the version of OCP being the issue.