21 #include "system_of_eqs.hpp"
22 #include "name_tools.hpp"
24 #include "tensor_impl.hpp"
27 template<> Profiled_object_base<std::chrono::duration<double>>::Stat_map
28 Profiled_object_base<std::chrono::duration<double>>::statistic_map{};
35 espace{sp}, dom_min{0}, dom_max{espace.get_nbr_domains()-1}, ndom{dom_max-dom_min+1},
36 nvar_double{0}, var_double{VARMAX}, names_var_double{VARMAX},
37 nvar{0}, var{VARMAX}, names_var{VARMAX},
38 nterm_double{0}, term_double{VARMAX * ndom}, assoc_var_double{VARMAX*ndom},
39 nterm{0}, term{VARMAX * ndom}, assoc_var(VARMAX*ndom),
40 ncst{0}, nterm_cst{0}, cst{VARMAX*ndom}, names_cst{VARMAX * ndom},
41 ncst_hard{0}, cst_hard{VARMAX}, val_cst_hard{VARMAX},
42 ndef{0}, def {VARMAX*ndom} , names_def {VARMAX*ndom},
43 ndef_glob{0}, def_glob {VARMAX*ndom}, names_def_glob {VARMAX*ndom},
44 nopeuser{0}, opeuser{}, paruser{VARMAX}, names_opeuser{VARMAX},
45 nopeuser_bin{0}, opeuser_bin{}, paruser_bin{VARMAX}, names_opeuser_bin{VARMAX},
46 met{nullptr}, name_met{nullptr},
47 neq_int{0}, eq_int{VARMAX}, neq{0}, eq{VARMAX}, results{VARMAX},
48 nbr_unknowns{sp.nbr_unknowns_from_variable_domains()}, nbr_conditions{-1}, which_coef{nullptr}
52 for (
int i=0 ; i<VARMAX ; i++) {
71 for (
int i=0 ; i<VARMAX*
ndom ; i++) {
81 espace{sp}, dom_min{dmin}, dom_max{dmax},ndom{dom_max-dom_min+1},
82 nvar_double{0}, var_double{VARMAX}, names_var_double{VARMAX},
83 nvar{0}, var{VARMAX}, names_var{VARMAX},
84 nterm_double{0}, term_double{VARMAX * ndom}, assoc_var_double{VARMAX*ndom},
85 nterm{0}, term{VARMAX * ndom}, assoc_var(VARMAX*ndom),
86 ncst{0}, nterm_cst{0}, cst{VARMAX*ndom}, names_cst{VARMAX * ndom},
87 ncst_hard{0}, cst_hard{VARMAX}, val_cst_hard{VARMAX},
88 ndef{0}, def {VARMAX*ndom} , names_def {VARMAX*ndom},
89 ndef_glob{0}, def_glob {VARMAX*ndom}, names_def_glob {VARMAX*ndom},
90 nopeuser{0}, opeuser{}, paruser{VARMAX}, names_opeuser{VARMAX},
91 nopeuser_bin{0}, opeuser_bin{}, paruser_bin{VARMAX}, names_opeuser_bin{VARMAX},
92 met{nullptr}, name_met{nullptr},
93 neq_int{0}, eq_int{VARMAX}, neq{0}, eq{VARMAX}, results{VARMAX},
94 nbr_unknowns{sp.nbr_unknowns_from_variable_domains()}, nbr_conditions{-1}, which_coef{nullptr}
98 for (
int i=0 ; i<VARMAX ; i++) {
117 for (
int i=0 ; i<VARMAX*
ndom ; i++) {
132 for (
int i=0 ; i<
nterm ; i++)
delete term[i] ;
137 for (
int i=0 ; i<
ndef ; i++)
delete def[i] ;
154 for (
int i=0 ; i<
neq ; i++)
delete eq[i] ;
156 for (
int i=0 ; i<VARMAX ; i++)
if (
results[i]!=
nullptr)
164 cerr <<
"Undefined metric in System_of_eqs" << endl ;
181 assert ((which>=0) && (which<
nvar)) ;
190 assert ((which>=0) && (which<
ncst)) ;
212 assert ((which>=0) && (which<
ndef)) ;
218 assert ((which>=0) && (which<
ndef_glob)) ;
236 for (
int vv=0 ; vv<
nvar ; vv++)
244 if ((nbr_char(nom,
'_')!=0) || (nbr_char(nom,
'^')!=0)) {
245 cerr <<
"No indices allowed in names of variables" << endl ;
267 if ((nbr_char(nom,
'_')!=0) || (nbr_char(nom,
'^')!=0)) {
268 cerr <<
"No indices allowed in names of variables" << endl ;
299 if ((nbr_char(nom,
'_')!=0) || (nbr_char(nom,
'^')!=0)) {
300 cerr <<
"No indices allowed in names of constants" << endl ;
305 trim_spaces(nomcst,nom) ;
326 trim_spaces(nomcst,nom) ;
365 cerr <<
"= needed for definitions" << endl ;
374 char* indices = nullptr ;
376 bool auxi = is_tensor (p1,
names_def[
ndef], valence, indices, ttype) ;
382 if (indices!=
nullptr)
400 cerr <<
"= needed for definitions" << endl ;
435 for (
int i=0 ; i<
nterm ; i++) {
442 int dom =
term[i]->get_dom() ;
445 term[i]->set_der_t(auxi) ;
450 int dom =
term[i]->get_dom() ;
452 term[i]->set_der_t(auxi) ;
467 for (
int i=0 ; i<
nvar ; i++)
477 trim_spaces(name, so) ;
484 bool foundpar = false ;
486 for (
int i=0 ; i<
ndef ; i++)
501 cerr <<
"Definition not found...." << endl ;
511 for (
int i=0 ; i<
ndef ; i++)
536 bool unable_to_compute{
false};
539 for (
int i{0},k{first_col} ; i<n_col && k < n; i++, k++) {
544 catch(std::exception
const & e) {
545 std::cerr <<
"---> unable to compute column " << k <<
"/" << n <<
" (rank "
547 unable_to_compute =
true;
551 for (
int j = 0; j < n; j++) matrix.
set(current, j) = column(j);
553 for (
int j = 0; j < n; j++) matrix.
set(j, current) = column(j);
557 first_col += num_proc * n_col;
561 if(unable_to_compute)
throw std::runtime_error{
"Unable to compute the jacobian"};
565 bool transpose, std::vector<vector<std::size_t>> *dm)
569 for(
int j{0};j<n_col;j++)
571 int const J{first_col+j};
575 for(
int i{0};i<n;i++) {matrix.
set(J,i) = column(i);
if(dm) (*dm)[i][J]++;}
577 for(
int i{0};i<n;i++) {matrix.
set(i,J) = column(i);
if(dm) (*dm)[J][i]++;}
591 for (
int i=0 ; i<
nvar ; i++) old_fields[i] =
new Tensor(*
var[i]);
593 for (
int i=0 ; i<
nvar ; i++)
595 *
var[i] = *old_fields[i] - *
var[i];
598 if (old_var_double!=
nullptr)
delete [] old_var_double;
599 for (
int i=0 ; i<
nvar ; i++)
delete old_fields[i];
600 delete [] old_fields;
reference set(const Index &pos)
Read/write of an element.
int get_ndim() const
Returns the number of dimensions.
int get_size(int i) const
Returns the size of a given dimension.
Describes the tensorial basis used by the various tensors.
int get_basis(int nd) const
Read only the basis in a given domain.
virtual void vars_to_terms() const
The Term_eq describing the variable shape of the Domain are updated.
virtual int nbr_unknowns(const Tensor &so, int dom) const
Computes the number of true unknowns of a Tensor, in a given domain.
virtual void affecte_tau(Tensor &so, int dom, const Array< double > &cf, int &pos_cf) const
Affects some coefficients to a Tensor.
Particular type of Tensor, dedicated to the desription of metrics.
Purely abstract class for metric handling.
Operator for a global definition (i.e.
Term_eq * get_res()
Returns the result.
Val_domain & set_domain(int)
Read/write of a particular Val_domain.
The Space class is an ensemble of domains describing the whole space of the computation.
virtual void xx_to_ders_variable_domains(const Array< double > &xx, int &conte) const
Update the vairable domains from a set of values.
const Domain * get_domain(int i) const
returns a pointer on the domain.
virtual void xx_to_vars_variable_domains(System_of_eqs *syst, const Array< double > &xx, int &conte) const
Update the variables of a system, from the variation of the shape of the domains.
MMPtr_array< Ope_def > def
Pointers on the definition (i.e. on the Ope_def that is needed to compute the result).
virtual void vars_to_terms_impl()
Sylvain's stuff.
MMPtr_array< Param > paruser
Parameters used by the user defined operators (single argument).
virtual void compute_matrix_adjacent(Array< double > &matrix, int n, int first_col=0, int n_col=ALL_COLUMNS, int num_proc=1, bool transpose=DO_NOT_TRANSPOSE, std::vector< std::vector< std::size_t >> *dm=nullptr)
Sylvain's stuff.
int nvar_double
Number of unknowns that are numbers (i.e. not fields)
MMPtr_array< Term_eq > results
Pointers on the residual of the various equations.
int nopeuser_bin
Number of operators defined by the user (with two arguments).
virtual void add_var(const char *name, double &var)
Addition of a variable (number case)
const Metric * get_met() const
Returns a pointer on the Metric.
int nterm
Number of Term_eq corresponding to the unknown fields.
Term_eq * give_term_double(int which, int dd) const
Returns a pointer on a Term_eq corresponding to an unknown number.
void init_proc_data()
Sylvain's stuff.
Array< double > do_col_J(int i)
Computes one column of the Jacobian.
~System_of_eqs() override
Destructor.
MMPtr_array< double > var_double
Pointer on the unknowns that are numbers (i.e. not fields)
MMPtr_array< Ope_def_global > def_glob
Pointers on the global definitions.
Array< int > assoc_var
Array giving the correspondance with the var pointers.
virtual void add_def(const char *name)
Addition of a definition.
static constexpr int ALL_COLUMNS
Dummy variable for the purpose of better readability.
virtual void add_cst(const char *name, double cst)
Addition of a constant (number case)
MMPtr_array< char > names_def_glob
Names of the global definitions.
MMPtr_array< char > names_var
Names of the unknown fields.
int mpi_proc_rank
Sylvain's stuff.
Term_eq * give_cst_hard(double xx, int dd) const
Returns a pointer on a Term_eq corresponding to a constant generated on the fly.
MMPtr_array< Term_eq > cst_hard
Pointers on the Term_eq coming from the constants generated on the fly (when encoutering things like ...
Term_eq * give_term(int which, int dd) const
Returns a pointer on a Term_eq corresponding to an unknown field.
Ope_def * give_def(int i) const
Returns a pointer on a definition (better to use give_val_def if one wants to access the result of so...
MMPtr_array< Term_eq > term_double
Pointers on the Term_eq corresponding to the unknowns that are numbers.
int nbr_unknowns
Number of unknowns (basically the number of coefficients of all the unknown fields,...
MMPtr_array< char > names_opeuser_bin
Names of the user defined operators (with two arguments).
int ndom
Number of domains used.
int ndef_glob
Number of global definitions (the one that require the knowledge of the whole space to give the resul...
Tensor give_val_def(const char *name) const
Gives the result of a definition.
Ope_def_global * give_def_glob(int i) const
Returns a pointer on a global definition.
int neq_int
Number of integral equations (i.e. which are doubles)
MMPtr_array< char > names_opeuser
Names of the user defined operators (single argument).
MMPtr_array< Equation > eq
Pointers onto the field equations.
bool is_ope_bin(const char *input, char *p1, char *p2, char symb) const
Checks if a string represents an operator of the type "a + b".
MMPtr_array< Index > which_coef
Stores the "true" coefficients on some boundaries (probably deprecated).
int nopeuser
Number of operators defined by the user (single argument).
MMPtr_array< Param > paruser_bin
Parameters used by the user defined operators (with two arguments).
MMPtr_array< Tensor > var
Pointer on the unknown fields.
Array< int > assoc_var_double
Array giving the correspondance with the var_double pointers.
MMPtr_array< Term_eq > cst
Pointers on the Term_eq coming from the constants passed by the user.
void xx_to_vars(const Array< double > &val, int &conte)
Sets the values the of the fields.
Ope_eq * give_ope(int dom, const char *name, int bb=0) const
Function that reads a string and returns a pointer on the generated Ope_eq.
MMPtr_array< char > names_cst
Names of the constants passed by the user.
virtual void add_ope(const char *name, Term_eq(*pope)(const Term_eq &, Param *), Param *par)
Addition of a user defined operator (one argument version)
static std::size_t default_block_size
Defines the sub-matrix size in the scalapack 2D cyclic block decomposition.
void vars_to_terms()
Copies the various unknowns (doubles and Tensors) into their Term_eq counterparts.
int ndef
Number of definitions.
MMPtr_array< char > names_var_double
Names of the unknowns that are numbers (i.e. not fields)
int nterm_cst
Number of Term_eq coming from the constants passed by the user.
virtual void add_def_global(const char *name)
Addition of a global definition.
char * name_met
Name by which the metric is recognized.
int nbr_conditions
Total number of conditions (the number of coefficients of all the equations, once regularities are ta...
MMPtr_array< Term_eq > term
Pointers on the Term_eq corresponding to the unknown fields.
int neq
Number of field equations.
int dom_max
Highest domain number.
void newton_update_vars(Array< double > const &xx)
Update the values of var and var_double from the solution of the linear system of the last Newton ite...
const Space & espace
Associated Space.
MMPtr_array< char > names_def
Names of the definitions.
int ncst
Number of constants passed by the user.
int ncst_hard
Number of constants generated on the fly (when encoutering things like "2.2" etc.....
Array< double > val_cst_hard
Values of the constants generated on the fly (when encoutering things like "2.2" etc....
int nterm_double
Number of Term_eq corresponding to the unknowns that are numbers.
MMPtr_array< Eq_int > eq_int
Pointers onto the integral equations.
Term_eq * give_cst(int which, int dd) const
Returns a pointer on a Term_eq corresponding to a constant.
int mpi_world_size
Sylvain's stuff.
void xx_to_ders(const Array< double > &vder)
Sets the values the variation of the fields.
int dom_min
Smallest domain number.
Metric * met
Pointer on the associated Metric, if defined.
virtual void compute_matrix_cyclic(Array< double > &matrix, int n, int first_col=0, int n_col=ALL_COLUMNS, int num_proc=1, bool transpose=DO_NOT_TRANSPOSE)
Compute some columns of the jacobian of the system of equations.
int nvar
Number of unknown fields.
Term_eq(* opeuser_bin[VARMAX])(const Term_eq &, const Term_eq &, Param *)
Pointers on the functions used by the user defined operators (with two arguments).
System_of_eqs(const Space &so)
Standard constructor nothing is done.
Term_eq(* opeuser[VARMAX])(const Term_eq &, Param *)
Pointers on the functions used by the user defined operators (single argument).
Param_tensor parameters
Possible additional parameters relevant for the current Tensor.
Param_tensor & set_parameters()
Read/write of the parameters.
const Param_tensor & get_parameters() const
Returns a pointer on the possible additional parameter.
Scalar & set(const Array< int > &ind)
Returns the value of a component (read/write version).
int get_index_type(int i) const
Gives the type (covariant or contravariant) of a given index.
const Base_tensor & get_basis() const
Returns the vectorial basis (triad) on which the components are defined.
int get_n_comp() const
Returns the number of stored components.
virtual Array< int > indices(int pos) const
Gives the values of the indices corresponding to a location in the array used for storage of the comp...
const Space & espace
The Space.
int get_valence() const
Returns the valence.
int & set_basis(int dd)
Assigns a new tensorial basis in a given domain.
This class is intended to describe the manage objects appearing in the equations.
void set_val_d(double)
Sets the double value.
void set_val_t(Tensor)
Sets the tensorial value (only the values in the pertinent Domain are copied).