TrioCFD 1.9.8
TrioCFD documentation
Loading...
Searching...
No Matches
IJK_Finite_Difference_One_Dimensional_Matrix_Assembler.h
1/****************************************************************************
2* Copyright (c) 2023, CEA
3* All rights reserved.
4*
5* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
6* 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
7* 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
8* 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
9*
10* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
11* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
12* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
13*
14*****************************************************************************/
15
16#ifndef IJK_Finite_Difference_One_Dimensional_Matrix_Assembler_included
17#define IJK_Finite_Difference_One_Dimensional_Matrix_Assembler_included
18
19#include <Objet_U.h>
20#include <Matrice_Bloc.h>
21#include <Matrice_Morse_Sym.h>
22#include <Matrice.h>
23#include <FixedVector.h>
24#include <Param.h>
25
26#define MAX_ORDER_DERIVATIVE 4
27#define FORTRAN_INDEX_INI 1
28/////////////////////////////////////////////////////////////////////////////
29//
30// .DESCRIPTION : class IJK_Finite_Difference_One_Dimensional_Matrix_Assembler
31//
32// <Description of class IJK_Finite_Difference_One_Dimensional_Matrix_Assembler>
33//
34/////////////////////////////////////////////////////////////////////////////
35
37{
38
40
41public :
42 void set_param(Param& param) const override;
43 int build(Matrice& matrix, const int& nb_elem, const int& derivative_order);
44 int build_with_unknown_pattern(Matrice& matrix, const int& nb_elem, const int& derivative_order);
45 int build_with_known_pattern(Matrice& matrix, const int& nb_elem, const int& derivative_order);
46 void modify_rhs_for_bc(Matrice& modified_matrix,
47 DoubleVect& modified_rhs,
48 const int& ini_boundary_conditions,
49 const int& end_boundary_conditions);
51 const DoubleVect& vector,
52 const int& boundary_conditions);
54 const DoubleVect& vector,
55 const int& subproblem_index,
56 const int& boundary_conditions,
57 const int& use_sparse_matrix,
58 const FixedVector<ArrOfInt,6> * first_indices_sparse_matrix);
59 void make_operation_on_sub_matrix_sparse(Matrice& local_sub_matrix,
60 Matrice * matrix,
61 const int& subproblem_index,
62 const FixedVector<ArrOfInt,6> * first_indices_sparse_matrix);
64 Matrice * matrix,
65 const int& subproblem_index,
66 const FixedVector<ArrOfInt,6> * first_indices_sparse_matrix);
67 void impose_boundary_conditions(Matrice& modified_matrix,
68 DoubleVect& mdified_rhs,
69 const int& ini_boundary_conditions,
70 const double& interfacial_value,
71 const int& end_boundary_conditions,
72 const double& end_values,
73 const double& dr_inv,
74 const int& first_time_step_temporal,
75 const int& first_time_step_explicit,
76 const DoubleVect& temperature_ini_temporal_schemes);
78 DoubleVect * global_rhs,
79 DoubleVect& local_rhs,
80 const int& ini_boundary_conditions,
81 const double& interfacial_value,
82 const int& end_boundary_conditions,
83 const double& end_value,
84 const int& subproblem_index,
85 const double& dr_inv,
86 const int& first_time_step_temporal,
87 const int& first_time_step_explicit,
88 const DoubleVect& temperature_ini_temporal_schemes,
89 const int& start_index,
90 const FixedVector<ArrOfInt, 6> * first_indices_sparse_matrix,
91 const int& use_sparse_matrix);
92 void sum_any_matrices_subproblems(Matrice& matrix_A, Matrice& matrix_B, const int& use_sparse_matrix, const int& debug);
93 void sum_sparse_matrices_subproblems(Matrice& matrix_A, Matrice& matrix_B, const int& debug);
94 void sum_matrices_subproblems(Matrice& matrix_A, Matrice& matrix_B);
95 void sum_matrices(Matrice& matrix_A, Matrice& matrix_B);
96 void initialise_sparse_matrix_subproblems(Matrice& matrix_subproblems,
97 Matrice& fd_operator,
98 const int& nb_subproblems,
99 const int& first_time_step_varying_probes,
100 FixedVector<ArrOfInt, 6>& first_indices_sparse_matrix,
101 const int& first_initialisation,
102 int& initialise_sparse_indices);
103 void initialise_matrix_subproblems(Matrice& matrix_subproblems,
104 Matrice& fd_operator,
105 const int& subproblems,
106 const int& first_time_step_varying_probes);
107 void reinitialise_any_matrix_subproblem(Matrice * matrix_subproblems,
108 const Matrice * fd_operator,
109 const int& nb_subproblems,
110 const int& use_sparse_matrix,
111 FixedVector<ArrOfInt,6> * first_indices_sparse_matrix,
112 const int& first_initialisation,
113 const int& keep_global_probes_discretisation);
114 void reinitialise_sparse_matrix_subproblem(Matrice * matrix_subproblems,
115 const Matrice * fd_operator,
116 const int& nb_subproblems,
117 FixedVector<ArrOfInt,6> * first_indices_sparse_matrix,
118 const int& first_initialisation,
119 const int& keep_global_probes_discretisation);
120 void reinitialise_matrix_subproblem(Matrice * matrix_subproblems,
121 const Matrice * fd_operator,
122 const int& nb_subproblems,
123 const int& keep_global_probes_discretisation);
124 void add_source_terms(DoubleVect * thermal_subproblems_rhs_assembly,
125 DoubleVect& rhs_assembly,
126 const DoubleVect& source_terms,
127 const int& index_start,
128 const int& boundary_condition_interface,
129 const int& boundary_condition_end);
130 void compute_operator(const Matrice * fd_operator, const DoubleVect& solution, DoubleVect& res);
131 void apply_euler_time_step(Matrice * convection_matrix,
132 Matrice * diffusion_matrix,
133 const int& subproblem_index,
134 const double& local_time_step,
135 const double& alpha);
136 void correct_sign_temporal_schemes_subproblems(Matrice * convection_matrix,
137 Matrice * diffusion_matrix,
138 const int& subproblem_index,
139 const double& local_time_step,
140 const double& alpha);
141
142 void pre_initialise_matrix_subproblems(Matrice& matrice, Matrice& fd_operator, const int& max_subproblems_predicted);
143 void pre_initialise_sparse_matrix_subproblems(Matrice& matrix_subproblems,
144 Matrice& fd_operator,
145 const int& max_subproblems_predicted);
146 void complete_empty_matrices_initialisation(Matrice& matrix_subproblems,
147 Matrice& fd_operator,
148 const int& empty_problem_start_index,
149 const int& empty_problem_end_index);
150
151 void reduce_solver_matrix(const Matrice_Morse& thermal_subproblems_matrix_assembly_for_solver,
152 Matrice_Morse& thermal_subproblems_matrix_assembly_for_solver_reduced,
153 const int& nb_points,
154 const int& pre_initialise_thermal_subproblems_list);
155
156protected :
160 // enum Boundary_conditions { dirichlet, neumann, flux_jump };
162 /*
163 * -elim_coeff_nul=0, on ne supprime pas les coefficients nuls de la matrice
164 * -elim_coeff_nul=1, on supprime les coefficients nuls de la matrice
165 * -elim_coeff_nul=2, on supprime les coefficients nuls et quasi-nuls de la matrice
166 */
169
170 /*
171 * Identity matrix
172 */
174 /*
175 * First order derivatives
176 */
177 // Forward
178 const std::vector<std::vector<double>> first_order_derivative_forward_vector_ = {{-1., 1.},
179 {-3./2., 2., -1./2.},
180 {-11./6., 3., -3./2., 1./3.},
181 {-25./12., 4., -3., 4./3., -1./4.}
182 };
184
185 // Centred
186 const std::vector<std::vector<double>> first_order_derivative_centred_vector_ = {{-1./2., 0., 1./2.},
187 {-1./2., 0., 1./2.},
188 {1./12., -2./3., 0., 2./3., -1./12.},
189 {1./12., -2./3., 0., 2./3., -1./12.}
190 };
192
193 // Backward
194 const std::vector<std::vector<double>> first_order_derivative_backward_vector_ = {{1., -1.},
195 {3./2., -2., 1./2.},
196 {11./6., -3., 3./2., -1./3.},
197 {25./12., -4., 3., -4./3., 1./4.}
198 };
200
201 /*
202 * Second order derivatives
203 */
204 // Forward
205 const std::vector<std::vector<double>> second_order_derivative_forward_vector_ = {{1., -2., 1.},
206 {2., -5., 4., -1.},
207 {35./12., -26./3., 19./2., -14./3., 11./12.},
208 {15./4., -77./6., 107./6., -13., 61./12., -5./6.}
209 };
211
212 // Centred
213 const std::vector<std::vector<double>> second_order_derivative_centred_vector_ = {{1., -2., 1.},
214 {1., -2., 1.},
215 {-2., -1., 0., 1., 2.},
216 {-2., -1., 0., 1., 2.}
217 };
219
220 // Backward
221 const std::vector<std::vector<double>> second_order_derivative_backward_vector_ = {{1., -2., 1.},
222 {-2., 5., -4., 1.},
223 {35./12., -26./3., 19./2., -14./3., 11./12.},
224 {15./4., -77./6., 107./6., -13., 61./12., -5./6.}
225 };
227
232 int nb_elem_ = 0;
237 int forward_left_offset_[3] = {0, 0, 0};
238 int forward_right_offset_[3] = {0, 0, 0};
239 int centred_left_offset_[3] = {0, 0, 0};
240 int centred_right_offset_[3] = {0, 0, 0};
241 int backward_left_offset_[3] = {0, 0, 0};
242 int backward_right_offset_[3] = {0, 0, 0};
243 bool computed_stencil_ = false;
245
246 void set_operators_size(const std::vector<std::vector<double>>& fd_operator_vector, FixedVector<FixedVector<DoubleVect,2>,MAX_ORDER_DERIVATIVE>& fd_operator);
247 void set_operators_indices(const std::vector<std::vector<double>>& fd_operator_vector,
248 FixedVector<FixedVector<DoubleVect,2>,MAX_ORDER_DERIVATIVE>& fd_operator,
249 const int& fd_coefficient_type);
250 int non_zero_stencil_values(const FixedVector<FixedVector<DoubleVect,2>,MAX_ORDER_DERIVATIVE>& fd_operator);
251 int get_max_operators(const FixedVector<FixedVector<DoubleVect,2>,MAX_ORDER_DERIVATIVE>& fd_operator_conv,
252 const FixedVector<FixedVector<DoubleVect,2>,MAX_ORDER_DERIVATIVE>& fd_operator_diff,
253 int (&stencil_left_offset) [3], int (&stencil_right_offset) [3]);
254 void get_max_stencil(const int& nb_elem,
255 int& non_zero_elem_max,
256 int& stencil_forward_max,
257 int& stencil_centred_max,
258 int& stencil_backward_max);
259 void compute_stencil_properties(const int nb_elem);
260 void fill_lines(Matrice& matrix);
261
262};
263
264#endif /* IJK_Finite_Difference_One_Dimensional_Matrix_Assembler_included */
void scale_matrix_by_vector(Matrice &matrix, const DoubleVect &vector, const int &boundary_conditions)
void impose_boundary_conditions(Matrice &modified_matrix, DoubleVect &mdified_rhs, const int &ini_boundary_conditions, const double &interfacial_value, const int &end_boundary_conditions, const double &end_values, const double &dr_inv, const int &first_time_step_temporal, const int &first_time_step_explicit, const DoubleVect &temperature_ini_temporal_schemes)
int non_zero_stencil_values(const FixedVector< FixedVector< DoubleVect, 2 >, MAX_ORDER_DERIVATIVE > &fd_operator)
FixedVector< FixedVector< DoubleVect, 2 >, MAX_ORDER_DERIVATIVE > identity_coefficient_
void reinitialise_any_matrix_subproblem(Matrice *matrix_subproblems, const Matrice *fd_operator, const int &nb_subproblems, const int &use_sparse_matrix, FixedVector< ArrOfInt, 6 > *first_indices_sparse_matrix, const int &first_initialisation, const int &keep_global_probes_discretisation)
void reinitialise_sparse_matrix_subproblem(Matrice *matrix_subproblems, const Matrice *fd_operator, const int &nb_subproblems, FixedVector< ArrOfInt, 6 > *first_indices_sparse_matrix, const int &first_initialisation, const int &keep_global_probes_discretisation)
void set_operators_indices(const std::vector< std::vector< double > > &fd_operator_vector, FixedVector< FixedVector< DoubleVect, 2 >, MAX_ORDER_DERIVATIVE > &fd_operator, const int &fd_coefficient_type)
FixedVector< FixedVector< DoubleVect, 2 >, MAX_ORDER_DERIVATIVE > second_order_derivative_forward_
void apply_euler_time_step(Matrice *convection_matrix, Matrice *diffusion_matrix, const int &subproblem_index, const double &local_time_step, const double &alpha)
int build_with_unknown_pattern(Matrice &matrix, const int &nb_elem, const int &derivative_order)
void add_source_terms(DoubleVect *thermal_subproblems_rhs_assembly, DoubleVect &rhs_assembly, const DoubleVect &source_terms, const int &index_start, const int &boundary_condition_interface, const int &boundary_condition_end)
FixedVector< FixedVector< DoubleVect, 2 >, MAX_ORDER_DERIVATIVE > first_order_derivative_backward_
void make_operation_on_sub_matrix_sparse(Matrice &local_sub_matrix, Matrice *matrix, const int &subproblem_index, const FixedVector< ArrOfInt, 6 > *first_indices_sparse_matrix)
int get_max_operators(const FixedVector< FixedVector< DoubleVect, 2 >, MAX_ORDER_DERIVATIVE > &fd_operator_conv, const FixedVector< FixedVector< DoubleVect, 2 >, MAX_ORDER_DERIVATIVE > &fd_operator_diff, int(&stencil_left_offset)[3], int(&stencil_right_offset)[3])
int build_with_known_pattern(Matrice &matrix, const int &nb_elem, const int &derivative_order)
void initialise_sparse_matrix_subproblems(Matrice &matrix_subproblems, Matrice &fd_operator, const int &nb_subproblems, const int &first_time_step_varying_probes, FixedVector< ArrOfInt, 6 > &first_indices_sparse_matrix, const int &first_initialisation, int &initialise_sparse_indices)
void compute_operator(const Matrice *fd_operator, const DoubleVect &solution, DoubleVect &res)
void set_operators_size(const std::vector< std::vector< double > > &fd_operator_vector, FixedVector< FixedVector< DoubleVect, 2 >, MAX_ORDER_DERIVATIVE > &fd_operator)
void impose_boundary_conditions_subproblem(Matrice *matrix, DoubleVect *global_rhs, DoubleVect &local_rhs, const int &ini_boundary_conditions, const double &interfacial_value, const int &end_boundary_conditions, const double &end_value, const int &subproblem_index, const double &dr_inv, const int &first_time_step_temporal, const int &first_time_step_explicit, const DoubleVect &temperature_ini_temporal_schemes, const int &start_index, const FixedVector< ArrOfInt, 6 > *first_indices_sparse_matrix, const int &use_sparse_matrix)
void sum_sparse_matrices_subproblems(Matrice &matrix_A, Matrice &matrix_B, const int &debug)
FixedVector< FixedVector< DoubleVect, 2 >, MAX_ORDER_DERIVATIVE > first_order_derivative_forward_
void recombined_local_sub_matrix_with_matrix(Matrice &local_sub_matrix, Matrice *matrix, const int &subproblem_index, const FixedVector< ArrOfInt, 6 > *first_indices_sparse_matrix)
void reinitialise_matrix_subproblem(Matrice *matrix_subproblems, const Matrice *fd_operator, const int &nb_subproblems, const int &keep_global_probes_discretisation)
void sum_any_matrices_subproblems(Matrice &matrix_A, Matrice &matrix_B, const int &use_sparse_matrix, const int &debug)
FixedVector< FixedVector< DoubleVect, 2 >, MAX_ORDER_DERIVATIVE > second_order_derivative_backward_
FixedVector< FixedVector< DoubleVect, 2 >, MAX_ORDER_DERIVATIVE > first_order_derivative_centred_
void modify_rhs_for_bc(Matrice &modified_matrix, DoubleVect &modified_rhs, const int &ini_boundary_conditions, const int &end_boundary_conditions)
void initialise_matrix_subproblems(Matrice &matrix_subproblems, Matrice &fd_operator, const int &subproblems, const int &first_time_step_varying_probes)
void reduce_solver_matrix(const Matrice_Morse &thermal_subproblems_matrix_assembly_for_solver, Matrice_Morse &thermal_subproblems_matrix_assembly_for_solver_reduced, const int &nb_points, const int &pre_initialise_thermal_subproblems_list)
void correct_sign_temporal_schemes_subproblems(Matrice *convection_matrix, Matrice *diffusion_matrix, const int &subproblem_index, const double &local_time_step, const double &alpha)
void complete_empty_matrices_initialisation(Matrice &matrix_subproblems, Matrice &fd_operator, const int &empty_problem_start_index, const int &empty_problem_end_index)
void scale_matrix_subproblem_by_vector(Matrice *matrix, const DoubleVect &vector, const int &subproblem_index, const int &boundary_conditions, const int &use_sparse_matrix, const FixedVector< ArrOfInt, 6 > *first_indices_sparse_matrix)
int build(Matrice &matrix, const int &nb_elem, const int &derivative_order)
FixedVector< FixedVector< DoubleVect, 2 >, MAX_ORDER_DERIVATIVE > second_order_derivative_centred_
void get_max_stencil(const int &nb_elem, int &non_zero_elem_max, int &stencil_forward_max, int &stencil_centred_max, int &stencil_backward_max)
void pre_initialise_sparse_matrix_subproblems(Matrice &matrix_subproblems, Matrice &fd_operator, const int &max_subproblems_predicted)
void pre_initialise_matrix_subproblems(Matrice &matrice, Matrice &fd_operator, const int &max_subproblems_predicted)
Classe Matrice_Morse Represente une matrice M (creuse), non necessairement carree.
Classe Matrice Classe generique de la hierarchie des matrices.
Definition Matrice.h:34
Objet_U()
Constructeur par defaut : attribue un numero d'identifiant unique a l'objet (object_id_),...
Definition Objet_U.cpp:55
Helper class to factorize the readOn method of Objet_U classes.
Definition Param.h:112