http://blog.163.com/zpfzcjndx@126/blog/static/6354568120135196735577/

最近一直在计算向量式有限元的膜单元,笔者真心给Matlab的计算速度给跪了,之前分析梁杆单元的时候还能接受,但现在真心无语了,电脑常跑了一夜,第二天早上却发现计算结果是错的。因此我不得不投向数值计算最经典的Fortan语言。

本文以一个简单的平面桁架算例,如图1,分别用Fortran和Matlab编写相同的分析程序进行计算,它们的计算速度可以说有天壤之别,如图2,分别增大计算循环步数两种语言的计算时间比较,图3为个人计算机的性能配置。这也印证了网上盛传的一句话“MATLAB只是个高级计算器”,当然,决不能因此一棒子拍死MATLAB,它在很多方面的功能还是很强大的,是其他一些软件是无法比拟的。

图1

计算模型

图2 计算速度对比

图3 计算机配置

MATLAB程序~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

clc

clear

Node=xlsread('Data.xls','Node');

Element=xlsread('Data.xls','Element');

Boundary=xlsread('Data.xls','Boundary');

Section=xlsread('Data.xls','Section');

Force=xlsread('Data.xls','Force');

%%读取数据

N_Element=size(Element,1);

N_Node=size(Node,1);

N_Force=size(Force,1);

N_Boundary=size(Boundary,1);

h=1e-4;

alltime=20;

Zeta =0.1;

EA=Section(1,1)*Section(1,2);

%%阻尼系数

C1 = 1+Zeta*h/2;

C2 = 1-Zeta*h/2;

Squre_h=h^2;

Mass=0.1;

%%定义位移

ExtForce=zeros(N_Node,2);

for i=1:N_Force

ExtForce(Force(i,1),:)=Force(i,2:3);

end

ExpB=ones(N_Node,2);

for i=1:N_Boundary

ExpB(Boundary(i,1),:)=Boundary(i,2:3);

end

First=Node;

Second=Node;

%约束标识

BD=ones(N_Node,2)-ExpB;

InternalForce=zeros(N_Node,2);

EleForce=zeros(N_Element,1);

tic

for time=h:h: alltime

UnbalancedForce=InternalForce+time*ExtForce/alltime;

Third=

(2*Second - C2*First + Squre_h*UnbalancedForce/Mass)/C1;

Third=Third.*ExpB+Node.*BD;

InternalForce=zeros(N_Node,2);

for

i=1:N_Element

n1=Element(i,1);

n2=Element(i,2);

Storeforce=EleForce(i,1);

Curforce=Truss2D(Third(n1,:),Third(n2,:),Second(n1,:),Second(n2,:),EA,Storeforce);

EleForce(i)=Curforce(1,5);

InternalForce(n1,:)=InternalForce(n1,:)+Curforce(1,1:2);

InternalForce(n2,:)=InternalForce(n2,:)+Curforce(1,3:4);

end

First=Second;

Second=Third;

end

toc

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

function

Eleforce=Truss2D(Th1,Th2,Sec1,Sec2,Mat,F)

Eleforce=zeros(1,5);

L=sqrt((Th1(1)-Th2(1))^2+(Th1(2)-Th2(2))^2);

L0=sqrt((Sec1(1)-Sec2(1))^2+(Sec1(2)-Sec2(2))^2);

Eleforce(1,5)=F+Mat*(L-L0)/L0;

Eleforce(1,1)=Eleforce(1,5)*(Th2(1)-Th1(1))/L;

Eleforce(1,2)=Eleforce(1,5)*(Th2(2)-Th1(2))/L;

Eleforce(1,3)=-Eleforce(1,1);

Eleforce(1,4)=-Eleforce(1,2);

end

Fortran程序~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

program main

implicit none

integer,parameter::Nnode=42,Nelement=81,NBoundary=2,Nforce=1

integer i,j,n1,n2

real*8 Node(Nnode,2),Third(Nnode,2),First(Nnode,2),Second(Nnode,2),Timeend,Timebegin

