# FEM in Python A Simple Start Guide Wrote this a couple of months back. Yet another tutorial in python, if you are interested in finite element analysis. Nicely goes with this excellent tutorial on FEM.

Click the below link to view the tutorial. FEM with Python

Advertisements

# A Gentle Introduction to the Finite Element Method Almost every engineer today have some knowledge of theoretical and practical aspects of FEM. And many have played with various software packages at some point of time.

Well that is enough if you just want to perform analysis but if you want to truly understand the mathematical aspects of FEM and want to get a feel of the numerical methods under the hood of FEM then this short lecture is for you.

Here’s the introduction, plucked straight from the course. IF you like it, you will enjoy the lecture.

The course is divided into five lessons and all this in 100 pages. Happy Learning!!

If you haven’t been hiding under a stone during your studies of engineering, mathematics or physics, it is very likely that you have already heard about the Finite Element Method. Maybe you even know some theoretical and practical aspects and have played a bit with some FEM software package. What you are going to find here is a detailed and mathematically biased introduction to several aspects of the Finite Element Method.

This is not however a course on the Analysis of the method. It is just a demonstration of how it works, written as applied mathematicians usually write it. There is going to be mathematics involved, but not lists of theorems and proofs. We are also going from the most particular cases towards useful generalizations, from example to theory.

It is going to be one hundred pages with many figures and many ideas repeated over and over, so that you can read it with ease. These notes have evolved during the decade I have been teaching finite elements to mixed audiences of mathematicians, physicists and engineers. The tone is definitely colloquial. I could just claim that these are my classnotes and that’s what I’m like.

There’s much more than that. First, I believe in doing your best at being entertaining when teaching. At least that’s what I try. Behind that there is
a deeper philosophical point: take your work (and your life) seriously but, please, don’t take yourself too seriously.

I also believe that people should be duly introduced when they meet. All this naming
old time mathematicians and scientists only by their last names looks to me too much
like the Army. Or worse, high school!

I think you have already been properly introduced to the great Leonhard Euler, David Hilbert, Carl Friedrich Gauss, Pierre Simon Laplace and George Green. If you haven’t so far, consider it done here. This is not about history.

It’s just good manners. Do you see what I mean by being colloquial?

Anyway, this is not about having fun, but since we are at it, let us try to have a good time while learning. If you take your time to read these notes with care and try the exercises at the end of each lesson, I can assure that you will have made a significant step in your scientific persona. Enjoy!

Click the below link to access the excellent PDF. Don’t forget to thanks to Francisco Jaview Sayas !

A gentle introduction to the Finite Element Method by Francisco–Javier Sayas

# Quick Intro to 2D and 3D Visualization in Python Posted a quick tutorial introducing visualization in python.

This tutorial offers a quick look at some common 2d and 3d Visualization available in python. This tutorial is meant to give anyone a quick start in matplotlib and mayavi.mlab.

The tutorial was written as part of CSRP program of AeSIAA which I am volunteering as a mentor to few aeronautical students.

View the tutorial by clicking this Quick Intro to 2D and 3D Visualization in Python

# Quick Basic Python Tutorial

I have just posted a Quick Basic Python Tutorial on github. View it here  Quick Introduction to Basic Python.

Short and simple for those who cannot wait to get started.

# Multimap in multimap with C++ — an example A colleague of mine is working in NXOpen and extracting the boundary conditions of the finite element model using Multimap.

Looking at the code, I suggested that he would be better up if he choose to use Multimap in Multimap for the functionality he is after.

To demonstrate the multimap in multimap concept, wrote a simple multimap in multimap example in c++

It helped him and should simplify his work. Putting it here in the hope that this will help someone.

