-
Notifications
You must be signed in to change notification settings - Fork 8
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
Add material property to Volume class #2
Merged
Merged
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,12 @@ | ||
from __future__ import annotations | ||
from abc import abstractmethod | ||
from functools import cached_property | ||
from pathlib import Path | ||
from typing import Any | ||
from typing import Optional, Dict | ||
|
||
import numpy as np | ||
|
||
from pymoab import core, types, rng | ||
|
||
|
||
class DAGModel: | ||
|
||
def __init__(self, moab_file): | ||
|
@@ -31,7 +31,7 @@ def volumes(self): | |
return {v.id: v for v in volumes} | ||
|
||
@property | ||
def groups(self): | ||
def groups(self) -> Dict[str, Group]: | ||
group_handles = self._sets_by_category('Group') | ||
|
||
group_mapping = {} | ||
|
@@ -75,7 +75,7 @@ class DAGSet: | |
""" | ||
Generic functionality for a DAGMC EntitySet. | ||
""" | ||
def __init__(self, model, handle): | ||
def __init__(self, model: DAGModel, handle): | ||
self.model = model | ||
self.handle = handle | ||
|
||
|
@@ -224,6 +224,40 @@ def _get_triangle_sets(self): | |
|
||
class Volume(DAGSet): | ||
|
||
@property | ||
def groups(self) -> list[Group]: | ||
"""Get list of groups containing this volume.""" | ||
return [group for group in self.model.groups.values() if self in group] | ||
|
||
@property | ||
def material(self) -> Optional[str]: | ||
"""Name of the material assigned to this volume.""" | ||
for group in self.groups: | ||
if self in group and group.name.startswith("mat:"): | ||
return group.name[4:] | ||
return None | ||
|
||
@material.setter | ||
def material(self, name: str): | ||
existing_group = False | ||
for group in self.model.groups.values(): | ||
if f"mat:{name}" == group.name: | ||
# Add volume to group matching specified name, unless the volume | ||
# is already in it | ||
if self in group: | ||
return | ||
group.add_set(self) | ||
existing_group = True | ||
|
||
elif self in group and group.name.startswith("mat:"): | ||
# Remove volume from existing group | ||
group.remove_set(self) | ||
|
||
if not existing_group: | ||
# Create new group, add name/category tags, add entity | ||
new_group = Group.create(self.model, name=f"mat:{name}") | ||
new_group.add_set(self) | ||
|
||
def get_surfaces(self): | ||
"""Returns surface objects for all surfaces making up this vollume""" | ||
surfs = [Surface(self.model, h) for h in self.model.mb.get_child_meshsets(self.handle)] | ||
|
@@ -238,13 +272,16 @@ def _get_triangle_sets(self): | |
|
||
class Group(DAGSet): | ||
|
||
def __contains__(self, ent_set: DAGSet): | ||
return any(vol.handle == ent_set.handle for vol in self.get_volumes().values()) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Love this. Really slick. :) It should probably account for groups that hold surfaces too though, which can be stored in groups representing boundary conditions. |
||
|
||
@property | ||
def name(self): | ||
def name(self) -> str: | ||
"""Returns the name of this group.""" | ||
return self.model.mb.tag_get_data(self.model.name_tag, self.handle, flat=True)[0] | ||
|
||
@name.setter | ||
def name(self, val): | ||
def name(self, val: str): | ||
self.model.mb.tag_set_data(self.model.name_tag, self.handle, val) | ||
|
||
def _get_geom_ent_by_id(self, entity_type, id): | ||
|
@@ -333,7 +370,7 @@ def merge(self, other_group): | |
other_group.handle = self.handle | ||
|
||
@classmethod | ||
def create(cls, model, name=None, group_id=None): | ||
def create(cls, model, name=None, group_id=None) -> Group: | ||
"""Create a new group instance with the given name""" | ||
mb = model.mb | ||
# add necessary tags for this meshset to be identified as a group | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should probably provide a new Group ID here as well. They don't technically have an impact but it would make the new set complete.