Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generalized freeze subroutine #108

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 20 additions & 9 deletions src/constraints_mod.F90
Original file line number Diff line number Diff line change
Expand Up @@ -64,18 +64,17 @@ MODULE CONSTRAINTS_MOD
!! The file is formated as follows:
!!
!! 3 #Number of freezed atoms
!! 10 #We are freezing all the coordinates of atom 10
!! 20 #We are freezing all the coordinates of atom 10
!! 40 #We are freezing all the coordinates of atom 10
!! \todo Generalize this to have constrains to different coordinates.
!! 10 1 0 0 #We are freezing the x coordinate of atom 10
!! 20 1 1 1 #We are freezing all the coordinates of atom 10
!! 40 0 0 1 #We are freezing the z coordinate of atom 10
!!
!! \param FTOT Total forces. FTOT(1,3) gives the force on x direction for atom 3.
!! \param VEL Velocities. VEL(1,3) gives the velocity on x direction for atom 3.
!!
SUBROUTINE FREEZE_ATOMS(FTOT,VEL)

INTEGER, SAVE :: NFREEZE
INTEGER, SAVE, ALLOCATABLE :: FREEZEID(:)
INTEGER, SAVE, ALLOCATABLE :: FREEZEID(:), FREEZEIDX(:), FREEZEIDY(:), FREEZEIDZ(:)
INTEGER :: I
REAL(DP), OPTIONAL, INTENT(INOUT) :: VEL(:,:)
REAL(DP), INTENT(INOUT) :: FTOT(:,:)
Expand All @@ -84,20 +83,32 @@ SUBROUTINE FREEZE_ATOMS(FTOT,VEL)
OPEN(444,FILE="freeze.in")
READ(444,*)NFREEZE
ALLOCATE(FREEZEID(NFREEZE))
ALLOCATE(FREEZEIDX(NFREEZE))
ALLOCATE(FREEZEIDY(NFREEZE))
ALLOCATE(FREEZEIDZ(NFREEZE))
DO I = 1,NFREEZE
READ(444,*)FREEZEID(I)
READ(444,*)FREEZEID(I), FREEZEIDX(I), FREEZEIDY(I), FREEZEIDZ(I)
FREEZEIDX(I) = 1 - FREEZEIDX(I)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe add a check that FREEZEID[XYZ] is really in [0, 1]?

FREEZEIDY(I) = 1 - FREEZEIDY(I)
FREEZEIDZ(I) = 1 - FREEZEIDZ(I)
ENDDO
CLOSE(444)
ENDIF

IF(PRESENT(VEL))THEN
DO I = 1,NFREEZE
VEL(:,FREEZEID(I)) = 0.0d0
FTOT(:,FREEZEID(I)) = 0.0d0
VEL(1,FREEZEID(I)) = REAL(FREEZEIDX(I),DP)*VEL(1,FREEZEID(I))
FTOT(1,FREEZEID(I)) = REAL(FREEZEIDX(I),DP)*FTOT(1,FREEZEID(I))
VEL(2,FREEZEID(I)) = REAL(FREEZEIDY(I),DP)*VEL(2,FREEZEID(I))
FTOT(2,FREEZEID(I)) = REAL(FREEZEIDY(I),DP)*FTOT(2,FREEZEID(I))
VEL(3,FREEZEID(I)) = REAL(FREEZEIDZ(I),DP)*VEL(3,FREEZEIDZ(I))
FTOT(3,FREEZEID(I)) = REAL(FREEZEIDZ(I),DP)*FTOT(3,FREEZEID(I))
ENDDO
ELSE
DO I = 1,NFREEZE
FTOT(:,FREEZEID(I)) = 0.0d0
FTOT(1,FREEZEID(I)) = REAL(FREEZEIDX(I),DP)*FTOT(1,FREEZEID(I))
FTOT(2,FREEZEID(I)) = REAL(FREEZEIDY(I),DP)*FTOT(2,FREEZEID(I))
FTOT(3,FREEZEID(I)) = REAL(FREEZEIDZ(I),DP)*FTOT(3,FREEZEID(I))
ENDDO
ENDIF

Expand Down
6 changes: 3 additions & 3 deletions tests/freeze.in
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
3
1
2
3
1 1 1 1
2 1 1 1
3 1 1 1