Professional Documents
Culture Documents
A MATLAB To Fortran Conversion "Manual": General Remarks and Programming
A MATLAB To Fortran Conversion "Manual": General Remarks and Programming
MATLAB
Built-in
Run-time compilation
Case sensitive (K = k)
Scalar variables need not be defined
Dynamic
allocation
NA
FORTRAN90
Built-in
Compile by Ctrl+Shift+b and run by Ctrl+F5
Case in-sensitive (K = k)
All variables must be defined:
integer :: n
real(8) :: length
real(8) :: d, f(17), k(13,13)
real(8), dimension(17) :: f
character(len = 6) :: word
logical :: banded
real(8), dimension(:,:), allocatable :: k
..
.
NA
We did not use it
[areas] = bisect(areas,amin, ...);
Modules
Types
Subroutine
calls
Programming
do loops
if statements
Indexing
Vector multiplication
Matrix multiplication
printing to
screen
MATLAB
f or i = 1 : n
...
end
i f (...)
...
end
K(edof,edof) = K(edof,edof) + k
FORTRAN90
do i = 1, n
...
end do
i f (...) then
...
end i f
k(edof,edof) = k(edof,edof) + ke
a = b*c
a = dot_product(b,c)
a = b*c
a = matmul(b,c)
remove ";"
print*,aout=,aout
print matrix
# of colums
in matrix
Assigning
variables
size(K,2)
do i = 1,neqn
print "(24(f4.2,tr1))",k(i,1:neqn)
end do
size(k,2)
i = 1500
d = 1500
d = 1500
banded = 0 (or 1)
word = blabla
i=1, j=3 => i/j = 0.3333
i = 1500 (integer)
d = 1.5e3 (or 1500.0) (real(4))
d = 1.5d3 (or 1500.0d0) (real(8))
banded = .false. [or .true.] (logical)
word = blabla (character)
i=1, j=3 => i/j = 0 (NB! Integer part of result!)
Integer division
1 Written
FEM-Heavy-specific remarks
Number
of
equations
Number of elements
Topology matrix
Nodal coordinate matrix
MATLAB
neqn
FORTRAN90
neqn
ne
ne
IX
ix
of
pr.
of
ele-
NA
element(e)%numnode
NA
element(e)%id
NA
IX(e,3)
2
element(e)%ix(i)
node i of element e
element(e)%mat
material property number of element e
nen=element(e)%numnode
X(IX(e,2),1)
x(element(e)%ix(2),1)
size(bound,1)
mprop(element(e)%mat)%young
mprop(element(e)%mat)%area
mprop(element(e)%mat)%nu
mprop(element(e)%mat)%thk
mprop(element(e)%mat)%dens
mprop(element(e)%mat)%youngy
mprop(element(e)%mat)%shear
nb
bound(:,3)
bound(1:nb,1:3)
size(loads,1)
np
Youngs mod.:
mprop(IX(e,3),1)
Material
property
matrix (type)
number
of
boundary
conditions
boundary
cond. matrix
number
of
loads
load matrix
equation solving
1 truss
2 4 node
Area:
mprop(IX(e,3),2)
loads(:,1:3)
(node,dof,force)
D=K\P
loads(1:np,1:4)
load-type=1: point load: (load-type,node,dof,force)
load-type=2: pressure load: (load-type,element,face,pressure)
call factor(k)
call solve(k,p)
d(1:neqn)=p(1:neqn)