CArl
Code Arlequin / C++ implementation
FETI_operations_IO.cpp
Go to the documentation of this file.
1 #include "FETI_operations.h"
2 
3 namespace carl
4 {
5 // --- Coupling matrix and preconditioner methods
7 {
8  homemade_assert_msg(m_bCouplingFolderSet,"Common coupling matrix path not set yet!");
9 
10  // Create matrix and, if needed, get sizes
11  MatCreate(m_comm.get(),&m_C_R_micro);
12 
13  // If the sizes were defined already, set them
15  {
17  }
18 
19  // Read the matrix
20  read_PETSC_matrix(m_C_R_micro,m_coupling_folder_path + "/coupling_matrix_micro.petscmat",m_comm.get());
21 
22  // If the micro sizes were not defined yet, define them
24  {
27  m_bmicro_sizes_set = true;
28  }
29 
30  // If the mediator sizes were not defined yet, define them
31  if(!m_bR_sizes_set)
32  {
34  m_bR_sizes_set = true;
35  }
36 
37  // Set null vector dimensions (if needed)
39  {
43  }
44 
45  // Set flags
48 }
49 
51 {
52  homemade_assert_msg(m_bCouplingFolderSet,"Common coupling matrix path not set yet!");
53 
54  // Create matrix and, if needed, get sizes
55  MatCreate(m_comm.get(),&m_C_R_BIG);
56 
57  // If the sizes were defined already, set them
59  {
61  }
62 
63  // Read the matrix
64  read_PETSC_matrix(m_C_R_BIG,m_coupling_folder_path + "/coupling_matrix_macro.petscmat",m_comm.get());
65 
66  // If the macro sizes were not defined yet, define them
67  if(!m_bBIG_sizes_set)
68  {
70  MatGetSize(m_C_R_BIG,&m_C_R_BIG_M,&m_C_R_BIG_N);
71  m_bBIG_sizes_set = true;
72  }
73 
74  // If the mediator sizes were not defined yet, define them
75  if(!m_bR_sizes_set)
76  {
78  m_bR_sizes_set = true;
79  }
80 
81  // Set null vector dimensions (if needed)
83  {
87  }
88 
89  // Set flags
90  m_bC_R_BIG_MatrixSet = true;
92 }
93 
95 {
96  homemade_assert_msg(m_bCouplingFolderSet,"Common coupling matrix path not set yet!");
97 
98  // Create matrix and, if needed, get sizes
99  MatCreate(m_comm.get(),&m_C_RR);
100 
101  // If the sizes were defined already, set them
102  if(m_bR_sizes_set)
103  {
105  }
106 
107  read_PETSC_matrix(m_C_RR,m_coupling_folder_path + "/coupling_matrix_mediator.petscmat",m_comm.get());
108 
109  // If the mediator sizes were not defined yet, define them
110  if(!m_bR_sizes_set)
111  {
112  MatGetLocalSize(m_C_RR,&m_C_RR_M_local,NULL);
113  MatGetSize(m_C_RR,&m_C_RR_M,NULL);
114  m_bR_sizes_set = true;
115  }
116 
117  // Set flags
118  m_bC_RR_MatrixSet = true;
120 }
121 
123 {
124  homemade_assert_msg(m_bCouplingFolderSet,"Common coupling matrix path not set yet!");
127  this->set_coupling_matrix_RR();
128 }
129 
130 // --- Null space / rigid body modes methods
131 void FETI_Operations::read_null_space_vecs(const std::string& RB_vectors_base, int nb_of_rb_vectors)
132 {
133 
134  /*
135  * Note: for now, this function reads both sets of null space vectors (the "original" ones and
136  * the ones multiplied by the coupling matrix), but I'm not sure if this less efficient than re-calculating
137  * these vectors each time. [Thiago]
138  */
139 
140  homemade_assert_msg(m_bNullVecsDimensionsSet,"Null vectors sizes not set yet!");
141  homemade_assert_msg(m_bScratchFolderSet,"Scratch folder not set yet!");
142 
143  // Set the null vec arrays
144  m_null_nb_vecs = nb_of_rb_vectors;
145 
146  // Set the first nullspace vectors
147  std::string rb_vec_filename = RB_vectors_base + "_0_n_" + std::to_string(m_null_nb_vecs) + ".petscvec";
148  VecCreate(m_comm.get(),&m_null_vecs[0]);
150  read_PETSC_vector(m_null_vecs[0],rb_vec_filename, m_comm.get());
151 
152  std::string rb_coupl_vec_filename = m_scratch_folder_path + "/rb_coupl_vector_0_n_" + std::to_string(m_null_nb_vecs) + ".petscvec";
153  VecCreate(m_comm.get(),&m_null_coupled_vecs[0]);
155  read_PETSC_vector(m_null_coupled_vecs[0],rb_coupl_vec_filename, m_comm.get());
156 
157  // Read and calculate the rest of the nullspace vectors
158  for(int iii = 1; iii < m_null_nb_vecs; ++iii)
159  {
160  rb_vec_filename = RB_vectors_base + "_" + std::to_string(iii) + "_n_" + std::to_string(m_null_nb_vecs) + ".petscvec";
161  VecDuplicate(m_null_vecs[0],&m_null_vecs[iii]);
162  read_PETSC_vector(m_null_vecs[iii],rb_vec_filename, m_comm.get());
163 
164  rb_coupl_vec_filename = m_scratch_folder_path + "/rb_coupl_vector_" + std::to_string(iii) + "_n_" + std::to_string(m_null_nb_vecs) + ".petscvec";
165  VecDuplicate(m_null_coupled_vecs[0],&m_null_coupled_vecs[iii]);
166  read_PETSC_vector(m_null_coupled_vecs[iii],rb_coupl_vec_filename, m_comm.get());
167  }
168 
169  // Set up flag
170  m_bNullVecsSet = true;
171 }
172 
174 {
175  homemade_assert_msg(m_bScratchFolderSet,"Scratch folder not set yet!");
176 
177  // A dummy vector which will be used to sync the matrices
178  std::vector<PetscScalar> dummy_matrix_contents(m_null_nb_vecs*m_null_nb_vecs, 0);
179 
180  MatCreateSeqDense(PETSC_COMM_SELF,m_null_nb_vecs,m_null_nb_vecs,NULL,&m_inv_RITRI_mat);
181 
182  // Only really read the matrix in the first processor
183  if(m_comm.rank() == 0)
184  {
185  read_PETSC_matrix(m_inv_RITRI_mat,m_scratch_folder_path + "/rb_inv_RITRI.petscmat",PETSC_COMM_SELF);
186 
187  // Get the data
188  PetscScalar *dummy_array;
189  MatDenseGetArray(m_inv_RITRI_mat,&dummy_array);
190 
191  for(int iii = 0; iii < m_null_nb_vecs*m_null_nb_vecs; ++iii)
192  {
193  dummy_matrix_contents[iii] = dummy_array[iii];
194  }
195 
196  MatDenseRestoreArray(m_inv_RITRI_mat,&dummy_array);
197  }
198 
199  // Sync the matrix!
200  m_comm.barrier();
201  m_comm.broadcast(dummy_matrix_contents);
202 
203  if(m_comm.rank() != 0)
204  {
205  std::vector<PetscInt> dummy_indexes(m_null_nb_vecs,0);
206 
207  for(int iii = 0; iii < m_null_nb_vecs; ++iii)
208  {
209  dummy_indexes[iii] = iii;
210  }
211 
212  MatSetValues(m_inv_RITRI_mat,m_null_nb_vecs,&dummy_indexes[0],m_null_nb_vecs,&dummy_indexes[0],&dummy_matrix_contents[0],INSERT_VALUES);
213  MatAssemblyBegin(m_inv_RITRI_mat,MAT_FINAL_ASSEMBLY);
214  MatAssemblyEnd(m_inv_RITRI_mat,MAT_FINAL_ASSEMBLY);
215  }
216 
217  // Set up flag
218  m_binvRITRIMatSet = true;
219 }
220 
221 // --- FETI read methods
223 {
224  homemade_assert_msg(m_bScratchFolderSet,"Scratch folder not set yet!");
225 
226  // Create the vectors and, if needed, set sizes
227  VecCreate(m_comm.get(),&m_u_0_BIG);
228  VecCreate(m_comm.get(),&m_u_0_micro);
229 
230  // If the sizes were defined already, set them
231  if(m_bBIG_sizes_set)
232  {
234  }
235 
237  {
239  }
240 
241  // Read them
242  read_PETSC_vector(m_u_0_BIG,m_scratch_folder_path + "/ext_solver_u0_A_sys_sol_vec.petscvec", m_comm.get());
243  read_PETSC_vector(m_u_0_micro,m_scratch_folder_path + "/ext_solver_u0_B_sys_sol_vec.petscvec", m_comm.get());
244 
245  // If the sizes were not defined yet, define them
246  if(!m_bBIG_sizes_set)
247  {
248  VecGetLocalSize(m_u_0_BIG,&m_C_R_BIG_N_local);
249  VecGetSize(m_u_0_BIG,&m_C_R_BIG_N);
250  m_bBIG_sizes_set = true;
251  }
252 
253  if(!m_bmicro_sizes_set)
254  {
255  VecGetLocalSize(m_u_0_micro,&m_C_R_micro_N_local);
256  VecGetSize(m_u_0_micro,&m_C_R_micro_N);
257  m_bmicro_sizes_set = true;
258  }
259 
260  // Set null vector dimensions (if needed)
262  {
263  switch (m_RB_modes_system)
264  {
265  case RBModesSystem::MACRO :
268  break;
269 
270  case RBModesSystem::MICRO :
273  break;
274  }
276  }
277 
278  // Set the flag
279  m_bSet_u_0 = true;
280 }
281 
283 {
284  homemade_assert_msg(m_bScratchFolderSet,"Scratch folder not set yet!");
285 
286  // Create the vectors
287  VecCreate(m_comm.get(),&m_ext_solver_sol_BIG);
288  VecCreate(m_comm.get(),&m_ext_solver_sol_micro);
289 
290  // If the sizes were defined already, set them
291  if(m_bBIG_sizes_set)
292  {
294  }
295 
297  {
299  }
300 
301  // Read them
302  read_PETSC_vector(m_ext_solver_sol_BIG,m_scratch_folder_path + "/ext_solver_A_sys_sol_vec.petscvec", m_comm.get());
303  read_PETSC_vector(m_ext_solver_sol_micro,m_scratch_folder_path + "/ext_solver_B_sys_sol_vec.petscvec", m_comm.get());
304 
305  // If the sizes were not defined yet, define them
306  if(!m_bBIG_sizes_set)
307  {
308  VecGetLocalSize(m_ext_solver_sol_BIG,&m_C_R_BIG_N_local);
309  VecGetSize(m_ext_solver_sol_BIG,&m_C_R_BIG_N);
310  m_bBIG_sizes_set = true;
311  }
312 
313  if(!m_bmicro_sizes_set)
314  {
317  m_bmicro_sizes_set = true;
318  }
319 
320  // Set null vector dimensions (if needed)
322  {
323  switch (m_RB_modes_system)
324  {
325  case RBModesSystem::MACRO :
328  break;
329 
330  case RBModesSystem::MICRO :
333  break;
334  }
336  }
337 
338  // Set the flag
339  m_bSet_ext_solver_sol = true;
340 }
341 
343 {
344  homemade_assert_msg(m_bScratchFolderSet,"Scratch folder not set yet!");
345  homemade_assert_msg(m_bNullVecsDimensionsSet,"Null vectors sizes not set yet!");
346 
347  // Create the vectors
348  VecCreate(m_comm.get(),&m_current_rb_correction);
350  read_PETSC_vector(m_current_rb_correction,m_scratch_folder_path + "/FETI_RB_correction.petscvec", m_comm.get());
351 
352  // Set flag
354 }
355 
357 {
358  homemade_assert_msg(m_bScratchFolderSet,"Scratch folder not set yet!");
359  homemade_assert_msg(m_bR_sizes_set,"Mediator space dimensions not set yet!");
360 
361  // Create the vectors
362  VecCreate(m_comm.get(),&m_previous_phi);
364  read_PETSC_vector(m_previous_phi,m_scratch_folder_path + "/FETI_iter__phi__current.petscvec", m_comm.get());
365 
366  // Set flag
367  m_bSet_previous_phi = true;
368 }
369 
371 {
372  homemade_assert_msg(m_bScratchFolderSet,"Scratch folder not set yet!");
373  homemade_assert_msg(m_bR_sizes_set,"Mediator space dimensions not set yet!");
374 
375  // Create the vectors
376  VecCreate(m_comm.get(),&m_previous_residual);
378  read_PETSC_vector(m_previous_residual,m_scratch_folder_path + "/FETI_iter__r__current.petscvec", m_comm.get());
379 
380  // Set flag
382 }
383 
385 {
386  homemade_assert_msg(m_bScratchFolderSet,"Scratch folder not set yet!");
387  homemade_assert_msg(m_bSet_previous_residual,"Previous residual vector not set yet!");
388  homemade_assert_msg(m_bR_sizes_set,"Mediator space dimensions not set yet!");
389 
390  // Create p(0 ... kkk),
391  m_previous_p_ptr = new Vec[m_kkk+1];
392  VecDuplicateVecs(m_previous_residual,m_kkk+1,&m_previous_p_ptr);
393 
394  // Read p(0 ... kkk)
395  for(int iii = 0; iii < m_kkk+1; ++iii)
396  {
397  read_PETSC_vector(m_previous_p_ptr[iii],m_scratch_folder_path + "/FETI_iter__p__" + std::to_string(iii) + ".petscvec", m_comm.get());
398  }
399 
400  // Set flag
401  m_bSet_previous_p_ptr = true;
402 }
403 
405 {
406  homemade_assert_msg(m_bScratchFolderSet,"Scratch folder not set yet!");
407  homemade_assert_msg(m_bSet_previous_residual,"Previous residual vector not set yet!");
408  homemade_assert_msg(m_bR_sizes_set,"Mediator space dimensions not set yet!");
409 
410  // Create q(0 ... kkk)
411  m_previous_q_ptr = new Vec[m_kkk+1];
412  VecDuplicateVecs(m_previous_residual,m_kkk+1,&m_previous_q_ptr);
413 
414  // Read q(0 ... kkk - 1)
415  if(m_kkk > 0)
416  {
417  for(int iii = 0; iii < m_kkk; ++iii)
418  {
419  read_PETSC_vector(m_previous_q_ptr[iii],m_scratch_folder_path + "/FETI_iter__q__" + std::to_string(iii) + ".petscvec", m_comm.get());
420  }
421  }
422 
423  // Set flags
424  m_bSet_previous_q_ptr = true;
425 }
426 
428 {
429  homemade_assert_msg(m_bScratchFolderSet,"Scratch folder not set yet!");
430 
431  // Import the scalar data
432  // File format: kkk rho(0) rho(kkk) [ RB_corr(kkk) ]
433 
434  // ONLY read in proc 0!
435  if(m_comm.rank() == 0)
436  {
437  std::ifstream scalar_data;
438 
439  scalar_data.open(m_scratch_folder_path + "/FETI_iter_scalar_data.dat");
440  scalar_data >> m_kkk >> m_rho_0 >> m_previous_rho;
441 
442  if(m_bUsingNullVecs)
443  {
444  scalar_data >> m_previous_RB_mode_corr;
445  }
446  scalar_data.close();
447  }
448 
449  // Broadcast the values
450  m_comm.broadcast(m_kkk);
451  m_comm.broadcast(m_rho_0);
452  m_comm.broadcast(m_previous_rho);
453  if(m_bUsingNullVecs)
454  {
455  m_comm.broadcast(m_previous_RB_mode_corr);
456  }
457 
458  // Import `p(0 ... kkk - 1).q(0 ... kkk - 1)`
459  m_p_dot_q.resize(m_kkk+1,0);
460  if(m_kkk != 0)
461  {
462  // ONLY read in proc 0!
463  if(m_comm.rank() == 0)
464  {
465  std::ifstream scalar_data;
466  scalar_data.open(m_scratch_folder_path + "/FETI_iter_p_dot_q.dat");
467 
468  for(int iii = 0; iii < m_kkk; ++iii)
469  {
470  scalar_data >> m_p_dot_q[iii];
471  }
472  scalar_data.close();
473  }
474 
475  // Broadcast the values
476  m_comm.broadcast(m_p_dot_q);
477  }
478 
479  // Set flag
480  m_bReadPreviousScalar = true;
481 }
482 
484 {
485  homemade_assert_msg(m_bScratchFolderSet,"Scratch folder not set yet!");
486  homemade_assert_msg(m_bReadPreviousScalar,"Scalar data not set yet!");
487 
488  /* Vectors to read: 'r(kkk)'
489  * 'phi(kkk)'
490  * 'p(0 ... kkk)'
491  * 'q(0 ... kkk - 1)'
492  */
493 
494  // Create and read the vectors
495  // r(kkk)
496  this->read_previous_r();
497 
498  // phi(kkk)
499  this->read_previous_phi();
500 
501  // p(0 ... kkk)
502  this->read_all_previous_p();
503 
504  // q(0 ... kkk)
505  // Create q(0 ... kkk), read q(0 ... kkk - 1)
506  this->read_all_previous_q();
507 }
508 
509 // --- Write methods
511 {
512  homemade_assert_msg(m_bScratchFolderSet,"Scratch folder not set yet!");
513 
514  homemade_assert_msg(m_bSet_current_p,"Current 'p' not calculated yet!");
516 }
517 
519 {
520  homemade_assert_msg(m_bScratchFolderSet,"Scratch folder not set yet!");
521 
522  homemade_assert_msg(m_bSet_current_z,"Current 'p' not calculated yet!");
524 }
525 
527 {
528  homemade_assert_msg(m_bScratchFolderSet,"Scratch folder not set yet!");
529  homemade_assert_msg(m_bSet_current_phi,"Current 'phi' not calculated yet!");
530 
532 }
533 
535 {
536  homemade_assert_msg(m_bScratchFolderSet,"Scratch folder not set yet!");
537  homemade_assert_msg(m_bSet_current_RB_correction,"Current RB correction not calculated yet!");
538 
539 
540  write_PETSC_vector(m_current_rb_correction,m_scratch_folder_path + "/FETI_RB_correction.petscvec",m_comm.rank(),m_comm.get());
541 
542 // Print MatLab debugging output? Variable defined at "carl_headers.h"
543 #ifdef PRINT_MATLAB_DEBUG
545 #endif
546 }
547 
549 {
550  homemade_assert_msg(m_bScratchFolderSet,"Scratch folder not set yet!");
551  homemade_assert_msg(m_bSet_current_p,"Current 'p' not calculated yet!");
552 
553  write_PETSC_vector(m_current_p,m_scratch_folder_path + "/FETI_iter__p__" + std::to_string(m_kkk+1) + ".petscvec",m_comm.rank(),m_comm.get());
554 
555 // Print MatLab debugging output? Variable defined at "carl_headers.h"
556 #ifdef PRINT_MATLAB_DEBUG
557  write_PETSC_vector_MATLAB(m_current_p,m_scratch_folder_path + "/FETI_iter__p__" + std::to_string(m_kkk+1) + ".m",m_comm.get());
558 #endif
559 }
560 
562 {
563  homemade_assert_msg(m_bScratchFolderSet,"Scratch folder not set yet!");
564  homemade_assert_msg(m_bSet_previous_q_ptr,"'q' vectors not calculated yet!");
565 
566  write_PETSC_vector(m_previous_q_ptr[m_kkk],m_scratch_folder_path + "/FETI_iter__q__" + std::to_string(m_kkk) + ".petscvec",m_comm.rank(),m_comm.get());
567 
568 // Print MatLab debugging output? Variable defined at "carl_headers.h"
569 #ifdef PRINT_MATLAB_DEBUG
570  write_PETSC_vector_MATLAB(m_previous_q_ptr[m_kkk],m_scratch_folder_path + "/FETI_iter__q__" + std::to_string(m_kkk) + ".m",m_comm.get());
571 #endif
572 }
573 
575 {
576  homemade_assert_msg(m_bScratchFolderSet,"Scratch folder not set yet!");
577  homemade_assert_msg(m_bSet_current_residual,"Current residual not calculated yet!");
578 
579  write_PETSC_vector(m_current_residual,m_scratch_folder_path + "/FETI_iter__r__current.petscvec",m_comm.rank(),m_comm.get());
580 
581 // Print MatLab debugging output? Variable defined at "carl_headers.h"
582 #ifdef PRINT_MATLAB_DEBUG
583  write_PETSC_vector_MATLAB(m_current_residual,m_scratch_folder_path + "/FETI_iter__r__current.m",m_comm.get());
584 #endif
585 }
586 
588 {
589  homemade_assert_msg(m_bScratchFolderSet,"Scratch folder not set yet!");
590  homemade_assert_msg(m_bSet_current_phi,"Current 'phi' not calculated yet!");
591 
592  write_PETSC_vector(m_current_phi,m_scratch_folder_path + "/FETI_iter__phi__current.petscvec",m_comm.rank(),m_comm.get());
593 
594 // Print MatLab debugging output? Variable defined at "carl_headers.h"
595 #ifdef PRINT_MATLAB_DEBUG
596  write_PETSC_vector_MATLAB(m_current_phi,m_scratch_folder_path + "/FETI_iter__phi__current.m",m_comm.get());
597 #endif
598 }
599 
601 {
602  // Export r(0) and p(0) ( p(0) is identical to z(0))
603  homemade_assert_msg(m_bScratchFolderSet,"Scratch folder not set yet!");
604  homemade_assert_msg(m_bSet_current_residual,"Current residual not calculated yet!");
605 
606  // In all cases, print r(0)
607  write_PETSC_vector(m_current_residual,m_scratch_folder_path + "/FETI_iter__r__current.petscvec",m_comm.rank(),m_comm.get());
608 
609 // Print MatLab debugging output? Variable defined at "carl_headers.h"
610 #ifdef PRINT_MATLAB_DEBUG
611  write_PETSC_vector_MATLAB(m_current_residual,m_scratch_folder_path + "/FETI_iter__r__current.m",m_comm.get());
612 #endif
613 
614  // p(0) is only identical to r(0) if neither a preconditioner or the RB modes are used
616  {
617  write_PETSC_vector(m_current_z,m_scratch_folder_path + "/FETI_iter__p__0.petscvec",m_comm.rank(),m_comm.get());
618 
619 // Print MatLab debugging output? Variable defined at "carl_headers.h"
620 #ifdef PRINT_MATLAB_DEBUG
622 #endif
623  }
624 }
625 
627 {
628  homemade_assert_msg(m_bScratchFolderSet,"Scratch folder not set yet!");
629 
630 
631  homemade_assert_msg(m_bSet_current_residual,"Current residual not calculated yet!");
632  PetscScalar residual = 0;
633  PetscScalar RB_correct = 0;
634 
635  if(m_bUsingNullVecs)
636  {
637  homemade_assert_msg(m_bSet_current_RB_correction,"Current RB modes correction not calculated yet!");
638  }
639 
640  // --- Calculate the values
641  // rho(0)
643  {
644  VecDot(m_current_residual,m_current_z,&residual);
645  } else {
646  VecDot(m_current_residual,m_current_residual,&residual);
647  }
648 
649  // RB_corr(0)
650  if(m_bUsingNullVecs)
651  {
652  VecNorm(m_current_rb_correction,NORM_2,&RB_correct);
653  }
654 
655  // ONLY write in proc 0!
656  if(m_comm.rank() == 0)
657  {
658  std::ofstream scalar_data;
659 
660  // Export the scalar data
661  scalar_data.open(m_scratch_folder_path + "/FETI_iter_scalar_data.dat");
662  scalar_data.precision(15);
663  scalar_data << m_kkk << " " << residual << " " << residual;
664 
665  if(m_bUsingNullVecs)
666  {
667  scalar_data << " " << RB_correct;
668  }
669 
670  scalar_data << std::endl;
671 
672  scalar_data.close();
673 
674  // Export the convergence data
675  scalar_data.open(m_scratch_folder_path + "/FETI_convergence.dat");
676  scalar_data.precision(15);
677  scalar_data << m_kkk << " " << residual;
678 
679  if(m_bUsingNullVecs)
680  {
681  scalar_data << " " << RB_correct;
682  }
683 
684  scalar_data << std::endl;
685 
686  scalar_data.close();
687  }
688 }
689 
691 {
692  homemade_assert_msg(m_bScratchFolderSet,"Scratch folder not set yet!");
693  homemade_assert_msg(m_bCalculatedScalar,"Scalar data not calculated yet!");
694 
695  // ONLY write in proc 0!
696  if(m_comm.rank() == 0)
697  {
698  std::ofstream scalar_data;
699 
700  // Export the scalar data
701  scalar_data.open(m_scratch_folder_path + "/FETI_iter_scalar_data.dat");
702  scalar_data.precision(15);
703  scalar_data << m_kkk + 1 << " " << m_rho_0 << " " << m_current_rho;
704 
705  if(m_bUsingNullVecs)
706  {
707  scalar_data << " " << m_current_RB_mode_corr;
708  }
709 
710  scalar_data << std::endl;
711 
712  scalar_data.close();
713 
714  // Export the convergence data
715  scalar_data.open(m_scratch_folder_path + "/FETI_convergence.dat",std::ofstream::app);
716  scalar_data.precision(15);
717  scalar_data << m_kkk + 1 << " " << m_current_rho;
718 
719  if(m_bUsingNullVecs)
720  {
721  scalar_data << " " << m_current_RB_mode_corr;
722  }
723  scalar_data << std::endl;
724 
725  scalar_data.close();
726 
727  // Export `p(kkk).q(kkk)`
728  if(m_kkk == 0)
729  {
730  scalar_data.open(m_scratch_folder_path + "/FETI_iter_p_dot_q.dat");
731  } else {
732 
733  scalar_data.open(m_scratch_folder_path + "/FETI_iter_p_dot_q.dat",std::ofstream::app);
734  }
735  scalar_data.precision(15);
736  scalar_data << m_p_dot_q[m_kkk] << std::endl;
737 
738  scalar_data.close();
739  }
740 }
741 
743 {
744  /* Export the iteration vectors
745  * Vectors to export: 'r(kkk+1)'
746  * 'phi(kkk+1)'
747  * 'p(kkk+1)'
748  * 'q(kkk)'
749  */
750 
751  // r(kkk+1)
752  this->export_r();
753 
754  // phi(kkk+1)
755  this->export_phi();
756 
757  // p(kkk+1)
758  this->export_p();
759 
760  // q(kkk)
761  this->export_q();
762 }
763 
764 void FETI_Operations::export_coupled_solution(std::string output_base)
765 {
766  homemade_assert_msg(m_bScratchFolderSet,"Scratch folder not set yet!");
767  homemade_assert_msg(m_bCoupled_sols_set,"Coupled solutions not calculated yet!");
768 
769  write_PETSC_vector(m_coupled_sol_BIG,output_base + "/coupled_sol_A.petscvec",m_comm.rank(),m_comm.get());
770  write_PETSC_vector(m_coupled_sol_micro,output_base + "/coupled_sol_B.petscvec",m_comm.rank(),m_comm.get());
771 
772 // Print MatLab debugging output? Variable defined at "carl_headers.h"
773 #ifdef PRINT_MATLAB_DEBUG
774  write_PETSC_vector_MATLAB(m_coupled_sol_BIG,output_base + "/coupled_sol_A.m",m_comm.get());
775  write_PETSC_vector_MATLAB(m_coupled_sol_micro,output_base + "/coupled_sol_B.m",m_comm.get());
776 #endif
777 }
778 
780 {
781  std::cout << std::endl;
782  std::cout << " --> Iteration no. " << m_kkk + 1 << " : ";
783 
785  {
786  std::cout << " > Abs. residual convergence : rho(kkk+1) < " << m_abs_residual_conv << std::endl;
787  }
789  {
790  std::cout << " > Rel. residual convergence : rho(kkk+1) < " << m_rel_residual_conv << " * rho(0) " << std::endl;
791  }
793  {
794  std::cout << " > Rel. residual DIVERGENCE : rho(kkk+1) > " << m_rel_residual_div << " * rho(0) " << std::endl;
795  }
797  {
798  std::cout << " > Negative residual DIVERGENCE" << std::endl;
799  }
801  {
802  std::cout << " > Iter. DIVERGENCE : kkk + 1 > " << m_max_iter_div << std::endl;
803  }
804  if(m_bUsingNullVecs)
805  {
806  if(m_bConvRBCorrRel)
807  {
808  std::cout << " > Rel. RB mode correction convergence : abs( RB(kkk+1) - RB_(kkk) ) / RB(kkk+1) < " << m_rb_modes_conv << std::endl;
809  }
810  }
811  std::cout << std::endl;
812 
813  std::cout << " --> Previous " << std::min(m_kkk+2,nb_of_iters) << " iterations convergence parameter : " << std::endl;
814  if(m_bUsingNullVecs)
815  {
816  std::cout << "[ kkk ] [ rho(kkk) ] [ | RB_corr(kkk) | ]" << std::endl;
817  }
818  else
819  {
820  std::cout << "[ kkk ] [ rho(kkk) ]" << std::endl;
821  }
822 
823  std::string command_string = "tail -n " + std::to_string(nb_of_iters) + " " + m_scratch_folder_path + "/FETI_convergence.dat";
824 
825  if(m_comm.rank() == 0)
826  {
827  std::cout << exec_command(command_string) << std::endl;
828  }
829  if( m_bConv ) {
830  std::cout << " --> Converged!" << std::endl;
831  } else if ( m_bDiv ) {
832  std::cout << " --> DIVERGED!" << std::endl;
833  } else {
834  std::cout << " --> Iterating ..." << std::endl;
835  }
836  std::cout << std::endl;
837 }
838 
839 }
double m_abs_residual_conv
Absolute residual convergence.
void export_inital_vecs()
Export the initial iteration vectors, r(0) and p(0)
Vec m_current_residual
Current residual vector, r(kkk+1) (r(0) for the initialization)
bool m_bC_RR_MatrixSet
Mediator - mediator coupling matrix has been set?
double m_rho_0
Double containing the initial rho(0)
PetscInt m_null_nb_vecs
Number of null space vectors.
bool m_bR_sizes_set
Have the mediator dimensions been set yet?
bool m_bSet_u_0
Have the u_0 vectors been set?
bool m_bNullVecsDimensionsSet
Have the null space vectors' dimensions been set?
bool m_bConvResidualRel
The residual converged? (relative to initial value)
bool m_bSet_previous_residual
Have the previous r(kkk) vector been set?
Vec m_previous_phi
Previous Lagrange multipliers / solution, phi(kkk)
std::string m_coupling_folder_path
Coupling matrices path.
void read_scalar_data()
Read the scalar data, rho(0 ... kkk), | RB_corr(0 ... kkk) | and p(0 ... kkk - 1).q(0 ... kkk - 1)
Mat m_C_RR
Mediator - mediator system coupling matrix.
double m_previous_RB_mode_corr
Double containing the previous RB_mode_corr(kkk)
bool m_binvRITRIMatSet
Have the inv(RI^T * RI) matrix been set?
void export_ext_solver_rhs(Vec vec_in)
Calculate and export the external solver RHS's.
void read_previous_phi()
Read the previous Lagrage multiplier / solution.
void read_all_previous_q()
Read all the previous q vectors.
Mat m_C_R_BIG
Mediator - macro system coupling matrix.
void write_PETSC_vector(libMesh::PetscVector< libMesh::Number > &input_vec, const std::string &filename, int dim=1)
bool m_bConv
Did the solver converge?
double m_rel_residual_conv
Relative residual convergence (relative to initial value)
Vec m_ext_solver_sol_micro
Micro model external solver solution.
void export_rb_correction_vector()
Export the rigid body modes correction.
std::string exec_command(const std::string &cmd)
void export_ext_solver_rhs_Ct_phi()
Calculate and export the external solver RHS's for the decoupled problem.
void set_coupling_matrix_R_micro()
Read the mediator - micro system coupling matrix.
void export_r()
Export the current r(kkk+1) residual vector.
Vec m_u_0_BIG
Solution of the decoupled macro model.
std::string m_scratch_folder_path
Scratch folder path.
void export_q()
Export the current q(kkk) vector.
Vec m_coupled_sol_micro
Coupled system solution for the micro model.
bool m_bC_R_BIG_MatrixSet
Mediator - macro coupling matrix has been set?
void read_previous_r()
Read the previous residual.
void read_rb_corr()
Read the rigid body modes correction vector.
Vec * m_previous_p_ptr
Pointer to the previous p vectors, p(0 ... kkk)
Mat m_inv_RITRI_mat
Matrix , used in some projectors.
int m_max_iter_div
Number of iterations divergence.
void export_p()
Export the current p(kkk+1) vector.
bool m_bSet_current_RB_correction
Have the RB modes correction RB_corr(kkk+1) vector been set?
void read_null_space_vecs(const std::string &RB_vectors_base, int nb_of_rb_vectors)
Read the null space vectors.
bool m_bCalculatedScalar
Calculated the current iterations scalar data?
Vec m_u_0_micro
Solution of the decoupled micro model.
void set_coupling_matrix_RR()
Read the mediator - mediator system coupling matrix.
bool m_bDivResidualNeg
The residual is negative? (more usefull for debugging, really)
Vec m_current_z
Current z(kkk+1) (z(0) for the initialization)
bool m_bBIG_sizes_set
Have the macro dimensions been set yet?
void read_vector_data()
Read the vector data - essentially calls the "read_previous" and "read_all_previous" methods...
Vec m_current_rb_correction
Current rigid body modes correction, RB_corr(kkk+1) (RB_corr(0) for the initialization) ...
bool m_bScratchFolderSet
Have the scratch folder been set?
Mat m_C_R_micro
Mediator - micro system coupling matrix.
bool m_bSet_previous_p_ptr
Have the previous p vectors, p(0 ... kkk), been set?
void export_initial_scalar_data()
Export the initial iteration scalar data, rho(0) and | RB_corr(0) |
void export_phi()
Export the current Lagrange multiplier / solution.
bool m_bSet_current_z
Have the current z(kkk+1) vector been set?
double m_current_RB_mode_corr
Double containing the current RB_mode_corr(kkk+1)
double m_rb_modes_conv
Relative RB correction convergence (relative to previous value)
Vec * m_previous_q_ptr
Pointer to the previous q vectors, q(0 ... kkk)
double m_previous_rho
Double containing the previous rho(kkk)
bool m_bDiv
Did the solver diverge?
bool m_bSet_current_residual
Have the current r(kkk+1) vector been set?
void read_all_previous_p()
Read all the previous p vectors.
void read_PETSC_matrix(Mat input_mat, const std::string &filename, MPI_Comm comm=PETSC_COMM_WORLD)
Vec m_coupled_sol_BIG
Coupled system solution for the macro model.
std::vector< double > m_p_dot_q
Vector containing the p.q scalar products.
RBModesSystem m_RB_modes_system
Which model is associated to the RB modes? Default: RBModesSystem::MICRO.
void set_coupling_matrix_R_BIG()
Read the mediator - macro system coupling matrix.
bool m_bSet_previous_q_ptr
Have the previous q vectors, q(0 ... kkk), been set?
bool m_bReadPreviousScalar
Read the previous iterations scalar data?
bool m_bConvRBCorrRel
The RB correction converged? (relative to previous value)
libMesh::Parallel::Communicator & m_comm
Communicator.
bool m_bCouplingFolderSet
Have the Coupling matrices folder been set?
void read_null_space_inv_RITRI_mat()
Read the matrix.
void read_coupling_matrices()
Read all the coupling matrices.
Vec m_ext_solver_sol_BIG
Macro model external solver solution.
bool m_bConvResidualAbs
The residual converged? (absolute)
bool m_bCouplingMatricesSet
All coupling matrices has been set?
double m_rel_residual_div
Relative residual divergence (relative to initial value)
void export_coupled_solution(std::string output_base)
void read_decoupled_solutions()
Read the decoupled solutions, .
bool m_bSet_ext_solver_sol
Have the external solvers solutions been set vectors been set?
bool m_bC_R_micro_MatrixSet
Mediator - micro coupling matrix has been set?
bool m_bmicro_sizes_set
Have the micro dimensions been set yet?
bool m_bSet_current_p
Have the current p(kkk+1) vector been set?
Vec m_current_phi
Current Lagrange multipliers / solution, phi(kkk+1) (phi(0) for the initialization) ...
#define homemade_assert_msg(asserted, msg)
Definition: common_header.h:63
void read_ext_solver_output()
Read the latest external solver output.
BaseCGPrecondType m_precond_type
Preconditioner type. Default: BaseCGPrecondType::NO_PRECONDITIONER.
bool m_bSet_previous_phi
Have the previous Lagrange multipliers / solution phi(kkk) been set?
void print_previous_iters_conv(int nb_of_iters=5)
void export_scalar_data()
Export the iteration scalar data, rho(kkk+1), | RB_corr(kkk+1) | and p(kkk).q(kkk) ...
bool m_bCoupled_sols_set
Have the coupled solutions been set yet?
Vec m_null_coupled_vecs[maxVecLimit]
Null space vectors times the coupling matrix.
bool m_bDivResidualRel
The residual diverged? (relative to initial value)
Vec m_previous_residual
Previous residual vector, r(kkk)
void export_ext_solver_rhs_Ct_p()
Calculate and export the external solver RHS's for the next iteration.
int m_kkk
Current iteration index.
void read_PETSC_vector(libMesh::PetscVector< libMesh::Number > &input_vec, const std::string &filename)
bool m_bSet_current_phi
Have the current Lagrange multipliers / solution phi(kkk+1) been set?
void write_PETSC_vector_MATLAB(Vec input_vec, const std::string &filename, MPI_Comm comm=PETSC_COMM_WORLD)
Vec m_current_p
Current p(kkk+1) (p(0) for the initialization)
void export_ext_solver_rhs_initial()
Calculate and export the external solver RHS's for the first iteration.
Vec m_null_vecs[maxVecLimit]
Null space vectors.
double m_current_rho
Double containing the current rho(kkk+1)
bool m_bUsingNullVecs
Do we need to use the null space vectors?
bool m_bNullVecsSet
Have the null space vectors been set?