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.
1D transport LivelinkComsol Matlab funciton com.comsol.model.impl.StudyImpl
Posted 06.03.2014, 05:54 GMT-5 0 Replies
Please login with a confirmed email address before reporting spam
I try to couple COMSOL with other program using MATLAB [LinkLiveComsol], and I have the following problem that I cannot understand.
Imagine you have a really simple advection-dispersion transport problem in 1D. (Groundwater, so the physical equation used is solute transport [esst])
Imagine now that you state a time step of 60 second for an interval of 720 seconds. Then, you create in MATLAB two function.
The first function [FUNCTION 1]runs through the whole interval of time, with a dt=60 and t=720. That is state in Comsol as follows: Study1--> Step 1: Time Dependent -->Study Settings-->Times: range(0,60,720)
The other function [FUNCTION 2] runs for just one interval in Comsol during several times (matlab for loop), namely:
Study1--> Step 1: Time Dependent -->Study Settings-->Times: range(0,60,60)
for loop of 12 iterations (720/60=12)
Cn+1=COMSOL(C n)
end
Cn=previous concentration
Cn+1=final concentration
After doing this two functions we saw that the running time of the first function was 19 times smaller than the running time of the second function.
Using the "run and time" function of MATLAB it was possible to observe that most of the time consumed was in the statement: model.study.create('std1').run which call 4 times the statement: com.comsol.model.impl.StudyImpl whic is a java method belonging to COMSOL.
We thought that maybe It had something to do with the solver, and we realized, thanks to the log window of COMSOL, that actually the BDF method was taking just around 20 steps for solve both interval of times, the one that goes from 0 to 720 in the first function and the one that goes from 0 to 60.
So, our next step was to control the integration time used by comsol, in order to do that we change the following parameter. [Change from BDF method to Generalized alpha (Manual)]
Study1--> Solver Configuration --> Solver1--> Time-Dependent Solver 1 -->Study Settings-->Time stepping--> Method: Generalized alpha
Study1--> Solver Configuration --> Solver1--> Time-Dependent Solver 1 -->Study Settings-->Time stepping--> Steps taken by the solver: Manual
Study1--> Solver Configuration --> Solver1--> Time-Dependent Solver 1 -->Study Settings-->Time stepping--> Time step: 60
To do we run in Matlab the following script:
model.sol.create('sol1');
model.sol('sol1').study('std1');
model.sol('sol1').feature.create('st1', 'StudyStep');
model.sol('sol1').feature('st1').set('study', 'std1');
model.sol('sol1').feature('st1').set('studystep', 'time');
model.sol('sol1').feature.create('v1', 'Variables');
model.sol('sol1').feature('v1').set('control', 'time');
model.sol('sol1').feature.create('t1', 'Time');
model.sol('sol1').feature('t1').set('timemethod', 'genalpha');
model.sol('sol1').feature('t1').set('tstepsgenalpha', 'manual');
model.sol('sol1').feature('t1').set('timestepgenalpha', num2str(t_step));
model.sol('sol1').feature('t1').set('predictor', 'linear');
model.sol('sol1').attach('std1');
std1.run;
where " num2str (t_step)" is a char class containing the number of time steps, in this case '60'.
After applying such code we observe that even though the number of iterations done by COMSOL was equal in both, using the function 1 and using function 2. The time of running function 2 was still around 19 times higher than the time used to run function one.
I will like to understand why the time of function 2 is much higher than the time of function 1. Is there some parameter that differ? Have The numerical methods been modified?
Thank you
Best
Hello Antoine Armandine Les Landes
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.