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.

Problem with create new solution in comsol 4.1

Please login with a confirmed email address before reporting spam

Hi
I have problem with crating a solution using script in Comsol 4.1. In help I read that Comsol enabled functionality to manipulate solutions (see help model.sol). I want to creates a solution object from more than one solutions. The Comsol provides function model.sol(<tag>).createSolution(). In accordingly with the Comosol Manual a new created solutions is based on the input from the following sets (real and imaginary components) setU(int,double[]),setPNames(String[]),setPVals(double[]),setPVals(int,double[]) The solution is created at this stage. Afterwards the user input is cleared. If a created solution is used before this function is run the result is unpredictable. When I call createSolution function we get following exception:
??? Java exception occurred:
Exception:
java.lang.NullPointerException
(rethrown as com.comsol.util.exceptions.FlException)
Messages:

Stack trace:
at com.comsol.model.impl.SolverSequenceImpl.K(Unknown Source)
at com.comsol.model.impl.SolverSequenceImpl.createSolution(Unknown Source)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at com.comsol.clientserver.impl.JobImpl.run(Unknown Source)
at com.comsol.server.internal.b.a(Unknown Source)
at com.comsol.server.internal.b.a(Unknown Source)
at com.comsol.server.internal.b$h.a(Unknown Source)
at com.comsol.server.internal.b$h.a(Unknown Source)
at com.comsol.server.internal.b$h$a.run(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Error in ==> przyklad at 147
model.sol('sol3').createSolution()
model.study.create('std3');
model.study('std3').feature.create('time', 'Transient');
model.study('std3').feature('time').set('tlist', {'0','0.1','0.2'});
model.sol.create('sol3');
model.sol('sol3').study('std3');
model.sol('sol3').feature.create('st1', 'StudyStep');
model.sol('sol3').feature('st1').set('study', 'std3');
model.sol('sol3').feature('st1').set('studystep', 'time');
model.sol('sol3').feature.create('v1', 'Variables');
model.sol('sol3').feature.create('t1', 'Time');
model.sol('sol3').feature('t1').set('tlist', {'0','0.1','0.2'});

%Create new solution
model.sol('sol3').setPNames(model.sol('sol2').getPNames());
model.sol('sol3').setPVals([0.0045,0.005,0.0055]);
model.sol('sol3').setPValsImag([0.0045,0.005,0.0055]);
model.sol('sol3').setU(1,model.sol('sol1').getU(1));
model.sol('sol3').setUImag(1,model.sol('sol1').getUImag(1));
model.sol('sol3').setU(2,model.sol('sol2').getU(2));
model.sol('sol3').setUImag(2,model.sol('sol2').getUImag(2));
model.sol('sol3').setU(3,model.sol('sol2').getU(3));
model.sol('sol3').setUImag(3,model.sol('sol2').getUImag(3));
model.sol('sol3').createSolution();

The sol1 and sol2 consist a results of calculation.
Can you help me!!! What should I do to create a new solution properly without any exception using script Comsol 4.1??

5 Replies Last Post 2013年2月18日 GMT-5 04:00
COMSOL Moderator

Hello Pawel Idziak

Your Discussion has gone 30 days without a reply. If you still need help with COMSOL and have an on-subscription license, please visit our Support Center for help.

If you do not hold an on-subscription license, you may find an answer in another Discussion or in the Knowledge Base.


Please login with a confirmed email address before reporting spam

Posted: 1 decade ago 2011年6月28日 GMT-4 18:29
I am also trying to do something similar, please let me know if you have figured out a solution to this. I have the same problem with COMSOL 4.1.
I am also trying to do something similar, please let me know if you have figured out a solution to this. I have the same problem with COMSOL 4.1.

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago 2011年12月13日 GMT-5 13:25
Hello,

I'll put another vote in for finding a solution to this problem. Here's exactly what I'm trying to do now. I developed a model in the COMSOL GUI and solved it with success. I then saved this model as an m-file and ran it in Matlab, again with success. I saved the solution and pvals vector as variables in matlab with the:

model.sol('sol1').getU(i);
model.sol('sol1').getPVals;

commands, and cleared the model. I ran the model all the way up to the sol('sol1').runAll command, and then tried to put the values from u and pvals into the model manually and run the createSolution command. It returned the error shown above. I've tried some other things as well with these commands and haven't had success with anything. Does anybody have an answer to this?

Thanks,
-Matt
Hello, I'll put another vote in for finding a solution to this problem. Here's exactly what I'm trying to do now. I developed a model in the COMSOL GUI and solved it with success. I then saved this model as an m-file and ran it in Matlab, again with success. I saved the solution and pvals vector as variables in matlab with the: model.sol('sol1').getU(i); model.sol('sol1').getPVals; commands, and cleared the model. I ran the model all the way up to the sol('sol1').runAll command, and then tried to put the values from u and pvals into the model manually and run the createSolution command. It returned the error shown above. I've tried some other things as well with these commands and haven't had success with anything. Does anybody have an answer to this? Thanks, -Matt

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago 2011年12月13日 GMT-5 13:33
Matt,
I finally had success with this. Unfortunately the only way this worked for me was in COMSOL 4.2 and 4.2a. The functionality is simply broken in 4.1. Here's a copy & paste of some notes I typed up for myself earlier. I think they should work for you.

2. Load the model in MATLAB using the command:
model = mphload('<modelname>');

3. If needed, get the size of the solution vector:
sizeVec = model.sol('sol1').getSize
u_rows = sizeVec(1);

4. Set the solution vector to some custom values:
model.sol('sol1').setU( rand(u_rows,1) )

5. Set the time value to something arbitrary (?)
model.sol('sol1').setPVals( 0 );

6. Create the solution
model.sol('sol1').createSolution

7. Obtain the mass/stiffness/load vector
MA = mphmatrix(model,'sol1','out',{'E','K','L'},'initmethod','sol')
Matt, I finally had success with this. Unfortunately the only way this worked for me was in COMSOL 4.2 and 4.2a. The functionality is simply broken in 4.1. Here's a copy & paste of some notes I typed up for myself earlier. I think they should work for you. 2. Load the model in MATLAB using the command: model = mphload(''); 3. If needed, get the size of the solution vector: sizeVec = model.sol('sol1').getSize u_rows = sizeVec(1); 4. Set the solution vector to some custom values: model.sol('sol1').setU( rand(u_rows,1) ) 5. Set the time value to something arbitrary (?) model.sol('sol1').setPVals( 0 ); 6. Create the solution model.sol('sol1').createSolution 7. Obtain the mass/stiffness/load vector MA = mphmatrix(model,'sol1','out',{'E','K','L'},'initmethod','sol')

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago 2013年2月12日 GMT-5 03:24
It seems to me the demo is not running any more in 4.3a -> java.lang.NullPointerException
It seems to me the demo is not running any more in 4.3a -> java.lang.NullPointerException


Please login with a confirmed email address before reporting spam

Posted: 1 decade ago 2013年2月18日 GMT-5 04:00

It seems to me the demo is not running any more in 4.3a -> java.lang.NullPointerException


Update: It does work after several attempts and the usage of a modified automatically created result.
[QUOTE] It seems to me the demo is not running any more in 4.3a -> java.lang.NullPointerException [/QUOTE] Update: It does work after several attempts and the usage of a modified automatically created result.

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.