## 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 ...

### My First Code in Python: Adding all Prime Numbers

As Python programming is highly hyped now-a-days and a frequent buzzword in machine learning and AI communities, I have decided to get myself familiar in this area. As I learn and decipher the Python coding day-by-day, I will be more than happy to share my coding in this blog. Here is my first program in Python - to develop a logic that adds all prime numbers between 0 and a given number.

We know that a prime number is an integer, which is greater than one and which is only divisible by one and itself. The following shows an algorithm that adds all prime numbers between 0 and a given number.

Development of an algorithm to add all prime numbers between 0 to n

I. First, we define the lower and upper number to initialize the program. For example, we set the lower number 0 and upper number 10; and we are interested to find the summation of prime numbers in this range.
II. Prime number is greater than one, so our logic begins that it must be greater than one. Therefore, we begin with number 2 and list all the numbers in our range.
III. Since, prime numbers are divisible only by itself and one; we create a loop, which confirms the prime numbers, and display them. We implement this by checking if the remainder of the number is zero or not. If the remainder is zero, then it is not a prime number.
IV. If the remainder of the number is not zero, then it is a prime number.
V. Display the prime numbers in the defined range and group the numbers in a list or array.
VI. Finally, we add all the prime numbers in the list.

The following Python code is developed based on the above algorithm, which displays all the prime numbers in a given range and add those numbers:

lower = 0

upper = 10     #Defining the range

sum1 = 0       #Setting Summation of prime numbers to zero

print("Prime numbers between", lower, "and", upper, "are:")

for num in range(lower, upper + 1):

if num > 1:                 #Prime number is greater than 1

for i in range(2, num):

if (num % i) == 0:  #Calculates & checks remainder of division

break
else:

print(num)  # Displays prime numbers

sum1 += num

print(sum1)

Program Outputs:

Prime numbers between 0 and 10 are:
2
3
5
7
17

#Blog #Blogger #Python #PrimeNumber #Algorithm

## A NOVEL LEMON SHAPED GUIDE TO MINIMIZE EXCESSIVE RUBBING IN ROTATING MACHINES

In industries, rotating machines are widely used, because rotation offers a great way to transfer power from one point to another and convert motion to different planes by gears, belts, shaft etc. A rotating machine typically includes a rotor, bearings and a support structure. There are critical relations among these components where each component of a system influences the overall dynamic behavior of a machine. For example, rotor-to-guide rub degrades a mechanical system over the years and may even cause fatal accidents earlier. It is, therefore, paramount in industries, to run rotating machines, operating at high speeds smoothly and reliably. The primary reasons of rubbing between a rotor and a guide are due to a manufacturing error, excessive imbalance, misalignment, bearing wear, smaller radial clearance between the rotating shaft and casing, bad assembly, etc. Rub occurs in rotor casing, seals, unlubricated journal bearings, loose rotor guide attached to restrict a large deflection. The problem is prevalent in the industry and demonstrated in several literatures. To deal with this problem, the industry has already been using circular shaped guide to minimize excessive vibration between a rotor and a stator. Although, the circular shaped guide may reduce the vibration, but the rub, between rotor and guide, may still be present, which may lead to the permanent damage of a mechanical system. The lemon shaped guide is not only effective in minimizing rubbing between rotor and stator, but also it suppresses the excessive vibration similar to the circular shaped guide.

