Statistiques
| Révision :

root / src / Decomp_frag.f90 @ 12

Historique | Voir | Annoter | Télécharger (5,07 ko)

1 1 pfleura2
!This subroutines decomposes a connectivity list into fragments.
2 1 pfleura2
SUBROUTINE Decomp_Frag(na,ListConnect,ListAt,nbfrag,Fragment,NbAtFrag,FragAt)
3 1 pfleura2
4 12 pfleura2
!----------------------------------------------------------------------
5 12 pfleura2
!  Copyright 2003-2014 Ecole Normale Supérieure de Lyon,
6 12 pfleura2
!  Centre National de la Recherche Scientifique,
7 12 pfleura2
!  Université Claude Bernard Lyon 1. All rights reserved.
8 12 pfleura2
!
9 12 pfleura2
!  This work is registered with the Agency for the Protection of Programs
10 12 pfleura2
!  as IDDN.FR.001.100009.000.S.P.2014.000.30625
11 12 pfleura2
!
12 12 pfleura2
!  Authors: P. Fleurat-Lessard, P. Dayal
13 12 pfleura2
!  Contact: optnpath@gmail.com
14 12 pfleura2
!
15 12 pfleura2
! This file is part of "Opt'n Path".
16 12 pfleura2
!
17 12 pfleura2
!  "Opt'n Path" is free software: you can redistribute it and/or modify
18 12 pfleura2
!  it under the terms of the GNU Affero General Public License as
19 12 pfleura2
!  published by the Free Software Foundation, either version 3 of the License,
20 12 pfleura2
!  or (at your option) any later version.
21 12 pfleura2
!
22 12 pfleura2
!  "Opt'n Path" is distributed in the hope that it will be useful,
23 12 pfleura2
!  but WITHOUT ANY WARRANTY; without even the implied warranty of
24 12 pfleura2
!
25 12 pfleura2
!  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
26 12 pfleura2
!  GNU Affero General Public License for more details.
27 12 pfleura2
!
28 12 pfleura2
!  You should have received a copy of the GNU Affero General Public License
29 12 pfleura2
!  along with "Opt'n Path". If not, see <http://www.gnu.org/licenses/>.
30 12 pfleura2
!
31 12 pfleura2
! Contact The Office of Technology Licensing, valorisation@ens-lyon.fr,
32 12 pfleura2
! for commercial licensing opportunities.
33 12 pfleura2
!----------------------------------------------------------------------
34 12 pfleura2
35 1 pfleura2
  Use Path_module, only : NMaxL
36 1 pfleura2
  Use Io_module
37 1 pfleura2
38 1 pfleura2
  IMPLICIT NONE
39 1 pfleura2
40 1 pfleura2
  INTEGER(KINT), INTENT(IN) :: na
41 1 pfleura2
  INTEGER(KINT), INTENT(IN) :: ListConnect(na,0:NMaxL)
42 1 pfleura2
  LOGICAL,       INTENT(IN) :: ListAt(na)
43 1 pfleura2
  INTEGER(KINT), INTENT(OUT) :: NbFrag,Fragment(na),NbAtFrag(na),FragAt(na,na)
44 1 pfleura2
45 2 pfleura2
  INTEGER(KINT) :: i, j, iat, jat
46 1 pfleura2
  INTEGER(KINT) :: IdxFrag, IdxtoDo, IFrag,IaFaire
47 1 pfleura2
  INTEGER(KINT), ALLOCATABLE :: ToDo(:)
48 1 pfleura2
49 1 pfleura2
  LOGICAL :: Debug
50 1 pfleura2
51 1 pfleura2
  INTERFACE
52 1 pfleura2
     function valid(string) result (isValid)
53 1 pfleura2
       CHARACTER(*), intent(in) :: string
54 1 pfleura2
       logical                  :: isValid
55 1 pfleura2
     END function VALID
56 1 pfleura2
  END INTERFACE
57 1 pfleura2
58 1 pfleura2
59 12 pfleura2
  debug=valid('decompfrag').OR.valid('Decomp_frag')
60 12 pfleura2
  if (debug) Call Header('Entering DecomFrag')
61 1 pfleura2
  !     We analyse the connectivity in terms of fragments
62 1 pfleura2
  ALLOCATE(ToDo(na))
63 1 pfleura2
64 1 pfleura2
  Fragment=0
65 1 pfleura2
  ToDo=0
66 1 pfleura2
  IdxFrag=0
67 1 pfleura2
  NbFrag=0
68 1 pfleura2
  NbAtFrag=0
69 1 pfleura2
  Fragment=0
70 1 pfleura2
  FragAt=0
71 1 pfleura2
72 1 pfleura2
  DO I=1,na
73 1 pfleura2
     IdxToDo=1
74 1 pfleura2
     ToDo(IdxToDo)=0
75 1 pfleura2
76 1 pfleura2
     if (debug) WRITE(*,*) 'Treating atom I, fragment(I)',I,Fragment(I)
77 1 pfleura2
     IF (ListAt(I).OR.(ListConnect(I,0).NE.0)) THEN
78 1 pfleura2
        IF (Fragment(I).EQ.0) THEN
79 1 pfleura2
           IdxFrag=IdxFrag+1
80 1 pfleura2
           NbFrag=NbFrag+1
