0% found this document useful (0 votes)
2 views5 pages

Assignment 1

The assignment focuses on computational mechanics using Fortran, emphasizing tensor analysis and programming skills. Students are required to implement various tensor operations and transformations, develop a tensor library, and solve specific problems related to linear elasticity. The document provides detailed instructions for setting up a Linux environment, coding in Fortran, and compiling and executing programs.

Uploaded by

Jules Chaperon
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views5 pages

Assignment 1

The assignment focuses on computational mechanics using Fortran, emphasizing tensor analysis and programming skills. Students are required to implement various tensor operations and transformations, develop a tensor library, and solve specific problems related to linear elasticity. The document provides detailed instructions for setting up a Linux environment, coding in Fortran, and compiling and executing programs.

Uploaded by

Jules Chaperon
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

ME725: Computational Mechanics of Materials

Assignment 1 – Fortran, Tensors and Transformations

Due: Friday June 14, 2018 (email with the files is preferred or drop off hard copies in EC4-1163 or
MME Dept mailbox)

Objectives and Outcomes:

(1) Gain experience with tensor analysis and its implementation into a numerical code
(2) Develop basic programming skills in Fortran
(3) Begin the development of a tensor library that will be used throughout the course to analyze
increasingly difficult problems
(4) Review of basic linear elasticity and stress transformations using tensor operations

1. Getting Started with Fortran:


This assignment is to be completed in Fortran. It is recommended that the Fortran code be written in a
Linux based environment that will make for an easier transition to LS-DYNA later in the course. However,
it is not required for this assignment so any Fortran environment could be used.

Installation of a virtual machine for Linux on Windows:

If you do not already have Linux available within your research group, it is recommended to install a
virtual machine on your Windows PC to install Linux. The virtual machine can be deleted at the end of the
course and does not require a dual-boot. It is relatively straight-forward to install a virtual machine using
free virtual box software (there are many and newer versions of windows may support this as well).

Here are some basic steps to install a virtual machine with linux that will have the necessary fortran, C++
compilers available.

Step 1. Check if your system supports virtual machines

Run “[Link]” and type “[Link]” in the command window. Under “Hyper-v” if you have 4 yes
statements you are good to go. Otherwise you likely have to enable virtualization in the BIOS during start-
up.

Step 2. Download and install the virtual box software: [Link]

Step 3. Download fedora linux

[Link]
splash?file=[Link]
ora-Workstation-Live-x86_64-[Link]

Step 4. Basic how-to guide on installation:

[Link]
*Tips:

1. Settings – General-Basic: Enable bi-directional copy-pasting

2. Settings – Storage: Under the IDE, look up the [Link] file. This is the virtual disc drive we are loading
the live cd into. Will remove it after the install and replace with [Link]

Step 5 (optional): After installation, download the guest additions ISO image and install it. It will enable
the virtual machine to have better functionality.

Download the guest additions ISO image and install it.

[Link]

2. Fortran Basics:

Fortran requires compiling of the source files into object files and then linking to create an executable
file that we then run. The data can be printed to the screen or to output files. It is not nearly as functional as
Matlab in this respect but Fortran is very computationally efficient.

The syntax of Fortran is very similar to Matlab but some commands will take getting used to. Professor
Google can help with most syntax questions 😊😊

Unlike Matlab, Fortran will allow you to make some large mistakes such as implicit variable definitions,
case-insensitive variables, and automatic pass-by-referencing with functions/subroutines.

Fortran tips:

1. The first 6 spaces in a line are reserved for other commands. We write code from column (space)
7 to 72. To continue a long executable beyond this we can use a label number for the line in column
6 or use a “.” at column 6. The compiler will catch this when you forget.

2. Declare variables always. Fortran will let you get away with not declaring variables unless you
write “implicit none” at the start of the program. Fortran will allow you to declare variables
implicitly. Any variables that start with the letter “i,j,k,l,m,n” will be automatic integers. Otherwise
it will be a floating point number type.

3. Fortran is case-insensitive. It does not differentiate between a variable with capital letters. For
example. Variable “X” is the same as “x”. Matlab distinguishes between them as separate variables
while Fortran will not.

4. “For” loops are called “Do” loops. An example setting an array to zero would be
do i=1,6
x(i) = 0
end do
5. Fortran passes variables by reference. For example, passing a variable into a function will allow
you to change the value of that variable within the function. This is important to be mindful of and
to not change “input variables” within the functions. Within C+, this would correspond to passing
pointers within functions. It is good practice to declare the “intent” of the variable within the
functions

6. Two Fortran files have been posted on Learn that will include some common commands to help
you get started.

Compiling and Executing your Program:

