fortran模板中的子程序可不可以互用

fortran模板中的子程序可不可以互用,第1张

是可以的,我写了如下程序 可以执行

program main

integer::n

common/datas/n

call a

end

subroutine a

integer::n

common/datas/n

n=n+1

call b

if(n>100)return

endsubroutine

subroutine b

integer::n

common/datas/n

n=n+1

call a

if(n>100)return

endsubroutine

但是一般来说,不建议子程序互相调用,就像是递归函数一样,互相调用导致程序结构不明朗,容易形成死循环,而且复杂点的程序的话这样调用检查起来很困难

1 bessel函数你可以直接调用IMSL的函数,详见vni官网

>

下面有些路径是根据我自己的程序安装路径。1)set environment variables for Fluent, C++, Fortran;//设置FLUENT,c++,Fortran的环境变量;2)put sorce code file into \src folder, put compiled fortran obj files into \ntx86\2d folder, copy sedexe, user_ntudf and makefile_ntudf to the same folder as compiled fortran obj files; (this two folders are created by yourself, you can put them under your case folder)将源文件代码放入\src文件夹下,将编译之后的fortran的obj文件放在路径为···\ntx86\2d的文件夹下,复制文件sedexe,user_ntudf和makefile_ntudf文件到路径为···\ntx86\2d的文件夹下(这两个是自己创建的,你可以放它们在你的case文件夹下)。3)modify user_ntudf file {follow the instructions eg USER_OBJECTS = testobj this obj file is the complied fortran obj file ,SOURCES = $(SRC)test_usec(c source file that is in the \src fold), VERSION = 2d(your model dimension), PARALLEL_NODE = none;按下面的方法修改user_ntudf文件:USER_OBJECTS = testobj // test是你编译之后的fortran程序文件名;SOURCES = $(SRC)test_usec(text_usec是你放入\src文件下的c程序的源码文件) ;VERSION = 2d //为你模型的维数。PARALLEL_NODE = none; //是否并行计算,一般选择不并行计算。4)change the name of file makefile_ntudf tomakefile, modify makefile, (add this line "FLUENT_INC= D:\FluentInc" below "UDFDATA = udf_namesc";改变makefile_ntudf的文件名为:makefile;并且添加在UDFDATA = udf_namesc这行后面添加FLUENT_INC= D:\FluentInc; 5)You might need to copy all the lib files under Fortran\lib fold to folder D:\FluentInc\fluent6326\ntx86\Fortran_lib (this folder is created by myself) change this line "LIBS = /Libpath:$(FLUENT_INC)\fluent$(RELEASE)\$(FLUENT_ARCH)\$(VERSION)" in the makefile file to "LIBS = /Libpath:$(FLUENT_INC)\fluent$(RELEASE)\$(FLUENT_ARCH)\$(VERSION)D:\FluentInc\fluent6326\ntx86\Fortran_lib\lib"你需要复制fortran的库文件到fluent的安装文件D:\FluentInc\fluent6326\ntx86\Fortran_lib(其中Fortran_lib为自己创建的文件名);并且改变makefile文件中的行LIBS = /Libpath:$(FLUENT_INC)\fluent$(RELEASE)\$(FLUENT_ARCH)\$(VERSION)为LIBS = /Libpath:$(FLUENT_INC)\fluent$(RELEASE)\$(FLUENT_ARCH)\$(VERSION)6)Type "nmake" in the command line console, make sure the console is displaying the right path that is including your files such as: "makefile","obj","sedexe"在编译之后,确保在fluent的界面中出现,文件"makefile","obj","sedexe"的正确路径。7)Put the generated dll file with your cas and data files together连接你的dll文件和你的case文件和date文件一起。

第一种方法:1建立工作目录/]"2将ABAQUS安装目录\64-pr11\site下的aba_param_dpinc或aba_param_spinc拷贝到工作目录,并改名为aba_paraminc;3将编译的fortran程序拷贝到工作目录;4将obj文件拷贝到工作目录;5建立好输

AB(:,:) 这种定义虚参的方法,叫 “假定形状”。

类似 AB( ) 这种定义虚参的方法,叫 “假定大小”(不建议使用该方法定义)

而显示给出 AB 大小的方法,类似 AB( n , n+1 ) 这种,是常规定义。

对于假定形状的函数声明,需要书写 interface 接口,以便使得编译器了解该函数的参数及其意义。

书写 interface 比较繁琐。我一般尽量避免书写 interface。更好的方法,是把子程序封装成 module,这样可以避免书写 interface。(我是说尽量避免,但书写 interface 的方法我还是建议你学习一下,认真看一本教材。)

以下是封装成 Module 的代码:(!// 为我的注释)

module Gauss_Mod !// 定义一个 Gauss_Mod 的模块

Contains !// 把高斯相关的两个函数 Contains 包含在模块内

subroutine Gauss_elimination(A,B,X)

implicit none

real(8),allocatable::AB(:,:)

real(8) A(:,:),B(:),X(:)

real(8) m,temp

integer i,j,n,k,rmax

n=size(B)

allocate(AB(n,(n+1)))

AB(:,1:n)=A(:,:)

AB(:,n+1)=B(:)

do k=1,n-1

temp=0d0

rmax=0d0

!选主元

do i=k,n

if(abs(temp)<abs(AB(i,k))) then

temp=AB(i,k)

rmax=i

endif

if(AB(rmax,k)==0) goto 1000

end do

if(rmax/=k) then

call swap(AB(:,:),rmax,k)

endif

do i=k+1,n

m=AB(i,k)/AB(k,k)

do j=1,n+1

AB(i,j)=AB(i,j)-AB(k,j)m

enddo

enddo

enddo

if(AB(n,n)==0) goto 1000

temp=0d0

do i=1,n

temp=temp+AB(i,n+1)

end do

if(temp==0) goto 1000

A(:,:)=AB(:,1:n)

B(:)=AB(:,n+1)

X(n)=B(n)/A(n,n)

do i=n-1,1,-1

temp=0

do j=i+1,n

temp=temp+A(i,j)B(j)

enddo

X(i)=(B(i)-temp)/A(i,i)

enddo

1000 write(,) "found no zero solution!"

deallocate(AB)

return

end subroutine Gauss_elimination

subroutine swap(A,rmax,k)

implicit none

real(8) A(:,:)

real(8),allocatable::temp(:)

integer i,m,n,rmax,k

m=size(A,1)

n=size(A,2)

write(,) m,n

allocate(temp(n))

if((rmax==k)or(rmax<1)or(rmax>m)or(k<1)or(k>m)) then

A=A

else

temp(:)=A(rmax,:)

A(rmax,:)=A(k,:)

A(k,:)=temp(:)

endif

return

end subroutine swap

End Module Gauss_Mod !// 结束模块

program main

Use Gauss_Mod !// 主程序 Use 使用 Gauss_Mod 模块

implicit none

real(8) A(3,3),B(3),X(3)

A(1,1)=0001

A(2,1)=-1000

A(3,1)=-2000

A(1,2)=2000

A(2,2)=3712

A(3,2)=1072

A(1,3)=3000

A(2,3)=4623

A(3,3)=5643

B(1)=1000

B(2)=2000

B(3)=3000

call Gauss_elimination(A,B,X)

write(,) X

end program main

以上就是关于fortran模板中的子程序可不可以互用全部的内容,包括:fortran模板中的子程序可不可以互用、关于fortran子程序的提问、如何在UDF中调用fortran子程序(整理网上资料)等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/zz/10130074.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2023-05-05
下一篇2023-05-05

发表评论

登录后才能评论

评论列表(0条)

    保存