Welcome to the World of Modelling and Simulation

What is Modelling?

This blog is all about system dynamics modelling and simulation applied in the engineering field, especially mechanical, electrical, and ...

Mohr's Circle Representation for the Stress Components of a Structure using Matlab

In this tutorial, we are going to solve a fundamental problem in mechanics of materials using the very popular Mohr's circle method. Mohr's circle is a two dimensional (2D) graphical representation of the stress components in a solid material. The following diagram shows a typical 2D element having all the stress components. Here,

𝞼x = Normal stress along x axis
𝞼y = Normal stress along y axis
𝞽xy = Shear stress on the plane
𝞡 = Inclination angle

Showing a 2D element with the stresses.















Now, let's assume the following parameters to represent the stresses by a Mohr's circle with Matlab codes.

𝞼x = Normal stress along x axis = 115 Mpa
𝞼y = Normal stress along y axis = - 50 Mpa
𝞽xy = Shear stress on the plane = 25 Mpa
𝞡 = Inclination angle = 25 Degree

With the above information at hand, we can draw a Mohr's circle to represent those stresses. The following figure shows the Mohr's circle, which is plotted by Matlab codes appended at the end of this blog post.

Showing Mohr's circle for the stress components














Showing stress versus cut plane angles














We can calculate the transformed normal and shear stresses, which  may be expressed as [2, 3],















The maximum principal stress is defined as [2, 3],











The following figure illustrates the maximum normal and shear stresses, along with other nomenclatures on a typical Mohr’s circle

Showing maximum normal and shear stresses along with other nomenclatures on the Mohr’s circle


MATLAB CODES

close all
clear
clc
 
% Parameters from the question
sigma_x = 115;
sigma_y = -50;
tau_xy = 25;
gridsize = 1000;
% Calling the function "mohrs_circle" defined in another script
[sigma_mohr,tau_mohr,sigma_1,sigma_2,tau_1,tau_2,center_circle,phi] = mohrs_circle(sigma_x,sigma_y,tau_xy,gridsize);
%%
% Plotting the figures
figure;
plot(sigma_mohr,tau_mohr);
grid on;
axis equal;
xlabel('Normal Stess, MPa');
ylabel('Shear Stress, MPa');
title('Mohr Circle for 2D Stresses');
hold on;
plot(sigma_1,0,'r*',sigma_2,0,'r*',center_circle,tau_1,'ro',center_circle,tau_2,'ro',center_circle,0,'r^');
%%
figure;
plot(phi*180/pi,sigma_mohr,'b',phi*180/pi,tau_mohr,'g');
grid on;
xlabel('Cut plane angle (deg)');
ylabel('Stress, MPA');
legend('Normal Stress','Shear Stress')
title('Mohr 2D Circle');

-----------------------------------------------------------------------------------------------------------------------------
function [sigma_mohr,tau_mohr,sigma_1,sigma_2,tau_1,tau_2,center_circle,phi]=mohrs_circle(sigma_x,sigma_y,tau_xy,gridsize)
% This function implements the calculation of the principal stresses
 
phi = linspace(0,pi,gridsize); % Defining the range of the angles for plotting
% Applying the formula or expression based on the stress theory
sigma_mohr = (sigma_x+sigma_y)/2+(sigma_x-sigma_y)/2*cos(2*phi)+tau_xy*sin(2*phi);
tau_mohr = -(sigma_x-sigma_y)/2*sin(2*phi)+tau_xy*cos(2*phi);
sigma_1 = (sigma_x+sigma_y)/2-sqrt(((sigma_x-sigma_y)/2)^2+tau_xy^2);
sigma_2 = (sigma_x+sigma_y)/2+sqrt(((sigma_x-sigma_y)/2)^2+tau_xy^2);
tau_1=sqrt(((sigma_x-sigma_y)/2)^2+tau_xy^2);
tau_2 = -tau_1;
center_circle = (sigma_x+sigma_y)/2;
%phi_p=atan(2*tau_xy/(sigma_x-sigma_y))/2;
end


