src/IntRank2/CartMx2A.cc
/* This function will assume that the Cartesian spatial tensor array A 
   (symmetric) has some asymmetry. That is, eta != 0 for A. It will also assume
   that the three tensor values {Aiso, delzz, eta} have been previously found.
   It will then attempt to obtain three Euler angles EA:{alpha,beta,gamma} that
   relate the irreducible rank 2 part of tensor A PAS to the input array axes.

   For this general case, the angles must be found through an iterative
   minimization process. Currently this uses Newtons Method (see function
   Minimize) which explicitly calculates Jacobian matrices and functional
   vectors. The Euler angles in Eo are used for an initial guess and placed
   into the vector |X>. This vector is then given to the minimization function
   which will return a revised |X> that contains the best fit values of the
   Euler angles. The "best fit" angles are then set to the tensor Euler angles. 

   Note that, since the Cartesian tensor elements are composed of multi-valued
   trigonometric functions, false minima can easily occur in an iterative 
   process to determine the Euler angles. Thus, the resulting Euler angles are
   ALWAYS checked by regeneration of the Cartesian matrix using the determined
   spherical PAS components {Ais, delzz, eta} and the minimized Euler angles
   {alpha,beta,gamma}, and a subsequent comparison with the original array A.

   If it is found that the minimization process has failed, there are three
   possible avenues the function automatically procede down. These are 

               1.) Try to minimize with new starting angles.
               2.) Try to minimize with more iterations.
               3.) Try to minimize on different Cartesian elements.

   the possibilities:

          Failure           
   =====================  ====================================================
   Did Not Reach Minimum  1.) If the vector norm of |Y> is small, then perhaps
                              it is simply very slow to converge on the EA set
                              Use more iterations and hope that works.
                          2.) If the vector norm of |Y> is not small, or more
                              iterations fail to generate a better norm, then
                              a different starting angle set should be used.
   Reached Wrong Minimum  1.) This can only be caused by falling into a local
                              minimum.  Retry the minimization with another
                              initial guess at the staring angle set.        */
This function will assume that the Cartesian spatial tensor array A
(symmetric) has some asymmetry. That is, eta != 0 for A. It will also assume
that the three tensor values {Aiso, delzz, eta} have been previously found.
It will then attempt to obtain three Euler angles EA:{alpha,beta,gamma} that
relate the irreducible rank 2 part of tensor A PAS to the input array axes.

For this general case, the angles must be found through an iterative
minimization process. Currently this uses Newtons Method (see function
Minimize) which explicitly calculates Jacobian matrices and functional
vectors. The Euler angles in Eo are used for an initial guess and placed
into the vector |X>. This vector is then given to the minimization function
which will return a revised |X> that contains the best fit values of the
Euler angles. The "best fit" angles are then set to the tensor Euler angles.

Note that, since the Cartesian tensor elements are composed of multi-valued
trigonometric functions, false minima can easily occur in an iterative
process to determine the Euler angles. Thus, the resulting Euler angles are
ALWAYS checked by regeneration of the Cartesian matrix using the determined
spherical PAS components {Ais, delzz, eta} and the minimized Euler angles
{alpha,beta,gamma}, and a subsequent comparison with the original array A.

If it is found that the minimization process has failed, there are three
possible avenues the function automatically procede down. These are

1.) Try to minimize with new starting angles.
2.) Try to minimize with more iterations.
3.) Try to minimize on different Cartesian elements.

the possibilities.

Failure

