module hydromodelUtil
implicit none
double precision, parameter :: pi=3.141593d0
type singleinfo
integer :: controlno
integer :: unittype
integer :: solid
double precision :: coearea
double precision :: volume
double precision, dimension(3) :: center
integer :: pointcount, trianglecount
double precision, dimension(:,:), allocatable :: pointchain
double precision, dimension(:,:,:), allocatable :: trianglechain
end type singleinfo
contains
subroutine cylindermeshing(r, h, cylinderinfo)
implicit none
double precision :: r, h
type(singleinfo) :: cylinderinfo
integer :: polyedge=60
double precision, dimension(:,:), allocatable :: point
double precision :: dtheta
integer :: meshi
dtheta=2*pi/real(polyedge)
cylinderinfo%volume=(0.5d0*polyedge*sin(dtheta)*r**2)*h
cylinderinfo%center=(/ 0.0d0, 0.0d0, 0.5d0*h /)
cylinderinfo%pointcount=2*polyedge
cylinderinfo%trianglecount=4*polyedge
allocate(point(2,polyedge+1) )
do meshi=1, polyedge, 1
point(1,meshi)=r*cos( (real(meshi)-1.0d0)*dtheta)
point(2,meshi)=r*sin( (real(meshi)-1.0d0)*dtheta)
end do
point(:, polyedge+1)=point(:, 1)
do meshi=1, polyedge, 1
cylinderinfo%pointchain(1:2,meshi)=point(1:2,meshi)
cylinderinfo%pointchain(3,meshi)=0.0d0
cylinderinfo%pointchain(1:2,polyedge+meshi)=point(1:2,meshi)
cylinderinfo%pointchain(3,polyedge+meshi)=h
end do
end subroutine cylindermeshing
function thirddet(deta)
double precision, dimension(3,3) :: deta
double precision :: thirddet
thirddet=deta(1,1)*(deta(2,2)*deta(3,3)-deta(3,2)*deta(2,3)) &
& -deta(2,1)*(deta(1,2)*deta(3,3)-deta(3,2)*deta(1,3)) &
& +deta(3,1)*(deta(1,2)*deta(2,3)-deta(2,2)*deta(1,3))
end function thirddet
end module hydromodelUtil
#include <iostream>
struct singleinfo{
int controlno;
int unittype;
int solid;
double coearea;
double volume;
double center[3];
int pointcount , trianglecount;
};
extern "C" {
void cylindermeshing( double & , double & , struct singleinfo * );
double thirddet( double * );
}
using namespace std;
int main()
{
struct singleinfo cylinderinfo;
double r = 3.0;
double h = 4.0;
cylinderinfo.controlno = 1;
cylinderinfo.unittype = 2;
cylinderinfo.solid = 3;
cylinderinfo.coearea = 4;
cylinderinfo.volume = 5;
cylinderinfo.unittype = 6;
cylinderinfo.pointcount = 7;
cylinderinfo.trianglecount = 8;
cylinderinfo.center[0] = 11;
cylinderinfo.center[1] = 11;
cylinderinfo.center[2] = 11;
cylindermeshing(r, h, &cylinderinfo);
double deta[3][3];
for (int i = 0; i < 3; i++){
for (int j = 0; j < 3; j++){
deta[j] = j*4 + i;
}
}
cout << thirddet( &deta[0][0] );
}
module hydromodelUtil
implicit none
double precision, parameter :: pi=3.141593d0
type , Bind( C ) :: singleinfo
integer :: controlno
integer :: unittype
integer :: solid
double precision :: coearea
double precision :: volume
double precision, dimension(3) :: center
integer :: pointcount, trianglecount
end type singleinfo
contains
subroutine cylindermeshing(r, h, cylinderinfo) Bind(C,Name="cylindermeshing")
implicit none
double precision :: r, h
type(singleinfo) :: cylinderinfo
write(*,*) r , h , cylinderinfo
end subroutine cylindermeshing
function thirddet(deta) Bind( C , Name = "thirddet" )
double precision, dimension(3,3) :: deta
double precision :: thirddet
thirddet=deta(1,1)*(deta(2,2)*deta(3,3)-deta(3,2)*deta(2,3)) &
& -deta(2,1)*(deta(1,2)*deta(3,3)-deta(3,2)*deta(1,3)) &
& +deta(3,1)*(deta(1,2)*deta(2,3)-deta(2,2)*deta(1,3))
end function thirddet
end module hydromodelUtil
kyra 发表于 2017-7-13 07:51
module中的函数,和普通的外部函数一样的。直接写 Bind( C , Name ) 就可以了。
你目前的设计,最难的地方 ...
捕获.PNG (25.36 KB, 下载次数: 1207)
kyra 发表于 2017-7-12 21:03
1. 我的代码是通用代码。不分动态库,静态库。
2. 用静态库的话,fortran编译得到obj或lib文件,加入C++的 ...
kyra 发表于 2017-7-12 21:03
1. 我的代码是通用代码。不分动态库,静态库。
2. 用静态库的话,fortran编译得到obj或lib文件,加入C++的 ...
pasuka 发表于 2017-7-13 16:02
为啥不能先看看ivf帮助文档和范例呢?
Intel® Fortran Compiler XE 12.1 User and Reference GuidesMixed ...
cfortran 发表于 2017-7-13 16:19
嗯 也在看modern fortran explained 这本书上的介绍 无奈英语渣的不行 只能一个词一个词的查。。。 ...
pasuka 发表于 2017-7-13 16:22
ivf帮助文档啃不动,ivf自带的sample 代码总归看得懂吧?!
cfortran 发表于 2017-7-13 15:58
链接时出现错误error LNK1104:无法打开文件‘ifconsol.lib’
我在附加依赖项中添加ifconsol.lib后还是不 ...
欢迎光临 Fortran Coder (http://bbs.fcode.cn/) | Powered by Discuz! X3.2 |