REFERENCES

[1] Saul K. Fenster, Ansel C. Ugural. Advanced Strength and Applied Elasticity, Fourth Edition. Published by Pearson, 2003

[2] Solid Mechanics Part I: An Introduction to Solid Mechanics by ‪Piaras Kelly‬‬



#Matlab   #SolidMechanics   #MechanicsofMaterials #MohrsCircle

App Development with the Matlab App Designer - Part 1: A Simple Mechanics Calculator

In this tutorial, I am going to walk you through the basics of the app development with the relatively new Matlab App Designer platform. Mathworks has introduced the App designer in the 2016 Matlab edition, which helps you to build your own apps with the default graphical user interface (GUI) and programming environment. I have come to know this handy tool lately, and I am very eager to share my knowledge with you, especially if you are interested in object-oriented programming

Let's see, first how we can access the App Designer option. Open the Matlab and click on the "APPS" from the top menus.

Matlab > APPS > Design App

Matlab App Designer





Next, after clicking the "Design App" icon, the following window will appear. As you can see, there are more options to choose. But, to begin with, we should select a "Blank App".

Selecting a blank app in Matlab App Designer

















Once, you select the "Blank App", you will see the following window. On the left hand, you have the default 'drag and drop' items for your app that you can simply select and bring it to the middle window "Design View", where the development works are carried out. On your right, you have the options to customize the default app items of the left side. For example, if you want to increase the font size of your display, you can do it from the right side menu bar.

A Blank Matlab App Designer Platform

















Now, if you click on the "Code View", you will see default codes already done by Matlab for the basic interface. You can edit codes here or enter your own codes that you would like to incorporate with the simulator.

Matlab App Designer Platform Code View


















Now, let's try a very simple example, let's make the very first app by the Matlab App Designer. We will make a calculator for basic calculation in mechanics where it will calculate the force based on the two input data: mass and acceleration. As we know from Newton's second law of motion that the force is a product of the mass and acceleration, this formula is simply implemented in the development of our very first app or simulator by Matlab. Let's follow the following screenshots closely.

Selecting objects in App Designer to build an app


In the above screenshot, as you can see, from the left side menu bar, objects are dragged and placed in the middle window or the design view section. To make a calculator with two inputs, I chose a simple display for the mass input and for the acceleration, I selected a knob, which can be rotated to fix a value. To show the output that is "Force", I dragged the text objects similarly from the left side. You can also format the style of the texts, sizes, etc. from the right side menu bar.

Now, it's time to code the objects that we just placed in the design window a while ago. This is the part that we may call object-oriented programming. So, what are the objects that have been selected here - an execution button, text displays, and a knob for the acceleration parameter. If we press the execution button after providing the inputs, we should have the output displayed on the right side. This is the goal for our first app development.

How to format app objects in the app environment

















We will now add codes to the "Execute" button for our goal achievement. In the following image, we see that how we can access the "Callbacks", which will eventually take us to the code environment that is shown in the next screenshot.

How to access the function Callbacks

















We need to add the formula "Force = Mass × Acceleration". To do so, as you see below, we need to copy the values of the functions under each object (e.g., "Object Mass (kg)", "Choose Acceleration", and "Force (N)") that are selected and write or organize them as per the given formula. For example, the output display is the "Force (N)" and its function value is "app.ForceNEditField.Value", which is the left side of the equation. Then, the right side is the mass times acceleration that is represented by the "app.ObjectMasskgEditField.Value" and "app.ChooseAccelerationKnob.Value" subsequently under the respective functions' values.

Coding platform for the Matlab App Designer

















So, that is all! We have achieved our goal - made a very simple app that calculates the force given the mass and acceleration inputs.

A simple app for mechanics calculation

























#Matlab   #MatlabAppDesigner   #MechanicsCalculator  #ObjectOrientedProgramming