Did Not Reach Minimum  1.) If the vector norm of |Y> is small, then perhaps
it is simply very slow to converge on the EA set
Use more iterations and hope that works.
2.) If the vector norm of |Y> is not small, or more
iterations fail to generate a better norm, then
a different starting angle set should be used.
Reached Wrong Minimum  1.) This can only be caused by falling into a local
minimum.  Retry the minimization with another
initial guess at the staring angle set.
This function will assume that the Cartesian spatial tensor array A ( symmetric ) has some asymmetry . That is eta ! = 0 for A . It will also assume that the three tensor values { Aiso delzz eta } have been previously found . It will then attempt to obtain three Euler angles EA : { alpha beta gamma } that relate the irreducible rank 2 part of tensor A PAS to the input array axes . For this general case the angles must be found through an iterative minimization process . Currently this uses Newtons Method ( see function Minimize ) which explicitly calculates Jacobian matrices and functional vectors . The Euler angles in Eo are used for an initial guess and placed into the vector |X > . This vector is then given to the minimization function which will return a revised |X > that contains the best fit values of the Euler angles . The " best fit " angles are then set to the tensor Euler angles . Note that since the Cartesian tensor elements are composed of multi - valued trigonometric functions false minima can easily occur in an iterative process to determine the Euler angles . Thus the resulting Euler angles are ALWAYS checked by regeneration of the Cartesian matrix using the determined spherical PAS components { Ais delzz eta } and the minimized Euler angles { alpha beta gamma } and a subsequent comparison with the original array A . If it is found that the minimization process has failed there are three possible avenues the function automatically procede down . These are 1 . ) Try to minimize with new starting angles . 2 . ) Try to minimize with more iterations . 3 . ) Try to minimize on different Cartesian elements . the possibilities . Failure Did Not Reach Minimum 1 . ) If the vector norm of |Y > is small then perhaps it is simply very slow to converge on the EA set Use more iterations and hope that works . 2 . ) If the vector norm of |Y > is not small or more iterations fail to generate a better norm then a different starting angle set should be used . Reached Wrong Minimum 1 . ) This can only be caused by falling into a local minimum . Retry the minimization with another initial guess at the staring angle set .
bool CartMx2A::ASymCartEA()
  {
  string fct("ASymCartEA");			
  ConvMeth = 6;					
  TrackConv(ConvMeth);				
  if(!EtaVal)
    {
    C2Aerror(27, 1);				
    C2Aerror(26, fct, 1);			
    C2Afatal(30);				
    }
  if(A.is_zero())
    {
    C2Aerror(17, 1);				
    C2Aerror(26, fct, 1);			
    C2Afatal(30);				
    }
  if(!PASDelzz)
    {
    C2Aerror(18, 1);				
    C2Aerror(26, fct, 1);			
    C2Afatal(30);				
    }
  bool TF = false;				
  bool TFM; 					
  bool TFA;					
  Step  = 0;					
  SStep = 0;					
  JStep = 0;					
  vector<EAngles> ASeeds = AngSeeds();		
  vector<int>     FSeeds = FctSeeds();		
  int NA = ASeeds.size();			
  int NJ = FSeeds.size();			
  int action = 0;				
  double lastnorm = HUGE_VAL;			
  EAngles EAoo = EAo;				
  while(!TF && Step<=NA)			
    {
    TrackMin(9);				
    TrackConv(11); 				
    TFM = Minimize();	 			
    TFA = Check() < ZeroMxCut;			
    TF  = (TFM & TFA);				
    action = MinAction(TFM,TFA,NJ,JStep,lastnorm);	
    switch(action)				
      {
      case 0: 					
        Step  = 0;				
        JStep = 0;				
        SStep = 0;				
        EAo = EAoo;				
        return true;
        break;
      case 1:					
        EAo = ASeeds[Step++];			
        TrackMin(21);				
        SStep = 0;				
        lastnorm = HUGE_VAL;			
        break;
      case 2:					
        EAo = EA;				
        SStep++;				
        lastnorm = Y.norm();			
        break;
      case 3:					
        TrackMin(22);				
        TrackMin(47);				
        JStep++;				
        JFuncts(FSeeds[JStep]);			
        TrackMin(48);				
        SStep = 0;				
        lastnorm = HUGE_VAL;			
        break;
      default:
       cout << "\n\nNo Action Yet Specified...";
       exit(-1);
       break;
      }
    }
  TrackConv(16); 				
  return TF;					
  }
