Author Archives: FERNDORN

Natural Convection Simulation- I: Mathematical Model

Working on my undergraduate degree in Mechanical Engineering, my favorite class was heat transfer. For a class project, I built a simple simulation that showed convection for a randomly generated temperature field. Unfortunately, I didn’t have enough programming skills to build a quality program. I want to revisit that class project with my improved science and computer skills. Along the way I will teach the science and programming behind building the model. The first step will be to research the fundamental equations for this system.

Problem Definition

In this project, we will model a compressible fluid. Natural convection forces will affect the fluid. The simulation will model the transient behavior of a starting temperature or input heat. The simulation will be 2-Dimensional to display the results easier. Lastly, the model will use constant Cartesian cell structure to simplify the problem.

Governing Equations

The Navier-Stokes momentum equations for 2D Cartesian flow will be used to determine the fluid velocities

\rho \left( \frac { du }{ dt } +u\frac { du }{ dx } +v\frac { du }{ dy } \right) =-\frac { dp }{ dx } +\mu \left( \frac { { d }^{ 2 }u }{ { dx }^{ 2 } } +\frac { { d }^{ 2 }u }{ { dy }^{ 2 } } \right) +\rho { g }_{ x } \\ \rho \left( \frac { dv }{ dt } +u\frac { dv }{ dx } +v\frac { dv }{ dy } \right) =-\frac { dp }{ dy } +\mu \left( \frac { { d }^{ 2 }v }{ { dx }^{ 2 } } +\frac { { d }^{ 2 }v }{ { dy }^{ 2 } } \right) +\rho { g }_{ y }

Conservation of mass will be used to determine fluid densities

\frac { d\rho }{ dt } +\rho \left( \frac { du }{ dx } +\frac { dv }{ dy } \right) =0

A conservation of energy equation was developed by including conduction, convection and external heat to the first law of thermodynamics

\rho { C }_{ v }\left( \frac { dT }{ dt } +u\frac { dT }{ dx } +v\frac { dT }{ dy } \right) =k\left( \frac { { d }^{ 2 }T }{ { dx }^{ 2 } } +\frac { { d }^{ 2 }T }{ { dy }^{ 2 } } \right) +S

The ideal gas law will be used to determine pressure

p=\rho { R }_{ specific }T

Finite Difference Approximation

A finite difference approximation will be used to solve the fluid state at future time intervals. A small time step and cell size will be desired to maximize accuracy. Central difference approximations will be used to reduce any directional biases.

When using a finite difference, we can encounter a problem.  The grid below uses the same area for pressure and velocity.

Since we are using a central difference approximation, the velocities of center square is based on the pressure difference between it’s neighbors.  We can see how the equation does not compare the squares current pressure between it’s neighbor squares.

{ u }_{ i,j }^{ t+1 }={ u }_{ i,j }^{ t }+\Delta t\left( -\frac { { p }_{ i+1,j }^{ t }-{ p }_{ i-1,j }^{ t } }{ \rho 2\Delta x } +\frac { \mu }{ \rho } \left( \frac { { u }_{ i+1,j }^{ t }+{ u }_{ i-1,j }^{ t }-2u_{ i,j }^{ t } }{ { \Delta x }^{ 2 } } +\frac { { u }_{ i,j+1 }^{ t }+{ u }_{ i,j-1 }^{ t }-2u_{ i,j }^{ t } }{ { \Delta y }^{ 2 } } \right) +{ g }_{ x }-{ u }_{ i,j }^{ t }\frac { { u }_{ i+1,j }^{ t }-{ u }_{ i-1,j }^{ t } }{ 2\Delta x } -{ v }_{ i,j }^{ t }\frac { { u }_{ i,j+1 }^{ t }-{ u }_{ i,j-1 }^{ t } }{ 2\Delta y } \right)

If there is not a pressure differential between the 2 opposite neighbor cells then we do not get flow. As a result, a checkerboard pattern will emerge. The image below shows a possible solution.

This solution solves the governing equations but creates a system that is unrealistic. In a real system, we would see flow from the 4-pressure elements into the 2-pressure elements.

A better solution uses different, overlapping areas for the pressures and velocities. In the improved solution, the pressures exist in each area of the grid and the velocities represent the flows between the pressure cells. This solution is represented below.

Solved Equations

With our improved solution, we can finally solve the governing equations using a finite difference approximation.

Navier-Stokes equations for velocity

