KADATH
eq_first_integral.cpp
1 /*
2  Copyright 2018 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 #include "name_tools.hpp"
26 namespace Kadath {
27 Eq_first_integral::Eq_first_integral(const System_of_eqs* syst, const Domain* innerdom, int dommin, int dommax, const char* integ_part, const char* const_part) : Equation(innerdom, dommin, dommax-dommin+2), dom_min(dommin), dom_max(dommax) {
28 
29 
30  // First the constant part
31  char auxicst[LMAX] ;
32  trim_spaces(auxicst, const_part) ;
33  parts[0] = syst->give_ope (dom_min, auxicst) ;
34 
35  // First all the integral parts
36  char auxiinteg[LMAX] ;
37  trim_spaces(auxiinteg, integ_part) ;
38 
39  for (int d=dom_min ; d<=dom_max; d++)
40  parts[d-dom_min+1] = syst->give_ope (d, auxiinteg) ;
41 }
42 
44 }
45 
46 
47 void Eq_first_integral::export_val (int& conte, Term_eq** residus, Array<double>& sec, int& pos_res) const {
48 
49  // Standard parts
50  assert (residus[conte]->get_type_data()==TERM_T) ;
51  // Recover pointer on the space
52  const Space& space = residus[conte]->get_val_t().get_space() ;
53 
54  // Get the constant part
55  Index pori (space.get_domain(dom_min)->get_nbr_points()) ;
56  double val_cst_part = residus[conte]->get_val_t()()(dom_min)(pori) ;
57  conte ++ ;
58 
59  // Recover origin value of first integral
60  double val_ori = residus[conte]->get_val_t()()(dom_min)(pori) ;
61 
62  // Inner domain
63  // Remove value at the origin
64  Scalar auximin (space) ;
65  auximin.set_domain(dom_min) = residus[conte]->get_val_t()()(dom_min) - val_ori ;
66  auximin.set_domain(dom_min).coef_i() ;
67 
68  // At the origin put the cst_part (no continuity but does it matter ?)
69  Index pos (space.get_domain(dom_min)->get_nbr_points()) ;
70  do {
71  if (pos(0)==0)
72  auximin.set_domain(dom_min).set(pos) = val_cst_part ;
73  }
74  while (pos.inc()) ;
75 
76  space.get_domain(dom_min)->export_tau (auximin, dom_min, 0, sec, pos_res, *n_cond) ;
77  conte ++ ;
78 
79  // Export all the other domains
80  for (int d=dom_min+1 ; d<=dom_max ; d++) {
81  Scalar auxi (space) ;
82  auxi.set_domain(d) = residus[conte]->get_val_t()()(d) - val_ori ;
83  space.get_domain(d)->export_tau (auxi, d, 0, sec, pos_res, *n_cond) ;
84  conte ++ ;
85  }
86 }
87 
88 
89 void Eq_first_integral::export_der (int& conte, Term_eq** residus, Array<double>& sec, int& pos_res) const {
90  // Standard parts
91  assert (residus[conte]->get_type_data()==TERM_T) ;
92  // Recover pointer on the space
93  const Space& space = residus[conte]->get_val_t().get_space() ;
94 
95  int start = pos_res ;
96 
97  // Get the constant part
98  Index pori (space.get_domain(dom_min)->get_nbr_points()) ;
99  double val_cst_part = residus[conte]->get_der_t()()(dom_min)(pori) ;
100  conte ++ ;
101 
102  // Recover origin value of first integral
103  double val_ori = residus[conte]->get_der_t()()(dom_min)(pori) ;
104 
105  // Inner domain
106  // Remove value at the origin
107  Scalar auximin (space) ;
108  auximin.set_domain(dom_min) = residus[conte]->get_der_t()()(dom_min) - val_ori ;
109  auximin.set_domain(dom_min).coef_i() ;
110 
111  // At the origin put the cst_part (no continuity but does it matter ?)
112  Index pos (space.get_domain(dom_min)->get_nbr_points()) ;
113  do {
114  if (pos(0)==0)
115  auximin.set_domain(dom_min).set(pos) = val_cst_part ;
116  }
117  while (pos.inc()) ;
118 
119  space.get_domain(dom_min)->export_tau (auximin, dom_min, 0, sec, pos_res, *n_cond) ;
120  conte ++ ;
121 
122  // Export all the other domains
123  for (int d=dom_min+1 ; d<=dom_max ; d++) {
124  Scalar auxi (space) ;
125  auxi.set_domain(d) = residus[conte]->get_der_t()()(d) - val_ori ;
126  space.get_domain(d)->export_tau (auxi, d, 0, sec, pos_res, *n_cond) ;
127  conte ++ ;
128  }
129 }
130 
131 
133 
134  Array<int> res (dom_max - dom_min+1) ;
135  for (int d=dom_min ; d<=dom_max ; d++)
136  res.set(d-dom_min) = tt.get_space().get_domain(d)->nbr_conditions (tt, ndom, 0)(0) ;
137  return res ;
138 }
139 
140 
141 bool Eq_first_integral::take_into_account (int target) const {
142  if ((target >= dom_min) && (target<=dom_max))
143  return true ;
144  else
145  return false ;
146 }
147 
148 }
reference set(const Index &pos)
Read/write of an element.
Definition: array.hpp:186
Abstract class that implements the fonctionnalities common to all the type of domains.
Definition: space.hpp:60
virtual void export_tau(const Tensor &eq, int dom, int order, Array< double > &res, int &pos_res, const Array< int > &ncond, int n_cmp=-1, Array< int > **p_cmp=0x0) const
Exports all the residual equations corresponding to a tensorial one in the bulk.
Definition: domain.cpp:1533
Dim_array const & get_nbr_points() const
Returns the number of points.
Definition: space.hpp:92
virtual Array< int > nbr_conditions(const Tensor &eq, int dom, int order, int n_cmp=-1, Array< int > **p_cmp=0x0) const
Computes number of discretized equations associated with a given tensorial equation in the bulk.
Definition: domain.cpp:1504
Array< int > do_nbr_conditions(const Tensor &tt) const override
Computes the number of conditions associated with the equation.
Eq_first_integral(const System_of_eqs *syst, const Domain *dom, int dommin, int dommax, const char *integ_part, const char *const_part)
Constructor.
int dom_min
Index of the first Domain.
void export_val(int &, Term_eq **, Array< double > &, int &) const override
Generates the discretized errors, from the various Term_eq computed by the equation.
void export_der(int &, Term_eq **, Array< double > &, int &) const override
Generates the discretized variations, from the various Term_eq computed by the equation.
int dom_max
Index of the last Domain.
bool take_into_account(int) const override
Check whether the variation of the residual has to be taken into account when computing a given colum...
virtual ~Eq_first_integral()
Destructor.
Class implementing an equation.
int ndom
Number of the domain.
Array< int > * n_cond
Number of discretized equations, component by component.
MMPtr_array< Ope_eq > parts
Array of pointers on the various terms.
Class that gives the position inside a multi-dimensional Array.
Definition: index.hpp:38
bool inc(int increm, int var=0)
Increments the position of the Index.
Definition: index.hpp:99
The class Scalar does not really implements scalars in the mathematical sense but rather tensorial co...
Definition: scalar.hpp:67
Val_domain & set_domain(int)
Read/write of a particular Val_domain.
Definition: scalar.hpp:555
The Space class is an ensemble of domains describing the whole space of the computation.
Definition: space.hpp:1362
const Domain * get_domain(int i) const
returns a pointer on the domain.
Definition: space.hpp:1385
Class used to describe and solve a system of equations.
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.
Definition: give_ope.cpp:559
Tensor handling.
Definition: tensor.hpp:149
const Space & get_space() const
Returns the Space.
Definition: tensor.hpp:499
This class is intended to describe the manage objects appearing in the equations.
Definition: term_eq.hpp:62
Tensor const & get_val_t() const
Definition: term_eq.hpp:355
Tensor const & get_der_t() const
Definition: term_eq.hpp:369
void coef_i() const
Computes the values in the configuration space.
Definition: val_domain.cpp:637
double & set(const Index &pos)
Read/write the value of the field in the configuration space.
Definition: val_domain.cpp:171