bool CartMx2A :: ASymCartEA ( ) { string fct ( " " ) ; ConvMeth = 6 ; TrackConv ( ConvMeth ) ; if ( ! EtaVal ) { C2Aerror ( 27 , 1 ) ; C2Aerror ( 26 , fct , 1 ) ; C2Afatal ( 30 ) ; } if ( A . is_zero ( ) ) { C2Aerror ( 17 , 1 ) ; C2Aerror ( 26 , fct , 1 ) ; C2Afatal ( 30 ) ; } if ( ! PASDelzz ) { C2Aerror ( 18 , 1 ) ; C2Aerror ( 26 , fct , 1 ) ; C2Afatal ( 30 ) ; } bool TF = false ; bool TFM ; bool TFA ; Step = 0 ; SStep = 0 ; JStep = 0 ; vector < EAngles > ASeeds = AngSeeds ( ) ; vector < int > FSeeds = FctSeeds ( ) ; int NA = ASeeds . size ( ) ; int NJ = FSeeds . size ( ) ; int action = 0 ; double lastnorm = HUGE_VAL ; EAngles EAoo = EAo ; while ( ! TF && Step <= NA ) { TrackMin ( 9 ) ; TrackConv ( 11 ) ; TFM = Minimize ( ) ; TFA = Check ( ) < ZeroMxCut ; TF = ( TFM & TFA ) ; action = MinAction ( TFM , TFA , NJ , JStep , lastnorm ) ; switch ( action ) { case 0 : Step = 0 ; JStep = 0 ; SStep = 0 ; EAo = EAoo ; return true ; break ; case 1 : EAo = ASeeds [ Step ++ ] ; TrackMin ( 21 ) ; SStep = 0 ; lastnorm = HUGE_VAL ; break ; case 2 : EAo = EA ; SStep ++ ; lastnorm = Y . norm ( ) ; break ; case 3 : TrackMin ( 22 ) ; TrackMin ( 47 ) ; JStep ++ ; JFuncts ( FSeeds [ JStep ] ) ; TrackMin ( 48 ) ; SStep = 0 ; lastnorm = HUGE_VAL ; break ; default : cout << " \n \n " ; exit ( -1 ) ; break ; } } TrackConv ( 16 ) ; return TF ; }
This function will assume that the Cartesian spatial tensor array A
(symmetric) has some asymmetry.
This function will assume that the Cartesian spatial tensor array A ( symmetric ) has some asymmetry .
// Our function name // Our conversion type // Track conv. process //         Insure Array A Has The Proper Structure For This Function //       (Or Lack Thereof, Any Structured A Handled In Other Routines) // Eta is zero // Bad function call // Cant get EA // Cartesian array 0 // Bad function call // Cant get EA // Anisotropy 0 // Bad function call // Cant get EA /*                         Minimization Section

    We Loop Over A Series Of Starting Angles And Iterate At Each Starting Guess
    To Get The Proper Euler Angles. Before Trying A New Guess At The Angles, We
    Try Another Three Functions (Of The Six Possible) To Build The Jacobian
    And Functional Vector.                                                   */ // Flag if Done // Flag if Minization OK // Check A consistency // No. Minimization tries // No. Repeat tries // No. J evaluations //           These Handle Changes To The Three Auv Functions // Get our angle seeds // Get our function seeds // Number of angle seeds // Number of J function sets			 // Action to take on next step // Set |Y> norm, last step // Store starting angles // Begin minimization attampts //   Track if desired //   Track conv. process //   Minimize for EAngles //   Check A consistency //   Overall flag if OK //   Get next action to take //   Set for next minmize. step // 0: Minimization complete! //   No Minimization steps //   No Jacobian evaluations //   No repeated steps now //   Back to original start angles // 1: Try New Angle Set //   Try these starting EA's //   Track if desired //   No repeated steps now //   Set last norm as big // 2: Just try more iterations //   Set new start angles //   Inc. repeat step  count //   Store last step norm // 3: Try new function set //   Track if desired //   Track if desired //   Increment J evalution //   Set new J functions //   Track if desired //   No repeated steps now //   Set last norm as big // Track conv. process // Return if we succeeded