Using the Transform Feature to Perform Transformation of Field Variables

In this month’s tips and tricks video, I will demonstrate with two different examples how to use the Transform feature to perform transformation of field variables from one coordinate system to another coordinate system.

Click below to watch me walk you through the process. We have included the video transcription below to help you follow along.

 

There’s no reason to learn software programs through trial and error, so in addition to our tips and tricks, our upcoming training classes will support you, the COMSOL user, in utilizing best practices with many of the COMSOL modules. Please visit our training calendar and find the course that is best for you.


Using the Transform Feature to Perform Transformation of Field Variables

Welcome to Tips and Tricks video. In this video we will demonstrate how to use Transform feature to perform transformation of field variables from one coordinate system to another coordinate system. We will show two examples. In the first example, we will demonstrate vector transformation utility. The second example deals with the matrix or tensor transformation.

Let’s look at the model of the electromagnetic field with permanent magnets. We use ‘Magnetic Fields, No Currents’ physics to solve the problem. Here we have a set of magnets with radial and circumferential magnetization. You solve the problem for the one sector only and assume rotational symmetry conditions. The resulting magnetic field is shown in the Slice Plot and here we use sector 3D data set to visualize magnetic field over the full geometry. The magnetic field has X, Y, and Z components related to the global Cartesian coordinate system. But, what if we want to look at the radial or circumferential components of the magnetic field? In other words, we want to evaluate components of the magnetic field in cylindrical coordinate system. Can we do this? The answer is yes, we can. This can be done using transform utility for variables. But first we need to activate these utilities. We go to the ‘Show More’ options and find section ‘Variable Utilities’. And then check this box and click OK. Before proceeding, you want to be sure that you do have cylindrical coordinate system. This coordinate system is defined at the component definitions ‘Cylindrical System 2’. We will use this coordinate system to perform transformation of the magnetic field vector from global coordinate system to this local cylindrical coordinate system. Now, we are ready to perform transformation. Under the Component 1 mode right click ‘Definitions’ and select ‘Variable Utilities’ and then select ‘Vector Transform’. Then, proceed to settings window for ‘Vector Transform 1’. First let’s select ‘All domains’ where transformation will be performed. Then you have to define Input vector. Click ‘Replace Expression’, go to the ‘Magnetic Fields’, ‘Magnetic’, ‘Magnetic flux density’, and double click ‘Magnetic flux density’. This is the field variable which will be used for transformation. Make sure that the Global coordinate system is selected as Input coordinate system and then for the Output coordinate system change a default setting to the Cylindrical System 2. This completes settings for the Vector Transform mode.

Now we can update solution and plot components of the magnetic vector field in cylindrical coordinate system. Let’s go to the Slice Plot. To plot components of the vector field in cylindrical coordinate system go to the ‘Replace Expression’, then ‘Definitions’, ‘Vector Transform 1’, ‘Transform vector’, and then double click component of the local field you want to visualize. Let’s visualize radial component of the magnetic field. Double click and click plot. So this is the radial component of the magnetic field defined in the cylindrical coordinate system. Similarly, you can plot the circumferential component. You go to the ‘Component Definitions’, ‘Vector Transform’, ‘Transform Vector’, and double click phi component of the transformed vector, ‘Plot’. And this is the plot of the circumferential component of the magnetic field.

So far we’ve demonstrated how to evaluate components of the vector field in local coordinate system. But what if we have tensor fields such as stress tensor or strain tensor? Can we do similar transformation for the tensor field? The answer is yes, we can. To see how it works, let’s take a look at the example of the solid mechanics. Let’s open ‘New Model’ file. Here we have solid domain and we use ‘Solid Mechanics’ to solve the problem. Bottom of this solid domain is fixed and we applied axial displacement at the top of this solid domain. After problem is solved you can take a look at the default plot for the Stress. This is the Mises stress; all components of the stress field are evaluated in the global X, Y, Z Cartesian coordinate system.

Now what if we want to evaluate hoop stress or radial stress? To do that you have to create first, cylindrical coordinate system. Go to the ‘Component Definitions’, right click ‘Coordinate Systems’ and select ‘Cylindrical System 2’. Next add matrix transform mode. To do that go to the ‘Component Definitions’, ‘Variable Utilities’, and select ‘Matrix Transform’. And then go to the setting windows, select ‘All domains’ and then go to ‘Replace Expression’ to select component of the tensor to be used for transformation. Click ‘Replace Expression’, ‘Solid Mechanics’, ‘Stress’, ‘Stress tensor’, and select ‘Stress tensor spatial frame’. Double click, these are the tensor components that will be used for transformation. We use a global coordinate system for the input, and for the output you have to use cylindrical coordinates. You have to use cylindrical coordinate system for the row and for the columns of the tensor. And this completes the settings for the matrix transform.

Next, we go to the Study and click ‘Update Solution’. Then you go to the ‘1D Plot Group’, ‘Line Graph’, and here you have Plot along the circumferential edge of the X component of the stress field. Next, we duplicate Line Graph 1 and now we want to plot hoop component of the stress field. You go to the ‘Replace Expression’, ‘Definitions’, ‘Matrix Transform 1’, ’Transform Matrix’ and find hoop component which is ‘Vphiphi’ component. Double click and plot. So the blue line is X component of the stress field the green line is hoop component of the stress field. The hoop component is negative and constant because we have uniform tension. Similarly, you can visualize radial component of the stress. Duplicate Line Graph 2, go to ‘Replace Expression’, ‘Definitions’, ‘Matrix Transform 1’, ‘Transformed matrix’, and find expression for the radio component which is ‘Vrr’. Click Plot and the red line is radial component of the stress field. Radial component is zero, as it should be, because normal component on the free surface of the stress tensor is zero.

That’s all for now. We have demonstrated how to use variable utilities to transform components of the vector field and components of the tensor field from global coordinate system to user-defined local system. Hope this was helpful and thank you.