KADATH
ope_def_global.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 
21 #include "system_of_eqs.hpp"
22 #include "ope_eq.hpp"
23 namespace Kadath {
24 Ope_def_global::Ope_def_global(const System_of_eqs* zesys, int zedom, const char* name_ope) :
25  Ope_eq(zesys, zedom, zesys->get_dom_max() - zesys->get_dom_min() + 1) {
26  for (int n=0 ; n<n_ope ; n++)
27  parts[n] = syst->give_ope (n+syst->get_dom_min(), name_ope) ;
28 
29  res = new Term_eq (dom, 0., 0.) ;
30  auxi = new Term_eq* [n_ope] ;
31  for (int i=0 ; i<n_ope ; i++)
32  auxi[i] = 0x0 ;
33  compute_res() ;
34 }
35 
36 Ope_def_global::~Ope_def_global() {
37  delete res ;
38  for (int i=0 ; i<n_ope ; i++)
39  if (auxi[i]!=0x0)
40  delete auxi[i] ;
41  delete [] auxi ;
42 }
43 
45  /*if (!called) {
46  res = new Term_eq(parts[0]->action()) ;
47  called = true ;
48  }
49  return *res ;*/
50  cerr << "Should not call Ope_def_global::action" << endl ;
51  abort() ;
52 }
53 
55  return res ;
56 }
57 
59 
60  for (int i=0 ; i<n_ope ; i++)
61  if (auxi[i]==0x0)
62  auxi[i] = new Term_eq (parts[i]->action()) ;
63  else
64  *auxi[i] = parts[i]->action() ;
65 
66  bool doder = true ;
67  for (int i=0 ; i<n_ope ; i++)
68  if (auxi[i]->der_d==0x0)
69  doder = false ;
70 
71  double val = 0 ;
72  for (int i=0 ; i<n_ope ; i++)
73  val += *auxi[i]->val_d ;
74 
75  if (!doder) {
76  *res = Term_eq (dom, val) ;
77  }
78  else {
79  double der = 0 ;
80  for (int i=0 ; i<n_ope ; i++)
81  der += *auxi[i]->der_d ;
82  *res = Term_eq (dom, val, der) ;
83  }
84 }}
Term_eq action() const override
Computes the action of the current Ope_eq using its various parts.
Term_eq ** auxi
Various parts of the result (i.e. the contributions of the various domains).
Definition: ope_eq.hpp:1343
Term_eq * res
Result.
Definition: ope_eq.hpp:1342
Ope_def_global(const System_of_eqs *syst, int dom, const char *name_ope)
Constructor.
Term_eq * get_res()
Returns the result.
void compute_res()
Forces the computation of the result (when things have changed).
Abstract class that describes the various operators that can appear in the equations.
Definition: ope_eq.hpp:32
const System_of_eqs * syst
The associated System_of_eqs.
Definition: ope_eq.hpp:35
MMPtr_array< Ope_eq > parts
Pointers of the various parts of the current operator.
Definition: ope_eq.hpp:38
int n_ope
Number of terms involved (2 for + for instance, only one for sqrt...)
Definition: ope_eq.hpp:37
int dom
Index of the Domain where the operator is defined.
Definition: ope_eq.hpp:36
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
int get_dom_min() const
Returns the smallest index of the domains.
This class is intended to describe the manage objects appearing in the equations.
Definition: term_eq.hpp:62