real*8 Section(1,2),EleForce(Nelement),Force(Nforce,3),EA,c1,c2,t,Squre_h

integer

Element(Nelement,2),Boundary(NBoundary,3),Oboundary(Nnode,2)

integer::Gboundary(Nnode,2)=1

real*8::

Gforce(Nnode,2)=0,InternalForce(Nnode,2)=0,UnbalancedForce(Nnode,2)=0,Curforce(5),Storeforce

real*8,parameter:: h=1e-4,zeta=0.1,alltime=10,mass=0.1

interface

function Truss2D(Th1,Th2,Sec1,Sec2,Mat,F)

implicit none

real*8 Truss2D(5),Th1(2),Th2(2),Sec1(2),Sec2(2),Mat,F,L0,L

end function

end interface

!定义函数接口

OPEN(UNIT=7,FILE='Node.dat',STATUS='OLD')

OPEN(UNIT=8,FILE='Element.dat',STATUS='OLD')

OPEN(UNIT=9,FILE='Boundary.dat',STATUS='OLD')

OPEN(UNIT=10,FILE='Section.dat',STATUS='OLD')

OPEN(UNIT=11,FILE='Force.dat',STATUS='OLD')

OPEN(UNIT=12,FILE='Result.dat',STATUS='UNKNOWN') !避开1,2,5,6,

call cpu_time(Timebegin)

do i=1, Nnode

read(7,*) Node(i,:)

end do

close(unit=7)

!放入坐标

do i=1, Nelement

read(8,*) Element(i,:)

end do

close(unit=8)

!放入单元

do i=1, NBoundary

read(9,*) Boundary(i,:)

end do

close(unit=9)

!放入边界条件

read(10,*) Section

close(unit=10)

!放入截面参数

do i=1, Nforce

read(11,*) Force(i,:)

end do

!放入荷载

close(unit=11)

do i=1,NBoundary

j=Boundary(i,1)

Gboundary(j,:)=Boundary(i,2:3)

end do

Oboundary=1-Gboundary

!定义整体边界约束矩阵和逆向约束矩阵

do i=1,Nforce

j=int(Force(i,1))

Gforce(j,:)=Force(i,2:3)

end do

!定义整体力矩阵

Squre_h=h*h

c1 = 1+zeta*h/2

c2 = 1-zeta*h/2

EA=Section(1,1)*Section(1,2)

Second=Node

First=Second

!x(n)

!%x(n-1)

do t=h,alltime,h

UnbalancedForce=InternalForce+t*Gforce/alltime

Third= (2*Second - c2*First +

Squre_h*UnbalancedForce/mass)/c1

Third=Third*Gboundary+Node*Oboundary

InternalForce=0;

do i=1,Nelement

n1=Element(i,1)

n2=Element(i,2)

Storeforce=EleForce(i)

Curforce(:)=Truss2D(Third(n1,:),Third(n2,:),Second(n1,:),Second(n2,:),EA,Storeforce)

EleForce(i)=Curforce(5)

InternalForce(n1,:)=InternalForce(n1,:)+Curforce(1:2)

InternalForce(n2,:)=InternalForce(n2,:)+Curforce(3:4)

end do

First=Second

Second=Third

end do

call cpu_time(Timeend)

write(12,*) Timeend-Timebegin

end program

!定义子程序

function Truss2D(Th1,Th2,Sec1,Sec2,Mat,F)

implicit none

real*8 Truss2D(5),Th1(2),Th2(2),Sec1(2),Sec2(2),Mat,F,L0,L

L=sqrt((Th1(1)-Th2(1))**2+(Th1(2)-Th2(2))**2)

L0=sqrt((Sec1(1)-Sec2(1))**2+(Sec1(2)-Sec2(2))**2)

Truss2D(5)=F+Mat*(L-L0)/L0

Truss2D(1)=Truss2D(5)*(Th2(1)-Th1(1))/L

Truss2D(2)=Truss2D(5)*(Th2(2)-Th1(2))/L

Truss2D(3)=-Truss2D(1)

