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.
avoid MPHLOAD every iteration in matlab livelink
Posted Oct 28, 2016, 6:40 p.m. EDT 2 Replies
Please login with a confirmed email address before reporting spam
Hello All,
I am using the genetic algorithm in Matlab which calls a Comsol permanent magnet simulation in each iteration of the optimization via livelink.
The simulation is very slow - running the simulation in comsol takes about 1-2 seconds, while running the simulation through matlab takes about 6 seconds which is killing my optimization. In each iteration, the fitness function runs the matlab code as follows
1)
model = mphopen('Topology_optimization_6_efficient_basic');
2)
model.param.set('mag1',val_n(1));
......... (set other parameters)
3)
model.sol('sol1').run;
The loading operation (1) takes about 3 seconds, operation (2) is almost instant and operation (3), actually solving the model, takes about 3 seconds. So it seems obvious - if I can remove the mphopen command, my 6 day simulation should run about twice as fast!
But doing this has not proved challenging. Basically, I would like to run the "mphopen" command BEFORE i call the genetic algorithm, then in each iteration the fitness function has access to model.param and model.sol, et cetera - thus it is a problem of the scope of "model". As such, is there a way I can define "model" in matlab to be global, such that I can change parameters in a different function without calling "mphopen" each time?
Any help here would be most appreciated.
Best,
Reed
p.s. Comsol 5.2, AC/DC module, matlab 2016a
I am using the genetic algorithm in Matlab which calls a Comsol permanent magnet simulation in each iteration of the optimization via livelink.
The simulation is very slow - running the simulation in comsol takes about 1-2 seconds, while running the simulation through matlab takes about 6 seconds which is killing my optimization. In each iteration, the fitness function runs the matlab code as follows
1)
model = mphopen('Topology_optimization_6_efficient_basic');
2)
model.param.set('mag1',val_n(1));
......... (set other parameters)
3)
model.sol('sol1').run;
The loading operation (1) takes about 3 seconds, operation (2) is almost instant and operation (3), actually solving the model, takes about 3 seconds. So it seems obvious - if I can remove the mphopen command, my 6 day simulation should run about twice as fast!
But doing this has not proved challenging. Basically, I would like to run the "mphopen" command BEFORE i call the genetic algorithm, then in each iteration the fitness function has access to model.param and model.sol, et cetera - thus it is a problem of the scope of "model". As such, is there a way I can define "model" in matlab to be global, such that I can change parameters in a different function without calling "mphopen" each time?
Any help here would be most appreciated.
Best,
Reed
p.s. Comsol 5.2, AC/DC module, matlab 2016a
2 Replies Last Post Nov 17, 2016, 5:57 p.m. EST