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.

Return a modified structure from Matlab to COMSOL for a new iteration.

Please login with a confirmed email address before reporting spam

Hello,

I am new on this discussion. I am working for my master thesis designing optimization algorithms in order to finding the minimum HTS tape usage on future wind turbines.

My question is: I am working with sensitivity analysis in COMSOL. I have a control variable which is "p" and an initial guess "IG". After my first iteration I obtain the expression fsens(p) and I evaluate this expression in Matlab. There I obtain a structure like this:

pSol =

expr: {'p'}
d1: [1x277 double]
p: [2x277 double]
t: [3x488 int32]
ve: [277x1 int32]
unit: {''}

My goal is to run an optimization algorithm in matlab which will give me a new result for the field "p.d1" which is the material distribution (1 - filled, 0- void). This new vector contains the value of "p" for each element in the model. I need to enter this new structure again to COMSOL to run the following iteration and get the new sensitivities for this new distribution. I tried million of things and nothing works.

Does someone knows how can I do this?

Thanks,
Matias

4 Replies Last Post Apr 4, 2012, 10:23 a.m. EDT

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago Apr 2, 2012, 11:02 p.m. EDT
Have you tried to polyfit the 'p' distribution as a function of space? You could reassign the material property 'p' at each simulation as a polynomial.
Have you tried to polyfit the 'p' distribution as a function of space? You could reassign the material property 'p' at each simulation as a polynomial.

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago Apr 3, 2012, 3:20 a.m. EDT
Thanks for your reply.

I understand what you mean, but I don't know how to implement that. Do you mean modify material properties and insert a new one named 'p' in a polynomial form? Could you elaborate a bit more?

At the moment what I did is to implement a MATLAB node which searches for a MATLAB function that returns the new distribution in a vector form and I assign this to the initial guess. But when I run the system, the following message appears:


Syntax error in expression.
- Expression: if(mod1.mf.normB==0,nojac((subst(mod1.mf.normH,mod1.mf.Bx,1.0E-6[T])-mod1.mf.normH)/1.0E-6[T])*mod1.mf.Bx,mod1.mf.normH*mod1.mf.Bx/sqrt(mod1.mf.Bx^2+mod1.mf.By^2+eps))

The magnetic field (mf.normH) is calculated with an ampere's law and as a function of the magnetic flux density with the HBcurve relation.

Do you have any help?

thank you very much.
Matias
Thanks for your reply. I understand what you mean, but I don't know how to implement that. Do you mean modify material properties and insert a new one named 'p' in a polynomial form? Could you elaborate a bit more? At the moment what I did is to implement a MATLAB node which searches for a MATLAB function that returns the new distribution in a vector form and I assign this to the initial guess. But when I run the system, the following message appears: Syntax error in expression. - Expression: if(mod1.mf.normB==0,nojac((subst(mod1.mf.normH,mod1.mf.Bx,1.0E-6[T])-mod1.mf.normH)/1.0E-6[T])*mod1.mf.Bx,mod1.mf.normH*mod1.mf.Bx/sqrt(mod1.mf.Bx^2+mod1.mf.By^2+eps)) The magnetic field (mf.normH) is calculated with an ampere's law and as a function of the magnetic flux density with the HBcurve relation. Do you have any help? thank you very much. Matias

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago Apr 3, 2012, 8:25 a.m. EDT
Hi,

I thought you were running all your code in Matlab, what I mean is (in "Comsol 4.2a with Matlab"):
1- run your script in a loop (search the forum, I wrote a detailed post on how to do that)
2- at the end of the loop, you mpheval the variable 'p' and you can polyfit it as function of space. All that you need for the polyfit is in the mpheval structure. You can easily find how to polyfit in matlab help or on the web.
3- redefine 'p' with the new polyfit polynomial at each loop.

I'm not familiar with a matlab node in comsol, I don't know what are the limits with using that.

hope it helps
Hi, I thought you were running all your code in Matlab, what I mean is (in "Comsol 4.2a with Matlab"): 1- run your script in a loop (search the forum, I wrote a detailed post on how to do that) 2- at the end of the loop, you mpheval the variable 'p' and you can polyfit it as function of space. All that you need for the polyfit is in the mpheval structure. You can easily find how to polyfit in matlab help or on the web. 3- redefine 'p' with the new polyfit polynomial at each loop. I'm not familiar with a matlab node in comsol, I don't know what are the limits with using that. hope it helps

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago Apr 4, 2012, 10:23 a.m. EDT
Thanks
Thanks

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.