Transcript for:
Meshing in COMSOL Multiphysics

[Music] in this video we will discuss why meshing is important and how to mess your model geometry in COMSOL multiphysics when building the mesh there are several factors that should be taken into consideration all of which can be addressed using various features and functionality available in the software these include choosing a mesh sequence type that either completely automates the process of meshing the geometry or enables you to build a custom mesh yourself the order of operations in your meshing sequence the element types available to be used the size and distribution of elements the element order being used and the mesh quality these and more contribute to your model geometry being properly and efficiently resolved by the measure we will also provide you with several tips and best practices to keep in mind as you are building the mesh for your model to start off let's provide some context as to how important and great a role that meshing plays in solving a problem so when you are creating a model the problem can be described by partial differential equations and the solution to your mathematical model is approximated through the finite element method which the COMSOL multiphysics software is based on so the finite element method is used to discretize the problem and thus divide and conquer the model and by discretize we mean to break down into smaller discrete parts this happens through the geometry being divided into several smaller discrete parts called elements and the solution is obtained through stitching together low order polynomials over each element to form a piecewise global function so in discretizing the problem there are three main factors we need to consider first how we divide the geometry second by what means we divide the geometry and third how the solution is interpolated between nodes so the first two points I mentioned are handled in the mesh settings while the third point is done through the physics so let's start by talking about how to divide an arbitrary domain such as this into several smaller subdomains first so when it comes to generating the mesh for the geometry in your model you have the ability to either completely automate this process in the software or do it manually yourself and this can be done through right-clicking the mesh node in the model builder window or by using the mesh ribbon tab for this component I'm going to build the mesh exclusively through the model builder window and right clicking the mesh node so first let's go over how the software creates the mesh automatically so the software makes several default choices including the mesh element type used depending on the physics that are included in your model here for example we have included heat transfer and applied it to our geometry but if we were to disable these physics and enable our fluid flow interface and laminar flow and then go to the mesh node and rebuild you'll see we have automatically generated a new mesh that adapted to those changes in the physics settings this also goes for any boundary conditions or domain conditions or constraints that you apply to your model geometry additionally if you want to adjust the mesh element size globally you can simply choose from the nine predefined element size setting types in this drop-down menu so building a physics controlled mesh requires little to no effort on our part we just simply select the mesh node and click build all so now that we've shown you what the software does by default let's show you how you can create the mesh yourself creating a custom user controlled mesh can be done one of a few ways we can do it by either editing or building off of a physics controlled mesh sequence or by using a user controlled mesh and starting completely from scratch so since we already have a physics controlled mesh built let's go ahead and demonstrate editing and building upon that so if we right click the mesh node and select edit physics into sequence this expands and reveals the meshing sequence that was used to generate the physics controlled mesh for our geometry so now we can go into any of these mesh operations and adjust the settings for any of them perhaps we wanted to add a local size sub node and create a more coarse mesh in the geometry we can select that and build all and make any edits or build upon the sequence as needed if we wanted to build the mesh for this geometry manually we can simply delete the sequence and confirm that start off by adding a mesh generator node let's use a free triangular mesh we can adjust the global size setting perhaps we want it to be a more coarse mesh since it's a fluid flow problem we'll want to add boundary layers and we can go ahead and apply this to all boundaries in the model and change some of the settings such as the thickness adjustment factor as well as the number of boundary layers and adjust these settings to our own specification if you ever at any time want to return back to the physics controlled sequence you can simply right click and select reset to the physics and do sequence and then confirm and rebuild to reset those settings now let's go into more detail regarding the meshing sequence and our model so the mesh is always built in a sequential order from the top downwards and the mesh generated is always a result of building this sequence of operations as well as any local attribute sub nodes in any sequence there will always be a mesh generator node which indicates the element type used to resolve the geometry and for many of the main mesh operations you can always right click and add an attribute such as a size size expression distribution or coordinate refinement sub node this also goes for the mesh one node you can right click and add all these same attributes some of which you can see we already have in our meshing sequence so you can modify the mesh operations by going in and making changes in these settings windows or by adding a subdural which the operations appear that if you happen to change or move around the order of any of these nodes you may encounter building errors if you have an operation that depends on an operation earlier on in the sequence all right so now that we've discussed how we can divide the geometry let's discuss by what means we can divide the geometry through the element type used so the element type used is the shape which is used to divide up your geometry in 1d models these are just intervals in 2d models you can subdivide your geometry into triangles or quadrilaterals with the default being triangular elements for 3d models you can subdivide your geometry into tetrahedrons hexahedron pyramids or prisms with the default being tetrahedral elements pyramid elements are added automatically by the software when necessary to transition between tetrahedrons and hexahedron in your mesh please note that in COMSOL hexahedron elements take on the shape of regular hexahedron which are essentially quadrilaterals swept along some distance this also goes for prism elements wherein we have a triangle that is swept along some length so when creating a user-controlled mesh or editing a physics controlled mesh you can also change the size of your mesh elements by using a size node a finer mesh will give you more accurate results however this will make your problem more computationally expensive and take longer to solve let's see how the software handles elements of different sizes in the same geometry using a simple example so this geometry consists of a smaller rectangle contained within a larger rectangle to make it easier for you to see visually how the software handles elements of different sizes contained in the same geometry we'll use two different element types both triangular elements and quadrilateral elements and please note that for this example I'm going to build the mesh exclusively through the mesh ribbon tab so let's add a free triangular mesh and apply that to a domain the larger domain and let's also add a quadrilateral mesh again apply it to one domain be smaller domain so if we click build all without making any changes you see we have a uniform sizing since both element types are using the global size note setting for the size of the elements and you can see the nodes on the quadrilateral elements as well as the nodes at the base of each of the triangular elements are completely aligned and this is a result of us in the geometry node using the form Union geometry finalization method so please note throughout this demonstration wherein we are changing demonstrating healthy software handles the different sizing between the two domains that form Union is being used since this provides us with a continuous mesh so let's first note the order in which our operations appear you see first we have our free triangular mesh and then following that we have our free quadrilateral mesh now if we want to adjust the sizing let's say we want to make our triangular elements extra fine and we click build all you'll notice that the domain containing quadrilateral elements reduced in size as it was approaching the shared boundary so it could accommodate the finer mesh element size setting in the domain containing triangular elements so the free triangular mesh enforced its sizing partially on our free quadrilateral mesh so let's say the order was reversed let's select and drag our quadrilateral mesh so it shows up first in our sequence and rebuild and you'll notice now that the domain containing our triangular elements as it's approaching these shared boundaries grew in size to again accommodate the more coarse mesh sizing for our quadrilateral elements so in meshing the geometry it's good to start with the entities that you want the most control over and have those settings appear earlier on in your meshing sequence let's say I wanted to make the domain containing quadrilateral elements extra coarse and rebuild you can see once again the free triangular mesh adjusted to accommodate those settings also please note that the mesh adjusted accordingly in these ways since we have a continuous mesh through the form Union geometry finalization method for more information on form union and form assembly and how they affect your geometry as well as the mesh please see our tutorial on the form you and form assembly geometry finalization methods so now let's employ this logic of how and when to use different sized elements in your geometry using a 3d real world example here you can see we have the meshing sequence tutorial model opened up and you can find this under windows in the application libraries by going under the COMSOL multiphysics branch meshing tutorials and then selecting and opening the meshing sequence tutorial model and all i've done ahead of time is added some of the physics heat transfer as well as included a time-dependent study step so here in this model we have a part of a circuit board on which a chip is mounted through an array of several solder joints so when meshing a more complex geometry such as this it's best to start with the mesh sizing that is going to be dominant throughout your geometry and set that as be setting under the global size node so in this case we would go to the mesh ribbon tab select that mesh edit be physics induced sequence by clicking the edit button and we could change that predefined mesh heading to coarser since the majority of our geometry we are going to want resolved with a more coarse mesh thereafter we can apply a finer mesh to the specific parts of the geometry through adding local size sub nodes in the case of this model we are going to want to create a more fine mesh on the solder joints and have a more coarse mesh in the chip as well as the circuit board and please note that for this example I'm going to build the mesh through the mesh ribbon tab so we can build our mesh using the coarser mesh size setting and now we can select the free tetrahedral mesh generator node and apply a normal size setting the solder joint domains by hiding the chip as well as the circuit board through the click and hide button using the Y Z plane view as well as the select box in selecting all of those domains at once now we can click build all and you can see these solder joints are resolved with a finer mesh while we still have retained that more coarse meshing on the chip as well as the circuit board so not only can the size of the elements in your mesh be controlled but also the number of elements if we can reduce the number of elements further this will require less memory needed to solve our problem so we can further reduce the elements in this geometry by using a swept mesh and applying it to the circuit boards as well as the chip so in order to use a swept mesh we first need to create a surface mesh which will be used to sweep through the respective domains so to do this first I'm going to update the settings for the free tetrahedra 1 node we are going to apply this meshing only to these solder joints so we can go ahead and omit the chip and circuit board from our selection and rebuild so now we can go ahead and add a surface triangular mesh to the top of the circuit board as well as the bottom of the chip and build that so now that we've done that we can go ahead and add a swept mesh at this point all we have to do is click build all and you can see that be meshing was swept through those respective domains with the more finer meshing in the center being the result of the solder joints being resolved with a finer mesh for more precise control over the number of elements in the mesh we can go ahead and add a distribution sub node so here we are able to explicitly state how many elements we want the geometry to be resolved with if we build with the default setting you can see the changes in the geometry but we actually want to use and include less elements so let's change that setting to two and rebuild and you can see again those adjustments made on the chip and circuit board portions of the geometry so in these ways we were able to keep a higher resolution for the domains most important to our analysis which would be the solder joints while retaining a more coarse mesh for the circuit board and chip components of the geometry so for any model that you are building in the software you may want to experiment with several different types of meshing sequences and using them to solve your problem in any model component you can include multiple meshes simply by using the add mesh button and then perhaps in this mesh we wanted to use a physics controlled mesh so we could build that and we have those two meshes to choose from in solving our model be sure to specify which mesh exactly you want for your study to use by going under these study settings in the mesh selection section and then specifying the exact mesh to be used so now that we've discussed with what shapes and in what ways we can divide the geometry let's now talk about the element discretization order so when your mesh is generated the elements that it consists of are formed by a collection of nodes and the descritization order used which is done through the physics settings effects the function which interpolates the solution between nodes so it's important to use a suitable element descritization order so if we go into our heat transfer in physics interface we can go to the disquisition section and if you are unable to see the section you can go and click on the shell button and select discredit a ssin to have that displayed so here we can choose the order of element descritization and type of shape function used in our model and this setting is important especially for multi physics problems since different element order settings can be optimal when computing a multi physics problem for example let's say if we were to add another physics for example solid mechanics and we also wanted to add and couple those physics together through a multi physics coupling here we have thermal stress so now if we return back to the heat transfer in solids interface and look at the discretization section you can see the setting has changed so this is important to keep in mind especially for when you're working with a multi physics problem so after we've finished defining the physics and computing the problem we want to be sure that the mesh generated for our model is good enough when we solve the model and be solver converges this only means that you have gotten the best approximation that could be obtained with the meshing currently in use in your model so this doesn't necessarily tell you if you are close enough to the solution of your mathematical model so to do this we need to validate or verify the mesh element quality and how we can do this is by performing a manual mesh refinement study or by having comps all do it automatically for us through performing adaptive mesh refinement and this can be found under these study settings going under the study extensions section and then toggling on that option also depending on the study step type you have included in your study it may also be located in the adaptation and error estimate section by simply selecting from that drop-down menu if you want to obtain a quick overview of the mesh you've generated at a glance you can always right-click the mesh node and select statistics so here you can see several statistics regarding the elements for your whole geometry or only certain portions you can choose the measure of quality that you want to look at statistics for as well as an element quality histogram so this is a great way to see various statistics including some element quality stats at a glance with that we have showed you the ways in which you can generate a mesh for your model geometry in COMSOL multiphysics we went over the two mesh sequence types you can choose from to either fully automate or manually tune the properties of the mesh the element types available in the software how you can change both the size and distribution of elements in your mesh the order of element descritization and how the selection for the shape function is important when dealing with multiphysics models and lastly how to inspect the quality of your mesh