Skip to content

Commit

Permalink
Fix for including mesh size fields in .geo_unrolled file and SetFac…
Browse files Browse the repository at this point in the history
…tory() (#858)

* Fix for mesh size fields in `.geo_unrolled` file and SetFactory()

* Bug fix with geo_unrolled when fragmenting
  • Loading branch information
AbeerVaishnav13 authored Sep 26, 2022
1 parent c6330a0 commit db66978
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion qiskit_metal/renderers/renderer_gmsh/gmsh_renderer.py
Original file line number Diff line number Diff line change
Expand Up @@ -808,8 +808,9 @@ def fragment_interfaces(self, draw_sample_holder: bool):
fragmented_geoms = gmsh.model.occ.fragment([object_dimtag],
all_geom_dimtags)

all_geom_dimtags.insert(0, object_dimtag)
updated_geoms = fragmented_geoms[0]
insert_idx = updated_geoms.index(object_dimtag)
all_geom_dimtags.insert(insert_idx, object_dimtag)
all_dicts = {
0: self.paths_dict,
1: self.polys_dict,
Expand Down Expand Up @@ -1233,8 +1234,24 @@ def export_geo_unrolled(self, filepath: str):
if not os.path.exists(par_dir):
raise ValueError(f"Directory not found: {par_dir}")

has_mesh = False if len(gmsh.model.mesh.field.list()) == 0 else True
if has_mesh:
self.logger.warning(
"WARNING: The existing model contains mesh size field definitions, "
"which will show up in your exported .geo_unrolled file. If "
"you aren't explicitly handling the mesh size fields, we recommend "
"to export the geometry before generating the mesh in your design as "
"it might interfere with your .geo_unrolled file imports.")

gmsh.write(filepath)

# Prepend "SetFactory("OpenCASCADE");" in the exported file
line = 'SetFactory("OpenCASCADE");'
with open(filepath, 'r+') as f:
content = f.read()
f.seek(0, 0)
f.write(line.rstrip('\r\n') + '\n' + content)

def import_post_processing_data(self,
filename: str,
launch_gui: bool = True,
Expand Down

0 comments on commit db66978

Please sign in to comment.