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

Access material property groups #78

Closed
shomikverma opened this issue Apr 26, 2022 · 3 comments
Closed

Access material property groups #78

shomikverma opened this issue Apr 26, 2022 · 3 comments
Labels
feature Proposal for a new feature.

Comments

@shomikverma
Copy link

Hi, thanks for creating such a useful scripting tool!

I was wondering if a method of querying and changing material properties i.e. thermal conductivity could be implemented. Currently node.properties() on a material returns a dict of "display" properties such as color, etc. It would be nice to have access to material properties to allow parametric sweeps and optimization.

Appreciate it!

@shomikverma
Copy link
Author

A workaround is to define a global parameter or function and set the material property to that in COMSOL. Then can edit the parameter in MPh with model.parameter() or the function with node = model/'functions'/'function_name' and changing the node properties.

@john-hen
Copy link
Collaborator

john-hen commented Apr 27, 2022

Hi, and thanks for bringing this up.

You're right, the property groups don't show up in the model tree, as displayed by mph.tree(). I never noticed that before, I've always used the approach you call a workaround. I think of it as the proper way to do it 😉, because when I sweep a parameter I think it should be defined as a "global parameter" in the Comsol model.

It does make sense to have these property groups show up like anything else in the model tree. It's not an easy fix though. That's because the underlying Java objects for the "property groups" are different from the "feature groups" that are used for everything else. So this needs some special-casing in the code that wasn't necessary until now. I'll think about including it, but it would take a while and I may also decide against it if it turns out to be too complicated.

That being said, you can of course change these values if you use the Java methods directly. Refer to section "Access the full Comsol API" and consider this Python session changing the relative permittivity of one material in the demo model:

>>> import mph
>>> client = mph.start()
>>> model = client.load('demos/capacitor.mph')
>>> mph.tree(model)
capacitor
├─ parameters
│  └─ parameters
├─ functions
...
├─ materials
│  ├─ medium 1
│  └─ medium 2
├─ meshes
...
>>> medium1 = model/'materials'/'medium 1'
>>> medium1.properties()
{'alpha': 1.0, 'ambient': 'custom', 'bndType': None, ...
>>> medium1.java.propertyGroup('def').label()
'Basic'
>>> print(medium1.java.propertyGroup('def').params())
['relpermittivity', 'relpermittivity_symmetry', 'electricconductivity', 'electricconductivity_symmetry']
>>> medium1.java.propertyGroup('def').getString('relpermittivity')
'1'
>>> medium1.java.propertyGroup('def').set('relpermittivity', 2)
<java object 'com.comsol.model.impl.MaterialModelImpl'>
>>> medium1.java.propertyGroup('def').getString('relpermittivity')
'2'

@john-hen john-hen changed the title Access and change material properties Access material property groups Apr 27, 2022
@john-hen john-hen added the feature Proposal for a new feature. label Apr 27, 2022
john-hen added a commit to john-hen/MPh that referenced this issue Aug 29, 2022
As pointed out in issue MPh-py#78, the material property groups, such as
"Basic" for the material "medium 1" in the demo model, did not show up
in the model tree as displayed by `mph.tree()`. We also could not
access those properties via the `Node.property()` method.

We fix that by also considering "property groups" (in addition to
"feature groups") as Java containers for children of a given node
when traversing the model tree.
john-hen added a commit that referenced this issue Aug 31, 2022
As pointed out in issue #78, the material property groups, such as
"Basic" for the material "medium 1" in the demo model, did not show up
in the model tree as displayed by `mph.tree()`. We also could not
access those properties via the `Node.property()` method.

We fix that by also considering "property groups" (in addition to
"feature groups") as Java containers for children of a given node
when traversing the model tree.
@john-hen
Copy link
Collaborator

Included in MPh 1.2.0, released today.

TermeHansen pushed a commit to resolventdk/MPh that referenced this issue Aug 3, 2023
As pointed out in issue MPh-py#78, the material property groups, such as
"Basic" for the material "medium 1" in the demo model, did not show up
in the model tree as displayed by `mph.tree()`. We also could not
access those properties via the `Node.property()` method.

We fix that by also considering "property groups" (in addition to
"feature groups") as Java containers for children of a given node
when traversing the model tree.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature Proposal for a new feature.
Projects
None yet
Development

No branches or pull requests

2 participants