Note: This discussion is about an older version of the COMSOL Multiphysics®software. The information provided may be out of date.

Discussion ClosedThis discussion was created more than 6 months ago and has been closed. To start a new discussion with a link back to this one,click here.

Comsol - Error in using a function to set the boundary condition dynamically in a program

Please login with a confirmed email address before reporting spam

Hi,

I have encountered a problem in using self-written function to set the boundary condition of a heat conduction problem. The following is the part of generated code for setting the intial, boundary conditions and material properties:

...
str_qb = 'sin(t*x*y)';
bnd.g = {0,0.005,str_qb};
bnd.ind = [1,1,2,3,1,1];
appl.bnd = bnd;
clear equ
equ.init = 55;
equ.c = 0.0145;
equ.f = 0;
equ.da = 0.004108;
equ.ind = [1];
appl.equ = equ;
fem.appl{1} = appl;
fem.border = 1;
fem.units = 'SI';
...

Running the program, it works and I obtained the computation results!!!
However, after I commented "str_qb = 'sin(t*x*y)';" and replaced the code "bnd.g = {0,0.005,str_qb};" with "bnd.g = {0,0.005,'qb_fun(t,x,y)'};", where qb_fun(t,x,y) is a function defined by
--------------------------------
function VI = qb_fun(t,x,y)
VI = sin(t*x*y);
--------------------------------
, the program crashed after running. Error message is displayed as follows:

--------------------------
??? Java exception occurred:
Exception:
com.femlab.server.MlError: Error using ==> mtimes
Inner matrix dimensions must agree.
(rethrown as com.femlab.jni.FlNativeException)
Messages:
Error using ==> mtimes
Inner matrix dimensions must agree.

Error in callback


Stack trace:

at callback.cpp, row 113, ()

at com.femlab.solver.FlSolver.femTime(Native Method)

at com.femlab.solver.FemTime.run(SourceFile:69)

at com.femlab.server.FlRunner.run(SourceFile:120)

at com.femlab.server.MlProgressDlg.runAndWait(SourceFile:142)

at com.femlab.server.FlRunnable.runAndWait(SourceFile:69)
.

Error in ==> femsolver at 225
solobj.runAndWait(report, 'Solution Progress', loopTime);

Error in ==> femtime at 61
varargout = femsolver(mfilename,'FemTime',varargin{:});

Error in ==> fp_model at 85
fem.sol=femtime(fem, ...
-------------------------------

I am so confused with the result (I have only set the same boundary condition by means of different ways). I'd greatly appreciate it if some comsol expert can help me find the error. Thanks a lot.

Windson

2 Replies Last Post 2009年7月30日 GMT+2 13:01
Ivar KJELBERG COMSOL Multiphysics(r) fan, retired, former "Senior Expert" at CSEM SA (CH)

Please login with a confirmed email address before reporting spam

Posted: 2 decades ago 2009年7月24日 GMT+2 19:21
Hi

I havnt tried out such functions myself, it looks intersting, but for me it sounds like COMSOL is passing an array to your function and you havn't written it in a comptible way (using .* ./ ...).

Somewhere in the script / matlab I/F doc its written that functions should accept arrays variables run a search on the pdf or the html docs.

Try it out, it might solve your issue, and pls continue to keep us updated

Goos luck
Hi I havnt tried out such functions myself, it looks intersting, but for me it sounds like COMSOL is passing an array to your function and you havn't written it in a comptible way (using .* ./ ...). Somewhere in the script / matlab I/F doc its written that functions should accept arrays variables run a search on the pdf or the html docs. Try it out, it might solve your issue, and pls continue to keep us updated Goos luck

Please login with a confirmed email address before reporting spam

Posted: 2 decades ago 2009年7月30日 GMT+2 13:01
Thanks a lot. It works now!
Thanks a lot. It works now!

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

Baidu
map