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.

state space export via comsol API

Please login with a confirmed email address before reporting spam

Hi,

Can someone please provide an example of how to export the state space matrices through COMSOL's API? I'm able to call the functions and it returns N x 1 matrices, which I thought would be an N x N matrix for MA and MB. Any help is appreciated.

Thanks,
Andrew Wang

7 Replies Last Post 3 mai 2011, 17:58 UTC−4
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: 1 decade ago 3 mars 2011, 10:59 UTC−5
Hi

indeed, even in matlab its not working as "written", as there seem to be typos in the 4.1 doc

Does anybody have a simple cantilever state space matrix extraction for a driving point somewhere along the beam and an output i.e. at the tip ?

--
Good luck
Ivar
Hi indeed, even in matlab its not working as "written", as there seem to be typos in the 4.1 doc Does anybody have a simple cantilever state space matrix extraction for a driving point somewhere along the beam and an output i.e. at the tip ? -- Good luck Ivar

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago 8 mars 2011, 11:13 UTC−5
Hi Ivar,

Thanks for responding to my question. I've talked with Remi Magnard about this problem and it seems that I have to get the row and column indices of the matrix (such as MA, MB) using

row = m.sol("sol1").feature("sp1").getSparseMatrixRow(name);
col = m.sol("sol1").feature("sp1").getSparseMatrixCol(name);

and then manually create the matrix in question by using a matlab command like:

MM(row(k),col(k)) = M(k)

However, when I look at the C matrix, I'm getting [ ], even when I set the input equal to the output. I don't think the C matrix should be empty, but I'm not sure what setting I missed. Here's my code:

First I define a probe:

model.probe().create("pdom1", "DomainPoint");
model.probe("pdom1").model("mod1");
model.probe("pdom1").set("method", "none");
model.probe("pdom1").setIndex("coords3", "10", 0, 0);
model.probe("pdom1").setIndex("coords3", "2.5", 0, 1);
model.probe("pdom1").setIndex("coords3", "2", 0, 1);
model.probe("pdom1").setIndex("coords3", "2.5", 0, 2);
model.probe("pdom1").feature("ppb1").set("expr", "tem.disp");
model.probe("pdom1").genResult("sol1");

Then I define the state space settings:

model.sol("sol1").feature().create("sp1", "StateSpace");
model.sol("sol1").feature("sp1").set("input", "T0");
model.sol("sol1").feature("sp1").set("output", "mod1.pdom1");
model.sol("sol1").feature("sp1").set("MA", true);
model.sol("sol1").feature("sp1").set("MB", true);
model.sol("sol1").feature("sp1").set("C", true);
model.sol("sol1").feature("sp1").set("D", true);

model.sol("sol1").run("sp1");

And regardless of what I put in output and input, I get an empty matrix for C. Can someone please help me with this problem?

Thanks,
Andrew Wang
Hi Ivar, Thanks for responding to my question. I've talked with Remi Magnard about this problem and it seems that I have to get the row and column indices of the matrix (such as MA, MB) using row = m.sol("sol1").feature("sp1").getSparseMatrixRow(name); col = m.sol("sol1").feature("sp1").getSparseMatrixCol(name); and then manually create the matrix in question by using a matlab command like: MM(row(k),col(k)) = M(k) However, when I look at the C matrix, I'm getting [ ], even when I set the input equal to the output. I don't think the C matrix should be empty, but I'm not sure what setting I missed. Here's my code: First I define a probe: model.probe().create("pdom1", "DomainPoint"); model.probe("pdom1").model("mod1"); model.probe("pdom1").set("method", "none"); model.probe("pdom1").setIndex("coords3", "10", 0, 0); model.probe("pdom1").setIndex("coords3", "2.5", 0, 1); model.probe("pdom1").setIndex("coords3", "2", 0, 1); model.probe("pdom1").setIndex("coords3", "2.5", 0, 2); model.probe("pdom1").feature("ppb1").set("expr", "tem.disp"); model.probe("pdom1").genResult("sol1"); Then I define the state space settings: model.sol("sol1").feature().create("sp1", "StateSpace"); model.sol("sol1").feature("sp1").set("input", "T0"); model.sol("sol1").feature("sp1").set("output", "mod1.pdom1"); model.sol("sol1").feature("sp1").set("MA", true); model.sol("sol1").feature("sp1").set("MB", true); model.sol("sol1").feature("sp1").set("C", true); model.sol("sol1").feature("sp1").set("D", true); model.sol("sol1").run("sp1"); And regardless of what I put in output and input, I get an empty matrix for C. Can someone please help me with this problem? Thanks, Andrew Wang

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: 1 decade ago 8 mars 2011, 15:20 UTC−5
Hi


Thanks for the feed back (indeed Remi is of good help ;)

are you sure your physics and material parameters are such that C would be populated ?

