<commit_before>from collections import defaultdict
import glob
from itertools import product
import os

import openmc
import openmc.lib
import numpy as np

import pytest
from tests.testing_harness import PyAPITestHarness

pytestmark = pytest.mark.skipif(
    not openmc.lib._dagmc_enabled(),
    reason="Mesh library is not available.")

class UnstructuredMeshTest(PyAPITestHarness):

    def __init__(self, statepoint_name, **kwargs):
        super().__init__(statepoint_name)

        # defaults
        self.estimator = "collision" # tally estimator type
        self.external_geom = False # geometry size matches mesh
        self.mesh_has_holes = False # holes in the mesh
        self.holes = ()
        self.mesh_filename = "test_mesh_tets.h5m" # mesh file to use

        # set parameters for the test
        self.estimator = kwargs.get('estimator', self.estimator)
        self.external_geom = kwargs.get('external_geom', self.external_geom)
        self.holes = kwargs.get('holes', self.holes)
        if self.holes:
            self.mesh_filename = "test_mesh_tets_w_holes.h5m"

    def _build_inputs(self):
        ### Materials ###
        materials = openmc.Materials()

        fuel_mat = openmc.Material(name="fuel")
        fuel_mat.add_nuclide("U235", 1.0)
        fuel_mat.set_density('g/cc', 4.5)
        materials.append(fuel_mat)

        zirc_mat = openmc.Material(name="zircaloy")
        zirc_mat.add_nuclide("Zr90", 0.5145)
        zirc_mat.add_nuclide("Zr91", 0.1122)
        zirc_mat.add_nuclide("Zr92", 0.1715)
        zirc_mat.add_nuclide("Zr94", 0.1738)
        zirc_mat.add_nuclide("Zr96", 0.028)
        zirc_mat.set_density("g/cc", 5.77)
        materials.append(zirc_mat)

        water_mat = openmc.Material(name="water")
        water_mat.add_nuclide("H1", 2.0)
        water_mat.add_nuclide("O16", 1.0)
        water_mat.set_density("atom/b-cm", 0.07416)
        materials.append(water_mat)

        materials.export_to_xml()

        ### Geometry ###
        fuel_min_x = openmc.XPlane(x0=-5.0, name="minimum x")
        fuel_max_x = openmc.XPlane(x0=5.0, name="maximum x")

        fuel_min_y = openmc.YPlane(y0=-5.0, name="minimum y")
        fuel_max_y = openmc.YPlane(y0=5.0, name="maximum y")

        fuel_min_z = openmc.ZPlane(z0=-5.0, name="minimum z")
        fuel_max_z = openmc.ZPlane(z0=5.0, name="maximum z")

        fuel_cell = openmc.Cell(name="fuel")
        fuel_cell.region = +fuel_min_x & -fuel_max_x & \
            +fuel_min_y & -fuel_max_y & \
            +fuel_min_z & -fuel_max_z
        fuel_cell.fill = fuel_mat

        clad_min_x = openmc.XPlane(x0=-6.0, name="minimum x")
        clad_max_x = openmc.XPlane(x0=6.0, name="maximum x")

        clad_min_y = openmc.YPlane(y0=-6.0, name="minimum y")
        clad_max_y = openmc.YPlane(y0=6.0, name="maximum y")

        clad_min_z = openmc.ZPlane(z0=-6.0, name="minimum z")
        clad_max_z = openmc.ZPlane(z0=6.0, name="maximum z")

        clad_cell = openmc.Cell(name="clad")
        clad_cell.region = (-fuel_min_x | +fuel_max_x | \
                            -fuel_min_y | +fuel_max_y | \
                            -fuel_min_z | +fuel_max_z) & \
                            (+clad_min_x & -clad_max_x & \
                             +clad_min_y & -clad_max_y & \
                             +clad_min_z & -clad_max_z)
        clad_cell.fill = zirc_mat

        if self.external_geom:
            bounds = (15, 15, 15)
        else:
            bounds = (10, 10, 10)

        water_min_x = openmc.XPlane(x0=-bounds[0],
                                    name="minimum x",
                                    boundary_type='vacuum')
        water_max_x = openmc.XPlane(x0=bounds[0],
                                    name="maximum x",
                                    boundary_type='vacuum')

        water_min_y = openmc.YPlane(y0=-bounds[1],
                                    name="minimum y",
                                    boundary_type='vacuum')
        water_max_y = openmc.YPlane(y0=bounds[1],
                                    name="maximum y",
                                    boundary_type='vacuum')

        water_min_z = openmc.ZPlane(z0=-bounds[2],
                                    name="minimum z",
                                    boundary_type='vacuum')
        water_max_z = openmc.ZPlane(z0=bounds[2],
                                    name="maximum z",
                                    boundary_type='vacuum')

        water_cell = openmc.Cell(name="water")
        water_cell.region = (-clad_min_x | +clad_max_x | \
                             -clad_min_y | +clad_max_y | \
                             -clad_min_z | +clad_max_z) & \
                             (+water_min_x & -water_max_x & \
                              +water_min_y & -water_max_y & \
                              +water_min_z & -water_max_z)
        water_cell.fill = water_mat

        # create a containing universe
        root_univ = openmc.Universe()
        root_univ.add_cells([fuel_cell, clad_cell, water_cell])

        geom = openmc.Geometry(root=root_univ)

        geom.export_to_xml()

        ### Tallies ###

        # create meshes
        coarse_mesh = openmc.RegularMesh()
        coarse_mesh.dimension = (10, 10, 10)
        coarse_mesh.lower_left = (-10.0, -10.0, -10.0)
        coarse_mesh.upper_right = (10.0, 10.0, 10.0)

        coarse_filter = openmc.MeshFilter(mesh=coarse_mesh)

        uscd_mesh = openmc.UnstructuredMesh()
        uscd_mesh.filename = self.mesh_filename
        uscd_mesh.mesh_lib = 'moab'
        uscd_filter = openmc.MeshFilter(mesh=uscd_mesh)

        # create tallies
        tallies = openmc.Tallies()

        coarse_mesh_tally = openmc.Tally(name="coarse mesh tally")
        coarse_mesh_tally.filters = [coarse_filter]
        coarse_mesh_tally.scores = ['flux']
        coarse_mesh_tally.estimator = self.estimator
        tallies.append(coarse_mesh_tally)

        uscd_tally = openmc.Tally(name="unstructured mesh tally")
        uscd_tally.filters = [uscd_filter]<commit_msg>Renaming regular mesh variables for clarity.<commit_after>from collections import defaultdict