First we compile the “.f” files into .o (object) files. If you have the intel fortran compiler we invoke the
“ifort” compiler name. The default fortran compiler in Linux is “gfortran” and is included during
installation. Enter into a Terminal window and go to your source file directory (use “cd” commands ). For
a file named “hello.f” we would compile it as:

gfortran -c hello.f

This will make the file hello.o. We would do this for all of our .f files. If we only have hello.o, we make
an executable program out of it by typing

gfortran -o program_name hello.o

We can also link libraries during this stage needed by our codes. This will come later in the course. With
many files to link, we will use a “makefile” to build the program.

To execute the program, we type: ./program_name

Note that when we have a small number of files, we can just compile and build in one step. This will do a
fresh compile of each file and do the linking. Using the two files in the Learn directory to help you get
started, if we call the program “test”, we type:

gfortran -o test hello.f tensor_lib.f

and then run it: ./test

3. Problems:

Solve and implement the following vector and tensor operations within Fortran or C/C++. Either of these
codes can be used. If you are more comfortable with C/C++ this is fine as well but it must be either C or
Fortran.

Where relevant, show hand calculations or write out the pseudo-code. Fourth order tensor problems can
generally not be solved by hand so listing the solution steps would all that is needed for a calculated
computation. Attach copies of the source files (.f or .c ).
Q1. Develop a library of tensor functions to perform the following operations. Each operation must be its
own subroutine. For consistency in the course (and to help with marking), please use the following names
in red or a similar naming convention

(i) Transpose of a second order tensor (tpose)


(ii) Determinant of a second order tensor (det_Aij)
(iii) Inverse of a second order tensor (inv_Aij). Include test for singularity.
(iv) Single contraction of two second order tensors (tc_2s2): Cij = A∙B = AikBkj
(v) Double contraction of two second order tensors (tc_2d2): c = A:B = AijBji
(vi) Double contraction between two fourth order tensors (tc_4d4): Cijkl = A:B = AijmnBmnkl
(vii) Tensor double contraction (tc_4d2): Cij = A:B=AijklBkl
(viii) Tensor double contraction (tc_2d4): Cij = A:B =AklBklij

Q2. Develop functions or subroutines to calculate:


(i) The three invariants of a second order tensor: I1, I2, I3
(ii) The three deviatoric invariants of a second order tensor: J1, J2, J3

Q3. (a) Develop a subroutine to transform a second-order tensor into a new frame of reference: B = Q∙A∙QT
called transform_Aij.
(b) Evaluate the function using a rotation about the z-axis of 60° and an input stress tensor:
 1 0.1 0 
σ ij = 0.1 0.5 0 
 0 0 0.01
Provide some type of validation that the implementation is correct.

Q4. Write subroutines to:


(i) Obtain the dyadic project of two second order tensors: (tp_2dy2): Aij ⊗ Bkl
(ii) Compute the fourth order unit tensors: 1ijkl(4), 1ijkl (4s), 1ijkl (dev), 1 ijkl (vol)
(iii) Evaluate the implementations by calculating the deviatoric stress tensors and von Mises
equivalent stress as:
1
sij = 1dev : σ ij  J 2 = s : s  σ eq = 3 J 2 ( sij )
2
for two tensors:
0.1 1.1 0   1 0.1 −0.2 
σ ij 1.1 −0.1 0 
= σ ij =  0.1 0.5 0.4 

 0 0 0   −0.2 0.4 0.05 

Recall that there are closed form expressions for the von Mises equivalent stress to check the solution. The
fourth-order unit tensors can also be checked easily.
Q5. Create a function to determine the fourth order elastic tensor using the elastic modulus, E, and Poisson’s
ratio, v, as:
Lel = λ (δ ⊗ δ ) + 2G1(4 s )

E E
Shear modulus: G = Bulk modulus: K = Lame’s constant: λ= K − 2G / 3
2(1 + v) 3(1 − 2v)

Q6. Determine the elastic stress tensor in MPa by inputting the strain tensor and elastic constants for steel:

σ = Lel : ε

 0.001 0.0001 0 
= 
ε 0.0001 −0.0005 0  E = 205 GPa v = 0.28
 0 0 −0.0005

Q7. Create a function for the fourth order elastic compliance tensor that relates the strain increment to the
applied stress:
ε = Cel : σ

−λ 1
=Cel (δ ⊗ δ ) + 1(4 s )
2G (3λ + 2G ) 2G

Input the solution for the stress tensor in the problem above and use the same elastic constants to verify that
function.

Optional: Test your implementation that Cel : Lel using the elastic constants for steel. Which fourth-order
identity tensor is obtained by this operation? We will use these calculations often throughout the course so
it is important to check they are correct.

You might also like