<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>COMSOL Blog &#187; LiveLink for MATLAB</title>
	<atom:link href="http://www.comsol.se/blogs/category/interfacing/livelink-for-matlab/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.comsol.se/blogs</link>
	<description></description>
	<lastBuildDate>Thu, 22 Nov 2018 09:33:42 +0000</lastBuildDate>
	<language>en-US</language>
		<sy:updatePeriod>hourly</sy:updatePeriod>
		<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.9.1</generator>
<atom:link rel="hub" href="http://pubsubhubbub.appspot.com"/><atom:link rel="hub" href="http://superfeedr.com/hubbub"/>	<item>
		<title>Optimizing the Geometry of Optical Antennas with Genetic Algorithms</title>
		<link>https://www.comsol.se/blogs/optimizing-the-geometry-of-optical-antennas-with-genetic-algorithms/</link>
		<comments>https://www.comsol.se/blogs/optimizing-the-geometry-of-optical-antennas-with-genetic-algorithms/#comments</comments>
		<pubDate>Tue, 12 Sep 2017 08:48:51 +0000</pubDate>
		<dc:creator><![CDATA[Caty Fairclough]]></dc:creator>
				<category><![CDATA[Electrical]]></category>
		<category><![CDATA[General]]></category>
		<category><![CDATA[Interfacing]]></category>
		<category><![CDATA[LiveLink for MATLAB]]></category>
		<category><![CDATA[Optimization & Inverse Methods]]></category>
		<category><![CDATA[RF & Microwave Engineering]]></category>
		<category><![CDATA[RF Module]]></category>

		<guid isPermaLink="false">http://com.staging.comsol.com/blogs?p=234071</guid>
		<description><![CDATA[When thinking about natural selection, antennas are probably not the first thing that comes to mind. But with genetic algorithms, we can use the basic principles of natural selection to solve antenna optimization problems. For example, genetic algorithms enabled one research group to optimize the geometry of an optical antenna. They implemented their study by using LiveLink™ for MATLAB®, an add-on product to the COMSOL Multiphysics® software. The Connection Between Natural Selection and Antenna Optimization The idea behind natural selection [&#8230;]]]></description>
				<content:encoded><![CDATA[<p>When thinking about natural selection, antennas are probably not the first thing that comes to mind. But with genetic algorithms, we can use the basic principles of natural selection to solve antenna optimization problems. For example, genetic algorithms enabled one research group to optimize the geometry of an optical antenna. They implemented their study by using LiveLink™ <em>for</em> MATLAB®, an add-on product to the COMSOL Multiphysics® software.</p>
<p><span id="more-234071"></span></p>
<h3>The Connection Between Natural Selection and Antenna Optimization</h3>
<p>The idea behind natural selection is based on the fact that there is a great deal of variation in the world; even organisms of the same species differ from one another. The organisms with traits best suited for their environment are more likely to survive and pass those traits on to the next generation, which increases the occurrence of the beneficial traits in future generations. As a result, each successive generation becomes more adapted to their environment. That&#8217;s natural selection, in a nutshell.</p>
<p><img src="https://cdn.comsol.com/wordpress/2017/09/Giraffe.jpeg" title="" alt="A photo of a giraffe, which gained its long neck through natural selection." width="640" height="480" class="alignnone size-full wp-image-234091" /><br />
<em>Over time, natural selection can result in the perpetuation of beneficial traits in a set of organisms, such as long necks in giraffes.</em></p>
<p>Genetic algorithms take the principles of natural selection and apply them to optimization problems. They study a set of &#8220;individuals&#8221; in an environment that has known values and characteristics. The studied population of individuals represents potential solutions to the problem. Appropriate mathematical functions define the fitness of each individual by representing how well adapted they are to the environment. </p>
<p>As with natural selection, using genetic algorithms is an iterative process, with the individuals in each &#8220;generation&#8221; potentially experiencing mutations and exchanging design characteristics. The process continues until the algorithms find an optimized solution for the particular environment or reach a maximum number of generations.</p>
<p>A research group from Universidad Autónoma de San Luis Potosí and Instituto Tecnológico de San Luis Potosí used genetic algorithms to improve the geometry of an optical antenna (nanoantenna). They wanted a design that optimally concentrates the electromagnetic field of a dipole nanoantenna at a 500-THz resonance frequency, which is a variable that depends on the dimensions of the nanostructure.</p>
<p>As an additional point of study, the team investigated if conventional RF macroscopic antenna geometries can be efficiently used for nanoscale optical frequency regimes. Here&#8217;s what they found out&#8230;</p>
<h3>Optimizing Nanoantenna Designs with COMSOL Multiphysics® and LiveLink™ <em>for</em> MATLAB®</h3>
<p>In their research, the team used LiveLink™ <em>for</em> MATLAB® to seamlessly link the MATLAB® software and the COMSOL® software. In doing so, they were able to use MATLAB® software to automatically drive their COMSOL Multiphysics® simulations. Using MATLAB® software, the researchers designed a user interface and genetic algorithm. The genetic algorithm was programmed with the Global Optimization Toolbox, available as an add-on to the MATLAB® software. The algorithm performed analyses to suggest various iterative design changes for the dipole nanoantenna geometry in 2D. These genetic algorithm results were then compared with the optimal conditions to evaluate their fit.</p>
<p><img src="https://cdn.comsol.com/wordpress/2017/09/geometry-changes-due-to-mutations-from-the-genetic-algorithm.png" title="" alt="An antenna geometry mutates based on a genetic algorithm." width="614" height="477" class="alignnone size-full wp-image-234101" /><br />
<em>The lines show how mutations modify the antenna geometry during the genetic algorithm process. Image by R. Diaz de Leon-Zapata, G. Gonzalez, A.G. Rodríguez, E. Flores-García, and F.J. Gonzalez and taken from their <a href="/paper/download/360511/diazdeleon_paper.pdf">COMSOL Conference 2016 Boston paper</a>.</em></p>
<p>Whenever the algorithm yielded a design possibility, the researchers could automatically solve the electromagnetic equations, generate antenna response data for a given frequency, and evaluate the fitness function without having to interact with the graphical user interface in COMSOL Multiphysics. The optimized fitness function determined the minimum loss of the electromagnetic field at a frequency of 500 THz. These findings were then used in MATLAB® software to perform further genetic algorithm adjustments. This entire iterative loop was performed automatically, increasing the efficiency of the study.</p>
<p><img src="https://cdn.comsol.com/wordpress/2017/09/population-fitness-increasing-due-to-genetic-algorithm.png" title="" alt="A 1D plot showing a minimized EM field loss per generation." width="763" height="522" class="alignnone size-full wp-image-234111" /><br />
<em>The trend toward a minimized electromagnetic field loss for each new generation. Image by R. Diaz de Leon-Zapata et al. and taken from their COMSOL Conference 2016 Boston paper.</em></p>
<p>The automatic process continued until the software reached convergent results for an improved antenna geometry. Using this procedure, the researchers obtained their final results at a lower computational cost and a shorter processing time than traditional analytical processes. </p>
<p><img src="https://cdn.comsol.com/wordpress/2017/09/final-optical-antenna-geometry-from-GA-optimization.png" title="" alt="An optimized antenna geometry produced via a genetic algorithm." width="374" height="344" class="alignnone size-full wp-image-234121" /><br />
<em>The final antenna geometry attained from genetic algorithm optimization. Image by R. Diaz de Leon-Zapata et al. and taken from their COMSOL Conference 2016 Boston paper.</em></p>
<h3>Producing an Ideal Optical Antenna Geometry with Genetic Algorithms</h3>
<p>Let&#8217;s take a closer look at the final design of the nanoantenna. The final design iteration (below, to the right) is quite different from the design of a conventional dipole antenna (below, to the left). The final design is the most fit in this case, since it has the lowest electromagnetic field loss at the center of the structure. </p>
<p><img src="https://cdn.comsol.com/wordpress/2017/09/Electromagnetic-field-concentration-genetic-algorithm-optimization.png" title="" alt="The evolution of optimizing optical antenna geometries via a genetic algorithm." width="1000" height="368" class="alignnone size-full wp-image-234131" /><br />
<em>Comparison of the electromagnetic field concentrations for a classical dipole antenna (left), the first design iteration from the genetic algorithm (middle), and the final geometry (right). Image by R. Diaz de Leon-Zapata et al. and taken from their COMSOL Conference 2016 Boston paper.</em></p>
<p>To visualize this in a different way, the research group plotted the electromagnetic field concentration for a conventional dipole antenna and the finalized geometry over a range of frequencies. The comparison shows that while both geometries encompass the same effective area, the version created using the genetic algorithm represents an optimal concentration. Compared with previous studies, the final design also has an increased electromagnetic signal and bandwidth.</p>
<p><img src="https://cdn.comsol.com/wordpress/2017/09/Electromagnetic-field-concentration-comparison-COMSOL-simulation-plot.png" title="" alt="A 1D plot comparing the EM field concentration for a classical dipole geometry and one that was produced algorithmically." width="761" height="489" class="alignnone size-full wp-image-234151" /><br />
<em>Comparison of the electromagnetic field concentration for a classical dipole geometry (red) and the geometry generated from the genetic algorithm (blue). Image by R. Diaz de Leon-Zapata et al. and taken from their COMSOL Conference 2016 Boston paper.</em></p>
<p>Using these findings, the researchers concluded that the genetic algorithm can enhance the maximum electromagnetic field concentration in the optical frequency regime. The team&#8217;s next step is to use the results of this analysis to study nanostructure fabrication and characterization, which could help foster the creation of renewable energy devices.</p>
<h3>Additional Resources</h3>
<ul>
<li>Read the research team&#8217;s original work: &#8220;<a href="/paper/genetic-algorithm-for-geometry-optimization-of-optical-antennas-35272">Genetic Algorithm for Geometry Optimization of Optical Antennas</a>&#8220;</li>
<li>Watch this 18-minute <a href="/video/introduction-to-livelink-for-matlab-in-18-minutes">video to learn about using LiveLink™ <em>for</em> MATLAB®</a></li>
<li>Read a blog post to <a href="/blogs/introduction-to-efficiently-modeling-antennas-in-comsol-multiphysics/">get an introduction to designing antennas in COMSOL Multiphysics</a></li>
</ul>
<p><em>MATLAB is a registered trademark of The MathWorks, Inc.</em></p>
]]></content:encoded>
			<wfw:commentRss>https://www.comsol.se/blogs/optimizing-the-geometry-of-optical-antennas-with-genetic-algorithms/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Studying the Migration of Mineral Oil Hydrocarbons in Food Packaging</title>
		<link>https://www.comsol.se/blogs/studying-the-migration-of-mineral-oil-hydrocarbons-in-food-packaging/</link>
		<comments>https://www.comsol.se/blogs/studying-the-migration-of-mineral-oil-hydrocarbons-in-food-packaging/#comments</comments>
		<pubDate>Thu, 17 Nov 2016 21:13:08 +0000</pubDate>
		<dc:creator><![CDATA[Bridget Cunningham]]></dc:creator>
				<category><![CDATA[Chemical]]></category>
		<category><![CDATA[Chemical Reaction Engineering]]></category>
		<category><![CDATA[Interfacing]]></category>
		<category><![CDATA[LiveLink for MATLAB]]></category>
		<category><![CDATA[Chemical Reaction Engineering Module]]></category>
		<category><![CDATA[Food Science]]></category>

		<guid isPermaLink="false">http://com.staging.comsol.com/blogs?p=193601</guid>
		<description><![CDATA[Food packaging is often composed of recycled materials, like newspapers or plastic, which may contain residual mineral oil inks. Traces of these potentially hazardous substances leftover from the recycled materials can migrate from the packaging to the stored food. To account for this, one research team developed a numerical model to analyze the migration patterns of mineral oil hydrocarbons for various packaging situations. Compared to experimental studies, their approach offers a more efficient and cost-effective way of optimizing food safety. [&#8230;]]]></description>
				<content:encoded><![CDATA[<p>Food packaging is often composed of recycled materials, like newspapers or plastic, which may contain residual mineral oil inks. Traces of these potentially hazardous substances leftover from the recycled materials can migrate from the packaging to the stored food. To account for this, one research team developed a numerical model to analyze the migration patterns of mineral oil hydrocarbons for various packaging situations. Compared to experimental studies, their approach offers a more efficient and cost-effective way of optimizing food safety. </p>
<p><span id="more-193601"></span></p>
<h3>The Importance of Food Packaging</h3>
<p>Walk down any aisle of a grocery store and you&#8217;ll find a variety of packaging types used for food. While these packages generally provide important nutritional information to consumers, their larger purpose is to protect and preserve the quality of the food stored inside. Limiting exposure to risks such as temperature, sunlight, and bacteria along with preventing loss and spillage can help extend the shelf life of food, while ensuring its overall safety and integrity.</p>
<p><img src="https://cdn.comsol.com/wordpress/2016/11/food-packaging.png" title="" alt="Photos highlighting two different examples of food packaging." width="678" height="214" class="alignnone size-full wp-image-193751" /><br />
<em>Different types of food are packaged in different ways for preservation and protection. Left: Carton of eggs. Image by Alisha Vargas. Licensed under <a href="https://creativecommons.org/licenses/by/2.0/" target="_blank">CC BY 2.0</a>, via <a href="https://www.flickr.com/photos/alishav/3773840052/" target="_blank">Flickr Creative Commons</a>. Right: Plastic carton filled with strawberries. Image by tuchodi. Licensed under <a href="https://creativecommons.org/licenses/by/2.0/" target="_blank">CC BY 2.0</a>, via <a href="https://www.flickr.com/photos/tuchodi/4555239535/" target="_blank">Flickr Creative Commons</a>.</em></p>
<p>In an effort to promote greater sustainability, many of today&#8217;s food packages are created with recycled materials. This approach helps the food industry contribute to the global quest of lowering energy use, reducing waste, and preventing pollution. But some of the recycled plastic, paper, and cardboard used for this purpose can contain mineral oil hydrocarbons (MOHs), both saturated (MOSHs) and aromatic (MOAHs), as they are used in the industrial inks that print information onto such products. This is a cause for concern, as these substances, which the <a href="https://www.efsa.europa.eu/en/topics/topic/mineraloilhydrocarbons" target="_blank">European Food Safety Authority</a> recognized as posing potential human health risks, can migrate from the recycled materials of the packaging to the product. </p>
<p><img src="https://cdn.comsol.com/wordpress/2016/11/recycled-paper.jpg" title="" alt="Photo of recycled newspapers, which can contain traces of mineral oil hydrocarbons." width="1000" height="627" class="alignnone size-full wp-image-193701" /><br />
<em>Some recycled materials used for food packaging, such as newspapers, can contain traces of mineral oil hydrocarbons. Image by waferboard. Licensed under <a href="https://creativecommons.org/licenses/by/2.0/" target="_blank">CC BY 2.0</a>, via <a href="https://www.flickr.com/photos/waferboard/4812345240" target="_blank">Flickr Creative Commons</a>.</em></p>
<p>With an experimental approach, understanding the migration kinetics of mineral oil hydrocarbons in food packaging can be rather time consuming and expensive. Looking for a more efficient alternative, researchers at the Technical University of Munich developed a numerical model to describe this process for a wide range of packaging situations. Their simulation work provides valuable insight into ways we can limit food&#8217;s exposure to such substances.</p>
<h3>Modeling the Migration Patterns of Mineral Oil Hydrocarbons in Food Packaging</h3>
<p>To design their model, the research team used LiveLink™ <em>for</em> MATLAB®, an add-on interfacing product to the COMSOL Multiphysics® software. This enabled them to easily define different packaging situations by modifying just a few parameters in the MATLAB® code. These parameters include:</p>
<ul>
<li>The number of layers of packaging</li>
<li>The packaging material</li>
<li>The packaging thickness</li>
<li>The number of mineral oil hydrocarbon substances</li>
<li>The substance names</li>
<li>The initial substance concentration</li>
</ul>
<p>For their analyses, the researchers simulated the migration of MOSH/MOAH components through a plastic packaging material. Because food packaging is typically quite thin in comparison to the food it stores, this was treated as a 1D problem, with the food assumed to be symmetric around the center. The migration of the mineral oil hydrocarbon substances through the packaging materials was described by <a href="https://www.comsol.com/multiphysics/diffusion-equation">Fick&#8217;s law of diffusion</a> via the <em>Transport of Diluted Species</em> interface. Note that the researchers did not account for the loss of the substances to the environment in this study.</p>
<p>The plot below represents the time-dependent concentration profiles for a single-layer packaging that is 1 mm thick following isothermal storage. In this case, there is diffusion resistance within the packaging and a large portion of the substance (a mixture of MOSH/MOAH components) migrates from the packaging to the food.</p>
<p><img src="https://cdn.comsol.com/wordpress/2016/11/concentration-profiles.png" title="" alt="A plot showing the time-dependent concentration profiles for a single-layer packaging." width="1000" height="537" class="alignnone size-full wp-image-193721" /><br />
<em>Plot depicting the concentration profiles for a single-layer packaging. Image by C. Kirse, F. Edel, and H. Briesen and taken from their <a href="https://www.comsol.com/paper/download/358231/christoph_poster.pdf">COMSOL Conference 2016 Munich poster</a>.</em></p>
<p>The following plot shows the amount of substance that has migrated into the food as a function of its molar mass. The results indicate that substances with a greater molecular weight have slower migration patterns. This can be attributed to the fact that these substances have lower diffusion coefficients. </p>
<p><img src="https://cdn.comsol.com/wordpress/2016/11/migrated-substance-plot.png" title="" alt="A plot showing the amount of substance in the food as a function of its molar mass." width="1000" height="522" class="alignnone size-full wp-image-193731" /><br />
<em>Plot depicting the amount of substance as a function of its molar mass. Image by C. Kirse, F. Edel, and H. Briesen and taken from their <a href="https://www.comsol.com/paper/download/358231/christoph_poster.pdf">COMSOL Conference 2016 Munich poster</a>.</em></p>
<p>While the example highlighted above accounts for isothermal storage, the model can also be used to describe temperature changes that occur during storage via stepwise and analytical functions. Including adsorption layers and evaporation of the substances to their surrounding environment is also an option.</p>
<p>Looking ahead, the researchers are planning to model diffusion in porous networks, such as that in paper packaging, as Fick&#8217;s law of diffusion can only adequately describe diffusion in these systems in some cases. They also plan to use experimental results from measuring migration to estimate parameters for their simulation studies. This will allow them to model more realistic food packaging designs and thus pave the way for further advancements in food safety.</p>
<h3>Learn More About Using Simulation to Improve Food Safety</h3>
<ul>
<li>Read the full paper &#8220;<a href="https://www.comsol.com/paper/download/358221/christoph_paper.pdf">Migration of MOSH/MOAH Through Multi-layered Packaging Into Food</a>&#8221; and take a look at the <a href="https://www.comsol.com/paper/download/358231/christoph_poster.pdf">conference poster</a></li>
<li>Explore further applications of COMSOL Multiphysics in improving food safety:
<ul>
<li><a href="https://www.comsol.com/blogs/using-apps-to-optimize-induction-heating-for-food-processing/">Using Apps to Optimize Induction Heating for Food Processing</a></li>
<li><a href="https://www.comsol.com/blogs/optimizing-the-hydration-operation-in-the-thermal-processing-of-dates/">Optimizing the Hydration Operation in the Thermal Processing of Dates</a></li>
</ul>
</li>
</ul>
<p><em>MATLAB is a registered trademark of The MathWorks, Inc.</em></p>
]]></content:encoded>
			<wfw:commentRss>https://www.comsol.se/blogs/studying-the-migration-of-mineral-oil-hydrocarbons-in-food-packaging/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Simulating a 3D Multilayered Graphene Biosensor Design</title>
		<link>https://www.comsol.se/blogs/simulating-a-3d-multilayered-graphene-biosensor-design/</link>
		<comments>https://www.comsol.se/blogs/simulating-a-3d-multilayered-graphene-biosensor-design/#comments</comments>
		<pubDate>Mon, 02 May 2016 08:10:54 +0000</pubDate>
		<dc:creator><![CDATA[Bridget Cunningham]]></dc:creator>
				<category><![CDATA[AC/DC & Electromagnetics]]></category>
		<category><![CDATA[Acoustics & Vibrations]]></category>
		<category><![CDATA[Electrical]]></category>
		<category><![CDATA[Heat Transfer & Phase Change]]></category>
		<category><![CDATA[Interfacing]]></category>
		<category><![CDATA[LiveLink for MATLAB]]></category>
		<category><![CDATA[Mechanical]]></category>
		<category><![CDATA[Structural Mechanics & Thermal Stress]]></category>
		<category><![CDATA[Acoustics Module]]></category>

		<guid isPermaLink="false">http://com.staging.comsol.com/blogs/?p=157091</guid>
		<description><![CDATA[Graphene is a material with a strong presence &#8212; and impact &#8212; throughout the scientific community. Amongst its many uses, researchers are looking to graphene as a potential material solution within sensor designs for medical and biosensing applications. Today, we&#8217;ll explore the role of simulation in analyzing and optimizing a 3D multilayered graphene biosensor. Graphene Brings Innovative Technology to Life Nanobots that reduce ocean pollution, solar cells that operate in the rain, and devices that transmit wireless data up to [&#8230;]]]></description>
				<content:encoded><![CDATA[<p>Graphene is a material with a strong presence &#8212; and impact &#8212; throughout the scientific community. Amongst its many uses, researchers are looking to graphene as a potential material solution within sensor designs for medical and biosensing applications. Today, we&#8217;ll explore the role of simulation in analyzing and optimizing a 3D multilayered graphene biosensor.</p>
<p><span id="more-157091"></span></p>
<h3>Graphene Brings Innovative Technology to Life</h3>
<p>Nanobots that <a href="http://www.sciencealert.com/graphene-based-nanobots-could-clean-up-the-metal-from-our-oceans" target="_blank">reduce ocean pollution</a>, solar cells that <a href="https://www.sciencedaily.com/releases/2016/04/160406075516.htm" target="_blank">operate in the rain</a>, and devices that <a href="https://www.sciencedaily.com/releases/2016/04/160406074510.htm" target="_blank">transmit wireless data</a> up to <em>ten</em> times faster. What binds these developing technologies together, aside from their innovative nature, is the use of a revolutionary material that has been a recurring topic of discussion on the COMSOL Blog. Its name? Graphene.</p>
<p>Recognizing the advantages of this strong, lightweight material, more and more industries have begun to embrace graphene&#8217;s potential use for a variety of applications. Take biosensors, for instance. Because of its high electrical conductivity and large surface area, graphene is an optimal material selection for these devices. This can be attributed to the fact that a faster transfer of electrons prompts greater accuracy and selectivity in the detection of biomolecules.</p>
<p><img src="https://cdn.comsol.com/wordpress/2016/04/Glucose-testing.jpg" title="" alt="A photograph of a glucose monitoring system." width="600" height="518" class="alignnone size-full wp-image-157181" /><br />
<em>Glucose monitoring is one application of biosensors. Image by David-i98 (talk) (Uploads) &#8212; Own work. Licensed under <a href="http://creativecommons.org/licenses/by-sa/3.0/" target="_blank">CC BY-CA 3.0</a>, via <a href="https://en.wikipedia.org/wiki/File:Blood_Glucose_Testing.JPG" target="_blank">Wikimedia Commons</a>.</em></p>
<p>In an effort to help bring new sophistication and reliability to biosensors for therapeutic solutions and personalized medical applications, a team from the Polytechnic University of Bucharest designed and analyzed a 3D multilayered graphene biosensor with COMSOL Multiphysics. Let&#8217;s have a look at their research, which was presented at the COMSOL Conference 2015 Grenoble.</p>
<h3>Designing a 3D Multilayered Graphene Biosensor with COMSOL Multiphysics</h3>
<p>As mentioned above, the research presented here is centered on a multilayered biosensor design. While single-layer graphene is known to be much more reactive than multilayered graphene structures, the edge of the material is more reactive than its surface. With graphene being rather inert, a multilayered graphene structure is an ideal option for biosensors.</p>
<p>In addition to the design of the biosensor itself, it is also important to consider the interface with which it will interact. In this case, that interface is human skin. Because it is the part of the human body with the largest surface area and because its responses to external and internal stimuli vary, human skin is a good environment through which to collect physical and chemical data.</p>
<p>Before developing their biosensor models, the team considered the following interfaces:</p>
<ul>
<li>Human skin to the PVA hydrogel</li>
<li>PVA hydrogel to the graphene-based structure</li>
<li>Graphene-based structure to the electrodes</li>
<li>Graphene/electrodes to the silicon substrate</li>
</ul>
<p>This series of interfaces led to the development of two biosensor device models that could describe the influence of process variables as well as environmental stimuli. The first of these models is a single-layer graphene/graphene-oxide sensor device with two electrodes. The second model is a multilayered sensor device with four electrodes. For the latter case, the inclusion and exclusion of the graphene composite structure was studied to further differentiate between the graphene responses.</p>
<p><img src="https://cdn.comsol.com/wordpress/2016/04/Graphene-biosensor-schematic.png" title="" alt="A schematic of a multilayered graphene biosensor device." width="870" height="422" class="alignnone size-full wp-image-157231" /><br />
<em>A multilayered graphene biosensor device. Image by E. Lacatus, G.C. Alecu, and A. Tudor and taken from their paper &#8220;<a href="https://www.comsol.com/paper/download/288381/lacatus_paper.pdf">Models for Simulation Based Selection of 3D Multilayered Graphene Biosensors</a>&#8220;.</em></p>
<p>With their models in place, the researchers ran a series of simulations in COMSOL Multiphysics to analyze the biosensing capabilities of both model configurations. Such analyses included measuring the temperature distribution at the interface of the device as well as the electrical potential (shown in the following set of figures). The findings revealed that the graphene-based structure possessed a sensing ability regardless of the specific design.</p>
<div class="row">
<div class="col-sm-6">
<img src="https://cdn.comsol.com/wordpress/2016/04/temperature-distribution-for-two-electrodes.png" title="" alt="A plot of the temperature distribution for a biosensor device with two electrodes." width="615" height="387" class="alignnone size-full wp-image-157211" />
</div>
<div class="col-sm-6">
<img src="https://cdn.comsol.com/wordpress/2016/04/temperature-distribution-for-four-electrodes.png" title="" alt="A plot showing the temperature distribution for a graphene biosensor with four electrodes." width="615" height="387" class="alignnone size-full wp-image-157201" />
</div>
</div>
<p><em>Temperature distribution plots at the interface for the device with two electrodes (left) and the device with four electrodes (right). Image by E. Lacatus, G.C. Alecu, and A. Tudor and taken from their paper &#8220;<a href="https://www.comsol.com/paper/download/288381/lacatus_paper.pdf">Models for Simulation Based Selection of 3D Multilayered Graphene Biosensors</a>&#8220;.</em></p>
<p><img src="https://cdn.comsol.com/wordpress/2016/04/electric-potential-two-and-four-electrodes.png" title="" alt="Side-by-side images showing the electric potential for graphene biosensors with two and four electrodes." width="870" height="256" class="alignnone size-full wp-image-157161" /><br />
<em>Electric potential plots on the interface for the device with two electrodes (left) and the device with four electrodes (right). Image by E. Lacatus, G.C. Alecu, and A. Tudor and taken from their paper &#8220;<a href="https://www.comsol.com/paper/download/288381/lacatus_paper.pdf">Models for Simulation Based Selection of 3D Multilayered Graphene Biosensors</a>&#8220;.</em></p>
<p>After identifying these sensing capabilities, the team tested a number of different biosensor device structures as a means of determining the optimal response for the PVA hydrogel on the sheets of graphene and for the protein-functionalized graphene biosensors. Simulation proved to be a useful tool for analyzing such properties. The simulation results shown below, for instance, highlight the spatial distribution of flux energy on the graphene biosensor as well as the interface charge distributions for the device with four electrodes.</p>
<p><img src="https://cdn.comsol.com/wordpress/2016/04/flux-energy-and-interface-charge-distributions.png" title="" alt="Side-by-side plots showing the flux energy and interface charge distributions in COMSOL Multiphysics." width="941" height="288" class="alignnone size-full wp-image-157171" /><br />
<em>Simulations corresponding to the spatial distribution of flux energy on the graphene biosensor (left) and the interface charge distributions (right) for the device with four electrodes. Image by E. Lacatus, G.C. Alecu, and A. Tudor and taken from their paper &#8220;<a href="https://www.comsol.com/paper/download/288381/lacatus_paper.pdf">Models for Simulation Based Selection of 3D Multilayered Graphene Biosensors</a>&#8220;.</em></p>
<p>Furthering the researchers&#8217; studies were analyses designed to show how different environmental stimuli influence the biosensor when reaching its active surface. Using the Acoustics Module, for example, the researchers were able to define the response of the interface to variations in acoustic pressure. The results below illustrate the effects of the acoustic stimuli on the graphene sensing structure for the device with four electrodes. </p>
<p><img src="https://cdn.comsol.com/wordpress/2016/05/Acoustic-stimuli-on-graphene-biosensor-device.png" title="" alt="An image showing the effect of acoustic stimuli on the graphene biosensor with four electrodes." width="400" height="285" class="alignnone size-full wp-image-157321" /><br />
<em>Analyzing the impact of acoustic stimuli on the device with four electrodes. Image by E. Lacatus, G.C. Alecu, and A. Tudor and taken from their presentation &#8220;<a href="https://www.comsol.com/paper/download/288401/lacatus_presentation.pdf">Models for Simulation Based Selection of 3D Multilayered Graphene Biosensors</a>&#8220;.</em></p>
<p>With COMSOL Multiphysics, the researchers could successfully identify the relevant properties of the graphene biosensing structures, all while relating them to the complex interface of the human skin. This simulation research, combined with the models themselves, provided valuable design solutions in the development of graphene-based biosensors.</p>
<h3>Additional Resources on Modeling Graphene and Biosensors</h3>
<ul>
<li>Download the full paper here: &#8220;<a href="https://www.comsol.com/paper/models-for-simulation-based-selection-of-3d-multilayered-graphene-biosensors-28201">Models for Simulation Based Selection of 3D Multilayered Graphene Biosensors</a>&#8220;</li>
<li>Learn more about <a href="/blogs/the-graphene-revolution-part-1/">graphene and graphene-based structures</a> on the COMSOL Blog</li>
<li>Modeling a biosensor? Read this blog post to see how you can easily <a href="https://www.comsol.com/blogs/sensing-the-bio-in-biosensor-design-with-a-simulation-app/">turn your model into an app</a> with the Application Builder in COMSOL Multiphysics</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>https://www.comsol.se/blogs/simulating-a-3d-multilayered-graphene-biosensor-design/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>A Strategy for Designing Corrosion-Resistant Materials</title>
		<link>https://www.comsol.se/blogs/strategy-designing-corrosion-resistant-materials/</link>
		<comments>https://www.comsol.se/blogs/strategy-designing-corrosion-resistant-materials/#comments</comments>
		<pubDate>Wed, 03 Sep 2014 08:02:32 +0000</pubDate>
		<dc:creator><![CDATA[Jennifer Segui]]></dc:creator>
				<category><![CDATA[Chemical]]></category>
		<category><![CDATA[Corrosion Processes]]></category>
		<category><![CDATA[Interfacing]]></category>
		<category><![CDATA[LiveLink for MATLAB]]></category>
		<category><![CDATA[Corrosion Module]]></category>
		<category><![CDATA[User Perspectives]]></category>

		<guid isPermaLink="false">http://com.staging.comsol.com/blogs/?p=36659</guid>
		<description><![CDATA[Billions of dollars are spent each year in the U.S. to repair corrosion damage. To help reduce the high cost of corrosion, engineers at the Naval Research Laboratory (NRL) in Washington, D.C. are using multiphysics simulation to gain a better understanding of the fundamental mechanism. A successful research outcome at NRL will establish the correlation between metal microstructure, corrosion, and mechanical strength. Material designers could then develop stronger, corrosion-resistant materials using this new information. Corrosion: A Maintenance Problem Siddiq Qidwai, [&#8230;]]]></description>
				<content:encoded><![CDATA[<p>Billions of dollars are spent each year in the U.S. to repair corrosion damage. To help reduce the high cost of corrosion, engineers at the Naval Research Laboratory (NRL) in Washington, D.C. are using multiphysics simulation to gain a better understanding of the fundamental mechanism. A successful research outcome at NRL will establish the correlation between metal microstructure, corrosion, and mechanical strength. Material designers could then develop stronger, corrosion-resistant materials using this new information.</p>
<p><span id="more-36659"></span></p>
<h3>Corrosion: A Maintenance Problem</h3>
<p>Siddiq Qidwai, a mechanical engineer at <a href="http://www.nrl.navy.mil/" target="_blank">NRL</a>, was <a href="http://www.comsol.com/blogs/comsol-conference-2013-boston-keynote-speaker-round-up/">a keynote speaker at the COMSOL Conference 2013 Boston</a>, where he enlightened a packed auditorium with a speech on the significant costs and hazards associated with corrosion. Qidwai also explained the important work they are doing to better understand the mechanism of corrosion in metals. They expect that this new knowledge will aid in designing corrosion-resistant materials.</p>
<p>“For the Navy specifically, corrosion is the number one maintenance problem,” explained Qidwai in his presentation. We can all certainly relate to that sentiment &#8212; on a much smaller scale &#8212; whether it’s a bicycle left in the rain, a car that’s endured a few too many harsh winters, or the pipes and metallic fixtures used regularly in our homes.</p>
<p>Inspired by his presentation, the work of Qidwai and his colleagues was featured in the <a href="http://www.comsol.com/zmags/comsol-news-2014">2014 edition of <em>COMSOL News</em></a>, in the article “<a href="http://www.comsol.com/story/simulation-led-strategy-for-corrosion-prevention-19739">Simulation-Led Strategy for Corrosion Prevention</a>” on page 36.</p>
<p><img src="https://cdn.comsol.com/wordpress/2014/09/group_photo2.jpg" title="" alt="Qidwai and his colleagues have dedicated their efforts toward corrosion prevention." width="700" height="465" class="alignnone size-full wp-image-36893" /><br />
<em>From left to right: Siddiq Qidwai (NRL), Virginia DeGiorgi (NRL), and Nithyanand Kota (Leidos Corp.), the researchers behind understanding the fundamental mechanism of corrosion in metals.</em></p>
<h3>Metal Microstructure, Pit Growth, and Mechanical Strength</h3>
<p>Where corrosion starts and how it propagates depends on the microstructure of a metal. In the following figure, an electron micrograph acquired at NRL demonstrates the formation of an irregular surface due to pit growth in an aluminum alloy. If the microstructure were not important, we’d expect to see a much smoother surface in the image.</p>
<p><img src="https://cdn.comsol.com/wordpress/2014/09/electron-micrograph.jpg" title="" alt="Image depicting an electron micrograph." width="700" height="367" class="alignnone size-full wp-image-36685" /><br />
<em>Electron micrograph. Image courtesy of C. Feng and S. Policastro, NRL.</em></p>
<p>Pitting corrosion in metals is caused by electrochemical reactions and mass transport in an electrolyte solution, as shown in the figure below. The diagram depicts the general corrosion process for steel submerged in seawater. As corrosion proceeds, metal ions, such as Fe<sup>2+</sup>, diffuse into the electrolyte solution away from the metal surface, leading to the formation of pits. The diagram not only shows pit growth, but also the formation of an irregular <em>corrosion front</em>. The corrosion front is the surface along which electrochemical reactions occur. </p>
<p><img src="https://cdn.comsol.com/wordpress/2014/09/corrosion-diagram.jpg" title="" alt="Diagram showing pit growth and the formation of an irregular corrosion front." width="700" height="473" class="alignnone size-full wp-image-36687" /><br />
<em>Diagram of the corrosion process.</em></p>
<p>Along the front, the reaction rate varies due to differences in the size, shape, and crystallographic orientation of each grain. The microstructure of stainless steel is shown with the grain boundaries labeled in the diagram. The varied rate associated with each grain leads to the formation of an irregular corrosion front. Therefore, it is important to take metal microstructure into account when studying pitting corrosion in metals.</p>
<p>Now, consider what happens as pitting corrosion progresses. The structure of a metal is disrupted, leading to areas of increased stress surrounding a pit, which consequently compromises its mechanical strength. If you’ve ever scored a piece of glass to make it easier to break, you can already relate to what&#8217;s going on. Unlike the process of breaking glass, for corrosion in metals, the reduced strength is undesirable and may lead to material or component failure. Hence, research at NRL aims to establish the relationship between microstructure, corrosion, and mechanical strength to aid in the design of corrosion-resistant materials.</p>
<h3>Using Simulation to Better Understand Corrosion</h3>
<p>Qidwai and his colleagues are working toward developing a fully-coupled multiphysics model of pitting corrosion in metals, including the electrochemical reactions and mass transport. To overcome the limitations of previous research in the field, they have developed a method to incorporate metal microstructure into their model of pitting corrosion.</p>
<p><img src="https://cdn.comsol.com/wordpress/2014/09/pitting-corrosion-model.jpg" title="" alt="Method for designing corrosion-resistant materials." width="700" height="304" class="alignnone size-full wp-image-36689" /><br />
<em>Incorporating metal microstructure in a pitting corrosion model.</em></p>
<p>Researchers at NRL were able to reconstruct the microstructure of steel from 3D images acquired using <a href="http://en.wikipedia.org/wiki/Orientation_imaging_microscopy" target="_blank">orientation imaging microscopy</a> (OIM). The reconstructed metal microstructure is presented to the left in the figure above, along with a legend indicating the crystallographic orientation of each grain. To the right, you can see the model geometry implemented in COMSOL Multiphysics&reg; simulation software.</p>
<p>To develop a complete model of pitting corrosion in 316 steel, Qidwai is using the <em>Transport of diluted species</em> interface for mass transport, the Laplace and Poisson’s equations for the electric potential, and the moving mesh (ALE) technology for the corrosion front. “You can use COMSOL Multiphysics with the Corrosion Module to solve this problem,” explains Qidwai. “All of the work that previously seemed so difficult, now is so easy because you have the module doing a lot of the work for you.”</p>
<p>Implementing the irregular corrosion front movement due to metal microstructure presented a unique challenge in their simulation work. “At every location along the corrosion front, we have to determine the crystal orientation to calculate the corresponding corrosion potential, which in turn determines the corrosion rate and movement of the front,” says Qidwai. “LiveLink&trade; <em>for</em> MATLAB&reg; has been an essential feature for us in order to include the effect of metal microstructure.” The corrosion potential, in particular, is determined in MATLAB&reg; for a particular crystallographic orientation.</p>
<p>Their work also includes decoupled structural mechanics analyses of pit growth in metals. You can see what that looks like to the left in the screenshot of the COMSOL Desktop&reg; environment below. The simulation results in the right-hand plot demonstrate pit growth with an irregular corrosion front.</p>
<p><img src="https://cdn.comsol.com/wordpress/2014/09/irregular-corrosion-front.png" title="" alt="Simulation of pit growth." width="700" height="474" class="alignnone size-full wp-image-36691" /></p>
<p>Future work at NRL will be directed toward creating a fully-coupled model of pitting corrosion that includes structural mechanics. This way, the effect of pit growth on the mechanical strength of the material is considered, along with the effect of mechanical loading on pitting corrosion. Once the model is completed and validated, it can serve as a valuable tool to aid material designers in creating corrosion-resistant materials, which is ultimately of enormous benefit to everyone.</p>
<h3>Further Reading</h3>
<ul>
<li>For more information about pitting corrosion research using multiphysics simulation at NRL, read the full article “<a href="http://www.comsol.com/story/simulation-led-strategy-for-corrosion-prevention-19739">Simulation-Led Strategy for Corrosion Prevention</a>”.</li>
<li>Watch the <a href="http://www.comsol.com/video/modeling-pitting-corrosion-microstructural-scale">original keynote presentation on modeling pitting corrosion at the microstructural scale</a> by Siddiq Qidwai from the COMSOL Conference 2013 Boston.</li>
<li>Kota, N.; Qidwai, S.M.; and DeGiorgi, V.G.; &#8220;Modeling the Influence of Microstructure on Corrosion Pit Growth and Resulting Stress Concentration,&#8221; <em>ECS Transactions</em>, Vol. 58, No. 31, pp. 35-44, 2014.</li>
</ul>
<p><em>MATLAB is a registered trademark of The MathWorks, Inc. All other trademarks are the property of their respective owners. For a list of such trademark owners, see <a href="http://www.comsol.com/tm">http://www.comsol.com/tm</a>. COMSOL AB and its subsidiaries and products are not affiliated with, endorsed by, sponsored by, or supported by these trademark owners.</em></p>
]]></content:encoded>
			<wfw:commentRss>https://www.comsol.se/blogs/strategy-designing-corrosion-resistant-materials/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Automatically Handling Selections in COMSOL Multiphysics®</title>
		<link>https://www.comsol.se/blogs/automatically-handling-selections-comsol-multiphysics/</link>
		<comments>https://www.comsol.se/blogs/automatically-handling-selections-comsol-multiphysics/#comments</comments>
		<pubDate>Wed, 02 Jul 2014 08:01:57 +0000</pubDate>
		<dc:creator><![CDATA[Lars Gregersen]]></dc:creator>
				<category><![CDATA[Interfacing]]></category>
		<category><![CDATA[LiveLink for MATLAB]]></category>
		<category><![CDATA[Technical Content]]></category>

		<guid isPermaLink="false">http://com.staging.comsol.com/blogs/?p=33939</guid>
		<description><![CDATA[This is Part 3 of a blog series on how to handle selections and entity numbers when using LiveLink™ for MATLAB® and the COMSOL® Application Programming Interface (API). In this section, I&#8217;ll discuss how the internal handling of selections and entity numbers in COMSOL Multiphysics® simulation software is performed and how you can utilize these methods when setting up your own models. Automatic Handling of Selections in a Model When you make a change to a model, including changes to [&#8230;]]]></description>
				<content:encoded><![CDATA[<p>This is Part 3 of a blog series on how to handle selections and entity numbers when using LiveLink™ <em>for</em> MATLAB® and the COMSOL® Application Programming Interface (API). In this section, I&#8217;ll discuss how the internal handling of selections and entity numbers in COMSOL Multiphysics® simulation software is performed and how you can utilize these methods when setting up your own models.</p>
<p><span id="more-33939"></span></p>
<h3>Automatic Handling of Selections in a Model</h3>
<p>When you make a change to a model, including changes to the geometry, COMSOL Multiphysics keeps track of most settings you have applied to the model and their associated selections. If you have a boundary condition applied to a set of boundaries, then the model remembers these settings &#8212; and even updates the entity numbers of the boundaries when they change due to changes to the geometry.</p>
<p>Of course, there are cases when settings can&#8217;t be kept. For instance, if you delete <em>all boundaries</em> that a certain boundary condition applies to, then the boundary condition will have an empty selection. Thus, it will not contribute to the model unless you manually add new boundaries to its selection.</p>
<p>In <a href="http://www.comsol.com/blogs/manually-work-entity-numbers-selections/">Part 2 of this blog series</a>, we showed you a method of using coordinate-based selections using functionality in LiveLink™ <em>for</em> MATLAB® to obtain entity numbers for setting up models. This is very easy to work with on the command line, but when working with selections in COMSOL Multiphysics, it is much easier to add selections via the user interface (UI) and then apply the physics settings to these selections rather than to the geometric entities. This way, you are leveraging the internal framework that keeps track of geometric entities and you do not need to use entity numbers when setting up a model.</p>
<p>There are two ways to add a selection to a model. The first method is to select the <em>Create Selections</em> check box that is available for every geometric operation. </p>
<p><img src="https://cdn.comsol.com/wordpress/2014/07/Create-selections-check-box-in-COMSOL-Multiphysics.png" title="" alt="Create selections check box in COMSOL Multiphysics" width="351" height="90" class="alignnone size-full wp-image-33951" /></p>
<p>This way, you can easily create selections that contain the output entities of the operation. Selections will be created for domain, boundaries, edges, and points. The name of the selections will consist of the tag of the geometry and object plus &#8220;_dom&#8221;, &#8220;_bnd&#8221;, &#8220;_edg&#8221;, and &#8220;_pnt&#8221;. For instance, for a rectangle with the tag <em>r2</em> the tag of the boundary selection becomes <em>geom1_r2_bnd</em>.</p>
<p>The second method of adding selections to a model is to create <em>named selections</em> in the model tree. These can be added as nodes in the <em>Definitions</em> branch of the model tree, as well as in the <em>geometry sequence</em> itself. It doesn&#8217;t matter very much where you add named selections, but selections in the geometry sequence can not only be used for physics or mesh settings but also as input to downstream geometry operations. By choosing descriptive names, you can obtain a good overview of the geometry sequence itself.</p>
<h3>Using COMSOL Multiphysics Selections to Track Changes to the Geometry</h3>
<p>Let&#8217;s take a look at a named selection in the geometry sequence. Navigate to the <em>Geometry 1</em> node in the model tree and right-click, then click on &#8220;Selections&#8221;. Upon doing so, you&#8217;ll see a list of different selection types:</p>
<p><img src="https://cdn.comsol.com/wordpress/2014/07/Menu-of-selections-in-COMSOL-Multiphysics.png" title="" alt="Menu of selections in COMSOL Multiphysics" width="227" height="205" class="alignnone size-full wp-image-33957" /></p>
<p>The Box Selection corresponds to the command <code>mphselectbox</code>, but since this selection is more tightly connected to the COMSOL Multiphysics geometry, it has more options. You can choose to include the entity either if <em>anything</em> is inside the Box or if <em>something</em> is inside it. You can also <em>group by continuous tangent</em>, which allows you to select adjacent faces or edges that have continuous tangent (by some tolerance). I will not use these advanced features in this example.</p>
<p>For the example model of the heat sink, I will add two selections: one selection for the hot part of the heat sink and another selection for the cold side. In comparison, I made three calls to <code>mphselectbox</code> in Part 2 of the blog series. In order to get the <em>hot</em> selection, I simply select the check box for <em>Create Selections</em> for the rectangle that defines the first component. Since this rectangle is used in an Array operation, the selection is automatically extended to cover all parts of the array. For the cold side, a Box Selection is added to the end of the geometry sequence to include the upper part of the heat sink. Now, even if I add more fins &#8212; more rectangles &#8212; to the heat sink, the box selection will automatically include them, since it is the last node in the geometry sequence.</p>
<p><a href="https://cdn.comsol.com/wordpress/2014/07/Box-Selection-configured-in-COMSOL-Multiphysics.png" target="_blank"><img src="https://cdn.comsol.com/wordpress/2014/07/Box-Selection-configured-in-COMSOL-Multiphysics.png" title="Box selection. (Click to enlarge)" alt="Box Selection configured in COMSOL Multiphysics" width="1083" height="818" class="alignnone size-full wp-image-33959" /></a><br />
<em>Box Selection configured to output the boundaries that fall within the specified limits, in this case the cold side of the heat sink.</em></p>
<p>After having set up the selections, the boundary conditions in the model have to be configured so they utilize the selections. From now on, the geometry can be updated without having to worry about the selections or the entity numbers that COMSOL Multiphysics uses internally. Now the model can be saved and used both from within the COMSOL Multiphysics® UI and from the MATLAB® software. Setting up the selections can, of course, also be carried out using the COMSOL API. To see how this is done, you can simply save the model as a model file for MATLAB® software, as described in <a href="http://www.comsol.com/blogs/best-practice-working-model-m-files/">Part 1 of the Working with M-Files series</a>.</p>
<p>When you load a model that contains selections using LiveLink™ <em>for</em> MATLAB®, you can view the selections using the wrapper function <code>mphviewselection</code>. To see the selection for the cold side, you can execute <code > mphviewselection(model,'geom1_boxsel1')</code>.</p>
<p><img src="https://cdn.comsol.com/wordpress/2014/07/Boundaries-in-MATLAB.png" title="" alt="Boundaries in MATLAB®" width="576" height="512" class="alignnone size-full wp-image-33965" /><br />
<em>Boundaries (in <span style="color:#FF0000">red</span>) output by the box selection for the cold side of the heat sink when viewed using the command <code>mphviewselection</code>.</em></p>
<h3>Simulation</h3>
<p>In the example in <a href="http://www.comsol.com/blogs/manually-work-entity-numbers-selections/">Part 2</a>, I modified the geometry by adding more fins to the heat sink. Instead of using <code>mphselectbox</code> multiple times for each version of the geometry as I did there, here I add the selections to the model just once and leave the hard work of updating geometry and selections to the software.</p>
<p>First, you load the model into MATLAB® software using the mphload command:</p>
<p><img src="https://cdn.comsol.com/wordpress/2014/07/mphload-command.png" title="" alt="mphload command" width="338" height="20" class="alignnone size-full wp-image-33967" /></p>
<p>It is very simple to write the code for changing the geometry and solving the model. By using the built-in COMSOL Multiphysics® software selections, there is no need to adjust anything when using MATLAB® software for updating the model. Thus, the loop becomes shorter than before:</p>
<p><img src="https://cdn.comsol.com/wordpress/2014/07/Code-for-changing-the-geometry.png" title="" alt="Code for changing the geometry" width="570" height="222" class="alignnone size-full wp-image-33969" /></p>
<p>Running this script produces the results plot shown below.</p>
<p><img src="https://cdn.comsol.com/wordpress/2014/07/Resulting-temperature-for-various-fin-configurations.png" title="" alt="Resulting temperature for various fin configurations" width="496" height="398" class="alignnone size-full wp-image-33971" /><br />
<em>Temperature distribution in the heat sink for different fin configurations.</em></p>
<h4>Verifying Selections</h4>
<p>You can verify the settings that are included in a model by writing &#8220;model.selections&#8221;. MATLAB® software will write the names (tags) of the selections in the model:</p>
<p><img src="https://cdn.comsol.com/wordpress/2014/07/MATLAB-software-writes-names-of-the-selections-in-the-model.png" title="" alt="MATLAB® software writes names of the selections in the model" width="552" height="114" class="alignnone size-full wp-image-33981" /></p>
<p>You can find out what a selection contains by using the &#8220;mphgetselection&#8221; function, which for the <em>geom1_r2_bnd</em> selection gives this result:</p>
<p><img src="https://cdn.comsol.com/wordpress/2014/07/Result-of-mphgetselection-function.png" title="" alt="Result of mphgetselection function" width="414" height="151" class="alignnone size-full wp-image-33977" /></p>
<h3>What We Have Learned About Working with M-Files</h3>
<p>There are several ways of making sure that selections for model settings are preserved when you introduce large changes to a model geometry. Using commands that come with <a href="http://www.comsol.com/livelink-for-matlab">LiveLink™ <em>for</em> MATLAB®</a>, you can keeping track of the entity numbers within specified coordinates. The downside of this approach is that you then have to continue using these commands for updating the geometry. The method will break down if you load the model into the COMSOL Desktop® environment. If you instead rely on named selections in the model tree, you can obtain the same result and also have the ability to work with the model both at the MATLAB® software command prompt and in the COMSOL Desktop®.</p>
<p>If you&#8217;ve been wondering whether or not we can do without entity numbers in selections, the answer is &#8220;Yes.&#8221; As you saw here, we can indeed do without manually fiddling with entity numbers in selections. It takes a little work to include named selections in the model, but they offer better usability and robustness.  </p>
<h3>Other Posts in This Series</h3>
<ol>
<li><a href="/blogs/best-practice-working-model-m-files/">Best Practice for Working with Model M-Files</a></li>
<li><a href="/blogs/manually-work-entity-numbers-selections/">How to Manually Work with Entity Numbers in Selections</a></li>
</ol>
<p><em>MATLAB is a registered trademark of The MathWorks, Inc. All other trademarks are the property of their respective owners. For a list of such trademark owners, see <a href="http://www.comsol.com/tm">http://www.comsol.com/tm</a>. COMSOL AB and its subsidiaries and products are not affiliated with, endorsed by, sponsored by, or supported by these trademark owners.</em></p>
]]></content:encoded>
			<wfw:commentRss>https://www.comsol.se/blogs/automatically-handling-selections-comsol-multiphysics/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>How to Manually Work with Entity Numbers in Selections</title>
		<link>https://www.comsol.se/blogs/manually-work-entity-numbers-selections/</link>
		<comments>https://www.comsol.se/blogs/manually-work-entity-numbers-selections/#comments</comments>
		<pubDate>Wed, 04 Jun 2014 12:09:54 +0000</pubDate>
		<dc:creator><![CDATA[Lars Gregersen]]></dc:creator>
				<category><![CDATA[Interfacing]]></category>
		<category><![CDATA[LiveLink for MATLAB]]></category>
		<category><![CDATA[Technical Content]]></category>

		<guid isPermaLink="false">http://com.staging.comsol.com/blogs/?p=32273</guid>
		<description><![CDATA[In Part 1 of this blog series, I introduced how you can export a model M-file from COMSOL Multiphysics® simulation software to learn about the structure of the COMSOL Application Programming Interface (API). One important part of a model M-file is the selections that are made in order to set up properties for the domain, boundaries, etc. These selections are identified using numbers. Here, we explain how you can automate the handling of the entity numbers using LiveLink™ for MATLAB®. [&#8230;]]]></description>
				<content:encoded><![CDATA[<p>In <a href="https://www.comsol.com/blogs/best-practice-working-model-m-files/">Part 1 of this blog series</a>, I introduced how you can export a model M-file from COMSOL Multiphysics® simulation software to learn about the structure of the COMSOL Application Programming Interface (API). One important part of a model M-file is the selections that are made in order to set up properties for the domain, boundaries, etc. These selections are identified using numbers. Here, we explain how you can automate the handling of the entity numbers using LiveLink™ <em>for</em> MATLAB®.  </p>
<p><span id="more-32273"></span></p>
<h3>Handling Selections When Changing the Geometry</h3>
<p>When large changes are introduced to a model&#8217;s geometry, keeping track of the numbers that domains, boundaries, edges, or vertices are assigned is a challenge. These numbers are used to specify where certain settings should be applied: </p>
<p><img src="https://cdn.comsol.com/wordpress/2014/06/numbering-domains.png" alt="Schematic showing  numbered domains, boundaries, edges, and vertices" title="" width="454" height="496" class="alignnone size-full wp-image-32335" /></p>
<p>The upper part of the above figure shows a heat sink with only one fin above the heat sink base. This is not a very efficient design, so I&#8217;ll add further fins in order to calculate the heat sink&#8217;s performance for different designs.</p>
<p>As you can see in the lower part of the figure, the numbering of the boundaries changes when a second fin is introduced on top of the heat sink base. Naturally, the boundaries that are a part of the newly introduced fin have to get numbers that are different from the previous design, since these boundaries have not been a part of the model so far. Introducing the new boundaries also means that some of the old numbers will change.</p>
<blockquote><p>Note that the numbering is usually very difficult to predict, even for a simple 2D model like this. For a more complicated model in 2D and 3D, it becomes even more complicated. The examples and code used here could just as easily have been made with a 3D model, but I&#8217;ve chosen to go with a 2D model, as it becomes much easier to follow what&#8217;s going on.</p></blockquote>
<p>When applying model settings to boundaries, the numbering becomes important. The figure below shows what the boundary condition for the cool side of the heat sink looks like:</p>
<p><img src="https://cdn.comsol.com/wordpress/2014/06/Boundary-condition-for-cool-side.png" alt="Screenshot showing the boundary conditions applied to the heat sink in the Heat Flux settings window" title="" width="770" height="429" class="alignnone size-full wp-image-32339" /><br />
<em>The boundaries are easily identified in the Graphics window on the right. The corresponding numbers are seen in the Heat Flux settings window in the middle (circled in pink)</em>.</p>
<h3>Selections in the Model M-file Code</h3>
<p>Let&#8217;s have a look at what the corresponding selections look like in the model M-file code:</p>
<p><img src="https://cdn.comsol.com/wordpress/2014/06/Selections-in-M-file.png" alt="Model-M file code showing number selections" title="" width="553" height="77" class="alignnone size-full wp-image-32343" /></p>
<p>The first set is for the upper part, where the cooling takes place, and the second set represents the hot part of the heat sink. When the second fin (or more, depending on your modeling scenario) is added to the model, we normally have little idea of which selection numbers to use.</p>
<p>There are two distinct ways of keeping track of the entity numbers:</p>
<ol>
<li>Using LiveLink™ <em>for</em> MATLAB® functionality to track geometric entities based on their coordinates</li>
<li>Working with selections from geometric operations to track geometric entities</li>
</ol>
<p>Method 1 is usually the easiest when you are introducing very large changes (such as new objects, for instance, like we will do here) into a geometry and the number of geometric entities change. This method makes it very easy to work with a model on the command line when changing the model bit by bit.</p>
<p>Method 2 usually requires more steps to set up, but has the added benefit that once the model has been set up, you can avoid the use of entity numbers altogether. The model can be used either via LiveLink™ <em>for</em> MATLAB® or directly in the COMSOL Multiphysics® user interface (UI), with ease.</p>
<blockquote><p>Note that if you have a model where you don&#8217;t add or remove objects and you do not change its topology, then the numbering of the selections in the model will automatically be updated when you change model settings, and, for example, move objects from one location to another.</p></blockquote>
<h3>Coordinate Based Selections Using LiveLink™ <em>for</em> MATLAB® Functionality</h3>
<p>The model is available as both an M-file and an MPH-file. Typically, the best solution is to use the MPH-file as a base for the changes to the model. Loading an MPH-file is usually faster than running the corresponding M-file. The MPH-file can, of course, contain meshes and solutions that can&#8217;t be saved as part of the M-file, which makes plotting model results a lot easier.</p>
<p>We load the model using this command: <code>model = mphload('heat_param1')</code></p>
<p>A new fin is introduced into the model by these simple commands:</p>
<p><img src="https://cdn.comsol.com/wordpress/2014/06/Fin-command.png" alt="Commands used to introduce new fins" title="" width="521" height="57" class="alignnone size-full wp-image-32347" /></p>
<p>The design is verified by using this command:</p>
<p><code>mphgeom(model,'geom1','edgelabels','on')</code>  </p>
<p>which plots the geometry in a MATLAB® figure.</p>
<p>This produces the lower part of the heat sink figure . In this figure, the numbers can be identified visually, but we would like to automate the process such that we can vary both the number of fins and their design. Getting the entity numbers of the boundaries that we need is easy if we use the <code>mphselectbox</code> command. This command selects entities using a box for which you have to specify the coordinates of two opposite corners. There is a corresponding function called <code > mphselectcoords</code> that selects entities inside a circle (or a sphere in 3D), but we will not use that function in this example.</p>
<p>Below, are the <code>mphselectbox</code> commands that we have to use for this model. For the cooling fins, we supply one set of coordinates that cover the entire upper part of the heat sink. This means that when I add more fins to the heat sink, these new fins will be covered by the rectangle and I can use the same code to get the selection numbers at that time. For the hot, lower part of the heat sink, I have to use two calls to mphselectbox and take the union of the selection numbers. &#8220;Union&#8221; is a standard MATLAB® function that takes the union of a set. It is also possible to use the MATLAB® functions, &#8220;setdiff&#8221; and &#8220;intersect&#8221;, in order to play around with the selection numbers to get the result you wish.</p>
<p><img src="https://cdn.comsol.com/wordpress/2014/06/Selectbox.png" alt="Screenshot of the mphselectbox in use" title="" width="630" height="86" class="alignnone size-full wp-image-32349" /></p>
<p>The output looks like this:</p>
<p><img src="https://cdn.comsol.com/wordpress/2014/06/Output-indices.png" alt="Output indices resulting from two calls to the mphselecbox" width="534" height="145" class="alignnone size-full wp-image-32351" title="Output indices" /></p>
<p>Now it is easy to update the model settings with the correct numbers:</p>
<p><img src="https://cdn.comsol.com/wordpress/2014/06/Model-settings-update.png" alt="Updating the model settings with correct numbers" width="484" height="40" class="alignnone size-full wp-image-32353" title="Model settings update" /></p>
<h3>Simulation</h3>
<p>Once the selections have been set up, it is easy to adjust the number of fins. The following script shows how to set up a simple loop that will add four fins (one by one) to a model and solve. The goal is to find the effect of adding more fins to the heat sink.</p>
<p>The first line is used to load the model from an MPH-file. This way, we don&#8217;t have to run an M-file, which usually takes longer time than loading an MPH-file.</p>
<p>In the for loop, some more fins are added to the model with a proper size and location. The selection numbers are retrieved using mphselectbox and the model is solved. We generate a plot of each result to be studied when the analysis is completed.</p>
<p><img src="https://cdn.comsol.com/wordpress/2014/06/Loop-to-add-fins.png" alt="Script on setting up the loops to add fins" title="" width="648" height="374" class="alignnone size-full wp-image-32355" /></p>
<p>The method &#8220;uniquetag&#8221; is used to get a tag for the new fin (Rectangle). When we use uniquetag, we don&#8217;t have to guess what tags are already taken and which might be available. This use of uniquetag with an &#8216;r&#8217; as argument will return a tag that consists of &#8216;r&#8217; and a number that is available.</p>
<h3>What We Have Learned</h3>
<p>When we change the geometry in a model (especially when we introduce new topology), it is important to keep track of the entity numbers for specifying model settings. An efficient way of doing this in a model M-file, or at the MATLAB® command line, is by using the wrapper functions, <code>mphselectbox</code> and <code > mphselectcoords</code>, that return entity numbers based on entity coordinates.</p>
<h3>Next Up</h3>
<p>The next blog post in this Working with M-files series will discuss how we can set up a model using selections from geometric operations. This leads to a model that is easy to handle both with LiveLink™ <em>for</em> MATLAB® and from within the COMSOL Multiphysics® user interface. Using this method means we are working directly with the selection objects and, in many cases, can avoid the use of entity numbers altogether.</p>
<h3>Other Posts in This Series</h3>
<ol>
<li><a href="/blogs/best-practice-working-model-m-files/">Best Practice for Working with Model M-Files</a></li>
<li><a href="/blogs/automatically-handling-selections-comsol-multiphysics/">Automatically Handling Selections in COMSOL Multiphysics®</a></li>
</ol>
<p><em>MATLAB is a registered trademark of The MathWorks, Inc.</em></p>
]]></content:encoded>
			<wfw:commentRss>https://www.comsol.se/blogs/manually-work-entity-numbers-selections/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Best Practice for Working with Model M-Files</title>
		<link>https://www.comsol.se/blogs/best-practice-working-model-m-files/</link>
		<comments>https://www.comsol.se/blogs/best-practice-working-model-m-files/#comments</comments>
		<pubDate>Wed, 14 May 2014 12:08:41 +0000</pubDate>
		<dc:creator><![CDATA[Lars Gregersen]]></dc:creator>
				<category><![CDATA[Interfacing]]></category>
		<category><![CDATA[LiveLink for MATLAB]]></category>
		<category><![CDATA[Technical Content]]></category>

		<guid isPermaLink="false">http://com.staging.comsol.com/blogs/?p=31203</guid>
		<description><![CDATA[When developing models in COMSOL Multiphysics® software, it is common to come across tasks that have to be carried out repeatedly. This three-part blog series will show you how repetitive tasks can be efficiently achieved using model M-files and LiveLink™ for MATLAB®. Introducing Variations into Models You can introduce many variations into your models through the COMSOL Multiphysics user interface (UI). Functionality, such as parametric sweeps and optimization, allow you to vary a set of parameters in tailor-made edit fields [&#8230;]]]></description>
				<content:encoded><![CDATA[<p>When developing models in COMSOL Multiphysics® software, it is common to come across tasks that have to be carried out repeatedly. This three-part blog series will show you how repetitive tasks can be efficiently achieved using model M-files and LiveLink™ <em>for</em> MATLAB®.</p>
<p><span id="more-31203"></span></p>
<h3>Introducing Variations into Models</h3>
<p>You can introduce many variations into your models through the COMSOL Multiphysics user interface (UI). Functionality, such as parametric sweeps and optimization, allow you to vary a set of parameters in tailor-made edit fields for this purpose.</p>
<p>Yet, some types of variations are not catered to by the UI. In these cases, LiveLink™ <em>for</em> MATLAB® comes in handy as it can access all the model settings, <a href="http://www.comsol.com/blogs/automate-modeling-tasks-comsol-api-use-java/">using the COMSOL® API for use with Java® (COMSOL API)</a>.</p>
<p>With LiveLink™ <em>for</em> MATLAB®, it is possible to:</p>
<ul>
<li>Start simulations automatically from a MATLAB® program</li>
<li>Introduce changes to model settings through the use of scripting</li>
<li>Create models from scratch
<ul>
<li>Creating the geometry, meshing, defining physics, calling a solver, and postprocessing the results</li>
</ul>
</li>
<li>Read CAD files and files containing meshes</li>
<li>Connect to other data sources and read data from files, databases, etc.</li>
<li>Create a simplified UI for novices to run models</li>
</ul>
<p>Many of these features are important if you wish to avoid repeating your work in the COMSOL Multiphysics UI.</p>
<h3>Building a Model from Scratch Using LiveLink™ <em>for</em> MATLAB®</h3>
<p>If you are new to LiveLink™ <em>for</em> MATLAB®, then the <em>Introduction to LiveLink™</em> for <em>MATLAB®</em> manual provides sufficient information to get you started. In particular, the <em>LiveLink™</em> for <em>MATLAB® User&#8217;s Guide</em> provides further resources about the commands within the COMSOL Multiphysics API and the equivalent MATLAB® functions they access. You can actually create your first model M-file, which controls a COMSOL Multiphysics model, without having to read this documentation. This is because such scripts can be auto-generated from the COMSOL Multiphysics UI.</p>
<p>Let&#8217;s look at a simple heat transfer example that only requires the COMSOL Multiphysics base package to build and solve. The geometry can be seen in the following figure, where a heat flux is introduced at the bottom boundaries and dissipates into the surrounding air at the top boundaries.</p>
<p><img src="https://cdn.comsol.com/wordpress/2014/05/Heat-flux-boundaries.png" alt="A geometry where heat flux originates at the bottom boundary and then dissipates into the air" title="" width="374" height="212" class="alignnone size-full wp-image-31217" /></p>
<p><img src="https://cdn.comsol.com/wordpress/2014/05/Surface-temperature-of-geometry.png" alt="Plot created with COMSOL Multiphysics that shows the surface temperature of a model" title="" width="501" height="303" class="alignnone size-full wp-image-31219" /></p>
<p>The geometry consists of a few rectangles that are either combined with or subtracted from each other. The M-file code for making this geometry can be seen below:</p>
<p><img src="https://cdn.comsol.com/wordpress/2014/05/M-file-code.png" alt="Example M-file code needed to make a geometry" title="" width="592" height="292" class="alignnone size-full wp-image-31221" /></p>
<p>Here, the code is commanding COMSOL Multiphysics to create rectangle nodes in the model tree, as well as the node that takes the difference between rectangles. You see that the size and position (pos) of the entities are defined. These definitions can be used to define the geometry as you&#8217;d like it to be. It is evident that even small geometries may lead to a lot of defining code. The next section shows how to create lines automatically.</p>
<h3>Automatic Generation of Model M-files</h3>
<p>All functionality within COMSOL Multiphysics can be represented by a line of code, and a full model would correspond to many lines of code. Instead of creating a model from scratch using a script, you can create it in the COMSOL software UI and then save it as an M-file. This is done by choosing File &gt; Save as and then selecting &#8220;Model File for MATLAB (*.m)&#8221;.</p>
<p>Such an M-file contains all the steps that have been followed when building the model. By running the file using LiveLink™ <em>for</em> MATLAB®, you will notice that all the commands that were performed are recorded. If the model was solved several times, there will be several calls to the solvers, which you typically don&#8217;t want. If you were to run the model from the MATLAB® command line, it will solve the model several times. In order to obtain an M-file that is compact, you can choose File &gt; Compact History before saving the file.</p>
<p><img src="https://cdn.comsol.com/wordpress/2014/05/Compact-History-workflow-LiveLink-for-MATLAB.png" alt="Diagram showing the steps necessary to obtain a compact M-file" title="" width="500" height="115" class="alignnone size-full wp-image-31349" /></p>
<p>Now that we have the entire model as an M-file, we are free to investigate &#8212; or change &#8212; any of the settings in the model. We can add new features to the model, as well. </p>
<p>Have a look at your M-file and see if you can identify the various sections of the model and how things are set up. Some things will be easy to understand in a model, such as how parameters and the geometry are defined. Other things, such as solver or plots settings, can be more obscure. However, if you have MATLAB® coding experience, you should easily be able to see <em>where</em> things are defined.</p>
<p>In the following example snippet:</p>
<p><img src="https://cdn.comsol.com/wordpress/2014/05/Mesh-settings-code.png" alt="Example code showing how mesh settings are defined" width="423" height="35" class="alignnone size-full wp-image-31233" title="Mesh settings code" /></p>
<p>you can see how the mesh settings are defined. When an M-file contains the definition of the geometry, physics, mesh, solvers, etc., a call is made to a &#8220;run()&#8221; method. This takes all the commands in the M-file and executes them in COMSOL Multiphysics. Calls to &#8220;run()&#8221; may take a long time if your model is big, so if you wish to follow the solution progress, you can switch on the Progress window by using this code (before calling run):</p>
<p><img src="https://cdn.comsol.com/wordpress/2014/05/Progress-window-code.png" alt="Code used to turn on the Progress window prior to calling a run" title="" width="231" height="22" class="alignnone size-full wp-image-31235" /></p>
<h3>Working Even Faster Without Model M-Files</h3>
<p>If you use MATLAB® to change a model using the COMSOL software API and lose track of changes, it is nice to know that you can always save the model as an MPH-file, load it into the COMSOL Multiphysics UI, and inspect it there. Furthermore, you can load MPH-files into MATLAB® and manipulate them from there, as well.</p>
<p>The following example loads an MPH-file and performs a &#8220;for&#8221; loop on the parts of the model that has changed (its geometry) before solving it.</p>
<p><img src="https://cdn.comsol.com/wordpress/2014/05/For-loop-code.png" alt="Code that loads a MPH file and runs a for loop on model parts that have been changed" title="" width="515" height="92" class="alignnone size-full wp-image-31239" /></p>
<h3>Selections</h3>
<p>One of the biggest reasons for working with M-files is to be able to manipulate geometries. In order to do this, you need to understand Selections:</p>
<p><img src="https://cdn.comsol.com/wordpress/2014/05/Code-to-manipulate-geometries-in-COMSOL-Multiphysics.png" alt="Code that sets up physics for heat transfer and boundary conditions for Heat Flux Boundary" title="" width="553" height="99" class="alignnone size-full wp-image-31243" /></p>
<p>The above code sets up some of the heat transfer physics, including two boundary conditions for a &#8220;Heat Flux Boundary&#8221; on a series of boundaries, identified by numbers. When a geometry is changed in a way that introduces more domains, boundaries, or vertices, these numbers will change too. You will need a way to either track these numbers, or avoid using them.</p>
<p>These will be the topics of the next two blog entries in this series. Stay tuned.</p>
<h3>Other Posts in This Series</h3>
<ol>
<li><a href="/blogs/manually-work-entity-numbers-selections/">How to Manually Work with Entity Numbers in Selections</a></li>
<li><a href="/blogs/automatically-handling-selections-comsol-multiphysics/">Automatically Handling Selections in COMSOL Multiphysics®</a></li>
</ol>
<p><em>MATLAB is a registered trademark of The MathWorks, Inc.</em></p>
]]></content:encoded>
			<wfw:commentRss>https://www.comsol.se/blogs/best-practice-working-model-m-files/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Using MATLAB® Functions in Your COMSOL Multiphysics® Models</title>
		<link>https://www.comsol.se/blogs/using-matlab-functions-comsol-multiphysics-models/</link>
		<comments>https://www.comsol.se/blogs/using-matlab-functions-comsol-multiphysics-models/#comments</comments>
		<pubDate>Fri, 18 Apr 2014 13:23:30 +0000</pubDate>
		<dc:creator><![CDATA[Fanny Griesmer]]></dc:creator>
				<category><![CDATA[Interfacing]]></category>
		<category><![CDATA[LiveLink for MATLAB]]></category>
		<category><![CDATA[Video]]></category>

		<guid isPermaLink="false">http://com.staging.comsol.com/blogs/?p=30043</guid>
		<description><![CDATA[Did you know that you can use MATLAB® functions in your COMSOL Multiphysics® models? Well, you can, and in this video tutorial we will show you how, using LiveLink™ for MATLAB®. Video: LiveLink™ for MATLAB® Demonstration Model Downloads Shown in the video: MEMS Heating Circuit Another example for using MATLAB functions: Temperature Distribution in a Vacuum Flask Video Transcription In this tutorial, we will learn how to model the joule heating and thermal expansion in a MEMS heating circuit. The [&#8230;]]]></description>
				<content:encoded><![CDATA[<p>Did you know that you can use MATLAB® functions in your COMSOL Multiphysics® models? Well, you can, and in this video tutorial we will show you how, using LiveLink™ <em>for</em> MATLAB®.</p>
<p><span id="more-30043"></span></p>
<h3>Video: LiveLink™ <em>for</em> MATLAB® Demonstration</h3>
<div class="wistia_responsive_padding" style="padding:56.25% 0 0 0;position:relative;">
<div class="wistia_responsive_wrapper" style="height:100%;left:0;position:absolute;top:0;width:100%;"><iframe src="https://fast.wistia.net/embed/iframe/m0dm15u7y2?videoFoam=true" title="Wistia video player" allowtransparency="true" frameborder="0" scrolling="no" class="wistia_embed" name="wistia_embed" allowfullscreen mozallowfullscreen webkitallowfullscreen oallowfullscreen msallowfullscreen width="100%" height="100%"></iframe></div>
</div>
<p><script src="https://fast.wistia.net/assets/external/E-v1.js" async></script></p>
<h4>Model Downloads</h4>
<ul>
<li>Shown in the video: <a href="http://www.comsol.com/model/heating-circuit-465">MEMS Heating Circuit</a></li>
<li>Another example for using MATLAB functions: <a href="http://www.comsol.com/model/temperature-distribution-in-a-vacuum-flask-12066">Temperature Distribution in a Vacuum Flask</a></li>
</ul>
<h3>Video Transcription</h3>
<p><em>In this tutorial, we will learn how to model the joule heating and thermal expansion in a MEMS heating circuit. The device consists of a thin, nichrome layer pattern on a thicker glass layer. Electric current conduction through the nichrome layer produces joule heating. Most of the material properties are assumed to be constant, except the thermal conductivity of glass.</p>
<p>A MATLAB® function is created that reads in temperature-dependent thermal conductivity data and interpolates to provide the conductivity value as a function of temperature at any point within the glass layer. The effect of spatial inhomogeneity in the material property is incorporated by adding a random component to the conductivity, which varies as a function of the Y-coordinate of the glass layer.</p>
<p>In order to set up the model in COMSOL Desktop®, we will create the geometry, set up the physics, assign material properties, mesh, and run the model.</p>
<p>Once we have run the basic model in the COMSOL Desktop, we will start the LiveLink™ </em>for<em> MATLAB® and load the COMSOL® model. We will then perform data fitting to obtain the parameters for temperature-dependent electrical conductivity and specify the limits of thickness of glass and nichrome layers. These parameters will be updated in the model. The model will be solved within a nested for-loop that will allow us to investigate the design space.</p>
<p>So, let&#8217;s create the model in COMSOL Desktop.</p>
<p>We will start by selecting a 3D space dimension and then, from the Add Physics menu, we’re going to select our three different physics interfaces of interest.</p>
<p>We will go to &#8220;Structural Mechanics&#8221;, select and add &#8220;Thermal Stress&#8221;. Then, we’ll go to &#8220;AC/DC&#8221; and select and add &#8220;Electric Currents, Shell&#8221;.</p>
<p>Then, we’ll go back to &#8220;Structural Mechanics&#8221; once again and we will add the </em>Shell<em> or the </em>Structural Shell<em> interface.</p>
<p>Let us go ahead and get into the geometry building steps to save some time. I’m going to get it from a file where these steps are already available, and let&#8217;s go ahead and build the geometry.</p>
<p>Now, we can go back to the global definitions and create a MATLAB function.</p>
<p>The name of the function will be thermal_conductivity and the arguments that we are going to send to this MATLAB function will be the temperature and the Y-coordinate.</p>
<p>The simulation will actually start with the </em>Structural Shell<em> interface. This will be assigned only to the nichrome layer, which is what we are modeling as a shell.</p>
<p>Now let&#8217;s go to the </em>Electric Currents, Shell<em> interface. Very similarly, we will assign the nichrome layer as the shell or the boundary of interest.</p>
<p>We will go ahead and then add a Boundary Heat Source boundary condition to the same surface and here we will basically connect the </em>Thermal Stress<em> interface to the surface losses produced by the </em>Electric Currents, Shell<em> interface.</p>
<p>So this is how we are telling the model that there&#8217;s some heat being generated on this boundary.</p>
<p>Let’s go to the Materials branch.</p>
<p>We’ll first go to the Material Browser, go to the built-in library and select &#8220;Silica glass&#8221;. This gets assigned to the glass layer.</p>
<p>Here, among all the material properties listed for silica glass, all these numbers are constant, and we’ll go ahead and change the value of &#8220;thermal conductivity&#8221;.</p>
<p>So, instead of that being a number, it will now be the MATLAB function thermal_conductivity and its value will be evaluated at temperature, T, and at any y-coordinate.</p>
<p>Once we’re done with setting up the material properties, let’s customize the mesh.</p>
<p>Once we are done with setting up the mesh, it is time to select &#8220;Compute&#8221;.</p>
<p>Once we have solved the model, we can create several plots to look at some of the quantities of interest. Let’s also look at the thermal conductivity of glass, which we obtain from the MATLAB function, thermal_conductivity. I mention that there is a randomness that we added to incorporate the effect of spatial inhomogeneity. We can see that randomness when we compare the conductivity distribution over space with the color map, here.</p>
<p>So, now that we have solved the basic model in COMSOL Desktop, let’s switch gears and take a look at the MATLAB graphical user interface that you get to see when you start LiveLink™ </em>for<em> MATLAB®.</p>
<p>We have a little script here and the first step that we perform is to load our model file that we created in COMSOL Desktop into the MATLAB workspace using the mphload command.</p>
<p>Once you do that, you get to see the model structure in the workspace.</p>
<p>Finally, let’s take a look at the main component in this script, where we use a nested for-loop to update the values of the glass layer thickness and the nichrome layer thickness, and solve the model repeatedly within this nested for-loop. We also create custom plots, which will only plot the temperature for the extreme design points.</p>
<p>We would also use a few specific functions, such as mphglobal and mphmean to obtain information such as the values of global quantities, like the &#8220;Maximum Interface Stress&#8221; and efficiency, and the average value of temperature on the bottom surface of the glass layer.</p>
<p>Once we obtain these values, we can assign them and store them in MATLAB variables.</p>
<p>We can also combine native MATLAB® functions with LiveLink™ functions. For example, mphinterp is a LiveLink™ </em>for<em> MATLAB® function that you can combine with the std, or standard deviation, function in MATLAB to obtain the standard deviation of temperature on the bottom surface of the glass layer, evaluated at a set of arbitrary coordinate points.</p>
<p>Once we have solved the problem for all these design cases, we can also create plots of interest. Such as the average temperature on the lower surface, the standard deviation of temperature on the lower surface, and surface plots of the Maximum Interface Stress and Heat Transfer Efficiency. All of these as functions of the thickness of the glass layer as well as the nichrome layer.</p>
<p>So, let’s go ahead and take a look at these plots. Here is our first plot, bunch of subplots actually, which shows the temperature at the different extremes of our design space. Minimum and maximum value of the glass thickness, and also minimum and maximum value of the nichrome layer thickness.</p>
<p>Let’s take a look at the plot of the average temperature on the lower surface of glass as a function of both glass layer thickness and the nichrome layer thickness. We see that the effect of changing the glass thickness is not so much on the average temperature, but there is some significant effect when we change the thickness of the nichrome layer. The thicker it is, the higher the temperature.</p>
<p>In the next figure, we are looking at the standard deviation of temperature as a function of, again, the glass thickness and the nichrome thickness &#8212; and we definitely see some nonlinear behavior here.</p>
<p>Let’s take a look at the surface plot where we can see the Maximum Interface Stress as a function of the two different layered thicknesses &#8212; and once again we see some nonlinearities. We see that the Maximum Interface Stress is obtained when we have a thicker glass layer and a much thinner nichrome layer.</p>
<p>MATLAB is a registered trademark of The MathWorks, Inc.</em></p>

<script charset="ISO-8859-1" src="//fast.wistia.com/static/concat/iframe-api-v1.js"></script>]]></content:encoded>
			<wfw:commentRss>https://www.comsol.se/blogs/using-matlab-functions-comsol-multiphysics-models/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Solutions as Starting Point Values with LiveLink™ for MATLAB®</title>
		<link>https://www.comsol.se/blogs/solutions-starting-point-values-livelink-matlab/</link>
		<comments>https://www.comsol.se/blogs/solutions-starting-point-values-livelink-matlab/#comments</comments>
		<pubDate>Mon, 10 Mar 2014 12:02:18 +0000</pubDate>
		<dc:creator><![CDATA[Amelia Halliday]]></dc:creator>
				<category><![CDATA[Interfacing]]></category>
		<category><![CDATA[LiveLink for MATLAB]]></category>

		<guid isPermaLink="false">http://com.staging.comsol.com/blogs/?p=28163</guid>
		<description><![CDATA[There are several techniques out there for saving memory when solving a model. One involves splitting it into separate sections and solving these individually, instead of the entire model at once. If you want to map data from one COMSOL Multiphysics® solution to the next using MATLAB® scripting, you can do so by connecting the two software programs via LiveLink™ for MATLAB®. One Method for Dividing and Conquering Your Model To save memory, you can partition a large model into [&#8230;]]]></description>
				<content:encoded><![CDATA[<p>There are several techniques out there for saving memory when solving a model. One involves splitting it into separate sections and solving these individually, instead of the entire model at once. If you want to map data from one COMSOL Multiphysics® solution to the next using MATLAB® scripting, you can do so by connecting the two software programs via LiveLink™ <em>for</em> MATLAB®.</p>
<p><span id="more-28163"></span></p>
<h3>One Method for Dividing and Conquering Your Model</h3>
<p>To save memory, you can partition a large model into separate consecutive sections and then map the solution of each part to the input value of each successive part in series. When considering this technique, the most important thing to think about is your simulation&#8217;s component couplings, i.e. the degree of information the components have or use from one another.</p>
<p>There are a few methods available for using solutions as starting point values in COMSOL Multiphysics®. However, if you have a model that is too large to be solved in one block and the errors that are introduced by the partitioning are acceptable, you can use LiveLink™ <em>for</em> MATLAB® to integrate a model .mph file with MATLAB®.</p>
<h3>Mapping Solutions to Boundary Conditions between Domains</h3>
<p>To show you how to use LiveLink™ <em>for</em> MATLAB® to serve this purpose, we have a <a href="http://www.comsol.com/model/pseudo-periodic-model-of-a-heat-channel-12057">Pseudo-Periodic Model of a Heat Channel</a> example available for download in our Model Gallery. A <em>periodic function</em> is a function whose values recur over a regular interval, most famously those of trigonometry (i.e. sine, cosine, etc). <em>Pseudo-periodicity</em> is a lesser known type of periodic response that seems periodic but never quite exactly repeats itself, such as your heartbeat or respiration rate, for example. </p>
<p>In the modeling example, we simulate convective heat transfer in a channel filled with water and solve the model by taking a pseudo-periodic section of the pipe and solving it repeatedly for temperature in successive sections up to the total length of the channel. We use the solution for temperature at the outlet boundary as the temperature at the inlet boundary for the following section of piping until we have solved for all the sections.</p>
<p><img src="https://cdn.comsol.com/wordpress/2014/03/Mapping-temperatures.jpg" alt="A diagram mapping temperatures between channel sections of a pipe" title="" width="663" height="355" class="alignnone size-full wp-image-28187" /><br />
<em>Mapping temperatures between channel sections.</em></p>
<p>Once we have set up our simulation in COMSOL Multiphysics, we can connect with MATLAB using <a href="http://www.comsol.com/livelink-for-matlab">LiveLink™ <em>for</em> MATLAB®</a>. Before each step in the model, the temperature from the outlet boundary of a section is mapped to the inlet boundary of the next section using the for-loop command within MATLAB.</p>
<div align="right">
    <em>Note that this is just one approach; you can also implement this by manually setting up a few sections in the COMSOL Multiphysics user interface (UI), then saving as an m-file and looking for the pattern that can be replaced by a for-loop.</em>
</div>
<p>The number of iterations we specify will determine the number of times the pseudo-periodic section is repeatedly solved, which represents the number of successive sections that will be solved for. In this case, we are dividing the channel into six pieces so, the number of iterations would be six. After the first solution computes, an if-statement command is incorporated into the script, so that the previous solution is pulled and used for the next iteration.</p>
<p><img src="https://cdn.comsol.com/wordpress/2014/03/MATLAB-commands.jpg" alt="A screenshot showing the for-loop and if-statement commands in the  MATLAB script" title="" width="658" height="242" class="alignnone size-full wp-image-28191" /><br />
<em>For-loop and if-statement commands in the MATLAB script.</em></p>
<p>After the model solves, we can generate a plot of the temperature distribution for each solution through the COMSOL Multiphysics wrapper function, &#8220;mphplot&#8221;. The image below shows the solution for each section of the channel, which corresponds to each of the six iterations performed.</p>
<p><img src="https://cdn.comsol.com/wordpress/2014/03/Temperature-distribution-along-channel.jpg" alt="An image showing the temperature distribution along channel length where the inlet is the left boundary of section 1" title="" width="557" height="518" class="alignnone size-full wp-image-28195" /><br />
<em>Temperature distribution along channel length, the inlet is the left boundary of section 1.</em></p>
<p>The sections can also be placed together to view the temperature distribution along the entire channel. As the water flows through, it reaches a maximum temperature of 306.5 K.</p>
<h3>Model Download</h3>
<ul>
<li><a href="http://www.comsol.com/model/pseudo-periodic-model-of-a-heat-channel-12057">Pseudo-Periodic Model of a Heat Channel</a></li>
</ul>
<p><em>MATLAB is a registered trademark of The MathWorks, Inc.</em></p>
]]></content:encoded>
			<wfw:commentRss>https://www.comsol.se/blogs/solutions-starting-point-values-livelink-matlab/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Combining COMSOL Multiphysics® and MATLAB®</title>
		<link>https://www.comsol.se/blogs/combining-comsol-multiphysics-and-matlab/</link>
		<comments>https://www.comsol.se/blogs/combining-comsol-multiphysics-and-matlab/#comments</comments>
		<pubDate>Thu, 13 Jun 2013 13:47:30 +0000</pubDate>
		<dc:creator><![CDATA[Supratik Datta]]></dc:creator>
				<category><![CDATA[Interfacing]]></category>
		<category><![CDATA[LiveLink for MATLAB]]></category>

		<guid isPermaLink="false">http://com.dev.comsol.com/blogs/?p=13335</guid>
		<description><![CDATA[Did you know that you can combine the strengths of COMSOL Multiphysics® and MATLAB® in real time to solve engineering simulations? To me, that sounds like getting the best of both worlds. Let me explain. Why use COMSOL Multiphysics and MATLAB® together? MATLAB® provides us with an interactive development environment, where you can use a high-level language as well as built-in features to perform data analysis and visualization, numerical computation, algorithm development, and application development. COMSOL Multiphysics, on the other [&#8230;]]]></description>
				<content:encoded><![CDATA[<p>Did you know that you can combine the strengths of COMSOL Multiphysics® and MATLAB® in real time to solve engineering simulations? To me, that sounds like getting the best of both worlds. Let me explain.</p>
<p><span id="more-13335"></span></p>
<h3>Why use COMSOL Multiphysics and MATLAB® together?</h3>
<p><a href="http://www.mathworks.com/products/matlab/index.html" target="blank">MATLAB®</a> provides us with an interactive development environment, where you can use a high-level language as well as built-in features to perform data analysis and visualization, numerical computation, algorithm development, and application development. COMSOL Multiphysics, on the other hand, allows you to customize and combine any number of physics, the way you want to. With MATLAB’s open-ended technical computing environment and COMSOL’s multiphysics modeling platform, you could take on almost any scientific challenge.</p>
<p>Most engineering problems revolve around finding optimal design parameters or operating conditions for a device. The device itself functions based on certain principles of physics (or even multiple physics). Let’s use an example. Say, you want to design an <a href="http://www.comsol.com/showroom/gallery/465/">electrical heater</a> that has a thin metallic layer deposited on top of glass. The heater works based on the principle of <a href="https://www.comsol.com/multiphysics/the-joule-heating-effect">Joule heating</a>, wherein a current passed through the metallic layer produces heat in the metallic layer, which then in turn creates a spatially varying temperature profile in both the metal and the glass layers. As a design engineer, you might want to ensure that the stress generated due to <a href="https://www.comsol.com/multiphysics/thermal-expansion-and-thermal-stresses">thermal expansion</a> at the interface of glass and metal is not too high to cause mechanical failure of the device. You also know that from a practical stand-point, you can control the thickness of the glass and metallic layers within the dimension limits provided by the fabrication specification. So how can you use COMSOL and MATLAB® to help you solve this design problem?</p>
<h3>How to Combine COMSOL and MATLAB®</h3>
<p>You could set up the multiphysics simulation that involves Joule heating and thermal expansion in COMSOL Multiphysics, and perform <a href="http://www.mathworks.com/help/stats/introduction-to-design-of-experiments.html" target="blank">Design of Experiments</a> (DOE) on the model using functionality that is available as part of the Statistics Toolbox™ in MATLAB®.</p>
<p><img src="https://cdn.comsol.com/wordpress/2013/06/heating-circuit-in-COMSOL-Multiphysics.png" alt="Heating circuit in COMSOL Multiphysics" title="Heating circuit" width="637" height="348" class="alignnone size-full wp-image-13343" /></p>
<p>You can certainly write a MATLAB® script that creates <a href="http://www.mathworks.com/help/stats/response-surface-designs.html#bq_oe60" target="blank">Response Surface Designs</a> (a DOE technique) for your COMSOL model. Or if you&#8217;re interested in easy repeated interactions with your model, or would like to share your work with others, you could write a custom MATLAB® app such as the one shown below. The app shown here can solve the COMSOL model recursively for a set of design points, and create a response surface that you or a decision-maker could then use to make an educated engineering decision.</p>
<p><img src="https://cdn.comsol.com/wordpress/2013/06/Heating-Circuit-response-surface.png" alt="Heating Circuit response surface in MATLAB" title="Heating Circuit response surface" width="633" height="298" class="alignnone size-full wp-image-13347" /><br />
<em>Heating Circuit response surface.</em></p>
<p>To make the simulation more realistic, you could even use experimental data that describes the variation in material properties as a function of temperature. Such numerical data could be pre-processed using MATLAB’s core functions or via specialized functions/apps available in toolboxes such as the Curve Fitting Toolbox™, and you can easily call those functions from within the COMSOL model.</p>
<p><img src="https://cdn.comsol.com/wordpress/2013/06/Curve-Fitting-Toolbox.png" alt="Curve Fitting Toolbox™" title="Curve Fitting Toolbox™" width="633" height="269" class="alignnone size-full wp-image-13351" /></p>
<p>Now you have a MATLAB® function describing the material behavior that is called by a COMSOL Multiphysics model, which in turn is called by a MATLAB® Design of Experiments app. You can’t ask for a tighter integration between the two software than this, can you?</p>
<h3>Integrate with LiveLink™ <em>for</em> MATLAB®</h3>
<p>In order to combine and use COMSOL Multiphysics together with MATLAB®, you will need <a href="http://www.comsol.com/products/livelink-matlab/">LiveLink™ <em>for</em> MATLAB®</a>. This interfacing tool allows you to create a bidirectional integration of COMSOL Multiphysics and MATLAB®. Besides solving the type of problem described above, you can perform a host of advanced modeling operations as a result of the flexibility provided by the interfacing tool. Below, I have listed some of its key benefits:</p>
<ul>
<li>Using functions and variables
<ul>
<li>Call built-in and user-defined MATLAB® function from COMSOL Desktop</li>
<li>Call COMSOL model as a function in MATLAB® workspace</li>
<li>Communication between COMSOL and MATLAB® variables</li>
</ul>
</li>
<li>Programmatic control for setting up and running models
<ul>
<li>Repetitive operations using <em>for</em>-loop and <em>while</em>-loop</li>
<li>Controls using <em>if-else</em>, <em>switch</em>, <em>break</em>, and <em>continue</em></li>
</ul>
</li>
<li>Data extraction and analysis
<ul>
<li>Customized data extraction and statistical analysis</li>
<li>State-space matrix for system level modeling</li>
</ul>
</li>
</ul>
<h3>Learn More in our Archived Webinar</h3>
<p>For more information on how to work with COMSOL Multiphysics and MATLAB® together, check out the archived version of our webinar on <em><a href="https://event.on24.com/eventRegistration/EventLobbyServlet?target=registration.jsp&amp;eventid=608233&amp;sessionid=1&amp;key=2E51CB8342F5512F0A832EE78945183B&amp;sourcepage=register" target="blank">Using MATLAB® with COMSOL Multiphysics® to Simulate and Customize Designs</a></em>. In this webinar, Deepak Ramaswamy from The MathWorks and I will take you through a number of simulation scenarios where the combined strengths of COMSOL Multiphysics and MATLAB® can turn out to be advantageous. You will also see a series of short tutorial videos showing the details of setting up and solving the design optimization problem of the heating circuit.</p>
<p><em>MATLAB is a registered trademark of The MathWorks Inc.</em></p>
]]></content:encoded>
			<wfw:commentRss>https://www.comsol.se/blogs/combining-comsol-multiphysics-and-matlab/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
