문제

I just want to assign a name to particles in a configuration. E.g. I have e.g N=125 particle in a 3D cubic structure and I have two kinds of particles A and B. I want to use a random generator r=ran(0,1) and if r<0.5 then particle is A in the otherwise particle is B. and then I want to use A, B to compute other properties like energy and etc.

How can I do that?

this is my code to make a mixture configuration

    subroutine init_order(rx,ry,rz,n)
use LJ_POT
    implicit none

!assign initial position to the particles double precision rx(num),ry(num),rz(num) integer i,j,k,n real*8 u,ir1

open(10,file='conf.in',status='unknown')
ir1=19375.d0
n=0
    do i=1,nx
    do j=1,ny
     do k=1,nz
     n=n+1
     rx(n)=(dble(i)-0.5d0)*gsize
     ry(n)=(dble(j)-0.5d0)*gsize
     rz(n)=(dble(k)-0.5d0)*gsize

     call usran(ir1,u)
     if (u.le.0.5d0) then
        write(10,*) rx(n),ry(n),rz(n),'red'
     else if (u.gt.0.5d0) then
        write(10,*) rx(n),ry(n),rz(n),'blue'
     end if
     end do
    end do
    end do
    close(10)

175 format(4(f12.5)) return end subroutine

Which make this configuration for N=8:

0.75000000000000000 0.75000000000000000 0.75000000000000000 red

0.75000000000000000 0.75000000000000000 2.2500000000000000 blue

0.75000000000000000 2.2500000000000000 0.75000000000000000 blue

0.75000000000000000 2.2500000000000000 2.2500000000000000 blue

2.2500000000000000 0.75000000000000000 0.75000000000000000 blue

2.2500000000000000 0.75000000000000000 2.2500000000000000 red

2.2500000000000000 2.2500000000000000 0.75000000000000000 red

2.2500000000000000 2.2500000000000000 2.2500000000000000 red

도움이 되었습니까?

해결책

what you are describing calls for a derived type:

 type particle
 real x(3)
 character*4 color
 end type

declare an array of particle types:

 type particle p(1000)

then reference your coordinates as

 p(i)%x(j) = 0.

and color/name as:

 p(i)%color = 'red'

of course you could go old school and just use a separate array:

 real p(3,1000)
 integer color(1000)

 p(j,i)=0
 color(i)='red'
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top