# Notes: Simple tensor algebra II

The vector space $\mathbb{V}$ is introduced in Simple tensor algrbra I, several rules are provided in it. To reduce the abstract, we represent the vectors $\boldsymbol{x}, \boldsymbol{y}$ with the scalar coefficients $\{{x_1},{x_2},{x_3} \}$ and $\{{y_1},{y_2},{y_3} \}$ in $\mathbb{E}^3$, respectively. The composition of two vectors $\boldsymbol{x}, \boldsymbol{y} \in\mathbb{E}^3$ is expanded by,

Dot product ($\cdot$):

$\displaystyle \boldsymbol{x} \cdot \boldsymbol{y} = {x_i}{\boldsymbol{g}^i} \cdot {y_j}{\boldsymbol{g}^j} = {x_i}{y_j}{\boldsymbol{g}^i} \cdot {\boldsymbol{g}^j} = {x_i}{y_j}{g^{ij}} = {x^i}{y_i} = {\begin{bmatrix} {{x_1}}&{{x_2}}&{{x_3}} \end{bmatrix}} {\begin{bmatrix} {{y_1}}\\ {{y_2}}\\ {{y_3}} \end{bmatrix}} = \sum_{i=1}^3 x_iy_i$

The dot product is also called scalar product or inner product under Cartesian coordinates and it provides the Euclidean magnitudes of these two vectors and the cosine of the angle between them.

Cross product ($\times$):

$\displaystyle \boldsymbol{x} \times \boldsymbol{y} = {x_i}{\boldsymbol{g}^i} \times {y_j}{\boldsymbol{g}^j} = {x_i}{y_j}{\boldsymbol{g}^i} \times {\boldsymbol{g}^j} = {x_i}{y_j}{\varepsilon ^{ijk}}g{\boldsymbol{g}_k} = \begin{vmatrix} {{x_1}}&{{x_2}}&{{x_3}}\\ {{y_1}}&{{y_2}}&{{y_3}}\\ {{\boldsymbol{e}_1}}&{{\boldsymbol{e}_2}}&{{\boldsymbol{e}_3}} \end{vmatrix}$

The cross product is also called vector product, and it represents the area of a parallelogram with the sides of these two vectors. Now, a new composition for two vectors $\boldsymbol{x}, \boldsymbol{y} \in\mathbb{E}^3$ is introduced here.

This is not a tutorial, please refer to the books for tensor algebra.

# Notes: Simple tensor algebra I

The vector space $\mathbb{V}$ with the operation (+) over a field of real number $\mathbb{R}$ is an abelian group with a scalar multiplication. So, suppose $\boldsymbol{x}$, $\boldsymbol{y}$ and $\boldsymbol{z} \in \mathbb{V}$, they satisfy the following conditions:

Abelian group:

• Closure: $\boldsymbol{x} + \boldsymbol{y} \in \mathbb{V}$,
• Associativity: $( \boldsymbol{x} + \boldsymbol{y} )+ \boldsymbol{z}= \boldsymbol{y} + ( \boldsymbol{x}+ \boldsymbol{z} )$,
• Identity: $\exists \boldsymbol{0} \in \mathbb{V}, \forall \boldsymbol{x} \in \mathbb{V}$ such that $\boldsymbol{0} + \boldsymbol{x} = \boldsymbol{x}$ and $\boldsymbol{x} + \boldsymbol{0} = \boldsymbol{x}$,
• Invertibility $\exists ! ( -\boldsymbol{x} ) \in \mathbb{V}, \forall \boldsymbol{x} \in \mathbb{V}$ such that $( -\boldsymbol{x} ) + \boldsymbol{x} = \boldsymbol{0}$ and $\boldsymbol{x} + ( -\boldsymbol{x} ) = \boldsymbol{0}$,
• Commutativity: $\boldsymbol{x} + \boldsymbol{y} = \boldsymbol{y} + \boldsymbol{x}$.

Scalar multiplication:

