Work : Nouvelle boucle fonctionnelle
This commit is contained in:
parent
0e16ce0dca
commit
5111956422
261
Work.ipynb
261
Work.ipynb
@ -2110,7 +2110,266 @@
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": []
|
||||
"source": [
|
||||
"(* Localisation de Edminstion *)\n",
|
||||
"\n",
|
||||
"(* Définitions de base nécessaire pour la suite *)\n",
|
||||
"let ee_ints = AOBasis.ee_ints ao_basis;;\n",
|
||||
"let m_C = MOBasis.mo_coef mo_basis;;\n",
|
||||
"let n_ao = Mat.dim1 m_C ;;\n",
|
||||
"let n_mo = Mat.dim2 m_C ;;\n",
|
||||
"let sum a = \n",
|
||||
" Array.fold_left (fun accu x -> accu +. x) 0. a\n",
|
||||
" \n",
|
||||
"(******************************************************************************************************)\n",
|
||||
"\n",
|
||||
"(*Fonction général de calcul des intégrales*) \n",
|
||||
"let integral_general g i j =\n",
|
||||
"Array.map (fun a ->\n",
|
||||
" let v = \n",
|
||||
" Array.map (fun b ->\n",
|
||||
" let u = \n",
|
||||
" Array.map (fun e ->\n",
|
||||
" let t = Array.map (fun f ->\n",
|
||||
" (g a b e f i j) *. ERI.get_phys ee_ints a e b f\n",
|
||||
" ) (Util.array_range 1 n_ao)\n",
|
||||
" in sum t\n",
|
||||
" ) (Util.array_range 1 n_ao)\n",
|
||||
" in sum u\n",
|
||||
" ) (Util.array_range 1 n_ao)\n",
|
||||
" in sum v\n",
|
||||
") (Util.array_range 1 n_ao)\n",
|
||||
"|> sum \n",
|
||||
";;\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"type alphaij = {\n",
|
||||
" alpha_max : float;\n",
|
||||
" indice_ii : int;\n",
|
||||
" indice_jj : int;};;\n",
|
||||
" \n",
|
||||
"let n_rec_alpha = 10;;\n",
|
||||
"\n",
|
||||
"(******************************************************************************************************)\n",
|
||||
"\n",
|
||||
"let rec final_m_C m_C n =\n",
|
||||
"\n",
|
||||
"Printf.printf \"%i\\n%!\" n;\n",
|
||||
"(*\n",
|
||||
"Util.debug_matrix \"m_C\" m_C;\n",
|
||||
"*)\n",
|
||||
"\n",
|
||||
"if n == 0 then m_C\n",
|
||||
" else\n",
|
||||
"\n",
|
||||
"let new_m_C m_C =\n",
|
||||
"\n",
|
||||
" (* Fonction de calcul de tous les alpha -> Matrice, dépend de m_a12, m_b12 qui dépendent de m_C *)\n",
|
||||
" let f_alpha m_C =\n",
|
||||
"\n",
|
||||
" (* Fonction de calcul de toutes les intégrales B_12 -> Matrice, dépend de m_C *)\n",
|
||||
" let m_b12 = Mat.init_cols n_ao n_ao (fun i j -> \n",
|
||||
" integral_general (fun a b e f i j ->\n",
|
||||
" ( m_C.{a,i} *. m_C.{b,i} -. m_C.{a,j} *. m_C.{b,j} ) *. m_C.{e,i} *. m_C.{f,j}\n",
|
||||
" ) i j\n",
|
||||
" )\n",
|
||||
"\n",
|
||||
" in\n",
|
||||
" (* Fonction de calcul de toutes les intégrales A_12 -> Matrice, dépend de m_C *)\n",
|
||||
" let m_a12 = Mat.init_cols n_ao n_ao (fun i j ->\n",
|
||||
" integral_general (fun a b e f i j -> m_C.{a,i} *. m_C.{b,j} *. m_C.{e,i} *. m_C.{f,j} \n",
|
||||
" -. 0.25 *. ( m_C.{e,i} *. m_C.{f,i} -. m_C.{e,j} *. m_C.{f,j} ) \n",
|
||||
" *. ( m_C.{a,i} *. m_C.{b,i} -. m_C.{a,j} *. m_C.{b,j} )\n",
|
||||
" ) i j\n",
|
||||
" )\n",
|
||||
" in\n",
|
||||
" Mat.init_cols n_ao n_ao ( fun i j ->\n",
|
||||
" asin(m_b12.{i,j} /. sqrt((m_a12.{i,j}**2.) +. (m_b12.{i,j}**2.))))\n",
|
||||
" in\n",
|
||||
" \n",
|
||||
" (* Calcul de D *)\n",
|
||||
" let s_D m_C = \n",
|
||||
" let v_D = \n",
|
||||
" let m_D = Mat.init_cols n_ao n_ao (fun i j ->\n",
|
||||
" integral_general (fun a b e f i j -> m_C.{a,i} *. m_C.{b,i} *. m_C.{e,i} *. m_C.{f,i} \n",
|
||||
" ) i j\n",
|
||||
" )\n",
|
||||
" in Vec.init n_ao ( fun i -> m_D.{i,1} )\n",
|
||||
" in Vec.sum v_D \n",
|
||||
" in\n",
|
||||
" let critere_D = s_D m_C (* Fonction -> constante *)\n",
|
||||
" in\n",
|
||||
" Printf.printf \"%f\\n%!\" critere_D;\n",
|
||||
" \n",
|
||||
" let m_alpha = f_alpha m_C (* Fonction -> constante *)\n",
|
||||
" in\n",
|
||||
" (*\n",
|
||||
" Util.debug_matrix \"m_alpha\" m_alpha;\n",
|
||||
" *)\n",
|
||||
" \n",
|
||||
" (* Détermination alpha_max et ses indices i et j.\n",
|
||||
" Si alpha max > pi/2 on soustrait pi/2 à la matrice des alphas de manière récursive *)\n",
|
||||
" let rec new_m_alpha m_alpha n_rec_alpha=\n",
|
||||
" let alpha_m =\n",
|
||||
" (*\n",
|
||||
" Printf.printf \"%i\\n%!\" n_rec_alpha;\n",
|
||||
" *)\n",
|
||||
" if n_rec_alpha == 0 \n",
|
||||
" then m_alpha \n",
|
||||
" else Mat.init_cols n_ao n_ao (fun i j -> \n",
|
||||
" if (m_alpha.{i,j}) > 3.14 /. 2. \n",
|
||||
" then (m_alpha.{i,j} -. ( 3.14 /. 2.))\n",
|
||||
" else if m_alpha.{i,j} < -. 3.14 /. 2.\n",
|
||||
" then (m_alpha.{i,j} +. ( 3.14 /. 2.))\n",
|
||||
" else if m_alpha.{i,j} < 0. \n",
|
||||
" then -. m_alpha.{i,j}\n",
|
||||
" else m_alpha.{i,j} )\n",
|
||||
" in \n",
|
||||
" (*\n",
|
||||
" Util.debug_matrix \"alpha_m\" alpha_m;\n",
|
||||
" *)\n",
|
||||
" (* Détermination de l'emplacement du alpha max *)\n",
|
||||
" let max_element3 alpha_m = \n",
|
||||
" Mat.as_vec alpha_m\n",
|
||||
" |> iamax\n",
|
||||
" in\n",
|
||||
" \n",
|
||||
" (* indice i du alpha max *)\n",
|
||||
" let indice_ii = \n",
|
||||
" let max = max_element3 alpha_m (* Fonction -> constante *)\n",
|
||||
" in\n",
|
||||
" (*\n",
|
||||
" Printf.printf \"%i\\n%!\" max;\n",
|
||||
" *)\n",
|
||||
" (max - 1) mod n_ao +1 \n",
|
||||
" in\n",
|
||||
" \n",
|
||||
" (* indice j du alpha max *)\n",
|
||||
" let indice_jj = \n",
|
||||
" let max = max_element3 alpha_m (* Fonction -> constante *)\n",
|
||||
" in\n",
|
||||
" (max - 1) / n_ao +1\n",
|
||||
" in\n",
|
||||
" \n",
|
||||
" (* Valeur du alpha max*)\n",
|
||||
" let alpha alpha_m = \n",
|
||||
" let i = indice_ii \n",
|
||||
" in\n",
|
||||
" let j = indice_jj \n",
|
||||
" in\n",
|
||||
" (*\n",
|
||||
" Printf.printf \"%i %i\\n%!\" i j;\n",
|
||||
" *)\n",
|
||||
" alpha_m.{i,j}\n",
|
||||
" \n",
|
||||
" in\n",
|
||||
" let alpha_max = alpha alpha_m (* Fonction -> constante *)\n",
|
||||
" in\n",
|
||||
" Printf.printf \"%f\\n%!\" alpha_max;\n",
|
||||
" if alpha_max < 3.14 /. 2.\n",
|
||||
" then {alpha_max; indice_ii; indice_jj}\n",
|
||||
" else new_m_alpha alpha_m (n_rec_alpha-1)\n",
|
||||
" in\n",
|
||||
" let alphaij = new_m_alpha m_alpha n_rec_alpha (* Fonction -> constante *)\n",
|
||||
" in\n",
|
||||
" \n",
|
||||
" (* Valeur de alpha max après calcul *)\n",
|
||||
" let alpha = alphaij.alpha_max (* Fonction -> constante *)\n",
|
||||
" in\n",
|
||||
" \n",
|
||||
" (* Matrice de rotation 2 par 2 *)\n",
|
||||
" let f_R alpha =\n",
|
||||
" Mat.init_cols 2 2 (fun i j -> if i=j then cos alpha\n",
|
||||
" else if i>j then sin alpha \n",
|
||||
" else -. sin alpha)\n",
|
||||
" in\n",
|
||||
" (* Indice i et j du alpha max après calcul *)\n",
|
||||
" let indice_i = alphaij.indice_ii (* Fonction -> constante *)\n",
|
||||
" in\n",
|
||||
" let indice_j = alphaij.indice_jj (* Fonction -> constante *)\n",
|
||||
" in\n",
|
||||
" (*\n",
|
||||
" Printf.printf \"%i %i\\n%!\" indice_i indice_j;\n",
|
||||
" *)\n",
|
||||
" let m_R = f_R alpha (* Fonction -> constante *)\n",
|
||||
" in\n",
|
||||
" \n",
|
||||
" (* Fonction d'extraction des 2 vecteurs propres i et j de la matrice des OMs pour les mettres dans la matrice Ksi (n par 2)\n",
|
||||
" pour appliquer R afin d'effectuer la rotation des orbitales *) (* {1,2} -> 1ere ligne, 2e colonne *)\n",
|
||||
" let f_Ksi indice_i indice_j m_C = Mat.init_cols n_ao 2 (fun i j -> if j=1 then m_C.{i,indice_i} else m_C.{i,indice_j} )\n",
|
||||
" in\n",
|
||||
" let m_Ksi = f_Ksi indice_i indice_j m_C (* Fonction -> constante *)\n",
|
||||
" in\n",
|
||||
" (*\n",
|
||||
" Util.debug_matrix \"m_Ksi\" m_Ksi;\n",
|
||||
" *)\n",
|
||||
" (* Fonction de calcul de ksi~ (matrice n par 2), nouvelle matrice par application de la matrice de rotation dans laquelle\n",
|
||||
" on obtient les deux orbitales que l'on va réinjecter dans la matrice Phi*)\n",
|
||||
" let f_Ksi_tilde m_R m_Ksi = gemm m_Ksi m_R\n",
|
||||
" in\n",
|
||||
" let m_Ksi_tilde = f_Ksi_tilde m_R m_Ksi (* Fonction -> constante *)\n",
|
||||
" in\n",
|
||||
" (*\n",
|
||||
" Util.debug_matrix \"m_Ksi_tilde\" m_Ksi_tilde;\n",
|
||||
" *)\n",
|
||||
" \n",
|
||||
" (* Pour la réinjection on créer des matrices intérmédiares, une matrice nulle partout sauf sur \n",
|
||||
" les colonnes de i et j et de i~ et j~. On fait la différence de la première matrice avec la matrice\n",
|
||||
" des OMs Phi afin de substituer les colonnes de i et j par des zéro et ensuite sommer cette matrice avec \n",
|
||||
" celle contenant i~ et j~ *)\n",
|
||||
" \n",
|
||||
" (* Matrice intérmédiare pour l'injection de ksi~ (i~ et j~) dans la matrice Phi *)\n",
|
||||
" let f_Psi_tilde m_Ksi_tilde indice_i indice_j = Mat.init_cols n_ao n_ao (fun i j -> if j=indice_i then m_Ksi_tilde.{i,1}\n",
|
||||
" else if j=indice_j then m_Ksi_tilde.{i,2}\n",
|
||||
" else 0.)\n",
|
||||
"\n",
|
||||
" in\n",
|
||||
"\n",
|
||||
" (* Matrice intermédiaire pour supprimer ksi (i et j) dans la matrice Phi *) \n",
|
||||
" let f_Psi m_Ksi indice_i indice_j = Mat.init_cols n_ao n_ao (fun i j -> if j=indice_i then m_Ksi.{i,1}\n",
|
||||
" else if j=indice_j then m_Ksi.{i,2}\n",
|
||||
" else 0.)\n",
|
||||
" in\n",
|
||||
" let m_Psi = f_Psi m_Ksi indice_i indice_j (* Fonction -> constante *)\n",
|
||||
" in\n",
|
||||
" (*\n",
|
||||
" Util.debug_matrix \"m_Psi\" m_Psi;\n",
|
||||
" *)\n",
|
||||
" let m_Psi_tilde = f_Psi_tilde m_Ksi_tilde indice_i indice_j (* Fonction -> constante *)\n",
|
||||
" in\n",
|
||||
" (*\n",
|
||||
" Util.debug_matrix \"m_Psi_tilde\" m_Psi_tilde;\n",
|
||||
" *)\n",
|
||||
" (* Matrice intérmédiaire où les orbitales i et j ont été supprimées et remplacées par des 0, par soustraction de la matrice Phi\n",
|
||||
" par la matrice *)\n",
|
||||
" let f_interm m_C m_Psi = Mat.sub m_C m_Psi\n",
|
||||
" in\n",
|
||||
" let m_interm = f_interm m_C m_Psi (* Fonction -> constante *)\n",
|
||||
"in\n",
|
||||
"Mat.add m_Psi_tilde m_interm\n",
|
||||
"in\n",
|
||||
"let m_new_m_C = new_m_C m_C (* Fonction -> constante *)\n",
|
||||
"in\n",
|
||||
"(*\n",
|
||||
"Util.debug_matrix \"m_new_m_C\" m_new_m_C;\n",
|
||||
"*)\n",
|
||||
"final_m_C m_new_m_C (n-1);;\n",
|
||||
"\n",
|
||||
"(*****************************)\n",
|
||||
"\n",
|
||||
"final_m_C m_C 1000;;\n",
|
||||
"\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"\n",
|
||||
" \n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
|
Loading…
Reference in New Issue
Block a user