Vous êtes sur la page 1sur 2

A MATLAB to Fortran conversion "Manual" 1

General remarks and programming


Editor
Compilation
Cases
Variables

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, ...);

allocate (k(neqn, neqn))


May contain "private" and "public" subroutines
see under "FEM specific remarks"
call bisect(areas, amin, ...)

Modules
Types
Subroutine
calls

function [areas] = bisect(aold,amin, ...)


..
.

subroutine bisect(aold, amin, ...)


real(8), intent(in) :: amin, ...
real(8), dimension(:), intent(inout) :: aold
..
.

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

for the course FEM-Heavy, Fall 2010 by Ole Sigmund.

FEM-Heavy-specific remarks
Number
of
equations
Number of elements
Topology matrix
Nodal coordinate matrix

MATLAB
neqn

FORTRAN90
neqn

ne

ne

IX

ix

Element vector (type)


Number
nodes
element
X-coord.
node 2 in
ment e

of
pr.
of
ele-

NA

element(e)%numnode

number of nodes in element e

NA

element(e)%id

element type of element e =

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)

Vous aimerez peut-être aussi