Development of a Simple Configurable Continuous Track Robot with SolidWorks

In this tutorial, I am going to show how to develop a continuous track robot that is flexible in delivering goods in industries. The robot consists a continuous flexible belt or chain, in which three rollers are constrained so that the robot can achieve adjustable motion when it is actuated. This is a very basic configuration that may be made more advanced according to your desired tasks to be accomplished by the robot.

The continuous tracking robot has the following configurable parts:

Belt or chain drive
Wheels or rollers
Motors or actuators
Couplings or bearings used as joints between parts


The following images shows the configuration for the tracking robot.

configuration for the tracking robot













configuration for the tracking robot

















configuration for the tracking robot















For convenience, in SolidWorks, you may have different visualization options. The following image depicts the wireframe type visualization of the assembly, which shows you the hidden lines, corners, and so forth.

assembly visualization of the configuration of the tracking robot

The following design shows the engineering or technical drawing of the robot system. All dimensions shown are in millimetres (mm).

technical drawing of the robot system
The following video shows the motion simulation of the continuous track robot. The animation is made by the SolidWorks Motion Simulation manager. This is a very intuitive tool if you would like to visualize the movement of your structure prior to manufacturing.





#SolidWorks #CADDesign #MotionSimulation #TrackingRobot #ModellingSimulation

A Python Program for Application of the Newton-Raphson Method

In this tutorial, we will develop a simple Python program to implement the famous Newton-Raphson algorithm. Let us consider the following function:

f(x) = exp (-0.5x) (4 - x ) - 2

We will find the roots of the above function by the Newton-Raphson approach and code them using Python. We will start with an initial guess for the solution and then change it to check for other initial guesses to see whether the solution converges or diverges. This is a very basic and fundamental application of the Newton-Raphson method to find the roots of an unknown function. In the following, Python codes are written by Anaconda to find the roots of the unknown function by the Newton-Raphson method. We begin with, x = 2 for our first initial guess.

Python Script for Newton-Raphson Method

import sympy as sp  # Importing symbolic mathematics library
import pandas as pd  # Importing pandas to work with arrays
import math # Importing mathematics library
def f(x):
    return (math.e**(-0.5*x)*(4-x))-2  # Given function 
x = sp.symbols('x')
fp = f(x).diff(x) # Derivative of the function
x_value = [2] # Initial guess
error = [1]
tol = 0.0001
MaxIter = 100
i = 0
while i <= MaxIter and abs(error[i]) > tol: # Setting convergence criteria
    x_new = x_value[i] - (f(x_value[i])/fp.subs(x,x_value[i])) # Newton-Raphson Algorithm
    x_value.append(x_new)
    ernew = (x_new - x_value[i])/x_new
    error.append(ernew)
    i+=1
solution = [[i, x_value[i], error[i]] for i in range(len(x_value))];
solution_new = pd.DataFrame(solution,columns=["No of Iterations", "x_value", "Error"])
print(solution_new)

Results:

When x = 2,

   No of Iterations            x_value                Error
0                 0                  2                    1
1                 1  0.281718171540955    -6.09929355660769
2                 2  0.776886845045375    0.637375541447737
3                 3  0.881707878928567    0.118884084386961
4                 4  0.885703241166645  0.00451094909940144
5                 5  0.885708801994023  6.27839236320089e-6

So, the algorithm converges for the initial guess, x = 2.


When x = 6,

The algorithm diverges, relative error is NAN or infinity.

When x = 8,

The algorithm again diverges, relative error is close to infinity.

As we see from the results that the algorithm converges only when x = 2, but it diverges for the other two cases. The reason behind this is the derivative of the given function is zero when x = 6 and close to zero for x = 8. Since the slope of the function reaches to zero, the algorithm fails to provide a converged solution. From this example, it is evident that for any numerical method to work for a solution, the initial condition is a very important parameter, which needs to have an educated guess.