{ u }_{ i,j }^{ t+1 }={ u }_{ i,j }^{ t }+\Delta t\left( -\frac { { p }_{ i,j }^{ t }-{ p }_{ i-1,j }^{ t } }{ \rho \Delta x } +\frac { \mu }{ \rho } \left( \frac { { u }_{ i+1,j }^{ t }+{ u }_{ i-1,j }^{ t }-2u_{ i,j }^{ t } }{ { \Delta x }^{ 2 } } +\frac { { u }_{ i,j+1 }^{ t }+{ u }_{ i,j-1 }^{ t }-2u_{ i,j }^{ t } }{ { \Delta y }^{ 2 } } \right) +{ g }_{ x }-{ u }_{ i,j }^{ t }\frac { { u }_{ i+1,j }^{ t }-{ u }_{ i-1,j }^{ t } }{ 2\Delta x } -\left( { v }_{ i,j }^{ t }+{ v }_{ i-1,j }^{ t } \right) \frac { \left( { u }_{ i,j }^{ t }-{ u }_{ i,j-1 }^{ t } \right) }{ 4\Delta y } -\left( { v }_{ i,j+1 }^{ t }+{ v }_{ i-1,j+1 }^{ t } \right) \frac { \left( { u }_{ i,j+1 }^{ t }-{ u }_{ i,j }^{ t } \right) }{ 4\Delta y } \right) \\ { v }_{ i,j }^{ t+1 }=v_{ i,j }^{ t }+\Delta t\left( -\frac { { p }_{ i,j }^{ t }-{ p }_{ i,j-1 }^{ t } }{ \rho \Delta y } +\frac { \mu }{ \rho } \left( \frac { { v }_{ i+1,j }^{ t }+{ v }_{ i-1,j }^{ t }-2v_{ i,j }^{ t } }{ { \Delta x }^{ 2 } } +\frac { { v }_{ i,j+1 }^{ t }+{ v }_{ i,j-1 }^{ t }-2v_{ i,j }^{ t } }{ { \Delta y }^{ 2 } } \right) +{ g }_{ y }-{ v }_{ i,j }^{ t }\frac { { v }_{ i,j+1 }^{ t }-{ v }_{ i,j-1 }^{ t } }{ 2\Delta y } -\left( { u }_{ i,j }^{ t }+{ u }_{ i,j-1 }^{ t } \right) \frac { \left( { v }_{ i,j }^{ t }-{ v }_{ i-1,j }^{ t } \right) }{ 4\Delta x } -\left( { u }_{ i+1,j }^{ t }+{ u }_{ i+1,j-1 }^{ t } \right) \frac { \left( { v }_{ i+1,j }^{ t }-{ v }_{ i,j }^{ t } \right) }{ 4\Delta x } \right)

Conservation of mass for density

\rho _{ i,j }^{ t+1 }=\rho _{ i,j }^{ t }+\frac { \Delta t }{ 2 } \left( \frac { u_{ i,j }^{ t } }{ \Delta x } \left( \rho _{ i,j }^{ t }+\rho _{ i-1,j }^{ t } \right) +\frac { u_{ i+1,j }^{ t } }{ \Delta x } \left( \rho _{ i,j }^{ t }+\rho _{ i,j-1 }^{ t } \right) +\frac { v_{ i,j }^{ t } }{ \Delta y } \left( \rho _{ i,j }^{ t }+\rho _{ i+1,j }^{ t } \right) -\frac { v_{ i,j+1 }^{ t } }{ \Delta y } \left( \rho _{ i,j }^{ t }+\rho _{ i,j+1 }^{ t } \right) \right)

Conservation of energy for temperature

T_{ i,j }^{ t+1 }=\frac { \Delta t }{ \rho _{ i,j }^{ t } } \left( \frac { u_{ i,j }^{ t } }{ 2\Delta x } \left( T_{ i-1,j }^{ t }-T_{ i,j }^{ t } \right) \left( \rho _{ i-1,j }^{ t }+\rho _{ i,j }^{ t } \right) +\frac { u_{ i+1,j }^{ t } }{ 2\Delta x } \left( T_{ i+1,j }^{ t }-T_{ i,j }^{ t } \right) \left( \rho _{ i+1,j }^{ t }+\rho _{ i,j }^{ t } \right) +\frac { v_{ i,j }^{ t } }{ 2\Delta y } \left( T_{ i,j-1 }^{ t }-T_{ i,j }^{ t } \right) \left( \rho _{ i,j-1 }^{ t }+\rho _{ i,j }^{ t } \right) +\frac { v_{ i,j+1 }^{ t } }{ 2\Delta y } \left( T_{ i,j+1 }^{ t }-T_{ i,j }^{ t } \right) \left( \rho _{ i,j+1 }^{ t }+\rho _{ i,j }^{ t } \right) +\frac { k }{ { C }_{ v } } \left( \frac { T_{ i-1,j }^{ t }+T_{ i+1,j }^{ t }-2T_{ i,j }^{ t } }{ { \Delta x }^{ 2 } } +\frac { T_{ i,j-1 }^{ t }+T_{ i,j+1 }^{ t }-2T_{ i,j }^{ t } }{ { \Delta y }^{ 2 } } \right) +{ S }_{ i,j } \right)

