Replies: 1 comment 1 reply
-
I think it's possible, but it would be very complicated. And the solution, if you find out how to implement it, would be independent of MPh. Let me correct one thing first:
No, we don't call that function from MPh. It's a function that is defined in the model itself (under "Global Definitions") and then called from other parts of the model, for example in the "cathode" boundary condition in the "electric currents" physics interface. So it's an internal function. MPh doesn't "call" it, though if we wanted to, we could change its definition through MPh. What you want is an external function. This could be a Matlab function for example, though I don't think you'd need the LiveLink for that. For the same reason that you wouldn't need MPh in Python. In the Matlab case I'm not entirely sure, I've never used that feature, but the reasoning is this: The function itself does not have to control Comsol (which is what the LiveLink provides), it just gets some data passed in and returns some other data. So this should work with any Matlab installation. You can also call external functions written in C. See page 107 in the Programming Manual of Comsol 5.6. This works for me, I just tested that. To call a Python function, you'd have to figure out how to call Python from C. This is where it gets complicated. It's certainly possible, there's plenty of documentation about it out there, but if you're not an experienced programmer then maybe you shouldn't bother trying. And again, this would have nothing to do with MPh. Comsol would call the external C library, which would start a Python interpreter, which would run the function, pass back the return data to the C library, which then passes it back to Comsol. At this point, you're better off dealing with C alone, that's hard enough. Or use Matlab. Strangely, I don't see a way to call external Java functions in the Comsol documentation, even though Comsol is itself a Java application, but maybe I missed something. |
Beta Was this translation helpful? Give feedback.
-
Hi,
I'm trying to understand whether it's possible to use a python function that I wrote myself. Let's say instead of the step function used in the capacitor.py example I'd like to use a python function. ( I should add that I'm not an expierienced programmer..)
As I understood from the tutorial, the step function for example, is a function that already exists in Comsol and can be called through the MPh package (or am I wrong?). I know that Matlab Livelink gives the option to create your own function. Is this also possible through this package?
The idea is as follows:
The python function (pyfunc) looks like this:
The python function (pyfunc) generates an
output
by taking theinital_value
. Thisoutput
is then used by Comsol, which generates anoutput_COMSOL
. After theoutput_COMSOL
has been generated thisoutput_COMSOL
is fed back to the pyfunc so that a newoutput
is genereted.This process shall be run as long as the solution is found by Comsol.
Is something like this possible and how can I intergrate the python function into comsol ?
I hope the question is clear.
Thank you for your help!
Beta Was this translation helpful? Give feedback.
All reactions