This section provides a hands-on tutorial on the basic usage of ALFE.
Introduction
2D Cantilever
Here is a very basic example. We can start from creating a simple 2D cantilever with 6 mm x 4 mm. It is meshed with 24 four-node plane-stress elements. The material is assumed with Young's modulus of 1 MPa and Poisson's ratio of 0.3.
1. Define a cantilever
Define nodes and elements. The number of nodes in the two directions can be represented by xnumand ynum.
List<Node> nodes = new List<Node>(xnum * ynum);
List<Element> elems = new List<Element>((xnum - 1) * (ynum - 1));
Then, all nodes can be found through two for loops.
for (int i = 0; i < xnum; i++)
{
for (int j = 0; j < ynum; j++)
{
nodes.Add(new Node(i, j));
}
}
Constructing a quadrilateral element (a pixel element) requires a nodal set and a specified material. The material can be created by the code below.
var materal = new Material(1.0, 0.3); // E = 1.0, u = 0.3
Next, elements can be defined easily through inputting the counterclockwise vertex indices.
for (int i = 0; i < xnum - 1; i++)
{
for (int j = 0; j < ynum - 1; j++)
{
List<Node> nodalSet = new List<Node>(4)
{
// Counterclockwise
nodes[i * ynum + j],
nodes[i * ynum + (j + 1)],
nodes[(i + 1) * ynum+ (j + 1)],
nodes[(i + 1) * ynum + j],
};
// Construct a pixel element
elems.Add(new Pixel(nodalSet, material));
}
}
2. Define loads and boundary conditions
Now, let's set loads and boundary conditions. So, we need to define two lists for loads and supports. The number of loads is 1 because we just apply a load on the center of the one side. Another side of the cantilever should be fixed, so the number of supports should be ynum.
List<Load> loads = new List<Load>(1);
List<Support> supports = new List<Support>(ynum);
The easiest way to define supports is adding a if structure when defining nodes.
for (int i = 0; i < xnum; i++)
{
for (int j = 0; j < ynum; j++)
{
nodes.Add(new Node(i, j));
if (i == 0) supports.Add(new Support(j, SupportType.Fixed));
}
}
Also, we can compute the index of the loaded node according to ynum. A 2D vector is used to present a force.
loads.Add(new Load(nodes.Count - (int)Math.Ceiling(ynum / 2.0), new Vector2D(0.0, -1.0)));
3. Do FEA
Before doing FEA, we need to create a model and a FE system through assembling above lists.
// Create a model
Model model = new Model(2, nodes, elems, loads, supports);
​
// Create a FE system
FESystem system = new FESystem(model);
After that, we can initialize the system and solve it.
// Initialize the system and solve it.
system.Initialize();
system.Solve();
Finally, let's print all displacements
// Print the displacement information
Console.WriteLine(system.DisplacementInfo());
Console.ReadKey();
4. Complete Code
static void Main(string[] args)
{
int xnum = 7;
int ynum = 5;
List<Node> nodes = new List<Node>(xnum * ynum);
List<Element> elems = new List<Element>((xnum - 1) * (ynum - 1));
List<Load> loads = new List<Load>(1);
List<Support> supports = new List<Support>(ynum);
// Define nodes
for (int i = 0; i < xnum; i++)
{
for (int j = 0; j < ynum; j++)
{
nodes.Add(new Node(i, j));
if (i == 0)
supports.Add(new Support(j, SupportType.Fixed));
}
}
// Define Material
Material material = new Material(1.0, 0.3);
// Define elements
for (int i = 0; i < xnum - 1; i++)
{
for (int j = 0; j < ynum - 1; j++)
{
List<Node> nodalSet = new List<Node>(4)
{
// Counterclockwise
nodes[i * ynum + j],
nodes[i * ynum + (j + 1)],
nodes[(i + 1) * ynum+ (j + 1)],
nodes[(i + 1) * ynum + j],
};
// Construct a pixel element
elems.Add(new Pixel(nodalSet, material));
}
}
// Apply the load
loads.Add(new Load(nodes.Count - (int)Math.Ceiling(ynum / 2.0), new Vector2D(0.0, -1.0)));
// Create a model
Model model = new Model(2, nodes, elems, loads, supports);
// Create a FE system
FESystem system = new FESystem(model);
// Initialize the system and solve it.
system.Initialize();
system.Solve();
// Print the displacement information
Console.WriteLine(system.DisplacementInfo());
Console.ReadKey();
}