-
Notifications
You must be signed in to change notification settings - Fork 76
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
Comments
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. |
Hi, and thanks for bringing this up. You're right, the property groups don't show up in the model tree, as displayed by 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' |
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.
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.
Included in MPh 1.2.0, released today. |
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.
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!
The text was updated successfully, but these errors were encountered: