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

Discussion Closed This 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.

Will COMSOL reset matlab global variable in each step?

Please login with a confirmed email address before reporting spam

Hi,

I am doing parametric sweep in COMSOL v4.3. the COMSOL model is connected with a matlab funtion fun() which has a global variable G inside. Will COMSOL clear/reset this G for each parameter automatically? If not, How to set up in COMSOL to make sure that G starts with 0 for each parametric sweep input?

Thank you

Dan

2 Replies Last Post 04.09.2012, 21:16 GMT-4

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago 04.09.2012, 20:11 GMT-4
I don't trust COMSOL working with global variables as I've seen it being inconsistent. If I need to reset global, I do it in the code. If I need to keep a variable, I define it as persistent variable.
I don't trust COMSOL working with global variables as I've seen it being inconsistent. If I need to reset global, I do it in the code. If I need to keep a variable, I define it as persistent variable.

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago 04.09.2012, 21:16 GMT-4

I don't trust COMSOL working with global variables as I've seen it being inconsistent. If I need to reset global, I do it in the code. If I need to keep a variable, I define it as persistent variable.


Thank you.

In COMSOL v3.5a, I just run my model in matlab, and this global variable is not a problem.
When I update my model to COMSOL v4.3, everything just changes, I cannot figure out.

Today, I learnt how to obtain stiffness and load matrix from COMSOL 4.3, and how to use a linear solver to get result vector U. Do you know how to write this "U" back to COMSOL so that I can open the solution in COMSOL?

My model has parametric sweep inside, in comsol, those lines are:
plist = [fem.sol.plist nvec(ii)];
u_tot = [fem.sol.u u_end];
fem.sol = femsol(u_tot,'pname','n','plist',plist);

Do you know what command is equivalent to femsol() in the new comsol?

Thanks a lot.

Dan
[QUOTE] I don't trust COMSOL working with global variables as I've seen it being inconsistent. If I need to reset global, I do it in the code. If I need to keep a variable, I define it as persistent variable. [/QUOTE] Thank you. In COMSOL v3.5a, I just run my model in matlab, and this global variable is not a problem. When I update my model to COMSOL v4.3, everything just changes, I cannot figure out. Today, I learnt how to obtain stiffness and load matrix from COMSOL 4.3, and how to use a linear solver to get result vector U. Do you know how to write this "U" back to COMSOL so that I can open the solution in COMSOL? My model has parametric sweep inside, in comsol, those lines are: plist = [fem.sol.plist nvec(ii)]; u_tot = [fem.sol.u u_end]; fem.sol = femsol(u_tot,'pname','n','plist',plist); Do you know what command is equivalent to femsol() in the new comsol? Thanks a lot. Dan

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.