Truss2D(4)=-Truss2D(2)

end function

转发至微博

转发至微博

阅读(0)|

评论(0)

|

用微信 “扫一扫”

将文章分享到朋友圈。

用易信 “扫一扫”

将文章分享到朋友圈。

喜欢 推荐 0人|

转载

历史上的今天

最近读者

热度

关闭

玩LOFTER,免费冲印20张照片,人人有奖!

评论

this.p={ m:2,

b:2,

loftPermalink:'',

id:'fks_087070085080082064084086095064072084080064081080080065083087',

blogTitle:'【转载】Fortran与Matlab的计算速度对比(Code by myself)',

blogAbstract:'\n

http://blog.163.com/zpfzcjndx@126/blog/static/6354568120135196735577/

最近一直在计算向量式有限元的膜单元,笔者真心给Matlab的计算速度给跪了,之前分析梁杆单元的时候还能接受,但现在真心无语了,电脑常跑了一夜,第二天早上却发现计算结果是错的。因此我不得不投向数值计算最经典的Fortan语言。

\n

本文以一个简单的平面桁架算例,如图1,分别用Fortran和Matlab编写相同的分析程序进行计算,它们的计算速度可以说有天壤之别,如图2,分别增大计算循环步数两种语言的计算时间比较,图3为个

', blogTag:'', blogUrl:'blog/static/213566271201492792140850',

isPublished:1, istop:false, type:0, modifyTime:0,

publishTime:1414416100850,

permalink:'blog/static/213566271201492792140850', commentCount:0,

mainCommentCount:0, recommendCount:0, bsrk:-100, publisherId:0,

recomBlogHome:false, currentRecomBlog:false, attachmentsFileIds:[],

vote:{}, groupInfo:{}, friendstatus:'none',

followstatus:'unFollow', pubSucc:'', visitorProvince:'',

visitorCity:'', visitorNewUser:false, postAddInfo:{}, mset:'000',

mcon:'', srk:-100, remindgoodnightblog:false, isBlackVisitor:false,

isShowYodaoAd:false, hostIntro:'', hmcon:'0',

selfRecomBlogCount:'0', lofter_single:'' }

{list a as x}

{if !!x}

{if

x.visitorName==visitor.userName}

{else}

{/if}

{if x.moveFrom=='wap'} {elseif

x.moveFrom=='iphone'} {elseif

x.moveFrom=='android'} {elseif

x.moveFrom=='mobile'} {/if}

${fn(x.visitorNickname,8)|escape}

{/if} {/list}

{if !!a}

${fn(a.nickname,8)|escape}

${a.selfIntro|escape}{if

great260}${suplement}{/if}

{/if}

