Using Comsol Java API to Evaluate Expression at Arbitrary Point

Please login with a confirmed email address before reporting spam

I am using the Java API to do some results post-processing on an electrostatics study. I came to a point in which I need to interpolate value of the electric potential at some specific point, but I cannot seem to find how to do that from the Java API documentation (alternative link)

In MATLAB Comsol, there is a function mphinterp which does exactly what I want. How can I replicate this functionality in my Java code?

Is it even possible to do that with the Java API only?

P.S. I am doing some optimization in the Java code, which is performance sensitive, which is why I cannot use Matlab mphinterp.


1 Reply Last Post 2023年12月4日 GMT-5 03:48
Gunnar Andersson COMSOL Employee

Please login with a confirmed email address before reporting spam

Posted: 5 months ago 2023年12月4日 GMT-5 03:48
Updated: 5 months ago 2023年12月4日 GMT-5 06:53

You can use the Interp numerical evaluation feature, see page 529 in your first link to the documentation. I think that this is what the mphinterp MATLAB function does.

Example: To evaluate the expression "my_expr" at x=0.5 in domain 1 in a 1D model, do as follows:

  • NumericalFeature ev = m.result().numerical().create("interp","Interp");
  • ev.selection().geom(1);
  • ev.selection().set(1);
  • ev.set("edim", 1);
  • ev.set("expr"," "my_expr");
  • ev.set("coord", new double[]{0.5});
  • double[][][] data = ev.getData();
You can use the Interp numerical evaluation feature, see page 529 in your first link to the documentation. I think that this is what the mphinterp MATLAB function does. Example: To evaluate the expression "my_expr" at x=0.5 in domain 1 in a 1D model, do as follows: * NumericalFeature ev = m.result().numerical().create("interp","Interp"); * ev.selection().geom(1); * ev.selection().set(1); * ev.set("edim", 1); * ev.set("expr"," "my_expr"); * ev.set("coord", new double[]{0.5}); * double[][][] data = ev.getData();

Reply

Please read the discussion forum rules before posting.

Please log in to post a reply.

Note that while COMSOL employees may participate in the discussion forum, COMSOL® software users who are on-subscription should submit their questions via the Support Center for a more comprehensive response from the Technical Support team.