```

#include "stdafx.h"
#include <iostream>
#include <map>
#include <string>

using namespace std;

void printmapvalues(multimap<string,int> p1,string ss1);
void printallmap(multimap<string,int> p1);
void printallmap2(multimap<string,multimap<string,int>> me);

int main()
{
multimap<string,int> mmap,mmap2;  // simple string integer multimap
multimap<string,multimap<string,int>> mera; // multimap of multimap

// add some values
mmap.insert(pair<string,int>("SSS",11));
mmap.insert(pair<string,int>("SSS",11));
mmap.insert(pair<string,int>("SSS",21));
mmap.insert(pair<string,int>("SSS",13));
mmap.insert(pair<string,int>("SSS",31));
mmap.insert(pair<string,int>("MMM",31));
mmap.insert(pair<string,int>("MMM",41));
mmap.insert(pair<string,int>("MMM",51));
mmap.insert(pair<string,int>("MMM",61));
mmap.insert(pair<string,int>("MMM",11));

// add another multimpap valuess
mmap2.insert(pair<string,int>("Sim",301));
mmap2.insert(pair<string,int>("Mim",310));

// insert the two above multimaps to this multimap in multimap
mera.insert(pair<string,multimap<string,int>>("Office",mmap));
mera.insert(pair<string,multimap<string,int>>("Ghar",mmap2));

//    cout<<"Size of  ss "<<mmap.count("SSS")<<endl; // cont the number of value for SSS
printallmap(mmap);
printallmap(mmap2);
printmapvalues(mmap,"MMM");
printallmap2(mera);

return 0;
}

void printmapvalues(multimap<string,int> p1,string ss1){
// print values of a given filed of a malutimap
pair <multimap<string,int>::iterator, multimap<string,int>::iterator> ret;
ret = p1.equal_range(ss1);

for (multimap<string,int>::iterator it=ret.first; it!=ret.second; ++it){
cout << ' ' << it->second;
cout << '\n';
}

}

void printallmap(multimap<string,int> p1){
// print all values of a multimap
for (multimap<string,int>::iterator it=p1.begin(); it!=p1.end(); ++it){
cout << it->first << ' ' << it->second << '\n';
}
}

void printallmap2(multimap<string,multimap<string,int>> me){
// prints values of a multimap containing a multimap
for (multimap<string,multimap<string,int>>::iterator it=me.begin(); it!=me.end(); ++it){
cout<<it->first<<" contains...."<<endl    ;
printallmap(it->second);
}

}

```

# Simple Introduction To Working With HDF In PYTHON? In May 2014 I wrote this tutorial, but stupidly made it as a gif format. Don’t know why?

Today had the chance to revisit that page and I felt the GIF format made the tutorial useless, so dumped it and used ipython notebook to create a more updated but simple tutorial to get started working with HDF in python.

If you are into scientific coding, you will encounter HDF and I hope this simple tutorial will get you started in python. Enjoy!

Click here to view the tutorial

# GIF animation in Python in 3 Steps GIF animation in Matlab in 3 steps is a popular post here on this blog. Learnt the technique while trying to plot the results from the Karhunen-Loeve Expansion in September 2012.

Since then, I have moved from matlab to python.

But I wanted to recreate that same thing in Python. This is where I have to say, Matlab is like iOS and Python is Android. For doing this in Matlab, all ingredients were in place, but in python, this isn’t the case.

So here are the 3 long steps in Python to get a GIF animation.

Step 1:
Download Figtodat and images2gif

Step 2:
Import Figtodat and writeGif

```import Figtodat
from images2gif import writeGif
```

Step 3:
Collect the figures into an array and call writeGif to get the animation

```
figure = plt.figure()
plot   = figure.add_subplot (111)
plot.hold(False)
images=[]
y = numpy.random.randn(100,5)
for i in range(y.shape):
plot.plot (numpy.sin(y[:,i]))
im = Figtodat.fig2img(figure)
images.append(im)

writeGif("images.gif",images,duration=0.3,dither=0)

```

Don’t want to spend time finding the listed modules, download them directly from the link at the end of the post.

Here’s the complete code.
Continue reading