The following video shows an experiment on how to minimize rubbing between a rotor and a guide that typically happens in a high speed rotating machine with a newly developed lemon shaped bearing or guide. We see here as the speed goes high, the system enters into its resonance frequency where it vibrates excessively. The lemon/elliptical shaped guide helps prevent the excessive rubbing while the rotor-bearing assembly is in the natural frequency zone. It has been found from our research that the lemon shaped guide minimizes rubbing better than the circular shaped guide where there the rotational speed is very high (https://doi.org/10.1115/1.4043817).

The next video shows an experiment on how to minimize rubbing between a rotor and a guide that typically happens in a high speed rotating machine with a circular bearing or guide. This is a traditional approach, which has been in operation in industries for long. We see in the video, as the speed goes high, the system enters into its resonance frequency where it vibrates excessively. The circular guide helps prevent the excessive vibration while the rotor-bearing assembly is in the natural frequency zone. However, if we notice carefully, the rubbing is still present between the rotor and guide, which deteriorates the system gradually.

A US provisional utility patent (US Patent App. 62/956,833) has already been filed for this design. I am looking for industrial partners or investors if they are interested in investing this product.

### Learning Mathematica, Lesson 1: Plotting a Function

This is the very first lesson or tutorial on Mathematica. As I am in the process of learning this tool, I will gradually post more articles on this, ranging from basic to advanced level problems. So, the first question is, what is Mathematica? It is simply a tool for computing, but it has an advantage that the symbolic expression is much user-friendly and more interactive than MATLAB.

Although, MATLAB is a much bigger platform than Mathematica, because MATLAB has numerous toolboxes and libraries that are designed for specific fields. Nevertheless, Mathematica, a product from Wolfram Research, is great for symbolic and interactive computing with a very neat interface. You may try it for free here just to see its environment. Let's start, how Mathematica looks like. After you install it (which isn't complex, it's pretty straightforward, if you just follow the instructions), click on your desktop shortcut and it will look like the following:

Then, you need to click on the "Documentations" to proceed which will bring the following:

Now, if you like to start writing you very first code on Mathematica, then click File, and select Notebook.

Now, write you first code here, and execute it. Let's say, we like to plot a function which looks as follows,

To execute the program above, you need to click on Evaluation and then, select Evaluate Notebook. The variable X varies from 0 to 5.

#Mathematica #Matlab #NoteBook #MatlabvsMathematica #Blog #Blogger

### A SIMULINK Model to Solve a Simple Shaft-Disk Dynamics Problem

The following figure 1 represents pretty simple model where two circular disks of inertia J1 and J2 are mentioned. Torque (T) is applied to the disk 1. The shaft has its own stiffness which is K.

 Fig.1: Showing a very simple model where two disks are connected by a shaft and torque is applied to one of them.

At first, let's find the state variables for this problem and then write the state equations.

State Variables and State Equations:

Next, we assume the following key parameters,

Initial Conditions:

Parameter Values:

J1 = 100, J2 = 100, K = 100, and T = 10000. (All values are considered unitless for simplicity)

The SIMULINK model is formed by implementing the state equations. And, the above parameter values are considered. The following simulation results are for the acceleration, velocity and position of the disks which are essentially the outputs from the SIMULINK block diagram.

Fig.2: SIMULINK model of the shaft-disk system.

 Fig.3: Showings the results of angular acceleration, velocity and displacement respectively of disk 1.

 Fig.4: Showings the results of angular acceleration, velocity and displacement respectively of disk 2.#Simulink #Matlab #ShaftDisk #BlockDiagram #Blog #Blogger

### Theory of Energy Conversion in Wind Turbine

In wind turbine, the wind energy is converted to first mechanical energy, and then this energy is converted to electrical energy. Damping is an essential part for a generator. However, it is not the key factor for energy conversion. If there were no damping or loss, we would have 100% efficient conversion. This is not possible in real life, as we would have certain losses during the energy conversion process. These losses are represented by non-conservative forces, such as friction, viscous damping etc. which are the essential parts to be considered in the energy conversion process. I want to show the fundamentals behind energy conversion in DC motor.

DC motor converts electrical energy (input voltage) to mechanical energy (shaft rotation). This electromechanical conversion involves Faraday’s law of induction and Ampere’s law for force generated on the conductor moving in a magnetic field. In ideal situation, the torque (T) developed on the motor shaft is proportional to the input current (I) and the induced electromotive force (EMF) (V) or back EMF is proportional to the speed (W) of the motor. This can be expressed as [1];

T = K1 I ..........................................................(1)

V = K2 W .......................................................(2)

Where, K1 and K2 are the proportionality constant.
The electrical power (Pe) input to the motor is the product of the induced EMF and current.

Pe = VI = K2 W T / K1  ..................................(3)

And, the mechanical power output (Pm) is the product of the speed of the motor and torque.

Pm = T W .......................................................(4)

Now, by comparing equation (3) and (4), the following relation is obtained.

Pe = (K2 /K1) Pm  ...........................................(5)

From Ohm’s law, it is known that,

E - V = I R  ..................................................(6)

Where, E is the input voltage to the motor, and R is the resistance of the motor armature.
Moreover, we also know that torque produced at the motor shaft is equal to the product of the inertia of the load (J) and rate of change of angular velocity or angular acceleration.

T = J (dW/dt)  .............................................(7)

Now, from equations (1), (6) and (7), it is found that

J (dW/dt) = K1 I = K1 / R (E - V)  ...........................................(8)

Using equation (2) further, the following expression can be established.

dW/dt = (K1 K2 / J R) W + (K1 / J R) E  ..................................(9)

The above equation refers to the first order linear differential equation model where ‘W’ represents the state of the system and ‘E’ is the external control input. This first order equation is good enough to predict the output speed of the motor. However, in terms of measuring the position’ it is necessary to add the following equation.

W = dÎ¸ / dt  ...........................................................................(10)

Where Î¸ is the output position of the DC motor and refers to another state of the system. Therefore, the model has one control input and two state variables (position and velocity).

By the above mathematical analysis, I want to specify, that the electrical energy is converted to mechanical energy by a gyrator which has a constant ratio K. Here, resistance of the armature is the energy loss during the conversion of electrical to mechanical energy which is also mechanical equivalence of a damper. A damper not only signifies the energy dissipation/loss from a system, but also helps to make a system stable by removing oscillations.

Reference
[1] Control system design : an introduction to state-space methods / Bernard Friedland.—Dover ed.

### Some Remarks on Forces at Contacts in Light of Bond Graph

So, you have already searched something related to "Contact Forces", and found this page. I welcome you to explore my perceptions behind the fundamental concept of contact forces which might satiate your query.

Figure 1 shows a single stage gear train. Torque T is applied on gear 1 which is further driving gear 2. The driver gear is the gear 1 and the driven gear is the gear 2. Here, I will try to explain the mechanics behind this gear mechanism. Figure 2 represents the torques and forces are acting on both of the gears. Gear 1 applies a force F1 which is the actual driving force to rotate the gear 2. This force F1 multiplied with the radius of the gear 2 generates eventually the driving torque T1. According to Newton’s third law, the force F1 applied by gear 1 on gear 2 will be equal and opposite to the force F2 which is the force applied by gear 2 on gear 1. The force F2 similarly generates a torque T2 on gear 1 by multiplication with gear 1 radius, but this torque is the resistive torque for gear 1 as the direction is opposite to the applied torque T. For two mating gears, their directions of angular displacements are opposite to one another, and if I am not wrong, this is physical in real life. For example, in figure 2, direction of angular displacement of gear 1 is clockwise whereas the direction of angular displacement of gear 2 is anti-clockwise.

 Figure 1: A single stage gear train.

Now, the question arises what is the type of the force F acting between the mating gears? Forces may be divided primarily as conservative and non-conservative forces. If it is conservative force, then the input and output energy must be balanced and the efficiency of the process is 100% which seems ideal. Now, if it is non-conservative force, then there would be energy dissipation from the system and work done by the non-conservative force on gear 2 is negative. Friction force is one of the common non-conservative forces that we experience in our daily life. My intuition in this regard is that this friction force cannot be the driving force for gear 2. The term “Driving Force”, by which, I mean the force helps to rotate gear 2. I will explain my point of view shortly, but before that let us have a look in figure 3 where the presence of the friction is considered. The nature of friction force is to oppose the motion of a moving body and in figure 3 this force acts opposite to the direction of rotation for both of the gears. In figure 3, there are also conservative forces (F1, F2) acting at the contact point p. What if there is only friction force acting at the contact? Then both of the gears would rotate in the same direction viz. clockwise in figure 3. But this is not physical in gear transmission. There have to be the presence of conservative forces with the friction as well.

 Figure 2: Free body diagram of the gear train system.

Now, I would like to explain the role of friction in both sliding and rolling motion. Figure 4 shows a sliding block on both horizontal and inclined planes. In figure 4, F is the applied force on the block which has mass M. While sliding on both the planes a frictional force f is acting between the block and the surface tries to resist the sliding motion of the block. And, the direction of friction is opposite to the direction of translational velocity of the block and it is true for every sliding motion.

 Figure 3: Friction force acting at the contact point between gears.

The picture is different in case of rolling motion. Following figure 5, represents a ball rolling on horizontal plane as well as inclined plane. In this case, the friction force acts in the direction of the C.G. translational velocity of the ball. There is no sliding, and that is why, both the directions are same, however, this friction force tries to resist the rotation of the ball. And, eventually the friction force creates a torque which is acting opposite to the applied torque. Here, friction force helps to keep the rolling motion of the body and it is not the driving force. If it were the driving force, then the conservation of energy law would have been violated. Friction might be called driving force in a sense that it helps maintaining rolling motion of the wheel and if there were no friction then the wheel would have been sliding. We see the sliding occurs if a car tries to run over the black ice.

Figure 4: Sliding blocks on horizontal (a) and inclined (b) planes.

In previous figure 2, the force F is not the friction force, and the way, I considered this force is proportional to the relative tangential displacements of the mating gears. I added a constraint for this force and why I did this, will be enlightened in the next passages.

Figure 6 shows the bond graph model of the previous single stage gear train pictured in both figure 1 and 2. There is a special reason to show the bond graph model here although it could simply be done by applying Newton's law. In figure 6, the inertia of the gear 2 is derivative causal, and it is no more acting as a restoring element. It does not create a state of the system. Apparently, the model seems okay, but there is an inherent flaw in the model which does not make the model physical. The natural causality of inertial element is to take effort from the source to generate flow and the relationship is maintained by integration. But, if it is forced to acquire opposite causality, the relationship is governed by differentiation. To overcome this scenario, something has to be present to avoid this derivative causality. We say that the force F1 in figure 2 is the driving force for gear 2 but, how the force is generated? The answer to this question is due the contact between the mating gears.

 Figure 5: Rolling ball on horizontal (a) and inclined (b) planes.

So, gear 1 pushes gear 2 to rotate and according to Newton, gear 2 will try to resist and gives back reaction force. For this to be happened, there should have a medium to transfer the effort from gear 1 to gear 2. And, this medium may be modelled by a compliant element. It should be noted also that this compliant element does not represent contact deformation as it is not considered here. Although, in reality, there is eventually be microscopic deformation between mating gears, but for the case considered here this may be safely ignored. Figure 7 shows the compliant element C which integrates the tangential velocities of the mating gears and the force generated at the contact is proportional to the relative tangential displacements of the mating gears. The tangential velocity at the contact point is obtained by multiplying angular velocity with the radius of the gear and this is performed in the bond graph by TF elements.

 Figure 6: Bond graph model of the gear train in figure 2 (Derivative Causality).

Newton stated in his third law of motion that every action has an equal and opposite reaction. This is universally true and there is no doubt on this law. So, for an action on a body, according to this law there would be same and opposite reaction which means, Fa = -Fr

 Figure 7: Bond graph model of the gear train in figure 2 (Integral Causality).

Where, Fa is the action force on a body and Fr is the reaction force by the body. But, the reaction force is created because of the contact or impact, and if we ignore the fact of force transmission between the contacting bodies we would have rigid mass coupling which again imposes derivative causality.

### Modelling a Multi-Degree of Freedom System with SIMULINK and Bond Graph

Differential equations of the system:

 System under consideration

Notations:
m₁ = mass of the cart 1
m₂=mass of the cart 2
m₃=mass of the cart 3
m₄=mass of the cart 4

b₁=friction coefficient of cart 1
b₂=friction coefficient of cart 2
b₃=friction coefficient of cart 3
b₄=friction coefficient of cart 4

x₁=displacement of cart 1
x₂=displacement of cart 2
x₃=displacement of cart 3
x₄=displacement of cart 4

For Cart 1,

For Cart 2,

For Cart 3,

For Cart 4,

To solve the above differential equations two approaches are considered. At first the equations are simulated in SIMULINK and then validated by Bond Graph method [1].

Figure 1 represents the model of the mass-springs system. Four subsystems are used to show the differential equations of each mass. Figures 2, 3, 4 and 5 highlight the dynamic model for the cart 1, 2, 3 and 4 respectively.

Figure 1: Showing the dynamic model of cart-springs system in SIMULINK.

Figure 2: Showing the dynamic model of cart 1.

Figure 3: Showing the dynamic model of cart 2.

Figure 4: Showing the dynamic model of cart 3.

Figure 5: Showing the dynamic model of cart 4.

Now, the parameters given in the question are used to get the simulation results. The simulated results show the position of the each cart with respect to time. Following figures 6, 7, 8, and 9 depict the position of the cart 1, 2, 3, and 4 respectively.

Figure 6: Showing the displacement of cart 1.

Figure 7: Showing the displacement of cart 2.

Figure 8: Showing the displacement of cart 3.

Figure 9: Showing the displacement of cart 4.

As it is mentioned earlier that to validate the model another method is also taken into consideration. The system is again simulated by bond graph technique. Bond graph depicts the picture of energy flow throughout the system and it considers the states which store energy which is eventually integrally causal element in the bond graph. Inertial (-I) and compliance (-C) elements are the energy storage elements. Bond graphs “bookkeep” energy and the instantaneous energy of the system is indicated by the energy variables (p’s on –I and q’s on -C). The dissipative elements (-R) are not considered as state variable in bond graph formulation because the energy storage elements are independent if these can accept integral causality [1].
Figure 10 shows the model of the system which is developed by CAMPG [2]. The distinguishing feature of this software is the ability to generate differential equations once the model is built. Figure 11 and 12 depict the displacement of the masses which confirm the simulation results obtained by the SIMULINK.

Figure 10: Showing the model of the system in CAMPG software.

Figure 11: Showing the position of the cart 1 and 2.

Figure 12: Showing the position of the cart 3 and 4.

Equilibrium position of the carts:
First way:
In this case, according to the question the simulation is run for longer time and the friction coefficient for each mass is changed to 100.

Figure 13: Showing the equilibrium position of the cart 1.

Figure 14: Showing the equilibrium position of the cart 1 (magnified).

From figure 14, the equilibrium position of the cart 1 is approximately 1.035 unit.

Figure 15: Showing the equilibrium position of the cart 2.

Figure 16: Showing the equilibrium position of the cart 2 (magnified).

From figure 16, it is observed that the cart 2 settles when its position is around 1.435 unit.

Figure 17: Showing the equilibrium position of the cart 3.

Figure 18: Showing the equilibrium position of the cart 3 (magnified).

From figure 18, it is found that the approximate equilibrium position of cart 3 is 2.29 unit.

Figure 19: Showing the equilibrium position of the cart 4.

Figure 20: Showing the equilibrium position of the cart 4 (magnified).

From figure 19, the approximate equilibrium position is obtained as 1.49 unit.

The following figures 21 and 22 show the equilibrium position of cart 1,2,3, and 4 respectively which further ensure the conformity of the previous simulated results.

Figure 21: Showing the equilibrium position of the cart 1 and 2.

Figure 22: Showing the equilibrium position of the cart 3 and 4.

Second way:

The concept of steady state is implemented here to find out the equilibrium position of each cart. To do so, the derivative terms are considered zero. The four algebraic equations are obtained:

(1)

(2)

(3)

(4)

Substituting x1 from equation (1),
Substituting the value of x1 and x2 from equation (1) and (2) respectively,
Finally, substituting the value of x2 and x3 from equation (2) and (3) in equation (4);
x4=1.6 unit
Substituting the value of x4 in equation 3;
x3=2.34 unit
Substituting the values of x3 and x4 in equation 2;
x2=1.54 unit
Substituting the value of x2 and x3 inequation 1;
x1=1.05 unit

References:
[1] D. C. Karnopp, D. L. Margolis and R. C. Rosenberg, ”System Dynamics: Modeling and Simulation of Mechatronic Systems”, fourth edition, John Wiley and Sons, New Jersey, 2006.
[2] http://www.bondgraph.com/