#Python #PythonScripting #NewtonRaphson #NumericalMethod

Understanding the Role of the Friction Force in Dynamics with an Example

In this blog post, I would like to discuss an example from the web, which may help understand better about the presence and significance of the friction force in dynamics. Friction plays a very vital role in our daily activities, for example walking, driving, etc. are all possible for us because of friction. We mostly know that the friction is a resistive force (opposes the motion), but it is also a driving force (aids the motion). The following example problem enlightens both the facts of the friction force. It is explained below.


Example Problem:

A 0.5 kg wooden block is placed on top of a 1.0 kg wooden block. The coefficient of static friction between the two blocks is 0.35. The coefficient of kinetic friction between the lower and the level table is 0.20. What is the maximum horizontal force that can be applied to the lower block without the upper block slipping?


Sliding blocks without slipping


Here, the lower block has twice the weight than the upper block. In order to keep the upper block from sliding while a horizontal force is applied to the lower block, the static friction between two blocks has to be the key factor. The maximum static force is calculated as follows,

Ff = 𝛍ₛ FN

According to the Coulomb’s friction model, this static friction is solely dependent on the weight of the body. The more the weight is the more static friction is generated. Say, if we apply a horizontal force on the lower block to move it to the right on the table as in the figure, the upper block would slide backward to the left on the table. And, this is dependent on the friction force between the block surfaces, which can resist the upper block’s sliding motion to the opposite to the lower block. For this problem, to satisfy the above mentioned condition, the friction force acting between the block surfaces must act to the right, which is acting same direction as the applied horizontal force on the lower block. This friction force will resist the upper block sliding backward and maintain the same acceleration for both of the blocks as well. Again, this friction force might be termed driving force in a sense to keep the upper block in its position while the actual driving force to create acceleration is done by the horizontal force applied on the lower block.

The following free body diagram for the upper block will show the direction of the forces and calculation of the system acceleration. Also, another free body diagram is shown later for the combined blocks where we apply the Newton’s second law to determine the required horizontal force on the lower block to keep preventing the  sliding of the upper block.

Friction force calculation















From the above calculation, we see that for the upper block, the direction of acceleration and maximum friction force is the same. So, for the upper block, we may imply that the friction works as a driving force. The magnitude of the friction force is 1.7 N. Next, we are going to calculate the acceleration based on this frictional force and consider the free body diagram of the two blocks together as well.

Free body diagram of the two blocks
























Here, we see from the combined free body diagram of the problem that the friction force acts opposite to the applied horizontal force. The applied horizontal force to the lower block is the driving force and friction is the resistive force in this case. Now, we will calculate the net maximum horizontal force that can be applied to the lower block without the upper block slipping using the Newton’s second law of motion again.

Net driving force


By this example, we see that the friction is a resistive force when we consider the overall system (two blocks together); however, it is a driving force for the upper block as per the fundamental laws of motion. The compliance or stiffness (inverse of compliance) is a tendency to resist tension or compression in a system, which is a conservative force (restores energy). But friction is a non-conservative force (dissipates energy), and due to its obvious presence in physical systems, we have some losses from the system in terms of heat, wear and tear, and so on. This may serve as an intuitive example, in regards to realizing the friction force in a conspicuous manner
.



#FreeBodyDiagram #Friction #CoulombFriction #ResistiveForce #NewtonsLaw #Blog #Blogger

How to Convert Graphics to Solid Body in CATIA

This tutorial demonstrates how to convert a Stereolithography Mesh (.stl) graphics object to solid editable body in CATIA V5. This is useful when we require to modify an STL object file in any CAD processing tool, such as, AutoCAD, Autodesk Inventor, SolidWorks, CATIA, and so forth. It is also important when we plan to do a Finite Element (FE) analysis of an object that is available only in the STL format. For the demonstration purpose, this tutorial uses an STL image of an anonymous patient having Scoliosis, which is available online. You can download the file from this site.

Processing an Image in CATIA