Ideal gas law for pressure

p_{ i,j }^{ t+1 }=\rho _{ i,j }^{ t+1 }{ R }_{ specific }T_{ i,j }^{ t+1 }

These equations can directly be used in our simulation. Beyond these equations, we will have to consider the boundary conditions. The boundaries can be modeled in many different ways so we will review them later. With all that in mind, we can begin the design and development of our simulation.

Symbol Definitions

u,v=Fluid\quad Velocity\quad x,y\quad \left( \frac { m }{ s } \right) \\ \rho =Density\quad \left( \frac { kg }{ { m }^{ 3 } } \right) \\ p=Pressure\quad \left( Pa \right) \\ \mu =Dynamic\quad Viscosity\quad \left( \frac { kg }{ m\cdot s } \right) \\ T=Temperature\quad \left( K \right) \\ g=Gravitational\quad Acceleration\quad \left( \frac { m }{ { s }^{ 2 } } \right) \\ { R }_{ specific }=Ideal\quad Gas\quad Constant\quad \left( \frac { J }{ kg\cdot K } \right) \\ { C }_{ v }=Heat\quad Capacity\quad at\quad Constant\quad Volume\quad \left( \frac { J }{ kg\cdot K } \right) \\ S=External\quad Heat\quad \left( \frac { J }{ { m }^{ 3 }s } \right)

Controlling 4-digit 7-segment LED Displays

In this project, we will discuss the functionality of a common 4-digit 7-segment LED display. First we will connect the display to constant voltage to test the displays multiplexing. Then we will connect the display to an Arduino

The LED used in this project is the “3461BS” 4-Digit 7-Segment, Common Anode display. This can be seen under similar names such as “HS-3461BX” or “ULF-3461BS” from other manufacturers. This display has 12 pins used for control. Similar displays can be found with 14 or 16 pins for controlling additional dots such as time and temperature. The pins for this display are shown below.

   

To reduce the number of needed control pins, 7 segment displays are typically multiplexed. Completing the circuit between a Digit pin and a segment pin will cause the corresponding led to light up. For example, if we connect the D1 pin to +3V and the g pin to ground, we will see the D1-g segment light up. But if we connect both the D1 and D2 pins to +3V and the g pin to ground, we will see D1-g and D2-g light up.

Unfortunately, this means we can only independently control one digit at a time. To surpass this limitation, most computers quickly cycle between the digits so that persistence of vision makes them all appear on.

Controlling the display with an Arduino

When connecting this to a Arduino or controller device, we are concerned about overloading the IO used for the Digit values. This is because load of 8 segment circuits combine into a single Digit circuit. The large current demands of the Digit-IO could potentially damage an Arduino. To protect the Arduino, we connect the Digit-pins through a transistor. The transistor’s collector provides the majority of the demand current.

In this example, we set the 2nd and 3rd digit though transistors.

Once the transistors have been tested, you may then connect all of the data lines to an Arduino.

With the data lines connected, you can test the display by blinking every-other bit. This should reveal any missed wires.

Once wired, you can make a simple program to output values to the display

 

In this project, we set the voltage across the LED screen as 5 volts. I want to point out that this display and many similar displays have a max VF rating of 2.3V. You will want to stay within that voltage if you want to preserve the life of your display.

Using Other 7 Segment Displays.

The display we are using is a common Anode display, this makes the display require positive voltage on the Digit-pins and ground voltage on the segment pins to light the LED. If the display was a common Cathode design, then the voltages would need to be reversed. A common Cathode display requires positive voltages on the segment pins and ground voltage on the digit pins to light up. When using common Cathode 7-segment displays, you will still need to connect the Digit pins to transistors to handle the large currents. 

The display’s name can be used to determine the specifications. In the device “3461BS”, “34” represents .34 inch height; “61” would represent the design type such as 4-digit; “B” represents common Anode (“A” would represent common Cathode); “S” represents the dot type.

Although I could not find a datasheet for “3461BS”, I found datasheets for similar displays here – https://e-radionica.com/productdata/LD3361BS.pdf

101 Cat facts

