Work : correction m_R et calcul de D, correction pattern match ER

This commit is contained in:
Yann Damour 2020-05-16 11:09:53 +02:00
parent 2fe18f3914
commit 9af99117c1

View File

@ -1024,13 +1024,13 @@
"$A^r_{12} = \\langle \\phi_1 | \\bar r | \\phi_2 \\rangle $\n", "$A^r_{12} = \\langle \\phi_1 | \\bar r | \\phi_2 \\rangle $\n",
"$*\\langle \\phi_1 | \\bar r | \\phi_2 \\rangle $\n", "$*\\langle \\phi_1 | \\bar r | \\phi_2 \\rangle $\n",
"$- \\frac {1}{4}(\\langle \\phi_1 | \\bar r | \\phi_1 \\rangle $\n", "$- \\frac {1}{4}(\\langle \\phi_1 | \\bar r | \\phi_1 \\rangle $\n",
"$- \\langle \\phi_2 | \\bar r | \\phi_2 \\rangle * \\langle \\phi_1 | \\bar r | \\phi_1 \\rangle$\n", "$- \\langle \\phi_2 | \\bar r | \\phi_2 \\rangle . \\langle \\phi_1 | \\bar r | \\phi_1 \\rangle$\n",
"$- \\langle \\phi_2 | \\bar r | \\phi_2 \\rangle)$\n", "$- \\langle \\phi_2 | \\bar r | \\phi_2 \\rangle)$\n",
"\n", "\n",
"Et \n", "Et \n",
"\n", "\n",
"$B^r_{12} = (\\langle \\phi_1 | \\bar r | \\phi_1 \\rangle - \\langle \\phi_2 | \\bar r | \\phi_2 \\rangle)$\n", "$B^r_{12} = (\\langle \\phi_1 | \\bar r | \\phi_1 \\rangle - \\langle \\phi_2 | \\bar r | \\phi_2 \\rangle)$\n",
"$ * \\langle \\phi_1 | \\bar r | \\phi_2 \\rangle $\n", "$ . \\langle \\phi_1 | \\bar r | \\phi_2 \\rangle $\n",
"\n", "\n",
"Avec \n", "Avec \n",
"\n", "\n",
@ -1038,7 +1038,7 @@
"\n", "\n",
"$B^r_{12}=B^x_{12} + B^y_{12} + B^z_{12}$\n", "$B^r_{12}=B^x_{12} + B^y_{12} + B^z_{12}$\n",
"\n", "\n",
"Et le critère à minimiser est :\n", "Et le critère à maximiser est :\n",
"\n", "\n",
"$D= \\sum_i < \\phi_i | r | \\phi_i >$\n", "$D= \\sum_i < \\phi_i | r | \\phi_i >$\n",
"\n", "\n",
@ -1491,6 +1491,7 @@
"outputs": [], "outputs": [],
"source": [ "source": [
"(* Fonction de calcul de tous les alpha ER -> Matrice, dépend de m_a12, m_b12 qui dépendent de m_C *)\n", "(* Fonction de calcul de tous les alpha ER -> Matrice, dépend de m_a12, m_b12 qui dépendent de m_C *)\n",
"(*\n",
"let f_alpha m_C =\n", "let f_alpha m_C =\n",
"\n", "\n",
" let n_mo = Mat.dim2 m_C in\n", " let n_mo = Mat.dim2 m_C in\n",
@ -1573,7 +1574,8 @@
"\n", "\n",
"(*********************)\n", "(*********************)\n",
"\n", "\n",
"f_alpha m_C;;\n" "f_alpha m_C;;\n",
"*)"
] ]
}, },
{ {
@ -1722,20 +1724,18 @@
" (Mat.init_cols n_mo n_mo ( fun i j ->\n", " (Mat.init_cols n_mo n_mo ( fun i j ->\n",
" if i= j then 0.\n", " if i= j then 0.\n",
" else 0.25 *. (acos(-. m_a12.{i,j} /. sqrt((m_a12.{i,j}**2.) +. (m_b12.{i,j}**2. ))))\n", " else 0.25 *. (acos(-. m_a12.{i,j} /. sqrt((m_a12.{i,j}**2.) +. (m_b12.{i,j}**2. ))))\n",
" ),v_d);;\n", " ),Vec.sum v_d);;\n",
"\n", "\n",
"(*********************)\n", "(*********************)\n",
"\n", "\n",
"f_alpha m_C;;\n", "f_alpha m_C;;\n",
"(*\n",
"let m_alpha , s_D = f_alpha m_C;;\n",
"\n", "\n",
"let m_alpha , v_d = f_alpha m_C;;\n", "*)\n",
"\n", "\n",
"\n", "\n",
"let s_D m_C = \n", "\n"
"Vec.sum v_d ;;\n",
"\n",
"\n",
"s_D m_C;;\n"
] ]
}, },
{ {
@ -1790,7 +1790,7 @@
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
"\n", "(*\n",
"(* Calcul de D -> critère à maximiser dans ER*)\n", "(* Calcul de D -> critère à maximiser dans ER*)\n",
"let s_D m_C = \n", "let s_D m_C = \n",
" let v_D = \n", " let v_D = \n",
@ -1809,7 +1809,8 @@
" ) i j\n", " ) i j\n",
" );;\n", " );;\n",
"let toto = s_D m_C;;\n", "let toto = s_D m_C;;\n",
"toto *. 6.;;\n" "toto *. 6.;;\n",
"*)"
] ]
}, },
{ {
@ -1922,10 +1923,12 @@
" in\n", " in\n",
" let d_boys = d_boys m_C\n", " let d_boys = d_boys m_C\n",
" in\n", " in\n",
" let alpha_er = f_alpha m_C\n", " let alpha_er , d_er = f_alpha m_C\n",
" in\n",
" (*let alpha_er = mat_alpha m_C\n",
" in\n", " in\n",
" let d_er = s_D m_C\n", " let d_er = s_D m_C\n",
" in\n", " in*)\n",
" let alpha methode =\n", " let alpha methode =\n",
" match methode with \n", " match methode with \n",
" | \"Boys\"\n", " | \"Boys\"\n",
@ -2045,10 +2048,11 @@
" else new_m_alpha alpha_m m_C (n_rec_alpha-1);;\n", " else new_m_alpha alpha_m m_C (n_rec_alpha-1);;\n",
"\n", "\n",
"(*************************)\n", "(*************************)\n",
"\n", "(*\n",
"let m_alpha = f_alpha m_C\n", "let m_alpha = f_alpha m_C\n",
"let alphaij = new_m_alpha m_alpha m_C 3;;\n", "let alphaij = new_m_alpha m_alpha m_C 3;;\n",
"alphaij.alpha_max;;\n" "alphaij.alpha_max;;\n",
"*)"
] ]
}, },
{ {
@ -2057,43 +2061,21 @@
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
"let f_id loc_deloc =\n",
" let id_loc = Mat.identity 2\n",
" in \n",
" let id_deloc = Mat.init_cols 2 2 (fun i j -> \n",
" if i = j \n",
" then -.1.\n",
" else 0. )\n",
" in\n",
" let toto loc_deloc = \n",
" match loc_deloc with \n",
" | \"loc\" -> id_loc\n",
" | \"deloc\" -> id_deloc\n",
" | _ -> invalid_arg \"Unknown method, please enter loc or deloc\"\n",
" \n",
"in toto loc_deloc;;\n",
"\n",
"f_id \"deloc\";;\n",
"\n",
"(* Matrice de rotation 2 par 2 *)\n", "(* Matrice de rotation 2 par 2 *)\n",
"let f_R alpha loc_deloc =\n", "let f_R alpha =\n",
" let m_id = f_id loc_deloc\n",
" in\n",
" let m_R = \n",
" Mat.init_cols 2 2 (fun i j -> \n", " Mat.init_cols 2 2 (fun i j -> \n",
" if i=j \n", " if i=j \n",
" then cos alpha\n", " then cos alpha\n",
" else if i>j \n", " else if i>j \n",
" then sin alpha \n", " then sin alpha \n",
" else -. sin alpha )\n", " else -. sin alpha )\n",
" in gemm m_id m_R;;\n",
"\n", "\n",
"(*************************)\n", "(*************************)\n",
"\n", "\n",
"\n", "(*\n",
"let alpha = alphaij.alpha_max;; (* Fonction -> constante *) \n", "let alpha = alphaij.alpha_max;; (* Fonction -> constante *) \n",
"f_R alpha \"loc\";;\n", "f_R alpha;;\n",
"f_R alpha \"deloc\";;\n" "*)\n"
] ]
}, },
{ {
@ -2181,7 +2163,9 @@
" in\n", " in\n",
" let n_ao = Mat.dim1 m_C\n", " let n_ao = Mat.dim1 m_C\n",
" in\n", " in\n",
" Printf.printf \"%i %i\\n\" n_mo n_ao;\n", " \n",
" (*Printf.printf \"%i %i\\n\" n_mo n_ao;*)\n",
" \n",
"Mat.init_cols n_ao n_mo (fun i j -> \n", "Mat.init_cols n_ao n_mo (fun i j -> \n",
" if j=indice_i \n", " if j=indice_i \n",
" then m_Ksi.{i,1}\n", " then m_Ksi.{i,1}\n",
@ -2298,7 +2282,7 @@
"(* Localisation de Edminstion ou de Boys *)\n", "(* Localisation de Edminstion ou de Boys *)\n",
"\n", "\n",
"(* Calcul de la nouvelle matrice des coefficient après n rotation d'orbitales *)\n", "(* Calcul de la nouvelle matrice des coefficient après n rotation d'orbitales *)\n",
"let rec final_m_C m_C methode loc_deloc epsilon n prev_critere_D cc=\n", "let rec final_m_C m_C methode epsilon n prev_critere_D cc=\n",
"\n", "\n",
" Printf.printf \"%i\\n%!\" n;\n", " Printf.printf \"%i\\n%!\" n;\n",
"\n", "\n",
@ -2309,7 +2293,7 @@
" else\n", " else\n",
" \n", " \n",
" (* Fonction de calcul de la nouvelle matrice de coef après rotation d'un angle alpha *)\n", " (* Fonction de calcul de la nouvelle matrice de coef après rotation d'un angle alpha *)\n",
" let new_m_C m_C methode loc_deloc =\n", " let new_m_C m_C methode =\n",
" \n", " \n",
" (* Fonction de pattern matching en fonction de la méthode *)\n", " (* Fonction de pattern matching en fonction de la méthode *)\n",
" let alphad = m_alpha_d methode m_C \n", " let alphad = m_alpha_d methode m_C \n",
@ -2352,10 +2336,10 @@
" (*Printf.printf \"%i %i\\n%!\" indice_i indice_j;*)\n", " (*Printf.printf \"%i %i\\n%!\" indice_i indice_j;*)\n",
" \n", " \n",
" (* Matrice de rotation *)\n", " (* Matrice de rotation *)\n",
" let m_R = f_R alpha loc_deloc (* Fonction -> constante *)\n", " let m_R = f_R alpha (* Fonction -> constante *)\n",
" in\n", " in\n",
"\n", "\n",
" Util.debug_matrix \"m_R\" m_R;\n", " (*Util.debug_matrix \"m_R\" m_R;*)\n",
"\n", "\n",
" (* Matrice qui va subir la rotation *)\n", " (* Matrice qui va subir la rotation *)\n",
" let m_Ksi = f_Ksi indice_i indice_j m_C (* Fonction -> constante *)\n", " let m_Ksi = f_Ksi indice_i indice_j m_C (* Fonction -> constante *)\n",
@ -2390,7 +2374,7 @@
" (* Matrice après rotation *)\n", " (* Matrice après rotation *)\n",
" ( Mat.add m_Psi_tilde m_interm, critere_D)\n", " ( Mat.add m_Psi_tilde m_interm, critere_D)\n",
" in\n", " in\n",
" let m_new_m_C , critere_D = new_m_C m_C methode loc_deloc(* Fonction -> constante *)\n", " let m_new_m_C , critere_D = new_m_C m_C methode (* Fonction -> constante *)\n",
" in\n", " in\n",
" let diff = prev_critere_D -. critere_D +. 1.\n", " let diff = prev_critere_D -. critere_D +. 1.\n",
" \n", " \n",
@ -2403,7 +2387,7 @@
" then m_new_m_C\n", " then m_new_m_C\n",
" else\n", " else\n",
"\n", "\n",
"final_m_C m_new_m_C methode loc_deloc epsilon (n-1) critere_D cc;;" "final_m_C m_new_m_C methode epsilon (n-1) critere_D cc;;"
] ]
}, },
{ {
@ -2415,7 +2399,7 @@
"(* Calcul *)\n", "(* Calcul *)\n",
"(* Fonction / Matrice des coef / Méthode(\"Boys\" ou \"ER\") / Localisation ou non (\"loc\" ou \"deloc\"/ Pas(<=1.) / Nombre d'itérations max / \n", "(* Fonction / Matrice des coef / Méthode(\"Boys\" ou \"ER\") / Localisation ou non (\"loc\" ou \"deloc\"/ Pas(<=1.) / Nombre d'itérations max / \n",
"0. (valeur de D pour initier la boucle) / critère de convergence sur D*)\n", "0. (valeur de D pour initier la boucle) / critère de convergence sur D*)\n",
"let new_m = final_m_C m_C \"ER\" \"loc\" 1. 5 0. 10e-7;;\n" "let new_m = final_m_C m_C \"ER\" 1. 5 0. 10e-7;;\n"
] ]
}, },
{ {
@ -2424,7 +2408,7 @@
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
"final_m_C new_m \"ER\" \"deloc\" 1. 5 0. 10e-7;;\n" "final_m_C new_m \"ER\" 1. 5 0. 10e-7;;\n"
] ]
}, },
{ {