Work : Redefinitions fonctions avec arguments par blocs
This commit is contained in:
parent
bd46ce9f7d
commit
0e16ce0dca
101
Work.ipynb
101
Work.ipynb
@ -1830,20 +1830,33 @@
|
||||
"\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_mo n_mo (fun i j ->\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_mo n_mo ( fun i j ->\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",
|
||||
"\n",
|
||||
"\n",
|
||||
";;\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"f_alpha m_C;;\n",
|
||||
" \n",
|
||||
"(******************************************************************************************************)\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",
|
||||
" \n",
|
||||
" s_D m_C;;\n",
|
||||
" \n",
|
||||
"(******************************************************************************************************)\n",
|
||||
" \n",
|
||||
@ -1961,6 +1974,12 @@
|
||||
"\n",
|
||||
"(* Si alpha max > pi/2 on doit soustraire pi/2 à la matrice des alphas *)\n",
|
||||
"let m_alpha = f_alpha m_C;;\n",
|
||||
"\n",
|
||||
"type alphaij = {\n",
|
||||
"alpha_max : float;\n",
|
||||
"indice_ii : int;\n",
|
||||
"indice_jj : int;}\n",
|
||||
"\n",
|
||||
"let rec new_m_alpha m_alpha n_rec_alpha=\n",
|
||||
" let alpha_m =\n",
|
||||
" Printf.printf \"%i\\n%!\" n_rec_alpha;\n",
|
||||
@ -2003,25 +2022,87 @@
|
||||
" in\n",
|
||||
" Printf.printf \"%f\\n%!\" alpha_max;\n",
|
||||
" if alpha_max < 3.14 /. 2.\n",
|
||||
" then alpha_max\n",
|
||||
" then {alpha_max; indice_ii; indice_jj}\n",
|
||||
" else new_m_alpha alpha_m (n_rec_alpha-1);;\n",
|
||||
" \n",
|
||||
"\n",
|
||||
"new_m_alpha m_alpha 10 ;;\n",
|
||||
"\n",
|
||||
"let alphaij = new_m_alpha m_alpha 10 ;;\n",
|
||||
"\n",
|
||||
"(******************************************************************************************)\n",
|
||||
"let alpha = alphaij.alpha_max\n",
|
||||
"\n",
|
||||
"(* Matrice de rotation 2 par 2 *)\n",
|
||||
"let m_R new_m_alpha =\n",
|
||||
" let alpha = new_m_alpha m_alpha 10\n",
|
||||
" in\n",
|
||||
"let m_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",
|
||||
"\n",
|
||||
"m_R new_m_alpha;;\n",
|
||||
"\n",
|
||||
"(******************************************************************************************)"
|
||||
"(******************************************************************************************)\n",
|
||||
"\n",
|
||||
"let indice_i = alphaij.indice_ii;;\n",
|
||||
"let indice_j = alphaij.indice_jj;;\n",
|
||||
"let m_R = m_R alpha;;\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 m_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",
|
||||
"\n",
|
||||
"m_Ksi indice_i indice_j m_C;;\n",
|
||||
"\n",
|
||||
"let m_Ksi = m_Ksi indice_i indice_j m_C;;\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 m_Ksi_tilde m_R m_Ksi = gemm m_Ksi m_R;;\n",
|
||||
"\n",
|
||||
"m_Ksi_tilde m_R m_Ksi ;;\n",
|
||||
"\n",
|
||||
"(******************************************************************************************)\n",
|
||||
"let m_Ksi_tilde = m_Ksi_tilde m_R m_Ksi\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 m_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",
|
||||
"m_Psi_tilde m_Ksi_tilde indice_i indice_j;;\n",
|
||||
"\n",
|
||||
"(* Matrice intermédiaire pour supprimer ksi (i et j) dans la matrice Phi *) \n",
|
||||
"let m_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",
|
||||
" \n",
|
||||
"m_Psi m_Ksi indice_i indice_j;;\n",
|
||||
"\n",
|
||||
"(******************************************************************************************)\n",
|
||||
"let m_Psi = m_Psi m_Ksi indice_i indice_j;;\n",
|
||||
"let m_Psi_tilde = m_Psi_tilde m_Ksi_tilde indice_i indice_j;; \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 m_interm m_C m_Psi = Mat.sub m_C m_Psi;;\n",
|
||||
"\n",
|
||||
"let m_interm = m_interm m_C m_Psi;;\n",
|
||||
"\n",
|
||||
"(* Construction de la nouvelle matrice d'OMs phi~ *)\n",
|
||||
"let m_Phi_tilde m_Psi_tilde m_interm = Mat.add m_Psi_tilde m_interm;;\n",
|
||||
"\n",
|
||||
"m_Phi_tilde m_Psi_tilde m_interm;;\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## Rassemblement des blocs"
|
||||
]
|
||||
},
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user