예제 #1
0
파일: sqrt_enkf.c 프로젝트: Ensembles/ert
void sqrt_enkf_initX(void * module_data , 
                     matrix_type * X , 
                     matrix_type * A , 
                     matrix_type * S , 
                     matrix_type * R , 
                     matrix_type * dObs , 
                     matrix_type * E , 
                     matrix_type *D ) {

  sqrt_enkf_data_type * data = sqrt_enkf_data_safe_cast( module_data );
  {
    int ncomp         = std_enkf_get_subspace_dimension( data->std_data );
    double truncation = std_enkf_get_truncation( data->std_data );
    int nrobs         = matrix_get_rows( S );
    int ens_size      = matrix_get_columns( S );
    int nrmin         = util_int_min( ens_size , nrobs); 
    matrix_type * W   = matrix_alloc(nrobs , nrmin);                      
    double      * eig = util_calloc( nrmin , sizeof * eig );    
    
    matrix_subtract_row_mean( S );   /* Shift away the mean */
    enkf_linalg_lowrankCinv( S , R , W , eig , truncation , ncomp);    
    enkf_linalg_init_sqrtX( X , S , data->randrot , dObs , W , eig , false);
    matrix_free( W );
    free( eig );

    enkf_linalg_checkX( X , false );
  }
}
예제 #2
0
void rml_enkf_common_initA__( matrix_type * A ,
                              matrix_type * S , 
                              matrix_type * Cd , 
                              matrix_type * E , 
                              matrix_type * D ,
                              double truncation,
                              double lamda,
                              matrix_type * Udr,
                              double * Wdr,
                              matrix_type * VdTr) {

  int nrobs         = matrix_get_rows( S );
  int ens_size      = matrix_get_columns( S );
  double a = lamda + 1;
  matrix_type *tmp  = matrix_alloc (nrobs, ens_size);
  double nsc = 1/sqrt(ens_size-1);

  
  printf("The lamda Value is %5.5f\n",lamda);
  printf("The Value of Truncation is %4.2f \n",truncation);

  matrix_subtract_row_mean( S );           /* Shift away the mean in the ensemble predictions*/
  matrix_inplace_diag_sqrt(Cd);
  matrix_dgemm(tmp, Cd, S,false, false, 1.0, 0.0);
  matrix_scale(tmp, nsc);
  
  printf("The Scaling of data matrix completed !\n ");


  // SVD(S)  = Ud * Wd * Vd(T)
  int nsign = enkf_linalg_svd_truncation(tmp , truncation , -1 , DGESVD_MIN_RETURN  , Wdr , Udr , VdTr);
  
  /* After this we only work with the reduced dimension matrices */
  
  printf("The number of siginificant ensembles are %d \n ",nsign);
  
  matrix_type * X1   = matrix_alloc( nsign, ens_size);
  matrix_type * X2    = matrix_alloc (nsign, ens_size );
  matrix_type * X3    = matrix_alloc (ens_size, ens_size );
  
  
  // Compute the matrices X1,X2,X3 and dA 
  enkf_linalg_rml_enkfX1(X1, Udr ,D ,Cd );  //X1 = Ud(T)*Cd(-1/2)*D   -- D= -(dk-d0)
  enkf_linalg_rml_enkfX2(X2, Wdr ,X1 ,a, nsign);  //X2 = ((a*Ipd)+Wd^2)^-1  * X1

  matrix_free(X1);

  enkf_linalg_rml_enkfX3(X3, VdTr ,Wdr,X2, nsign);  //X3 = Vd *Wd*X2
  printf("The X3 matrix is computed !\n ");

  matrix_type *dA1= matrix_alloc (matrix_get_rows(A), ens_size);
  matrix_type * Dm  = matrix_alloc_copy( A );

  matrix_subtract_row_mean( Dm );      /* Remove the mean from the ensemble of model parameters*/
  matrix_scale(Dm, nsc);

  enkf_linalg_rml_enkfdA(dA1, Dm, X3);      //dA = Dm * X3   
  matrix_inplace_add(A,dA1); //dA 

  matrix_free(X3);
  matrix_free(Dm);
  matrix_free(dA1);
}