 Welcome to lecture 20. So, in the previous lecture we have seen a 2D FEM code which is developed to solve a two dimensional magneto static problem. In that FEM code we have used the mesh that has been generated manually ok, but that kind of mesh is easily applicable for rectangular geometries where the discretization is also uniform. But in case of electrical machines most of the geometries will have circular boundaries. So, in that case that algorithm will be difficult to mesh such kind of geometry. So, for that case we have to use some ah machine softwares which are available online. So, one such kind of freeware to mesh a 2D geometry of any shape is G mesh ok. So, you can download G mesh you can download G mesh software using the link that is given in this slide ok. And preferably you download this version of software because the mesh data available that comes out of this software is more easy to understand. Now, in this lecture we are going to solve the same 2D geometry using the mesh generated by using G mesh ok. So, this geometry we have seen in the previous lecture already. So, first in this lecture we will go to the G mesh ah software interface and then we will draw this geometry we will mesh it and we will extract the mesh data in terms of TET matrices. And then we use the same TET matrices in the same code that we have seen in the previous lecture with very few modifications. Only in this lecture we are going to focus only on the modifications of the code in the previous lecture ok. So, now first we will go to the G mesh software you can directly download from that link and it will come in the form of a ah ZIF file ok like this. So, if you extract that ZIF file you can open that folder here there is no need of installation also. Directly you double click on the application of this icon. This is the application icon. So, you directly double click on this you can open the G mesh interface ok. Now, here on the left hand side you can see 3 3 different things 1 first is geometry. So, under this you you have different entities to draw the geometry ok. So, here these are the entities these are the entities that are used to draw the geometry ok. So, geometry according to these these list of entities we can draw geometry either by using circles rectangles circular arcs and so on. But here in this lecture we are going to draw the geometry by using points and straight lines ok. So, here why why because most of the electrical machines the geometries are basically of circular arcs and they are not complete circles and complete rectangle is it not. If you imagine how a slot looks it is like this it is not a complete arc also it is a it is it is not a complete circle it is a arc. So, better we draw geometry using nodes and join by straight lines that is a better way. So, here also I am going to do the same thing. So, here in this slide you can see these are the coordinates of the 8 nodes. Here the 2 rectangles are formed by 8 points is it not here the 2 rectangles are formed by 8 nodes. So, first we are going to place these nodes in the geometry ok. So, here first you click on point ok. Once this window comes here you enter all the coordinates ok. So, our coordinates are 0 0 first first coordinate is 0 0 and length of the outer boundary is 0.1 you have seen that. So, I am changing my x coordinate as 0.1 ok and then height of the rectangle is 0.1 again. So, I am changing y coordinate as 0.1 and now I am closing the rectangle with 0 comma 0.1 ok. So, we have formed the outer nodes of the nodes of the outer rectangle ok. Now, we are going to form the inner nodes of the inner rectangle ok. So, here you. So, here you just enter 0.3 0 3 and 0.3 and length is 40 mm is it not. So, you have to increase the x coordinate by 0.04 ok and then height is 0.04. So, increase y coordinate to 0.07 and then close the rectangle by placing the fourth node ok. Now, you have placed the nodes. Now, you have to frame the geometry by closing these nodes using straight lines is not it is a rectangle not. So, it will have straight lines. So, here I want to highlight one thing in case of g mesh. So, as we have discussed in the previous lecture as we have discussed in the previous lecture, we make use of the mesh information to form the to apply the boundary condition is it not. So, we need to know the something called as global edge number that is like on which there will be a label for this edge complete edge. So, that label we need to know to you to explore that condition. In g mesh the way you draw in the sequence you draw the numbering will be assigned in the same sequence ok. Similarly, for sub domain numbers also the in the sequence you assign the sub domain number in the same sequence that global known that sub domain number will be assigned ok. So, that advantage we can explore. So, to see what are all the global edge numbers and global sub domain numbers. So, you have to right click here ok go to all geometry options in visibility tab you check the line labels surface labels ok. So, now as you draw the straight line. So, I am drawing the first vertical line like this ok. Here you can see for the for this edge one has been assigned ok is it clear. Similarly, if I draw this as second this will get the second similarly third similarly fourth. So, to avoid confusion while you draw the geometry you assign the outer boundary where in general we apply most of the cases we apply a is equal to 0 with 1, 2, 3, 4 first you draw those edges. So, so that that part of the code where you assign the boundary conditions will remain same for any geometry ok. Now, after that you draw the straight lines for the inner rectangle inner rectangle ok. Now, after this we need to assign the sub domain number is it not. So, sub domain numbers here there are two sub domain ok. The first sub domain is in between the outer rectangle and the inner rectangle. So, this outer rectangle and inner rectangle form the boundary of the air sub domain ok. So, to define the plane surface you click on the two boundaries you click plane surface here and you select the two boundaries. So, these two form the boundaries of the first sub domain. So, whatever may be the sub domain sub domain you need to choose you click the two click the all boundaries in which which is bounded for that sub domain and then you click E here you can see press E to end here it is written press E to end. So, you click on E. So, that will assign the first sub domain number here you can see there is one ok. Similarly, to to second the sub domain click on second sub domain click on plane surface and select the boundary. So, for the inner inner rectangle which is rectangular conductor the boundary is only this rectangle. So, I am choosing only this one and then click on E that will select you the second sub domain ok after this. So, now we have assigned the sub domains also. Now, we need to mesh this geometry. So, here geometry thing is completed. Now, go to mesh. So, this is a 2D geometry is it not here you can mesh a 3D geometry also this is a 2D geometry. So, click on 2D. So, mesh has generated, but this is a very coarse mesh now you need to refine refine this mesh is it not. So, click on refine mesh by splitting. So, like this if you keep on refining the mesh will get refined automatically ok, but in this mesh there is a problem here you can see for these elements these triangles are obtuse angle triangle. So, it is advisable to have equilateral triangles to to to get an accurate result. So, you need to avoid this kind of obtuse angle. So, for that you need to you need to change the algorithm. So, there will be a default algorithm for G mesh which can mesh the geometry. So, you need to change the algorithm of machine. So, for that you rightly on this space go to all mesh options here in general you have 2D algorithm or getting here there is automatically automatic is selected. In that place you select this this algorithm this is Deloni algorithm ok. So, after selecting this you click on 2D. So, you can see the mesh shape has changed. Now, more or less all the elements are equilateral triangle they are equally spaced almost ok. So, and the two sub sub regions and the elements in two sub regions are with different colors ok. Now, here I want to highlight one point. So, in case of electro statics you no need to mesh the geometry mesh the geometry that correspond to conductor because E field is 0 there. So, you need no need to calculate the potential in that region ok. So, in that case to unmesh to not to mesh that region you do not select the boundary you do not select its plane surface like the way we selected this conductor you do not select that conductor. So, by doing that it will not mesh that region ok. That is how you can reduce your mesh sizes ok. Now, we have generated the mesh after generating the mesh we need to export this mesh into Sylab code ok. First of all for that first of all we need to save this mesh data. So, here under the mesh tree you have save option you click on save here you can see where it has been saved ok. So, it is it has saved here app data roaming. So, first actually you need to save this geometry file in a folder. So, that you get the mesh data in one file now you just go to that folder ok. Here you can see example 1 dot msh file. So, mesh data will get saved in the msh file. So, you just right click on this file and then open with notepad ok. We will get the complete information about the generated mesh in this file this file contains two sets of information. The first set of information will be saved under section nodes under section nodes you can see there is a number 270 this 270 corresponds to total number of nodes in the mesh and the rest of the information corresponds to the coordinates of the nodes in the mesh. So, here what you have to do is you have to copy the information that corresponds to the coordinates in a text file and you have to save it as p dot txt in a folder where you will save the code cell app code. So, you open it notepad file and copy the information and save it with p dot txt file. Now, the second set of information will be saved under section elements and this section contains three sets of data. The first set of data corresponds to the global nodes that are placed to draw the geometry and the second set of information corresponds to edges that are on the boundaries of the geometry and the third set of information corresponds to triangles in the mesh which is nothing but the connectivity matrix that we have seen in the previous lecture. So, here the question that arises is since the three set of data are saved under the same section how to distinguish these three sets of data. So, here you can see the data that corresponds to the node will have six columns the data that corresponds to edges will have seven columns and the data that corresponds to triangles will have eight columns. So, what you have to do is here we will save only the information that corresponds to edges and triangles why because the information that corresponds to nodes will have no use in our code. So, first you first you have to copy the information that corresponds to edges in a notepad file like the way we have done for the nodes and you have to save it as e dot txt file in the same folder where the p file is saved. Similarly, you have to copy the information that corresponds to triangles in a notepad file and then you have to save it in the same folder where the p and e files are saved. So, with this we have completed the task of extracting the mesh information in terms of three matrices that are p, e and t and now we will see how to use this information in the Sylab code to solve a 2D magnetostatic problem. Now, going into the slides. So, this we have seen already now here this ELC clear all you know what it is now the next part. So, now the next part is this pf scan f mat. So, this command is will read the text files this command will read the data in text files into a matrix in Sylab ok. So, there we this p dot txt we have saved already ok. So, here in this case this f scan f will take out all the information that is in the p dot txt file into this p matrix ok. So, what is the information that is in p dot txt is this ok. Here the first column is load numbers ok. Second column is x coordinates of all the nodes, third column is y coordinates of all the nodes and fourth column is z coordinates ok. As this is a 2D problem the z coordinates are by default 0 ok. So, what are all the things that we needed here? So, we have to take only the things that we need only x and y coordinates is it not. So, here I am taking only 2 and second and third columns and I am updating my p matrix with the data and I am taking a transpose of it. So, that it will be in line with the form of matrices that we have seen in the previous lectures ok. So, after this operation my p matrix will be like this. So, the column numbers of this p matrices of this p matrix is nothing, but load number ok and the size of this p matrix is 2 by number of nodes. Now, similarly e matrix. So, e dot txt file we will read into the e matrix and in the in this e matrix in this e text file we have as I have discussed earlier there are 7 columns is it not. Of these 7 columns first is element number. This element number means combination of all the 3 set of data ok. This has this numbering has of no use ok and the and these 3 also g mesh generated thing this is also has no use in this case ok. Only thing that we use here is the last 3 columns ok. The first this column this fifth column is global edge number. So, this information we will be used to assign the boundary condition ok. So, for the first for the first edge you you may remember while we are drawing the geometry the first edge got assigned to the vertical. So, that first edge similarly second for the second edge this will be changed to 2. Similarly, for the third edge and this and starting node number will be placed in the sixth column and the ending node number will be placed in the seventh column. So, after this operation so, we are taking only fifth to seventh column and we are take and we are transposing it. So, that we will get an E matrix of this kind. So, the first row of this updated E matrix will have global edge number, second row will have starting node number, third row will have ending node number ok. So, this is the that is how so, the finally, the E matrix size is 3 by number of nodes and then T matrix. Similar to the other two matrices we can get the data of T matrix and we can save it in a matrix of which is whose name is T and then as similar to E matrix the first four columns are of no use we are going to use only the columns 5 to 8 ok. That is why we are taking columns 5 to 8 and we are taking making a transpose ok. So, that our updated T matrix will be of this kind ok. So, here the fifth column this first row which is nothing, but this column this first row denotes the sub domain number ok and this sub domain number it will be used to assign the material properties and assign the source conditions and first second and sorry second third and fourth rows contains the global node numbers of each element are you getting is it clear. So, the first the second the second row third row and fourth row will have the global node numbers of each element and the element number is nothing, but column number this column corresponds to first element, this column corresponds to second element, this column corresponds to third element that is why the column number corresponds to element number ok. Now, the size of finally, the size of T matrix will be 4 by number of elements ok. So, up to here the machine and taking that machine to the code we have seen. So, this part is completely different from the code that we have seen in the previous lecture. So, from here the next part will is same up to calculation of element coefficient matrices only next thing what we need to change is assigning the source conditions is it not. So, in the previous lecture if you remember we have assigned the source conditions by verifying whether its centroid is inside that rectangular region or not is it not. So, in this lecture in this code we are not using that logic we are just checking its sub domain number. So, for every element as we have seen earlier the first row corresponds to sub domain number we are checking whether the sub domain number is 2 or not. If it is true we are assigning the source if not we are not assigning the source. If not since there are only two one is rectangle second is one is rectangular conductor second is air. So, we are assigning only to the to the rectangular conductor only. So, this part of the code will be changed for that code that we have seen in the previous lecture. Similarly the next step that we need to change is assigning the boundary conditions. So, boundary in the previous lecture we have seen boundary conditions are assigned node wise is it not. We have done a bookkeeping of all the node numbers and we have made a logic for which all the bottom edge nodes top edge nodes like that we have done. But here with the help of G mesh we know the global edge number this 1 2 3 4 ok. This we can remember as we have drawn we have drawn the geometry and we have assigned that outer 4 edges are the main boundaries outer boundaries where A should be assigned. So, that we will be check we will check whether the global edge number of each edge is 1 or 2 or 3 or 4 and we will assign the boundary conditions. This part of the code is same. There you you will see that we are applying boundary condition to one node at a time because we are assigning node wise here each edge will have two nodes ok. So, that is why we are assigning boundary conditions to two nodes at a time ok. That is why there you have seen three steps here we will see six steps ok. Now after this plotting, plotting has to be changed. So, the surf and contour plots that those commands are applicable only for rectangular grids ok. You cannot use those commands to plot for triangular mesh ok. So, that is why we need to form a rectangular grid first. So, we got the solution already and then you after getting the solution you discretize the geometry into a rectangular grid and you calculate the potential at each and every node of this rectangular grid using the solution that you have obtained. So, you frame a grid and it will have many number of points like this. Each node you check in which element it is present and then you calculate the potential at the of that node of the grid node using the three potentials of potentials of the three node ok. So, that you can calculate the potential of this complete rectangular grid ok. This is the logic that we are going to follow to plot the potentials in this case. So, here how how can you know whether a point is inside a triangle inside a triangle or not. So, if a point is inside the triangle ok if let us say a point is inside a triangle one point can be always be inside one triangle only is not. So, if a point is inside the triangle then you frame three triangles ok with this node and the triangle like this is this is that unknown potential node you form triangle with nodes 1 and 3 of the triangle that is delta 1 form a triangle with nodes 1 and 2 that is delta 2 form a triangle with nodes 2 and 3 that is delta 3 ok. If the sum of these three triangles is equal to the area of this big triangle then the node is inside the triangle if not then that area will be more than the area of big triangle that you can visualize directly using these two figures is it not. So, here to calculate the potentials on this grid for plotting purpose we are going to do this same logic. So, first we are going to discretize in the same fashion that we have done in the previous code and then for each element we are checking we are taking the difference delta 1 delta 2 delta 3 we will be calculating using that node information and then we are calculating the difference. Why we are taking difference is numerically this is a computing software sometimes that may not be numerically equal that delta 1 plus delta 2 plus delta 3 may not be numerically equal to delta. So, that is why we are calculating the difference between sum of that area and area of the triangle and we are storing it in difference matrix ok. Once we will store it for all the elements after that we will take the minimum difference triangle for the triangle for which that difference is minimum we will take the triangle number ok. So, now we got to know in which triangle that node is present ok. Now, using this formula a inside an element can be approximated as a plus b x plus c y this is our initial step of formulation ok. Using this we will calculate and using the potentials at the three nodes using this formula and potentials at the three nodes we will calculate a b c by just by inverting this step also we have seen previously ok. Now, once this is done we will get a b c a b c values you just substitute x and y coordinates you can get the potential at that point ok. So, this part of the code is nothing, but this logic ok. Here this m matrix correspond to this matrix 1 x 1 y 1 1 x 2 y 2 1 x 3 y 3. So, here x 1 y 1 is x coordinate and y coordinates are stored in p matrix first row of x first row of p matrix is x coordinate and second row of p matrix is y coordinate and global node number 1 is second row of p matrix. So, like that you can calculate you you can get the information of x 1 y 1 x 2 y 2 x 3 y 3 form this matrix like this take inverse of m into pot potential you will get a b c values and I am storing those values in a b c matrix. So, this will be a 3 by 1 matrix in which a b c 1 corresponds to a a b c 2 corresponds to b a b c 3 corresponds to c ok and substitute the x and y coordinates you will get the potential at that corresponding grid point ok. So, you can now you can plot that using the same surface command. So, this logic of plotting by using a rectangular grid on a triangular mesh is common to all the codes this this logic will be there in all the Sylab codes ok. Whereas, in case of MATLAB there is an inbuilt PDE toolbox where that toolbox also generates same PET matrices using that PDE toolbox commands which is called as PDE plot you can plot that directly, but in case of Sylab we do not have such kind of command that is why we are using this logic to plot ok. Similarly, you can plot a contour plot also for this ok. Thank you.