KADATH
equation.cpp
1 /*
2  Copyright 2017 Philippe Grandclement
3 
4  This file is part of Kadath.
5 
6  Kadath is free software: you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation, either version 3 of the License, or
9  (at your option) any later version.
10 
11  Kadath is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU General Public License for more details.
15 
16  You should have received a copy of the GNU General Public License
17  along with Kadath. If not, see <http://www.gnu.org/licenses/>.
18 */
19 
20 #include "system_of_eqs.hpp"
21 #include "ope_eq.hpp"
22 #include "term_eq.hpp"
23 #include "scalar.hpp"
24 #include "tensor_impl.hpp"
25 namespace Kadath {
26 // const Domain* dom ;
27 // int ndom ;
28 // int n_ope ;
29 // Memory_mapped_array<Ope_eq*> parts ;
30 // bool called ;
31 // int n_comp ;
32 // int n_cond_tot ;
33 // Array<int>* n_cond ;
34 //
35 // int n_cmp_used ;
36 // Memory_mapped_array<Array<int>*> p_cmp_used ;
37 
38 Equation::Equation (const Domain* zedom, int nd, int np, int nused, Array<int>** pused) :
39  dom{zedom}, ndom{nd}, n_ope{np}, parts{n_ope,initialize}, called{false}, n_cond{nullptr}, n_cond_tot{},
40  n_cmp_used{nused}, p_cmp_used{pused}
41 {}
42 
43 
45  for(auto & p : parts) safe_delete(p);
46  if (called) delete n_cond ;
47 }
48 
49 void Equation::apply(int& conte, Term_eq** res) {
50  int old_conte = conte ;
51  for (int i=0 ; i<n_ope ; i++) {
52  if (res[conte]!=nullptr)
53  *res[conte] = parts[i]->action() ; //NOT THREAD SAFE
54  else
55  res[conte] = new Term_eq (parts[i]->action()) ; //NOT THREAD SAFE
56  conte ++ ;
57  }
58 
59  if (!called) {
60  Tensor copie (res[old_conte]->get_val_t()) ;
61  n_cond = new Array<int> (do_nbr_conditions(copie)) ;
62  n_comp = n_cond->get_size(0) ;
63  n_cond_tot = 0 ;
64  for (int i=0 ; i<n_cond->get_size(0) ; i++)
65  n_cond_tot += (*n_cond)(i) ;
66  called = true ;
67  }
68 }}
int get_size(int i) const
Returns the size of a given dimension.
Definition: array.hpp:331
Abstract class that implements the fonctionnalities common to all the type of domains.
Definition: space.hpp:60
bool called
Indicator checking whther the result has been computed already once.
virtual Array< int > do_nbr_conditions(const Tensor &tt) const =0
Computes the number of conditions associated with the equation.
virtual void apply(int &conte, Term_eq **res)
Computes the terms involved in computing the residual of the equations.
Definition: equation.cpp:49
virtual ~Equation()
Destructor.
Definition: equation.cpp:44
int n_ope
Number of terms involved in the equation (one for bulk, two or more fot matching.....
int n_comp
Number of components of the residual (1 for a scalar, 6 for a symmetric rank-2 tensor etc).
Array< int > * n_cond
Number of discretized equations, component by component.
MMPtr_array< Ope_eq > parts
Array of pointers on the various terms.
Equation(const Domain *dom, int nd, int nope, int n_cmp=-1, Array< int > **p_cmp=nullptr)
Constructor.
Definition: equation.cpp:38
int n_cond_tot
Total number of discretized equations (essentially the number of all coefficients of the residual).
Tensor handling.
Definition: tensor.hpp:149
This class is intended to describe the manage objects appearing in the equations.
Definition: term_eq.hpp:62