--
Good luck
Ivar
Hi Thanks for the feed back (indeed Remi is of good help ;) are you sure your physics and material parameters are such that C would be populated ? -- Good luck Ivar

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago 8 mars 2011, 16:19 UTC−5
Hi Ivar,

That's a possibility, I'll check on that. However, I am just exporting an example from the Model library into eclipse and adding in the above code. Also, I am able to run the .java model in the COMSOL GUI and it gives me an output that I expect.

Best Regards,
Andrew
Hi Ivar, That's a possibility, I'll check on that. However, I am just exporting an example from the Model library into eclipse and adding in the above code. Also, I am able to run the .java model in the COMSOL GUI and it gives me an output that I expect. Best Regards, Andrew

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago 23 mars 2011, 13:34 UTC−4
The problem is with the probe. When you export state space matrices with the probe, then you will always get an empty C matrix. Remi suggests using a variable instead and then use:

model.sol("sol1").feature().create("sp1", "StateSpace");
> > model.sol("sol1").feature("sp1").set("input", new String[]{"T0"});
> > model.sol("sol1").feature("sp1")
> > .set("output", new String[]{"mod1.intop1(mod1.outvar)"});
> > model.sol("sol1").feature("sp1").set("C", true);
> > model.sol("sol1").run("sp1");
> > model.sol("sol1").feature("sp1").getSparseMatrixVal("C");

to extract the state space matrices. In the example, outvar is a variable defined in the geometry and intop1 is an integration coupling variable.
The problem is with the probe. When you export state space matrices with the probe, then you will always get an empty C matrix. Remi suggests using a variable instead and then use: model.sol("sol1").feature().create("sp1", "StateSpace"); > > model.sol("sol1").feature("sp1").set("input", new String[]{"T0"}); > > model.sol("sol1").feature("sp1") > > .set("output", new String[]{"mod1.intop1(mod1.outvar)"}); > > model.sol("sol1").feature("sp1").set("C", true); > > model.sol("sol1").run("sp1"); > > model.sol("sol1").feature("sp1").getSparseMatrixVal("C"); to extract the state space matrices. In the example, outvar is a variable defined in the geometry and intop1 is an integration coupling variable.

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago 3 mai 2011, 17:58 UTC−4
Hello Ivar

I am currently working on a simple cantilever beam state space extraction but there are some unresolved issues. I am not certain which parameter should be defined as input -- I give a point load at a point in the free end of the beam -- so I use the corresponding load parameter Fp (which is a vector: Fp={0,Fy,0} , where Fy -- vertical point load parameter) as input in mphstate command. For the output, I use domain point probe as mentioned by you (but defined at the loading point ).

When I run this model, it gives the following error:

------------------------------------------------------------------
??? Java exception occurred:
Exception:
com.comsol.util.exceptions.FlException: The following feature has encountered a problem
Messages:
The following feature has encountered a problem


Stack trace:

at com.comsol.solver.SolverOperation.addError(Unknown Source)

at com.comsol.solver.SolverOperation.execute(Unknown Source)

at com.comsol.model.impl.SolverSequenceImpl.a(Unknown Source)

.....

.....

.....

.....
... 3 more


Error in ==> C:\COMSOL41\mli\mphstate.p>mphstate at 95


