atomes 1.1.16
atomes: an atomic scale modeling tool box
Loading...
Searching...
No Matches
chemistry.F90
Go to the documentation of this file.
1! This file is part of the 'atomes' software.
2!
3! 'atomes' is free software: you can redistribute it and/or modify it under the terms
4! of the GNU Affero General Public License as published by the Free Software Foundation,
5! either version 3 of the License, or (at your option) any later version.
6!
7! 'atomes' is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
8! without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
9! See the GNU General Public License for more details.
10!
11! You should have received a copy of the GNU Affero General Public License along with 'atomes'.
12! If not, see <https://www.gnu.org/licenses/>
13!
14! Copyright (C) 2022-2024 by CNRS and University of Strasbourg
15!
20
21INTEGER (KIND=c_int) FUNCTION chemistry () bind (C,NAME='chemistry_')
22
23!
24! Density, number density, concentrations, empirical formula
25!
26
27USE parameters
28
29IMPLICIT NONE
30
31INTEGER :: ref1, ref2, ref3
32INTEGER, DIMENSION(:), ALLOCATABLE :: index_form ! Formula index
33INTEGER, DIMENSION(:), ALLOCATABLE :: refp
34
35LOGICAL :: unclear, unfrac
36
37!
38! Determination of the empirical formula
39! Détermination de la formule brute
40!
41if (allocated(index_form)) deallocate(index_form)
42allocate(index_form(nsp), stat=err)
43if (err .ne. 0) then
44 call show_error ("Impossible to allocate memory"//char(0), &
45 "Function: chemistry"//char(0), "Table: INDEX_FORM"//char(0))
46 chemistry = 0
47 goto 001
48endif
49
50if (allocated(refp)) deallocate(refp)
51allocate(refp(nsp), stat=err)
52if (err .ne. 0) then
53 call show_error ("Impossible to allocate memory"//char(0), &
54 "Function: chemistry"//char(0), "Table: REFP"//char(0))
55 chemistry = 0
56 goto 001
57endif
58
59do i=1, nsp
60 refp(i)= nbspbs(i)
61enddo
62
63do i=1, nsp
64
65 if (i .eq. 1)then
66
67 ref1=nbspbs(i)
68 ref2=i
69
70 else
71
72 ref3=ref1
73 ref1=min(nbspbs(i),ref1)
74 if (ref3 .ne. ref1) ref2=i
75
76 endif
77
78enddo
79
80unclear=.true.
81unfrac=.false.
82l=1
83do while (unclear)
84
85 unclear=.false.
86 do i=1, nsp
87 if (i .ne. ref2) then
88 if (.not.unfrac) then
89 m=1
90 do while (mod(m*refp(i),ref1).ne.0 .and. m.lt.ref1)
91 m=m+1
92 enddo
93 if (mod(m*refp(i),ref1) .eq. 0) then
94 index_form(i)=m*refp(i)/ref1
95 unclear=.true.
96 else
97 index_form(i)=nbspbs(i)
98 unclear=.true.
99 unfrac=.true.
100 endif
101 else
102 index_form(i)=nbspbs(i)
103 endif
104 endif
105 enddo
106 if (unfrac) then
107 index_form(ref2)=nbspbs(ref2)
108 else
109 index_form(ref2)=refp(ref2)/nbspbs(ref2)
110 endif
111 if (unclear) then
112 unclear=.false.
113 do i=1, nsp-1
114 do j=i+1, nsp
115 y=dble(index_form(i))/dble(index_form(j))
116 z=dble(nbspbs(i))/dble(nbspbs(j))
117 if (y .ne. z) unclear=.true.
118 enddo
119 enddo
120 if (unclear) then
121 refp=refp/l
122 l=l+1
123 refp=refp*l
124 endif
125 endif
126enddo
127
128! To send_chem_info_
129call send_chem_info (index_form)
130
131chemistry = 1
132
133001 continue
134
135if (allocated(index_form)) deallocate(index_form)
136if (allocated(refp)) deallocate(refp)
137
138END FUNCTION
integer(kind=c_int) function chemistry()
Definition chemistry.F90:22
#define min(a, b)
Definition global.h:81
void show_error(char *error, int val, GtkWidget *win)
show error message
Definition interface.c:293
integer, dimension(:), allocatable nbspbs
double precision z
integer err
double precision y
integer nsp