Remi Magnard
                                                                                                                                                    COMSOL Employee
                                                         
                            
                                                                                                                                                
                         
                                                
    
        Please login with a confirmed email address before reporting spam
     
    
 
                                                Posted:
                            
                                3 years ago                            
                            
                                2022年10月20日 GMT+8 21:49                            
                        
                        Updated:
                            
                                3 years ago                            
                            
                                2022年10月20日 GMT+8 22:35                            
                        
                        
                                                    Dear John,
You are right, Livelink for Simulink only supports scalar as input/output to run cosimulation. 
If you want to implement a controller on a field you need to do it in COMSOL, either implement the controller with a COMSOL expression or using an extra equation. If you have the controller implemented in MATLAB you can call an M-function directly inside the COMSOL model (see in the Home tab >  Functions > MATLAB). The function argument and output are assumed to be field variable. Note that the size for the input and output variables has to be the same and thus pointwise operation may be necessary.
Best regards,
Rémi Magnard
                                                 
                                                
                            Dear John, 
You are right, Livelink for Simulink only supports scalar as input/output to run cosimulation. 
If you want to implement a controller on a field you need to do it in COMSOL, either implement the controller with a COMSOL expression or using an extra equation. If you have the controller implemented in MATLAB you can call an M-function directly inside the COMSOL model (see in the Home tab >  Functions > MATLAB). The function argument and output are assumed to be field variable. Note that the size for the input and output variables has to be the same and thus pointwise operation may be necessary.
Best regards,
Rémi Magnard                        
                                                
                                                                                                            
                                             
                                            
                                                
    
        Please login with a confirmed email address before reporting spam
     
    
 
                                                Posted:
                            
                                3 years ago                            
                            
                                2022年10月22日 GMT+8 00:36                            
                        
                        
                                                    Hi Remi,
That is good to know about Simulink’s capabilities. For implementing a field controller with a Matlab function inside Comsol, would you be able to guarantee that Comsol calls it at every timestep for a transient study? I was under the impression that the two main ways to get a “real time” controller would be to either use Simulink concurrently, or to run a case at every timestep and update the Comsol solve via a Matlab function before the next run. Thank you for your help.
John
                                                 
                                                
                            Hi Remi,
That is good to know about Simulink’s capabilities. For implementing a field controller with a Matlab function inside Comsol, would you be able to guarantee that Comsol calls it at every timestep for a transient study? I was under the impression that the two main ways to get a “real time” controller would be to either use Simulink concurrently, or to run a case at every timestep and update the Comsol solve via a Matlab function before the next run. Thank you for your help.
John                        
                                                
                                                                                                            
                                             
                        
                        
                            
                                                                                        
                                Remi Magnard
                                                                                                                                                    COMSOL Employee
                                                         
                            
                                                                                                                                                
                         
                                                
    
        Please login with a confirmed email address before reporting spam
     
    
 
                                                Posted:
                            
                                3 years ago                            
                            
                                2022年10月25日 GMT+8 19:14                            
                        
                        Updated:
                            
                                3 years ago                            
                            
                                2022年10月25日 GMT+8 20:01                            
                        
                        
                                                    Yes the MATLAB function callback is performed at every time step as any functions defined in COMSOL.
Note that COMSOL may assemble the system in different blocks; this means that the same function can be called several times for the same time step. If you need to keep track of the solution in a previous time step, then you may need to define a persistent variable in your MATLAB function.
If you have further questions, I invite you to send them via the COMSOL support (you can mention me in the subject); this will ensure you a proper follow up.
                                                 
                                                
                            Yes the MATLAB function callback is performed at every time step as any functions defined in COMSOL. 
Note that COMSOL may assemble the system in different blocks; this means that the same function can be called several times for the same time step. If you need to keep track of the solution in a previous time step, then you may need to define a persistent variable in your MATLAB function.
If you have further questions, I invite you to send them via the COMSOL support (you can mention me in the subject); this will ensure you a proper follow up.