python和matlab计算速度对比_【转载】Fortran与Matlab的计算速度对比(Code by myself)...相关推荐

  1. 雨棚板弹性法计算简图_造价工程师:钢结构工程量计算注意事项

    造价工程师:钢结构工程量计算注意事项 一.图纸:根据图纸目录,清理核对图纸数量,检查是否有遗漏. 二.建筑施工图 1. 设计总说明 1.1 建筑面积.结构形式.柱距.跨度.结构布置情况: 1.2 工程 ...

  2. python中cock什么意思_[转载]原创脚本逐步实现Autodcock-Vina的虚拟筛选及筛选后分析...

    [转载]原创脚本逐步实现Autodcock-Vina的虚拟筛选及筛选后分析 (2013-07-03 11:31:56) 标签: 转载 Vina是在Autodock4基础上改进的算法,相比autodoc ...

  3. python数据框常用操作_转载:python数据框的操作

    我们接着上次分享给大家的两篇文章:Python数据分析之numpy学习(一)和Python数据分析之numpy学习(二),继续讨论使用Python中的pandas模块进行数据分.在接下来的两期pand ...

  4. python程序设计简明教程知识点_[转载]看完《python简明教程》笔记及第一个python程序...

    主要是摘抄了一些书上需要注意的地方: 1.Python 是一门解释性语言. 在计算机内部, Python 解释器把源代码转换成称为字节码的中间形式,然后再把它翻译成计算机使用的机器语言并运行. 2.版 ...

  5. 如何在matlab里输入复杂公式_[转载]如何在Matlab绘制的图形中显示复杂公式

    Matlab文本的Interpreter属性使我们能在图形中显示一个较为复杂的公式,例如在公式中除了有希腊字母外,还有分号.根号等数学符号. 当键入:>> set(text,'Interp ...

  6. 基于python的风险管理方式属于_张家港高校邦_Python科学计算_网课答案

    张家港高校邦_Python科学计算_网课答案3rh4 张家港高校邦_Python科学计算_网课答案 关注公众号{帅搜}即可查询答案 支持:大学网课,智慧树,知到,超星,尔雅,学习通,选修课,公务员,外 ...

  7. python中停车收费问题_使用CKRule实现停车场收费计算

    1,收费公式 停车场都有其明确的收费标准,但不同地区地段都有不同的规定,这种规定的可变性比较多,如果要快速实现自动计算停车收费功能,那么使用CKRule是一个很好的选择.而一般的停车场计费都会使用类似 ...

  8. matlab批量储存变量_[转载]整理:matlab批量读入数据文件的方法

    主程序: clc; clear; fidin=fopen('title.txt','r'); fidout=fopen('result.txt','w'); while ~feof(fidin) %w ...

  9. python解放二次开发_[转载]Python二次开发程序详解

    ###################################### ## Fundamentschwingungsstudie ## ## nur geeignet fuer ABAQUS ...

  10. python中读取文件编码_[转载]python中使用文件的读取编码问题

    原文链接:https://www.cnblogs.com/qianboping/p/6524420.html 今天想写个程序合并文件的,以前一直觉得python的编码解码好烦,只要处理文件合并之类的都 ...

最新文章

  1. 家族关系查询系统程序设计算法思路_【学习笔记】数据库基础 - 查询优化
  2. 是时候理解下HTTPS及背后的加密原理了
  3. 请求地址出现不明的字符%E2%80%8E(Zero-Width Space)
  4. superoneclick 2.2_一季度食品监督抽检2.2%不合格:农兽药残留超标等系主因
  5. 我的WCF4 Rest Service及Entity Framework with POCO之旅(三)——用Entity Framework和POCO Template实现数据模型及存储...
  6. qt写的一个计算器程序
  7. 前端预览PDF:PDFObject、PDF.js
  8. 盖世兔I9100刷机心得
  9. pycharm和webstorm下载安装流程
  10. SQL总结 学期前8周学习内容
  11. Python爬虫开源项目代码(爬取微信、淘宝、豆瓣、知乎、新浪微博、QQ、去哪网 等等)...
  12. 特斯拉技术支持工程师实习笔试题
  13. 生命中不仅仅只有代码
  14. 【中文题库】CISCO CCNP题库 642-892(P3.23)中文解释
  15. 一文看懂HTTPS、证书机构(CA)、证书、数字签名、私钥、公钥
  16. 基于Greenplum构建下一代数据分析平台
  17. matlab中 spm,使用SPM批处理在MATLAB中运行预处理
  18. AMD和CMD的区别
  19. 适配 iPhone13、iPhone13 pro、iPhone13 proMax
  20. vue使用百度统计埋点

热门文章

  1. 预约挂号项目之预约挂号模块
  2. 钉钉:开放不是玩流量
  3. fl studio怎么设置中文,fl studio21下载后如何语言设置/切换中文版
  4. photoshop自动批阅_如何使用Photoshop智能对象自动执行多对象编辑
  5. 蓝牙模块—HC-05调试
  6. 肌肉骨骼康复学-习题-单选
  7. 《SpringBoot2.0 实战》系列-整合kafka实现消息发送、消费
  8. JeecgBoot【iconfont】iCon图标扩展方法【亲测实践】
  9. Im4java接口调用ImageMagick图片处理服务简单demo学习
  10. 运动型蓝牙耳机推荐:骨传导运动耳机