At first, open CATIA V5, then go to 'Start' and select ‘Shape’, then choose ‘Digitized Shape Editor’. See the screenshot below for the process.

Opening CATIA V5 Digitized Shape Editor




















After that, in the following window, just click ‘ok’ to create a new part file.

Creating Part in CATIA V5 Digitized Shape Editor




















We will now import the (.stl) by clicking the ‘Import’ option as highlighted below.

Importing a STL file in CATIA V5


















Next, click ‘Apply’ and then select ‘ok’ to import the (.stl) file, which looks like below:

Importing a STL file in CATIA V5




















Since, we have imported an STL file from third-party source, we need to check the quality of the image, and clean it up. There is an option ‘Mesh Cleaner’, click it, and the following window will appear.

Mesh cleaning in CATIA V5


















A pop-up small window will appear. Select the object, and then click ‘Analyze’. Click on the ‘Isolated Triangles’ option, and change the color, so that you can visualize it clearly. In this case, we see it is yellow.

The process of removing corrupt meshes from the STL file in CATIA V5



















As you notice that we are in the ‘Deletion’ mode of the ‘Mesh Cleaner’ window. So, we need to delete those unwanted or corrupted triangles to make it a valid solid body. Otherwise, the conversion either might fail or proceed, but in that case with lots of corrupt meshes that will hamper your analysis.

As we see, there are 60999 corrupt triangles, which need to be discarded. This may also remove some parts from the image, but if that part is not significant, then it may be alright to proceed depending on our requirement. We just need to make sure that we have our concerned region unaffected for the analysis. Next, click on the ‘Long Edges’ and continue the same process for removing the corrupt regions. The last option is the ‘Small Angles’, which we need to select and click ‘Apply’. 

The process of removing corrupt meshes from the STL file in CATIA V5



















After the process is done, the following window will appear. We see that there are three ‘Non-manifold Vertices’ that need to be removed as well in a similar way.
We need to continue the mesh cleaning process at least twice to make sure that we have removed all the corrupt segments. After doing so, we will have the following image without the unwanted meshes.

The process of removing corrupt meshes from the STL file in CATIA V5



















Next, we need to click on the ‘Structure’ tab and subsequently, click on the ‘Orientation’, and ‘Split in Connected Zones’ options to check the followings. If the color for the ‘Orientation’ stays same, as in this case, ‘Yellow’, then we are good to go. For the ‘Split in Connected Zones’, there should be nothing specified in the window as highlighted by the following two screenshots below.

The process of removing corrupt meshes from the STL file in CATIA V5











The process of removing corrupt meshes from the STL file in CATIA V5


















After the above process, we need to click Start > Shape > Quick Surface Reconstruction. The steps are depicted below.

Surface reconstruction process in CATIA V5


















Next, click Insert > Surface Creation > Automatic Surface. Just follow the following instructions shown by the image.

Surface reconstruction process in CATIA V5


















The following window will appear. Try to keep the parameters same as shown in the tiny popped-up window. Then, hit ‘ok’.

Surface reconstruction process in CATIA V5 and selection of key parameters


















We are almost done in creating the Solid Body. After the automatic surface creation, we need to close the surface, which is depicted below. Click Start > Mechanical Engineering > Part

Closing the surface after reconstruction in CATIA V5


















Then follow this sequence: Insert > Surface-Based Features > Close Surface.

Closing the surface after reconstruction in CATIA V5


















We are all done. Finally, we need to save it as a 'CATIA part' file and also export it to (.igs) format in case if somebody wants to perform FE analysis.

The final reconstructed 3D solid body ready for further modification


















The following image shows the closed view of the processed solid 3D Scoliosis skeleton that may be used for any analysis that needs geometry manipulation. 

Reconstructed 3D Solid Body in CATIA showing the Scoliosis Skeleton

























#Catia #ReverseEngineering #3Drendering #3Dmodel #ImageProcessing #Blog #Blogger