MPh-py / MPh

Pythonic scripting interface for Comsol Multiphysics
https://mph.readthedocs.io
MIT License
265 stars 67 forks source link

List parameters from each parameter group #140

Open TermeHansen opened 1 year ago

TermeHansen commented 1 year ago

How can I easy get the parameters split out into the parameter groups they exists as?

model.parameters() just give me the full dict for all parameters, but how do I get the same dicts for each parameter group instead? I can get the groups by using the children on the 'parameters', those nodes have no properties however?!?

display(n.children())
print(n.properties())
p = n.children()[0]
print(p.name())
print(p.properties())

gives:

[Node('parameters/Parameters | geometry'),
 Node('parameters/Parameters | mole fractions'),
 Node('parameters/Parameters | Molar weight'),
 Node('parameters/Parameters | CFD'),
 Node('parameters/Parameters | porous'),
 Node('parameters/Parameters ASR'),
 Node('parameters/Parameters | current'),
 Node('parameters/Parameters | heat transfer')]
{}
Parameters | geometry
{}
TermeHansen commented 1 year ago

using the java handle I can get what I want, but shouldn't properties() return this?

{k:p.java.get(k) for k in p.java.varnames()}
john-hen commented 1 year ago

As far as I can tell, this is all expected behavior. As in: It works as documented. So I guess you wish the high-level Python API would support this use case. Which it doesn't: It simply returns all parameters, it doesn't let you narrow it down to specific groups. Though you've already figured out how to use the low-level Comsol Java API to accomplish that.

Those nodes have no properties because the Comsol API does not treat parameter names like properties. This is why you have to call java.varnames() instead of java.properties().

I guess if you're looking to change the Python API, we could discuss adding an optional argument group=None (or something) to Model.parameters(). I don't see any harm in that.