TABLE OF CONTENTS


ABINIT/matr3inv [ Functions ]

[ Top ] [ Functions ]

NAME

 matr3inv

FUNCTION

 Invert and transpose general 3x3 matrix of real*8 elements.

COPYRIGHT

 Copyright (C) 1998-2018 ABINIT group (DCA, XG, GMR)
 This file is distributed under the terms of the
 GNU General Public License, see ~abinit/COPYING
 or http://www.gnu.org/copyleft/gpl.txt .

INPUTS

 aa = 3x3 matrix to be inverted

OUTPUT

 ait = inverse of aa input matrix

NOTES

 Returned array is TRANSPOSE of inverse, as needed to get g from r.

PARENTS

      berryphase,chkdilatmx,conducti_nc,ddb_hybrid,dfpt_mkvxc,dfpt_mkvxcstr
      dfpt_symph,electrooptic,ep_el_weights,ep_fs_weights,ep_ph_weights
      fock_getghc,get_kpt_fullbz,getkgrid,getspinrot,gstate,harmonic_thermo
      invars2,inwffil,m_cut3d,m_ddb,m_ddk,m_double_grid,m_dynmat
      m_effective_potential,m_esymm,m_ewald,m_fock,m_fstab,m_ifc,m_pimd
      m_psps,m_strain,m_supercell,m_tdep_latt,make_efg_el,make_efg_ion,metric
      mover,optic,outwant,pimd_langevin_npt,prtxf,relaxpol,respfn,smpbz
      stresssym,symbrav,symlatt,symmetrize_rprimd,symrelrot,symrhg,tddft
      testkgrid,thmeig,uderiv,xcart2xred,xfpack_x2vin

CHILDREN

SOURCE

39 #if defined HAVE_CONFIG_H
40 #include "config.h"
41 #endif
42 
43 #include "abi_common.h"
44 
45 
46 subroutine matr3inv(aa,ait)
47 
48  use defs_basis
49  use m_errors
50 
51 !This section has been created automatically by the script Abilint (TD).
52 !Do not modify the following lines by hand.
53 #undef ABI_FUNC
54 #define ABI_FUNC 'matr3inv'
55 !End of the abilint section
56 
57  implicit none
58 
59 !Arguments ------------------------------------
60 !arrays
61  real(dp),intent(in) :: aa(3,3)
62  real(dp),intent(out) :: ait(3,3)
63 
64 !Local variables-------------------------------
65 !scalars
66  real(dp) :: dd,det,t1,t2,t3
67  character(len=500) :: message
68 
69 ! *************************************************************************
70 
71  t1 = aa(2,2) * aa(3,3) - aa(3,2) * aa(2,3)
72  t2 = aa(3,2) * aa(1,3) - aa(1,2) * aa(3,3)
73  t3 = aa(1,2) * aa(2,3) - aa(2,2) * aa(1,3)
74  det  = aa(1,1) * t1 + aa(2,1) * t2 + aa(3,1) * t3 
75 
76 !Make sure matrix is not singular
77  if (abs(det)>tol16) then
78    dd=one/det
79  else
80    write(message, '(2a,2x,9es16.8,a,a,es16.8,a)' )&
81 &   ' Attempting to invert real(8) 3x3 array',ch10,&
82 &   aa(:,:),ch10,&
83 &   '   ==> determinant=',det,' is zero.'
84    MSG_BUG(message)
85  end if
86 
87  ait(1,1) = t1 * dd
88  ait(2,1) = t2 * dd
89  ait(3,1) = t3 * dd
90  ait(1,2) = (aa(3,1)*aa(2,3)-aa(2,1)*aa(3,3)) * dd
91  ait(2,2) = (aa(1,1)*aa(3,3)-aa(3,1)*aa(1,3)) * dd
92  ait(3,2) = (aa(2,1)*aa(1,3)-aa(1,1)*aa(2,3)) * dd
93  ait(1,3) = (aa(2,1)*aa(3,2)-aa(3,1)*aa(2,2)) * dd
94  ait(2,3) = (aa(3,1)*aa(1,2)-aa(1,1)*aa(3,2)) * dd
95  ait(3,3) = (aa(1,1)*aa(2,2)-aa(2,1)*aa(1,2)) * dd
96 
97 end subroutine matr3inv