Did you know that a cat can jump up to six times its length?
Did you know that every year, four million cats are eaten by one person in Asia?
Did you know that some cats can use the toilet?

Did you know that cats grow ear hairs called ear furnishings?
Did you know that cats only use 10% of their brain because they do not want to be labeled as nerds?
Did you know that cats have the most softest belly hairs?
Did you know that cats use their whiskers to detect if they can fit though an opening?
Did you know that cat pregnancies last for 9 weeks?
Did you know that all cats have 9 lives?

Did you know that the cat brain is 90% the size of a humans?
Did you know that baby cats are blind and use echolocation to navigate?
Did you know that Abraham Lincoln was actually four cats in a trench coat? The hat was to cover up his cat ears.
Did you know that cats become two cats when cut in half?
Did you know that all cats live for 12 to 15 years?

Did you know that cats know when you will die and they use the information against you?
Did you know that cats’ favorite holiday is Halloween because it never falls on a Monday?
Did you know that cats have free-floating clavicle bones that allow them to fit though spaces as tiny as 1/2 inch”
Did you know that cats have 20 muscles that control their ears?
Did you know that cat poop grows into cat trees when planted? That is why cats bury their poop.

Did you know that cats have four paws?
Did you know that cats sleep 70% of their lives?
Did you know that cats lick themselves to keep clean?
Did you know that cats are carnivores?
Did you know that Garfield is a cat that does not like Mondays?
Did you know that men think of cats every 7 seconds?

Did you know that cats mate for life?
Did you know that little dogs are actually cats?
Did you know that calico cats are all female because the males died in the great war?
Did you know that cats only have 4 teeth?
Did you know that lions can change colors to match their surroundings just like chameleons?
Did you know that when a cat licks you, they are showing you where a tumor is?
Did you know that cats use their tails for balance and have nearly 30 individual bones in their tails?

Did you know that cats can get diabetes?
Did you know that fortune cookies where originally invented in china and contained cat facts?
Did you know that computer mice get their name to keep cats away from the keyboard?
Did you know that Issac Newton is famous for inventing the cat door?
Did you know that cats think of us as large cats?
Did you know that house cats usually weigh around 4 to 5 kilograms?

Did you know that cats always land on their feet?
Did you know that some cats are black and the rest are white?
Did you know that cats are lactose intolerant just like Sheldon from the Big Bang?
Did you know that the first cat show was held in 1871 at the Crystal Palace in London?
Did you know that 1 in 3 pet owners think cats can read their minds? They are not wrong.
Did you know that cats are allergic to people who are allergic to cats?

Did you know that cats can see in the dark?
Did you know that cats hide under the bed because they are scared?
Did you know that many bird species are being threatened by cats?
Did you know that a group of cats is called a clowder?
Did you know that cats in the northern hemisphere are left pawed and cats in the southern hemisphere are right pawed? This is due to the Coriolis effect.
Did you know that vikings wore horns on their helmets to mimic cat ears?
Did you know that over 200 cats live at Disneyland?
Did you know that cats like it when you pet them?
Did you know that cats only sweat through their paws?

Did you know that cats are the most venomous animal but the shape of their mouth makes them unable to bite humans?
Did you know that baby cats are called kittens?
Did you know that cats hunt mice because of their hubris?
Did you know that when astronomers first went to the moon, they found cats living there? That is why they never went back.
Did you know that fur-less cats actually have glass fur that acts as a high-viscosity liquid?
Did you know that houseflies have a lifespan of 24 hours because they are killed by cats?
Did you know that cats can regenerate limbs but many of them choose not to?

Did you know that cat tongues feel like sandpaper but cant actually be used as sandpaper?
Did you know that the black plague was caused by cats going on strike?
Did you know that cats are born with blue eyes?
Did you know that all members of the cat family can live together in harmony?
Did you know that cats cannot taste anything sweet because they are already the sweetest things in the whole world?
Did you know that cats do not like to swim because they get stomach cramps when they eat less than an hour before?
Did you know that cats have an extra eyelid that allows them to see in 3d?
Did you know that cats have the most beautiful sing voice but they only sing when you are sleeping?
Did you know that the ridges on cats noses are unique just like snowflakes?
Did you know that cats are everywhere and you are never more than 7 feet from a cat?

Did you know that cats knead with their paws when they are happy?
Did you know that cats can drink sea water because they have crazy efficient kidneys?
Did you know that whiskers can be all shades of the rainbow?
Did you know that cats can live underwater, but they then turn into catfish?
Did you know that the smallest cat is invisible to the naked eye?
Did you know that a cat with stripes is called a tabby?
Did you know that homeless cats are called feral?