81 1 pfleura2
           IFrag=IdxFrag
82 1 pfleura2
           Fragment(I)=IFrag
83 1 pfleura2
           NbAtFrag(IFrag)=NbAtFrag(IFrag)+1
84 1 pfleura2
           FragAt(IFrag,NbAtFrag(IFrag))=I
85 1 pfleura2
        ELSE
86 1 pfleura2
           IFrag=Fragment(I)
87 1 pfleura2
        END IF
88 1 pfleura2
        DO J=1,ListConnect(I,0)
89 1 pfleura2
           Iat=ListConnect(I,J)
90 1 pfleura2
           IF ((Fragment(Iat).NE.0).AND.(Fragment(Iat).NE.IFrag)) THEN
91 1 pfleura2
              WRITE(*,*) 'Error : Atoms ',I,' and ',Iat
92 1 pfleura2
              WRITE(*,*) 'are linked, but belongs to fragments ',IFrag,' and ',Fragment(Iat)
93 1 pfleura2
              STOP
94 1 pfleura2
           END IF
95 1 pfleura2
           IF (Fragment(Iat).EQ.0) THEN
96 1 pfleura2
              ToDo(IdxToDo)=Iat
97 1 pfleura2
              Fragment(Iat)=IFrag
98 1 pfleura2
              NbAtFrag(IFrag)=NbAtFrag(IFrag)+1
99 1 pfleura2
              FragAt(IFrag,NbAtFrag(IFrag))=Iat
100 1 pfleura2
              IdxToDo=IdxToDo+1
101 1 pfleura2
           END IF
102 1 pfleura2
        END DO
103 1 pfleura2
        ToDo(IdxToDo)=0
104 1 pfleura2
105 1 pfleura2
        If (debug) WRITE(*,*) 'ToDo:',ToDo(1:IdxToDo)
106 1 pfleura2
        If (debug) WRITE(*,*) 'IFrag=',IFrag
107 1 pfleura2
108 1 pfleura2
        IAfaire=1
109 1 pfleura2
110 1 pfleura2
        DO WHILE (ToDo(IAfaire).NE.0)
111 1 pfleura2
           Iat=ToDo(IaFaire)
112 1 pfleura2
           IF (ListAt(I).OR.(ListConnect(I,0).NE.0)) THEN
113 1 pfleura2
              if (debug) WRITE(*,*) 'ToDo treating ',Iat
114 1 pfleura2
              IF (Fragment(Iat).EQ.0) THEN
115 1 pfleura2
                 WRITE(*,*) 'Error: Atom ',Iat,' does not belong to any fragment !'
116 1 pfleura2
                 STOP
117 1 pfleura2
              END IF
118 1 pfleura2
119 1 pfleura2
              DO J=1,ListConnect(Iat,0)
120 1 pfleura2
                 Jat=ListConnect(Iat,J)
121 1 pfleura2
                 IF ((Fragment(ListConnect(Iat,J)).NE.0).AND.(Fragment(ListConnect(Iat,J)).NE.IFrag)) THEN
122 1 pfleura2
                    WRITE(*,*) 'Error: Atoms ',Iat,' and ',ListConnect(Iat,J)
123 1 pfleura2
                    WRITE(*,*) 'are linked, but belongs to fragments ',IFrag,' and ',Fragment(ListConnect(Iat,J))
124 1 pfleura2
                    STOP
125 1 pfleura2
                 END IF
126 1 pfleura2
                 IF (Fragment(Jat).EQ.0) THEN
127 1 pfleura2
                    ToDo(IdxToDo)=ListConnect(Iat,J)
128 1 pfleura2
                    Fragment(Jat)=IFrag
129 1 pfleura2
                    NbAtFrag(IFrag)=NbAtFrag(IFrag)+1
130 1 pfleura2
                    FragAt(IFrag,NbAtFrag(IFrag))=Jat
131 1 pfleura2
                    IdxToDo=IdxToDo+1
132 1 pfleura2
                 END IF
133 1 pfleura2
              END DO
134 1 pfleura2
              ToDo(IdxToDo)=0
135 1 pfleura2
              If (debug) WRITE(*,*) 'IAfaire, IdxToDo,ToDo :',IAfaire,IdxToDo,' == ',ToDo(IaFaire+1:IdxToDo)
136 1 pfleura2
              IAFaire=IAFaire+1
137 1 pfleura2
           END IF
138 1 pfleura2
        END DO
139 1 pfleura2
     END IF
140 1 pfleura2
  END DO
141 1 pfleura2
142 1 pfleura2
  IF (debug) THEN
143 1 pfleura2
     WRITE(*,*) 'DECOMP_FRAG: I found ',NbFrag, 'fragments'
144 1 pfleura2
     DO I=1,NbFrag
145 1 pfleura2
        WRITE(*,*) 'Fragment ', i,' with ',NbAtFrag(I),' atoms.'
146 1 pfleura2
        WRITE(*,*) "FragAt:",(FragAt(I,j),j=1,NbAtFrag(I))
147 1 pfleura2
     END DO
148 1 pfleura2
  END IF
149 1 pfleura2
150 12 pfleura2
  if (debug) Call Header('DecomFrag over')
151 1 pfleura2
152 1 pfleura2
END SUBROUTINE Decomp_Frag