CArl
Code Arlequin / C++ implementation
FETI_operations.h
Go to the documentation of this file.
1 /*
2  * FETI_operations.h
3  *
4  * Created on: Apr 23, 2017
5  * Author: Thiago Milanetto Schlittler
6  */
7 
8 #ifndef FETI_OPERATIONS_H_
9 #define FETI_OPERATIONS_H_
10 
11 #include "carl_headers.h"
12 #include "common_enums.h"
14 
15 namespace carl
16 {
17 
37 {
38 protected:
39 
40  // --- Miscellaneous declarations
41  libMesh::Parallel::Communicator& m_comm;
44  std::string m_scratch_folder_path;
45  std::string m_coupling_folder_path;
47  int m_kkk;
48 
49  // --- Coupling matrix and preconditioner declarations
50 
51  // Coupling matrices
53  Mat m_C_R_BIG;
54  Mat m_C_RR;
55 
56  // Matrix dimensions
57  /*
58  * M x N
59  * m_C_R_micro : n_med x n_sys_micro
60  * m_C_R_BIG : n_med x n_sys_BIG
61  * m_C_RR : n_med x n_med
62  *
63  */
67 
68  // Objects used by the preconditioner
71 
72  // Boolean flags
77 
81 
83 
84  // --- Null space / rigid body modes declarations
86 
89 
90  // Vectors
91  /*
92  * Note: using Vec arrays does not pose a memory problem, since a PETSc `Vec` is essentially a
93  * pointer in the stack. The `Vec`'s contents arre allocated in the heap when calling functions such as
94  * `VecCreate` and such.
95  *
96  */
97  PetscInt m_null_nb_vecs;
98  enum { maxVecLimit = 6 };
101 
102  // Null vector dimensions
104 
105  // Matrices
108 
109  // Boolean flags
114 
115  // --- FETI operations declarations
116  // Vectors
118  Vec m_u_0_BIG;
119 
122 
126 
129 
134 
135  // Real values
136  double m_gamma;
137  double m_rho_0;
138  double m_current_rho;
140  double m_previous_rho;
142 
143  // Boolean flags
144  bool m_bSet_u_0;
146 
152 
157 
158  // --- Vectors containing the scalar data
159  std::vector<double> m_p_dot_q;
160 
161  // Boolean flags
164 
165  // --- Convergence parameters
171 
172  // Boolean flags
178  bool m_bDivIter;
179  bool m_bConv;
180  bool m_bDiv;
181 
182  // --- Converged coupled solution vectors
185 
187 
188  // --- Protected methods
189  // Preconditioner methods
191 
193 
195 
196  void apply_inverse_coupling_precond(Vec vec_in, Vec vec_out);
197 
198  void apply_jacobi_coupling_precond(Vec vec_in, Vec vec_out);
199 
200  void apply_precond(Vec vec_in, Vec vec_out);
201 
202  // Projection methods
203  void apply_RB_projection(Vec vec_in, Vec vec_out);
204 
206  void export_ext_solver_rhs(Vec vec_in);
207 
209  void clear_PETSc();
210 
212  FETI_Operations();
213 
214 public:
216  FETI_Operations(libMesh::Parallel::Communicator& comm, const std::string& scratch_folder_path , const std::string& coupling_folder_path) :
217  m_comm { comm },
218  m_bScratchFolderSet { true },
219  m_bCouplingFolderSet { true },
220  m_scratch_folder_path { scratch_folder_path },
221  m_coupling_folder_path { coupling_folder_path },
222  m_FETI_solver_status { IterationStatus::ITERATING },
223  m_kkk { 0 },
224  m_C_R_micro_M { -1},
225  m_C_R_micro_N { -1},
226  m_C_R_micro_M_local { -1},
227  m_C_R_micro_N_local { -1},
228  m_C_R_BIG_M { -1},
229  m_C_R_BIG_N { -1},
230  m_C_R_BIG_M_local { -1},
231  m_C_R_BIG_N_local { -1},
232  m_C_RR_M { -1},
233  m_C_RR_M_local { -1},
234  m_bC_R_micro_MatrixSet { false },
235  m_bC_R_BIG_MatrixSet { false },
236  m_bC_RR_MatrixSet { false },
237  m_bCouplingMatricesSet { false },
238  m_bmicro_sizes_set { false },
239  m_bBIG_sizes_set { false },
240  m_bR_sizes_set { false },
241  m_precond_type { BaseCGPrecondType::NO_PRECONDITIONER },
242  m_RB_modes_system { RBModesSystem::MICRO },
243  m_bCreatedPrecondSolver { false },
244  m_bCreatedPrecondJacobiVec { false },
245  m_null_nb_vecs { -1 },
246  m_null_vecs_N { -1 },
247  m_null_vecs_N_local { -1 },
248  m_bUsingNullVecs { false },
249  m_bNullVecsSet { false },
250  m_bNullVecsDimensionsSet { false },
251  m_binvRITRIMatSet { false },
252  m_gamma { -1 },
253  m_rho_0 { -1 },
254  m_current_rho { -1 },
255  m_current_RB_mode_corr { -1 },
256  m_previous_rho { -1 },
257  m_previous_RB_mode_corr { -1 },
258  m_bSet_u_0 { false },
259  m_bSet_ext_solver_sol { false },
260  m_bSet_current_residual { false },
261  m_bSet_current_z { false },
262  m_bSet_current_p { false },
263  m_bSet_current_phi { false },
264  m_bSet_current_RB_correction { false },
265  m_bSet_previous_residual { false },
266  m_bSet_previous_phi { false },
267  m_bSet_previous_p_ptr { false },
268  m_bSet_previous_q_ptr { false },
269  m_bReadPreviousScalar { false },
270  m_bCalculatedScalar { false },
271  m_abs_residual_conv { -1 },
272  m_rel_residual_conv { -1 },
273  m_rb_modes_conv { -1 },
274  m_rel_residual_div { -1 },
275  m_max_iter_div { -1 },
276  m_bConvResidualAbs { false },
277  m_bConvResidualRel { false },
278  m_bConvRBCorrRel { false },
279  m_bDivResidualRel { false },
280  m_bDivResidualNeg { false },
281  m_bDivIter { false },
282  m_bConv { false },
283  m_bDiv { false },
284  m_bCoupled_sols_set {false}
285  {
286  };
287 
289  FETI_Operations(libMesh::Parallel::Communicator& comm, const std::string& scratch_folder_path) :
290  m_comm { comm },
291  m_bScratchFolderSet { true },
292  m_bCouplingFolderSet { false },
293  m_scratch_folder_path { scratch_folder_path },
294  m_coupling_folder_path { "" },
295  m_FETI_solver_status { IterationStatus::ITERATING },
296  m_kkk { 0 },
297  m_C_R_micro_M { -1},
298  m_C_R_micro_N { -1},
299  m_C_R_micro_M_local { -1},
300  m_C_R_micro_N_local { -1},
301  m_C_R_BIG_M { -1},
302  m_C_R_BIG_N { -1},
303  m_C_R_BIG_M_local { -1},
304  m_C_R_BIG_N_local { -1},
305  m_C_RR_M { -1},
306  m_C_RR_M_local { -1},
307  m_bC_R_micro_MatrixSet { false },
308  m_bC_R_BIG_MatrixSet { false },
309  m_bC_RR_MatrixSet { false },
310  m_bCouplingMatricesSet { false },
311  m_bmicro_sizes_set { false },
312  m_bBIG_sizes_set { false },
313  m_bR_sizes_set { false },
314  m_precond_type { BaseCGPrecondType::NO_PRECONDITIONER },
315  m_RB_modes_system { RBModesSystem::MICRO },
316  m_bCreatedPrecondSolver { false },
317  m_bCreatedPrecondJacobiVec { false },
318  m_null_nb_vecs { -1 },
319  m_null_vecs_N { -1 },
320  m_null_vecs_N_local { -1 },
321  m_bUsingNullVecs { false },
322  m_bNullVecsSet { false },
323  m_bNullVecsDimensionsSet { false },
324  m_binvRITRIMatSet { false },
325  m_gamma { -1 },
326  m_rho_0 { -1 },
327  m_current_rho { -1 },
328  m_current_RB_mode_corr { -1 },
329  m_previous_rho { -1 },
330  m_previous_RB_mode_corr { -1 },
331  m_bSet_u_0 { false },
332  m_bSet_ext_solver_sol { false },
333  m_bSet_current_residual { false },
334  m_bSet_current_z { false },
335  m_bSet_current_p { false },
336  m_bSet_current_phi { false },
337  m_bSet_current_RB_correction { false },
338  m_bSet_previous_residual { false },
339  m_bSet_previous_phi { false },
340  m_bSet_previous_p_ptr { false },
341  m_bSet_previous_q_ptr { false },
342  m_bReadPreviousScalar { false },
343  m_bCalculatedScalar { false },
344  m_abs_residual_conv { -1 },
345  m_rel_residual_conv { -1 },
346  m_rb_modes_conv { -1 },
347  m_rel_residual_div { -1 },
348  m_max_iter_div { -1 },
349  m_bConvResidualAbs { false },
350  m_bConvResidualRel { false },
351  m_bConvRBCorrRel { false },
352  m_bDivResidualRel { false },
353  m_bDivResidualNeg { false },
354  m_bDivIter { false },
355  m_bConv { false },
356  m_bDiv { false },
357  m_bCoupled_sols_set {false}
358  {
359  };
360 
363  {
364  this->clear_PETSc();
365  };
366 
367  // --- Coupling matrix and preconditioner methods
370 
373 
375  void set_coupling_matrix_RR();
376 
378  void read_coupling_matrices();
379 
383  void set_preconditioner(BaseCGPrecondType CG_precond_type, bool bInitialSet = true);
384 
385  // --- Null space / rigid body modes methods
387  void using_rb_modes(bool bUseRigidBodyModes);
388 
390  void set_null_space(const std::string& input_filename_base, int nb_of_vecs);
391 
393  void read_null_space_vecs(const std::string& RB_vectors_base, int nb_of_rb_vectors);
394 
397 
399  void calculate_null_space_phi_0(const std::string& force_path);
400 
401  // --- Read methods
404 
406  void read_ext_solver_output();
407 
409  void read_rb_corr();
410 
412  void read_previous_phi();
413 
415  void read_previous_r();
416 
418  void read_all_previous_p();
419 
421  void read_all_previous_q();
422 
424  void read_scalar_data();
425 
427  void read_vector_data();
428 
429  // --- FETI steps methods
431  void calculate_initial_p();
432 
434  void calculate_initial_r();
435 
437  void calculate_p();
438 
440  void calculate_q();
441 
443  void calculate_r();
444 
446  void calculate_z();
447 
449  void calculate_phi();
450 
453 
455  void calculate_scalar_data();
456 
459 
461  IterationStatus check_convergence(double rel_residual_conv, double abs_residual_conv, int max_iter_div, double rel_residual_div, double rb_modes_conv = -1);
462 
464  void increase_iter_counter();
465 
466  // --- Write methods
469 
472 
475 
478 
480  void export_p();
481 
483  void export_q();
484 
486  void export_r();
487 
489  void export_phi();
490 
492  void export_inital_vecs();
493 
496 
498  void export_scalar_data();
499 
500  // Export the iteration vectors
501  void export_iter_vecs();
502 
503  // Export the final coupled solution
504  void export_coupled_solution(std::string output_base);
505 
506  // Print on `std::cout` the current values of the convergence parameters - and if we converged
507  void print_previous_iters_conv(int nb_of_iters = 5);
508 };
509 }
510 
511 #endif /* FETI_OPERATIONS_H_ */
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?
void set_null_space(const std::string &input_filename_base, int nb_of_vecs)
Set and print the null space vectors and matrices.
bool m_bSet_u_0
Have the u_0 vectors been set?
bool m_bNullVecsDimensionsSet
Have the null space vectors' dimensions been set?
IterationStatus m_FETI_solver_status
Current FETI / CG solver status.
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.
FETI_Operations()
Default constructor.
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.
KSP m_coupling_precond_solver
Preconditioner system solver.
void read_previous_phi()
Read the previous Lagrage multiplier / solution.
void read_all_previous_q()
Read all the previous q vectors.
void calculate_q()
Calculate the current q(kkk) vector.
double m_gamma
Double containing the value of rho(kkk) / p(kkk) . q(kkk)
Mat m_C_R_BIG
Mediator - macro system coupling matrix.
~FETI_Operations()
Destructor, deallocates the PETSc.
void calculate_null_space_phi_0(const std::string &force_path)
Calculate the inital solution, .
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.
void export_ext_solver_rhs_Ct_phi()
Calculate and export the external solver RHS's for the decoupled problem.
bool m_bDivIter
The number of iterations diverged?
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 calculate_z()
Calculate the current z(kkk+1) vector.
void export_q()
Export the current q(kkk) vector.
FETI_Operations(libMesh::Parallel::Communicator &comm, const std::string &scratch_folder_path, const std::string &coupling_folder_path)
Constructor with scratch folder path, coupling matrices base filename, and libMesh communicator...
RBModesSystem
Definition: common_enums.h:61
Vec m_coupled_sol_micro
Coupled system solution for the micro model.
void calculate_phi()
Calculate the current phi(kkk+1) solution vector.
bool m_bC_R_BIG_MatrixSet
Mediator - macro coupling matrix has been set?
void calculate_scalar_data()
Calculate the scalar quantities.
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.
void calculate_initial_p()
Calculate the initial p(0) vector.
bool m_bSet_current_RB_correction
Have the RB modes correction RB_corr(kkk+1) vector been set?
Class containing the operations needed for the FETI solver.
void read_jacobi_precond_vector()
Read the Jacobi coupling matrix preconditioner vector.
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...
void calculate_coupled_solution()
Calculate the final coupled solution.
Vec m_current_rb_correction
Current rigid body modes correction, RB_corr(kkk+1) (RB_corr(0) for the initialization) ...
void clear_PETSc()
PETSc Vec and Mat deallocation, called by the destructor.
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 calculate_rb_correction()
Calculate the rigid body modes corrections.
void export_initial_scalar_data()
Export the initial iteration scalar data, rho(0) and | RB_corr(0) |
bool m_bCreatedPrecondSolver
Have the preconditioner system solver been set?
void export_phi()
Export the current Lagrange multiplier / solution.
bool m_bSet_current_z
Have the current z(kkk+1) vector been set?
void increase_iter_counter()
Increase the iteration counter.
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?
void calculate_r()
Calculate the current r(kkk+1) residual vector.
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.
IterationStatus check_convergence(double rel_residual_conv, double abs_residual_conv, int max_iter_div, double rel_residual_div, double rb_modes_conv=-1)
Check the convergence.
void calculate_p()
Calculate the current p(kkk+1) vector.
void set_jacobi_precond_vector()
Set up the Jacobi coupling matrix preconditioner vector.
void apply_inverse_coupling_precond(Vec vec_in, Vec vec_out)
Apply the full inversed coupling matrix preconditioner.
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?
Vec m_coupling_jacobi_precond_vec
Preconditioner Jacobi vector.
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?
IterationStatus
Definition: common_enums.h:41
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.
void using_rb_modes(bool bUseRigidBodyModes)
Set up the.
bool m_bConvResidualAbs
The residual converged? (absolute)
bool m_bCreatedPrecondJacobiVec
Have the preconditioner system solver been set?
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) ...
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 apply_RB_projection(Vec vec_in, Vec vec_out)
Apply the rigid body modes projection operation.
void export_scalar_data()
Export the iteration scalar data, rho(kkk+1), | RB_corr(kkk+1) | and p(kkk).q(kkk) ...
BaseCGPrecondType
Definition: common_enums.h:35
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 apply_jacobi_coupling_precond(Vec vec_in, Vec vec_out)
Apply the Jacobi coupling matrix preconditioner vector.
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.
bool m_bSet_current_phi
Have the current Lagrange multipliers / solution phi(kkk+1) been set?
void apply_precond(Vec vec_in, Vec vec_out)
Common interface to the preconditionners.
Vec m_current_p
Current p(kkk+1) (p(0) for the initialization)
void calculate_initial_r()
Calculate the inital residual vector, r(0)
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.
void set_preconditioner(BaseCGPrecondType CG_precond_type, bool bInitialSet=true)
double m_current_rho
Double containing the current rho(kkk+1)
void set_inverse_precond_solver()
Set up the full inversed coupling matrix preconditioner.
FETI_Operations(libMesh::Parallel::Communicator &comm, const std::string &scratch_folder_path)
Constructor with scratch folder path and libMesh communicator.
bool m_bUsingNullVecs
Do we need to use the null space vectors?
bool m_bNullVecsSet
Have the null space vectors been set?