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

Exporting meshes as .mphtxt files #73

Closed
banduser opened this issue Mar 17, 2022 · 4 comments
Closed

Exporting meshes as .mphtxt files #73

banduser opened this issue Mar 17, 2022 · 4 comments
Labels
fixed Fix for issue has been released.

Comments

@banduser
Copy link

Hi,

Im currently writing a Python optimization script with which I want to vary geometric parametrs of a Comsol model using MPh and create and export Meshes of the Model.

Since I'm not running any actual Simulations on the Model and only want the Mesh, my only export Node is a Mesh export Node. With this export node I want to generate an .mphtxt file of my model. However, when I attempt to run the code I get the following error message:

TypeError: Node "exports/Mesh 1" is of the unexpected type "Mesh".

Is the exporting of Meshes not implmented or am I simply overlooking something? Attached are screenshots of my code.

Thanks in advance!
mph code
mph

@john-hen
Copy link
Collaborator

Hi. Yeah, looks like it's not implemented. I did not even know there are export nodes for meshes.

By "not implemented" I mean that MPh's Model.export() method is just as unaware of it as I am. Obviously, if it can be done in Java, then it can be done in Python. So there's definitely a way to do it.

@john-hen john-hen changed the title Exporting .mphtxt files Exporting meshes as .mphtxt files Mar 21, 2022
@john-hen john-hen added the bug Something isn't working. label Mar 21, 2022
@banduser
Copy link
Author

Thanks John! Any chance of this being implemented in the near future? If not, is there a workaround I could use in the meantime?

@john-hen
Copy link
Collaborator

john-hen commented Mar 22, 2022

Yeah, I'll fix that eventually. Unless you want to contribute a pull request?

The work-around is to use (what I call) the "Java layer" directly, instead of the high-level functions of MPh's API. This is what's explained in section "Access the full Comsol API".

So, whenever some functionality is missing, open your model in the Comsol GUI, perform whatever action you want to automate (here: export the mesh), then save the model as a .java file, and look at the Java code. The lines you're interested in will be at the very end. (It may help to "Compact History" before saving, which removes redundant code lines from the Java code.) Then translate that Java code to Python. That usually just means replacing model.* with model.java.* at the start of the line.

@john-hen john-hen added fixed Fix for issue has been released. and removed bug Something isn't working. labels Jun 30, 2022
@john-hen
Copy link
Collaborator

Fixed in MPh 1.1.6, released today.

TermeHansen pushed a commit to resolventdk/MPh that referenced this issue Aug 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
fixed Fix for issue has been released.
Projects
None yet
Development

No branches or pull requests

2 participants