• $\forall \alpha, \beta \in \mathbb{R}$, $\forall \boldsymbol{x} \in \mathbb{V}$ such that $( \alpha \beta ) \boldsymbol{x} = \alpha ( \beta \boldsymbol{x} )$,
• $\forall \alpha, \beta \in \mathbb{R}$, $\forall \boldsymbol{x}, \boldsymbol{y} \in \mathbb{V}$ such that $\alpha ( \boldsymbol{x} + \boldsymbol{y} ) = \alpha \boldsymbol{x} + \alpha \boldsymbol{y}$ and $( \alpha + \beta ) \boldsymbol{x} = \alpha \boldsymbol{x} + \beta \boldsymbol{x}$,
• $1 \boldsymbol{x} = \boldsymbol{x}$.

This is not a tutorial, please refer to the books for tensor algebra.

# Build VTK 8.1.0 with Qt in Mac

This is the second time I try to build the VTK in Mac. One month ago, I took a lot of time to find how to compile it with CMake and built it successfully, but it is much easier to forget the process. Here I record the entire compiling process.

First step is to download the VTK from the VTK official website. Then, unzip the package to a folder. Here I put it into the folder called “VTK-8.1.0”. By the way, you should also install CMake from the CMake website (Please ensure that the Qt and Xcode are installed in your Mac). Now, create another folder called “VTK_Build”. This is the target folder to save the files generated by CMake. Open CMake and set the “source code” and “binaries” folder:

# Snippet: Matrix with Euler angles

This snippet posts an Excel to calculate the matrix with Euler angles. To discribe the rotation of a crystal frame, commonly, we use three angles: $\alpha$, $\beta$, and $\gamma$. They are also known as Bunge angles. The matrix to rotate the crystal frame in reference frame is described with Euler angles as below:

$\displaystyle \mathbf{B}=\begin{bmatrix} \begin{matrix} \cos(\alpha)\cos(\gamma) \\ - \sin(\alpha)\sin(\gamma)\cos(\beta) \end{matrix}& \begin{matrix} \sin(\alpha)\cos(\gamma) \\ +\cos(\alpha)\sin(\gamma)\cos(\beta) \end{matrix}& \sin(\gamma)\sin(\beta)\\ \begin{matrix} -\cos(\alpha)\sin(\gamma) \\ - \sin(\alpha)\cos(\gamma)\cos(\beta) \end{matrix}& \begin{matrix} -\sin(\alpha)\sin(\gamma) \\ + \cos(\alpha)\cos(\gamma)\cos(\beta) \end{matrix}& \cos(\gamma)\sin(\beta)\\ \sin(\alpha)\sin(\beta) & -\cos(\alpha)\sin(\beta) & \cos(\beta) \end{bmatrix}$

In this Excel (Cf06b0.xlsx), you just need to input three Euler angles and the vector in reference frame. It will give the matrix and the inverse matrix with these three Euler angles. Also, it will give the vector in crystal frame.

This snippet is very useful for debugging the code with rotation of Euler angles.

# Add a 3D convex hull in ABAQUS

Convex hull is the smallest envelope that contains the points set. It is used to construct the grain in grain-based model. There are several methods to generate the convex hull data, but it may need some efforts if you want to put it into ABAQUS model. Here, I post a simple method which is suitable for programming.

### Generate convex hull data

Several methods can be used to generate the convex hull data. I am used to generate the convex hull data with my own code. But if you do not like write code, you can use Mathematica or Matlab to generate the data.

For example, in Mathematica, you can use following code to generate a 3D convex hull:

pts = RandomReal[{-1, 1}, {20, 3}];
ConvexHullMesh[pts]

# A simple example of MD simulation

This is a homework of computational nano mechanics. The basic requirement is to use Lagrangian function to describe the motion of particles. In homework, it requires 5 particles. As an enhancement, I rewrote the code with Qt and use GNU Scientific Library(GSL) to finish the task.

### Concept

The Lagrangian equation of motion describe the particle motion with energy method, the equation is:

$\displaystyle \frac{d}{dt}\frac{\partial L}{\partial \dot{x}_k}-\frac{\partial L}{\partial x_k}=0$

$L$ is the Lagrangian function of the system, $k$ denotes the degree of freedom.

$\displaystyle L = T - U$

$T$ is the kinetic energy and $U$ is the potential energy.