- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Module ParticleOneModule
Implicit none
Type :: ParticleOne
Real(8) :: Vx,Vy,Vz
contains
procedure :: POPInit=>ParticleOnePositionInitialization
procedure :: POVInit=>ParticleOneVelocityInitialization
procedure :: POAInit=>ParticleOneAccelerationInitialization
procedure :: POWInit=>ParticleOneWeightInitialization
End Type ParticleOne
Type,extends(ParticleOne) :: ParticleOne1D
Real(8) :: X
contains
End Type ParticleOne1D
Type,extends(ParticleOne) :: ParticleOne2D
Real(8) :: X,Y
contains
End Type ParticleOne2D
Type,extends(ParticleOne) :: ParticleOne3D
Real(8) :: X,Y,Z
contains
End Type ParticleOne3D
Type,extends(ParticleOne) :: ParticleOne1DDI
Real(8) :: X,Ax
End Type ParticleOne1DDI
Type,extends(ParticleOne) :: ParticleOne2DDI
Real(8) :: X,Y,Ax,Ay
End Type ParticleOne2DDI
Type,extends(ParticleOne) :: ParticleOne3DDI
Real(8) :: X,Y,Z,Ax,Ay,Az
End Type ParticleOne3DDI
Type,extends(ParticleOne) :: ParticleOne1DC
Real(8) :: R,X,Y,W
End Type ParticleOne1DC
Type,extends(ParticleOne) :: ParticleOne2DC
Real(8) :: Z,R,X,Y,W
End Type ParticleOne2DC
contains
subroutine ParticleOnePositionInitialization(PO,X,Y,Z)
Class(ParticleOne), intent(inout) :: PO
Real(8),intent(in),optional :: X,Y,Z
Real(8) :: Theta,R,PI=3.1415926d0
Select Type(PO)
Type Is(ParticleOne1D)
PO%X=X
Type Is(ParticleOne2D)
PO%X=X
PO%Y=Y
Type Is(ParticleOne3D)
PO%X=X
PO%Y=Y
PO%Z=Z
Type Is(ParticleOne1DDI)
PO%X=X
Type Is(ParticleOne2DDI)
PO%X=X
PO%Y=Y
Type Is(ParticleOne3DDI)
PO%X=X
PO%Y=Y
PO%Z=Z
Type Is(ParticleOne1DC)
PO%R=X
Call RANDOM_NUMBER(R)
Theta=2.d0*PI*R
PO%X=Y*DCos(Theta)
PO%Y=Y*DSIn(Theta)
Type Is(ParticleOne2DC)
PO%Z=X
PO%R=Y
Call RANDOM_NUMBER(R)
Theta=2.d0*PI*R
PO%X=Y*DCos(Theta)
PO%Y=Y*DSIn(Theta)
END Select
end subroutine ParticleOnePositionInitialization
subroutine ParticleOneVelocityInitialization(PO,Vx,Vy,Vz)
Class(ParticleOne), intent(inout) :: PO
Real(8),intent(in),optional :: Vx,Vy,Vz
PO%Vx=Vx
PO%Vy=Vy
PO%Vz=Vz
end subroutine ParticleOneVelocityInitialization
subroutine ParticleOneAccelerationInitialization(PO,Ax,Ay,Az)
Class(ParticleOne), intent(inout) :: PO
Real(8),intent(in),optional :: Ax,Ay,Az
Select Type(PO)
Type Is(ParticleOne1DDI)
PO%Ax=Ax
Type Is(ParticleOne2DDI)
PO%Ax=Ax
PO%Ay=Ay
Type Is(ParticleOne3DDI)
PO%Ax=Ax
PO%Ay=Ay
PO%Az=Az
END Select
end subroutine ParticleOneAccelerationInitialization
subroutine ParticleOneWeightInitialization(PO,W)
Class(ParticleOne), intent(inout) :: PO
Real(8),intent(in) :: W
Select Type(PO)
Type Is(ParticleOne1DC)
PO%W=W
Type Is(ParticleOne2DC)
PO%W=W
END Select
end subroutine ParticleOneWeightInitialization
END Module ParticleOneModule
Module ParticleBundleModule
Use ParticleOneModule
Implicit none
Type :: ParticleBundle
Integer(4) :: NPar=0,NParNormal=1000
Real(8) :: Charge,Mass,Weight
Real(8) :: XFactor,VFactor
Real(8) :: Dx,Dt
Class(ParticleOne),Allocatable :: PO(:)
contains
End Type ParticleBundle
contains
subroutine ParticleBundlePositionInitialization(PB)
Type(ParticleBundle), intent(inout) :: PB
Real(8) :: X=1.d0,Y=2.0,Z=3.0
Integer(4) :: i,NPar=10
Do i=1,NPAR
Call PB%PO(i)%POPInit(X,Y)
ENd DO
end subroutine ParticleBundlePositionInitialization
END Module ParticleBundleModule
Program PIC_MCC_for_CCP
Use ParticleBundleModule
Implicit none
TYPE(ParticleBundle) :: PBGlobal
TYPE(ParticleOne2D) :: PBS(20)
!Allocate(PBGlobal%PO,source=PBS)
Allocate(ParticleOne1D::PBGlobal%PO(10))
Call ParticleBundlePositionInitialization(PBGlobal)
stop
end Program
I want to try some OOP features, so I want to have a Type, in which the type of some component will be dynamically allocated.I assumed with Class in the type particle bundle, PBGlobal%OS will be allocated as ParticleOne1D, but in two cases with source or type defined in the allocate, it still only allocate a array of ParticleOne. I think it is a bug of the compiler. Any one can helpl me with that problem? Thanks!
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I am not seeing incorrect behavior when this program is compiled with version 17.0.1. When ParticleOneInitializationPosition is called for each element of component PO, the SELECT TYPE correctly chooses the ParticleOne1D case. What are you seeing instead and which compiler version are you using?
Perhaps it would help if you instrumented the code with PRINT statements that show the path it's taking.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Dear Steve
Thanks a lot for the help and quick reply, I just found that that the debug can not show the PO%X and PO%Y correctly, but PO%X and PO%Y have been correctly allocated and valued. It is not a compiler bug. Thanks a lot!
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page