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.

Access depenant variable in Matlab code

Please login with a confirmed email address before reporting spam

Hi

I am trying to develop a diffusion-reaction model using COMSOL - MATLAB interface. My model requires access to dependent variables during the execution so that they can be passed to an external function to calculate the flux at each point.
Can you please help me how to access dependent variables?



1 Reply Last Post 24.07.2013, 05:42 GMT-4

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago 24.07.2013, 05:42 GMT-4
Hi,


In 4.3a, this is possible in many ways. (I think in 4.3b, these commands may have been revised).

1. You can output the solution vector for the entire problem using "mphgetU" command (see API reference manual). The only caution is that you must study the output format especially when you have more than one degree of freedom per node or when you have multiple domains with different element type or discretization orders.

2. Alternatively, the simplest is to use "mpheval" command to extract either nodal or gaussian point values of dependent variables. Again see recent manual for syntax.

I am not familiar with corresponding commands for version 3.5a. But if I faintly remember,

1. To get solution vector similar to (1) above, you may need to use the fem structure with the syntax being somewhat like:

dependent_variable = fem.sol.u()

2. And similar to (2) above, you may need to use postinterp I think. It will be somewhat like:

dependent_variable = postinterp(fem,'u',coords(),'Solnum','end')';

As I said you need to get the exact syntax from ver 3.5a manuals. May be there are other more appropriate commands for your purpose.



Suresh
Hi, In 4.3a, this is possible in many ways. (I think in 4.3b, these commands may have been revised). 1. You can output the solution vector for the entire problem using "mphgetU" command (see API reference manual). The only caution is that you must study the output format especially when you have more than one degree of freedom per node or when you have multiple domains with different element type or discretization orders. 2. Alternatively, the simplest is to use "mpheval" command to extract either nodal or gaussian point values of dependent variables. Again see recent manual for syntax. I am not familiar with corresponding commands for version 3.5a. But if I faintly remember, 1. To get solution vector similar to (1) above, you may need to use the fem structure with the syntax being somewhat like: dependent_variable = fem.sol.u() 2. And similar to (2) above, you may need to use postinterp I think. It will be somewhat like: dependent_variable = postinterp(fem,'u',coords(),'Solnum','end')'; As I said you need to get the exact syntax from ver 3.5a manuals. May be there are other more appropriate commands for your purpose. Suresh

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.