com.f90

来自「蒙特卡罗的一个程序分析 与大家分享 共同研究」· F90 代码 · 共 60 行

F90
60
字号

subroutine CenterOfMass( Length, X, Y, Z, TYPEg, Ngrs, MASS, xcom, ycom, zcom )

implicit none

! This routine calculates the center of mass of a chain of molecules.

! Length is the number of beads in the molecule.
! X, Y, and Z are the coordinates of the molecules.
! TYPEg contains the group identity of each molecule.

integer, intent(in)								:: Length
real, dimension(Length), intent(in)				:: X, Y, Z
integer, dimension(Length), intent(in)			:: TYPEg

! Ngrs is the number of groups within the molecule.
! MASS is the mass of each group.

integer, intent(in)								:: Ngrs
real, dimension(Ngrs), intent(in)				:: MASS

! xcom, ycom, and zcom are the coordinates of the center of mass of the molecule.

real, intent(out)								:: xcom, ycom, zcom

! Local Variables

integer											:: i
real											:: MassSum
real											:: XMSum, YMSum, ZMSum

MassSum = 0.0
XMSum = 0.0
YMSum = 0.0
ZMSum = 0.0

do i = 1, Length
	
	MassSum = MassSum + MASS( TYPEg(i) )

	XMSum = XMSum + X(i) * MASS( TYPEg(i) )
	YMSum = YMSum + Y(i) * MASS( TYPEg(i) )
	ZMSum = ZMSum + Z(i) * MASS( TYPEg(i) )

end do

xcom = XMSum / MassSum
ycom = YMSum / MassSum
zcom = ZMSum / MassSum

return

end	subroutine CenterOfMass






⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?