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.

How to automate "Integrate"

Please login with a confirmed email address before reporting spam

Possibly a dumb question, I am new at this...

I am modelling oxygen diffusion to an array of spheres through a substrate with some heterogeneities. One objective is to integrate oxygen flux to each sphere, report those values, and then afterwards I can look at the distribution of these values to check if we can reasonably claim that they all get more or less the same amount.

So I can do this manually, by creating an "Integral" under Data Sets for each sphere individually and manually selecting and adding all the faces, and then exporting the diffusive flux magnitude. The problem is I need meaningful n values so maybe 100 or more spheres, and this would take a long time of just clicking around to set up (and then I'd have to combine the 100 exported individual data files). Also I'd like to be able to modify the model easily in the future. Is there a way to do this in a more automated way? The spheres themselves are arrayed copies of a single original sphere. Ideally I'd like to end up with one exported file that has a separate value in it for the integrated flux magnitude for each sphere.

Thanks

Mark

4 Replies Last Post 12 gen 2012, 21:31 GMT-5
Ivar KJELBERG COMSOL Multiphysics(r) fan, retired, former "Senior Expert" at CSEM SA (CH)

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago 11 gen 2012, 18:06 GMT-5
Hi

I would say you should consider scripting your model via Matlab or an API programming approach

to start you can build a first model in the GUI and then save it as a "m" file, then build ur model based on this m file

but clicking around is rather common, we have models with > 800 magnets generated within COMSOL and disposed on a spherical surface, + coils and sources, this requires quite some clicking (and a tennis elbow from the right-clicks ;) but it works 100% inside the GUI

--
Good luck
Ivar
Hi I would say you should consider scripting your model via Matlab or an API programming approach to start you can build a first model in the GUI and then save it as a "m" file, then build ur model based on this m file but clicking around is rather common, we have models with > 800 magnets generated within COMSOL and disposed on a spherical surface, + coils and sources, this requires quite some clicking (and a tennis elbow from the right-clicks ;) but it works 100% inside the GUI -- Good luck Ivar

Nagi Elabbasi Facebook Reality Labs

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago 11 gen 2012, 22:35 GMT-5
If there is a gap between the spheres you can select all the spheres in one integral and multiply the integrated quantity by something like (x>A)*(x<B)*(y>C)*(y<D) where A and B are the bounds of one sphere in the x-direction and C and D are the bounds in the y-direction. That way, you can, either manually or through a Matlab/Java API, just change A-D and reevaluate the integral.

Nagi Elabbasi
Veryst Engineering
If there is a gap between the spheres you can select all the spheres in one integral and multiply the integrated quantity by something like (x>A)*(xC)*(y

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago 11 gen 2012, 23:08 GMT-5

Hi

I would say you should consider scripting your model via Matlab or an API programming approach

to start you can build a first model in the GUI and then save it as a "m" file, then build ur model based on this m file

but clicking around is rather common, we have models with > 800 magnets generated within COMSOL and disposed on a spherical surface, + coils and sources, this requires quite some clicking (and a tennis elbow from the right-clicks ;) but it works 100% inside the GUI

--
Good luck
Ivar


That looks very useful. I have made an example and done some text editing, but now how do you get the modified M file back into COMSOL (4.2 with multiphysics)?

thanks

Mark
[QUOTE] Hi I would say you should consider scripting your model via Matlab or an API programming approach to start you can build a first model in the GUI and then save it as a "m" file, then build ur model based on this m file but clicking around is rather common, we have models with > 800 magnets generated within COMSOL and disposed on a spherical surface, + coils and sources, this requires quite some clicking (and a tennis elbow from the right-clicks ;) but it works 100% inside the GUI -- Good luck Ivar [/QUOTE] That looks very useful. I have made an example and done some text editing, but now how do you get the modified M file back into COMSOL (4.2 with multiphysics)? thanks Mark

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago 12 gen 2012, 21:31 GMT-5
OK, so I have found what looks like a solution (still one thing I'm having trouble with though).

I define a surface under "Results", and select all of the surfaces of all the spheres (technically the faces all belong to the material surrounding the spheres) using the "Select box" tool. Then I export this surface giving me diffusive flux magnitude. As the spheres are in a grid pattern it's easy to assign faces to the correct sphere based on their X and Y coordinates.

The trouble is, the output is diffusive flux magnitude per square meter (results match what I get manually wth Fick's Law for the toy model), and I can't figure out how to get the area of the corresponding mesh element to multiply it by to find out the absolute flux for each element. Also, there are many more exported data points than i expected. For example, I made a toy model moving O2 through a cube and set the mesh to "extremely coarse", so the end face only consists of two triangles. However, when I export this surface instead of the expected 2, I get 25 nodes if i export gauss points (order 1) or 79 (!) if I export Lagrangian points. The only mesh parameter I can export in the same file is "h" - my impression is that this number represents the longest edge of the 3D mesh element to which the specific triangle is attached and forms the surface - so it may not even be an edge shared with the triangle I care about. Any idea where i can get the relevant area numbers?

thanks

Mark
OK, so I have found what looks like a solution (still one thing I'm having trouble with though). I define a surface under "Results", and select all of the surfaces of all the spheres (technically the faces all belong to the material surrounding the spheres) using the "Select box" tool. Then I export this surface giving me diffusive flux magnitude. As the spheres are in a grid pattern it's easy to assign faces to the correct sphere based on their X and Y coordinates. The trouble is, the output is diffusive flux magnitude per square meter (results match what I get manually wth Fick's Law for the toy model), and I can't figure out how to get the area of the corresponding mesh element to multiply it by to find out the absolute flux for each element. Also, there are many more exported data points than i expected. For example, I made a toy model moving O2 through a cube and set the mesh to "extremely coarse", so the end face only consists of two triangles. However, when I export this surface instead of the expected 2, I get 25 nodes if i export gauss points (order 1) or 79 (!) if I export Lagrangian points. The only mesh parameter I can export in the same file is "h" - my impression is that this number represents the longest edge of the 3D mesh element to which the specific triangle is attached and forms the surface - so it may not even be an edge shared with the triangle I care about. Any idea where i can get the relevant area numbers? thanks Mark

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.