Error in ==> Test_2D_Beam_Deflection_Analysis_A at 106
M = mphstate(model,'sol1','out',{'MA' 'MB' 'C' 'D'},...

------------------------------------------------------------------

So, I am not able to figure out how to solve this issue -- any comment regarding this is highly appreciated. For your reference, I have attached the MATLAB and COMSOL files with this. The most part of the MATLAB file is the one that is generated by COMSOL, but I have added a few lines in between to plot the geometry, mesh as well as the simulation results as the program execution is carried out in addition to the mphstate command line which is right at the bottom of the file.

------
On a lighter note, I realized, once you are within MATLAB, in order to convert the sparse state space matrices to full matrix, we can use the "full()" command available in MATLAB which seems to be easier compared to the one posted in this forum. If I am wrong here as well, please correct me.
------

Thanks
Madu
Hello Ivar I am currently working on a simple cantilever beam state space extraction but there are some unresolved issues. I am not certain which parameter should be defined as input -- I give a point load at a point in the free end of the beam -- so I use the corresponding load parameter Fp (which is a vector: Fp={0,Fy,0} , where Fy -- vertical point load parameter) as input in mphstate command. For the output, I use domain point probe as mentioned by you (but defined at the loading point ). When I run this model, it gives the following error: ------------------------------------------------------------------ ??? Java exception occurred: Exception: com.comsol.util.exceptions.FlException: The following feature has encountered a problem Messages: The following feature has encountered a problem Stack trace: at com.comsol.solver.SolverOperation.addError(Unknown Source) at com.comsol.solver.SolverOperation.execute(Unknown Source) at com.comsol.model.impl.SolverSequenceImpl.a(Unknown Source) ..... ..... ..... ..... ... 3 more Error in ==> C:\COMSOL41\mli\mphstate.p>mphstate at 95 Error in ==> Test_2D_Beam_Deflection_Analysis_A at 106 M = mphstate(model,'sol1','out',{'MA' 'MB' 'C' 'D'},... ------------------------------------------------------------------ So, I am not able to figure out how to solve this issue -- any comment regarding this is highly appreciated. For your reference, I have attached the MATLAB and COMSOL files with this. The most part of the MATLAB file is the one that is generated by COMSOL, but I have added a few lines in between to plot the geometry, mesh as well as the simulation results as the program execution is carried out in addition to the mphstate command line which is right at the bottom of the file. ------ On a lighter note, I realized, once you are within MATLAB, in order to convert the sparse state space matrices to full matrix, we can use the "full()" command available in MATLAB which seems to be easier compared to the one posted in this forum. If I am wrong here as well, please correct me. ------ Thanks Madu


Please login with a confirmed email address before reporting spam

Posted: 1 decade ago 3 mai 2011, 17:58 UTC−4
Hello Ivar

I am currently working on a simple cantilever beam state space extraction but there are some unresolved issues. I am not certain which parameter should be defined as input -- I give a point load at a point in the free end of the beam -- so I use the corresponding load parameter Fp (which is a vector: Fp={0,Fy,0} , where Fy -- vertical point load parameter) as input in mphstate command. For the output, I use domain point probe as mentioned by you (but defined at the loading point ).

When I run this model, it gives the following error:

------------------------------------------------------------------
??? Java exception occurred:
Exception:
com.comsol.util.exceptions.FlException: The following feature has encountered a problem
Messages:
The following feature has encountered a problem


Stack trace:

at com.comsol.solver.SolverOperation.addError(Unknown Source)

at com.comsol.solver.SolverOperation.execute(Unknown Source)

at com.comsol.model.impl.SolverSequenceImpl.a(Unknown Source)

.....

.....

.....

.....
... 3 more


Error in ==> C:\COMSOL41\mli\mphstate.p>mphstate at 95


Error in ==> Test_2D_Beam_Deflection_Analysis_A at 106
M = mphstate(model,'sol1','out',{'MA' 'MB' 'C' 'D'},...

------------------------------------------------------------------

So, I am not able to figure out how to solve this issue -- any comment regarding this is highly appreciated. For your reference, I have attached the MATLAB and COMSOL files with this. The most part of the MATLAB file is the one that is generated by COMSOL, but I have added a few lines in between to plot the geometry, mesh as well as the simulation results as the program execution is carried out in addition to the mphstate command line which is right at the bottom of the file.

------
On a lighter note, I realized, once you are within MATLAB, in order to convert the sparse state space matrices to full matrix, we can use the "full()" command available in MATLAB which seems to be easier compared to the one posted in this forum. If I am wrong here as well, please correct me.
------

Thanks
Madu
Hello Ivar I am currently working on a simple cantilever beam state space extraction but there are some unresolved issues. I am not certain which parameter should be defined as input -- I give a point load at a point in the free end of the beam -- so I use the corresponding load parameter Fp (which is a vector: Fp={0,Fy,0} , where Fy -- vertical point load parameter) as input in mphstate command. For the output, I use domain point probe as mentioned by you (but defined at the loading point ). When I run this model, it gives the following error: ------------------------------------------------------------------ ??? Java exception occurred: Exception: com.comsol.util.exceptions.FlException: The following feature has encountered a problem Messages: The following feature has encountered a problem Stack trace: at com.comsol.solver.SolverOperation.addError(Unknown Source) at com.comsol.solver.SolverOperation.execute(Unknown Source) at com.comsol.model.impl.SolverSequenceImpl.a(Unknown Source) ..... ..... ..... ..... ... 3 more Error in ==> C:\COMSOL41\mli\mphstate.p>mphstate at 95 Error in ==> Test_2D_Beam_Deflection_Analysis_A at 106 M = mphstate(model,'sol1','out',{'MA' 'MB' 'C' 'D'},... ------------------------------------------------------------------ So, I am not able to figure out how to solve this issue -- any comment regarding this is highly appreciated. For your reference, I have attached the MATLAB and COMSOL files with this. The most part of the MATLAB file is the one that is generated by COMSOL, but I have added a few lines in between to plot the geometry, mesh as well as the simulation results as the program execution is carried out in addition to the mphstate command line which is right at the bottom of the file. ------ On a lighter note, I realized, once you are within MATLAB, in order to convert the sparse state space matrices to full matrix, we can use the "full()" command available in MATLAB which seems to be easier compared to the one posted in this forum. If I am wrong here as well, please correct me. ------ Thanks Madu

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.