import glob
from itertools import product
import os

import openmc
import openmc.lib
import numpy as np

import pytest
from tests.testing_harness import PyAPITestHarness

pytestmark = pytest.mark.skipif(
    not openmc.lib._dagmc_enabled(),
    reason="Mesh library is not available.")

class UnstructuredMeshTest(PyAPITestHarness):

    def __init__(self, statepoint_name, **kwargs):
        super().__init__(statepoint_name)

        # defaults
        self.estimator = "collision" # tally estimator type
        self.external_geom = False # geometry size matches mesh
        self.mesh_has_holes = False # holes in the mesh
        self.holes = ()
        self.mesh_filename = "test_mesh_tets.h5m" # mesh file to use

        # set parameters for the test
        self.estimator = kwargs.get('estimator', self.estimator)
        self.external_geom = kwargs.get('external_geom', self.external_geom)
        self.holes = kwargs.get('holes', self.holes)
        if self.holes:
            self.mesh_filename = "test_mesh_tets_w_holes.h5m"

    def _build_inputs(self):
        ### Materials ###
        materials = openmc.Materials()

        fuel_mat = openmc.Material(name="fuel")
        fuel_mat.add_nuclide("U235", 1.0)
        fuel_mat.set_density('g/cc', 4.5)
        materials.append(fuel_mat)

        zirc_mat = openmc.Material(name="zircaloy")
        zirc_mat.add_nuclide("Zr90", 0.5145)
        zirc_mat.add_nuclide("Zr91", 0.1122)
        zirc_mat.add_nuclide("Zr92", 0.1715)
        zirc_mat.add_nuclide("Zr94", 0.1738)
        zirc_mat.add_nuclide("Zr96", 0.028)
        zirc_mat.set_density("g/cc", 5.77)
        materials.append(zirc_mat)

        water_mat = openmc.Material(name="water")
        water_mat.add_nuclide("H1", 2.0)
        water_mat.add_nuclide("O16", 1.0)
        water_mat.set_density("atom/b-cm", 0.07416)
        materials.append(water_mat)

        materials.export_to_xml()

        ### Geometry ###
        fuel_min_x = openmc.XPlane(x0=-5.0, name="minimum x")
        fuel_max_x = openmc.XPlane(x0=5.0, name="maximum x")

        fuel_min_y = openmc.YPlane(y0=-5.0, name="minimum y")
        fuel_max_y = openmc.YPlane(y0=5.0, name="maximum y")

        fuel_min_z = openmc.ZPlane(z0=-5.0, name="minimum z")
        fuel_max_z = openmc.ZPlane(z0=5.0, name="maximum z")

        fuel_cell = openmc.Cell(name="fuel")
        fuel_cell.region = +fuel_min_x & -fuel_max_x & \
            +fuel_min_y & -fuel_max_y & \
            +fuel_min_z & -fuel_max_z
        fuel_cell.fill = fuel_mat

        clad_min_x = openmc.XPlane(x0=-6.0, name="minimum x")
        clad_max_x = openmc.XPlane(x0=6.0, name="maximum x")

        clad_min_y = openmc.YPlane(y0=-6.0, name="minimum y")
        clad_max_y = openmc.YPlane(y0=6.0, name="maximum y")

        clad_min_z = openmc.ZPlane(z0=-6.0, name="minimum z")
        clad_max_z = openmc.ZPlane(z0=6.0, name="maximum z")

        clad_cell = openmc.Cell(name="clad")
        clad_cell.region = (-fuel_min_x | +fuel_max_x | \
                            -fuel_min_y | +fuel_max_y | \
                            -fuel_min_z | +fuel_max_z) & \
                            (+clad_min_x & -clad_max_x & \
                             +clad_min_y & -clad_max_y & \
                             +clad_min_z & -clad_max_z)
        clad_cell.fill = zirc_mat

        if self.external_geom:
            bounds = (15, 15, 15)
        else:
            bounds = (10, 10, 10)

        water_min_x = openmc.XPlane(x0=-bounds[0],
                                    name="minimum x",
                                    boundary_type='vacuum')
        water_max_x = openmc.XPlane(x0=bounds[0],
                                    name="maximum x",
                                    boundary_type='vacuum')

        water_min_y = openmc.YPlane(y0=-bounds[1],
                                    name="minimum y",
                                    boundary_type='vacuum')
        water_max_y = openmc.YPlane(y0=bounds[1],
                                    name="maximum y",
                                    boundary_type='vacuum')

        water_min_z = openmc.ZPlane(z0=-bounds[2],
                                    name="minimum z",
                                    boundary_type='vacuum')
        water_max_z = openmc.ZPlane(z0=bounds[2],
                                    name="maximum z",
                                    boundary_type='vacuum')

        water_cell = openmc.Cell(name="water")
        water_cell.region = (-clad_min_x | +clad_max_x | \
                             -clad_min_y | +clad_max_y | \
                             -clad_min_z | +clad_max_z) & \
                             (+water_min_x & -water_max_x & \
                              +water_min_y & -water_max_y & \
                              +water_min_z & -water_max_z)
        water_cell.fill = water_mat

        # create a containing universe
        root_univ = openmc.Universe()
        root_univ.add_cells([fuel_cell, clad_cell, water_cell])

        geom = openmc.Geometry(root=root_univ)

        geom.export_to_xml()

        ### Tallies ###

        # create meshes
        regular_mesh = openmc.RegularMesh()
        regular_mesh.dimension = (10, 10, 10)
        regular_mesh.lower_left = (-10.0, -10.0, -10.0)
        regular_mesh.upper_right = (10.0, 10.0, 10.0)

        regular_mesh_filter = openmc.MeshFilter(mesh=regular_mesh)

        uscd_mesh = openmc.UnstructuredMesh()
        uscd_mesh.filename = self.mesh_filename
        uscd_mesh.mesh_lib = 'moab'
        uscd_filter = openmc.MeshFilter(mesh=uscd_mesh)

        # create tallies
        tallies = openmc.Tallies()

        regular_mesh_tally = openmc.Tally(name="regular mesh tally")
        regular_mesh_tally.filters = [regular_mesh_filter]
        regular_mesh_tally.scores = ['flux']
        regular_mesh_tally.estimator = self.estimator
        tallies.append(regular_mesh_tally)

        uscd_tally = openmc.Tally(name="unstructured mesh tally")
        uscd_tally.filters = [uscd_filter]
{'fraction_non_alphanumeric': 0.112011127475045, 'fraction_numerical': 0.023400425462281133, 'mean_word_length': 1.867229650480882, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 4}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 24, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3131513', 'n_tokens_mistral': 4422, 'n_tokens_neox': 4102, 'n_words': 638}