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
Posted Mar 3, 2011, 10:50 a.m. EST Studies & Solvers Version 4.1 7 Replies
Please login with a confirmed email address before reporting spam
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
Please login with a confirmed email address before reporting spam
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
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
Please login with a confirmed email address before reporting spam
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
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
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
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
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.
Suggested Content
- KNOWLEDGE BASE Solving Models with Step Changes to Loads in Time
- BLOG Building COMSOL Multiphysics Models with Excel® and Visual Basic®
- KNOWLEDGE BASE COMSOL Not Working on a Linux Cluster
- FORUM State Space Export
- KNOWLEDGE BASE Failed to load data from the database while saving.