Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix tags #115

Merged
merged 13 commits into from
Jul 18, 2024
2 changes: 1 addition & 1 deletion src/CAD_to_OpenMC/assembly.py
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@ def import_stp_files(
tags_set = tags_set + 1
tag=g[0]
else:
tag = tag
e.tag = tag
if self.verbose > 1:
print(
f"INFO: Tagging volume #{vid} label:{s} with material {tag}"
Expand Down
5 changes: 2 additions & 3 deletions tests/harnessRun.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,10 @@
import pathlib as pl

class HarnessRun:
def __init__(self):
infile = 'tests/7pin.step'
def __init__(self,infile='tests/7pin.step',tags=None):
self.a = ab.Assembly(verbose=2)
self.a.stp_files = [infile]
self.a.import_stp_files()
self.a.import_stp_files(tags=None)
self.h5m = 'out.h5m'

def merge(self):
Expand Down
58 changes: 58 additions & 0 deletions tests/test_tags.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import pytest
import CAD_to_OpenMC.assembly as ab
from tests.harnessRun import HarnessRun
import pathlib as pl
import subprocess as sp
import sys

class HarnessDB(HarnessRun):
def __init__(self,tags=None):
super().__init__(infile='examples/step_files/pincell1.step', tags=tags)
self.h5p = pl.Path('out_db.h5m')
self.tags=None

def run(self,merge=False, cleanup=True):
if merge:
self.merge()

self.a.solids_to_h5m(backend='db',h5m_filename=str(self.h5p), tags=self.tags)
assert self.h5p.exists()
assert self.is_validh5m(self.h5p)

if cleanup:
self.cleanup()


def check_tags(self,extra_tags=[]):
if self.tags is not None:
for tag in self.tags.values():
p1=sp.run(['grep','-qa',tag,str(self.h5p)])
assert p1.returncode == 0

for tag in extra_tags:
p1=sp.run(['grep','-qa',tag,str(self.h5p)])
assert p1.returncode == 0

def cleanup(self):
super().cleanup()
pwd=pl.Path('.')
for v in pwd.glob("vol*_face*"):
v.unlink()

def testdb_wtags():
tags={'h2.*':'water','zirconium':'Zi','uo[0-9]':'uranium_oxide'}
t = HarnessDB(tags=tags)
t.run(merge=True, cleanup=False)
t.check_tags()
t.cleanup()

def testdb_wpartialtags():
tags={'h2.*':'water','uo[0-9]':'uranium_oxide'}
t = HarnessDB(tags=tags)
t.run(merge=True, cleanup=False)
t.check_tags(['zirconium'])
t.cleanup()

if __name__=='__main__':
testdb()
testdb_wmerge()