KADATH
space_adapted_bh.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 "headcpp.hpp"
21 #include "adapted_bh.hpp"
22 #include "utilities.hpp"
23 #include "point.hpp"
24 #include "scalar.hpp"
25 #include "tensor_impl.hpp"
26 #include "system_of_eqs.hpp"
27 #include "name_tools.hpp"
28 namespace Kadath {
29 Space_adapted_bh::Space_adapted_bh (int ttype, const Point& center, const Dim_array& res, const Array<double>& bounds) {
30 
31  // Verif :
32  assert (bounds.get_ndim()== 1) ;
33 
34  ndim = 3 ;
35 
36  nbr_domains = bounds.get_size(0) ;
37  type_base = ttype ;
38  domains = new Domain* [nbr_domains] ;
39 
40  domains[0] = new Domain_shell_inner_adapted (*this, 1, ttype, bounds(0), bounds(1), center, res) ;
41  for (int i=1 ; i<nbr_domains-1 ; i++)
42  domains[i] = new Domain_shell(i, ttype, bounds(i), bounds(i+1), center, res) ;
43 
44  domains[nbr_domains-1] = new Domain_compact (nbr_domains-1, ttype, bounds(nbr_domains-1), center, res) ;
45 
46  const Domain_shell_inner_adapted* pshell_inner = dynamic_cast<const Domain_shell_inner_adapted*> (domains[0]) ;
47  pshell_inner->vars_to_terms() ;
48 }
49 
50 
52  fread_be (&nbr_domains, sizeof(int), 1, fd) ;
53  fread_be (&ndim, sizeof(int), 1, fd) ;
54  fread_be (&type_base, sizeof(int), 1, fd) ;
55  domains = new Domain* [nbr_domains] ;
56 
57  domains[0] = new Domain_shell_inner_adapted (*this, 0, fd) ;
58  //Shells :
59  for (int i=1 ; i<nbr_domains-1 ; i++)
60  domains[i] = new Domain_shell(i, fd) ;
61  // Compactified
63 
64  const Domain_shell_inner_adapted* pshell_inner = dynamic_cast<const Domain_shell_inner_adapted*> (domains[0]) ;
65  pshell_inner->vars_to_terms() ;
66 }
67 
69  Domain_shell_inner_adapted* pshell_inner = dynamic_cast<Domain_shell_inner_adapted*> (domains[0]) ;
70  pshell_inner->del_deriv() ;
71 }
72 
73 void Space_adapted_bh::save (FILE* fd) const {
74  fwrite_be (&nbr_domains, sizeof(int), 1, fd) ;
75  fwrite_be (&ndim, sizeof(int), 1, fd) ;
76  fwrite_be (&type_base, sizeof(int), 1, fd) ;
77  for (int i=0 ; i<nbr_domains ; i++)
78  domains[i]->save(fd) ;
79 }
80 
82  return domains[0]->nbr_unknowns_from_adapted() ;
83 }
84 
85 void Space_adapted_bh::affecte_coef_to_variable_domains (int& pos, int cc, Array<int>& zedoms) const {
86 
87  bool found = false ;
88  domains[0]->affecte_coef(pos, cc, found) ;
89 
90  if (found)
91  zedoms.set(0) = 0 ;
92  else
93  zedoms.set(0) = -1 ;
94 }
95 
97 
98  domains[0]->xx_to_ders_from_adapted(xx, conte) ;
99 }
100 
102 
103  // First get the corrections :
104  Val_domain cor_inner (domains[0]) ;
105  domains[0]->xx_to_vars_from_adapted(cor_inner, xx, pos) ;
106 
107  // Now update the variables :
108  for (int i=0 ; i<sys->nvar ; i++) {
109  for (int n=0 ; n<sys->var[i]->get_n_comp() ; n++) {
110  Scalar res(*this) ;
111  domains[0]->update_variable(cor_inner, *sys->var[i]->cmp[n], res) ;
112 
113  sys->var[i]->cmp[n]->set_domain(0) = res(0) ;
114  }
115  }
116 
117  // Now the constants :
118  for (int i=0 ; i<sys->ncst ; i++)
119  if (sys->cst[i*(sys->dom_max-sys->dom_min+1)]->get_type_data()==TERM_T)
120  for (int n=0 ; n<sys->cst[i*(sys->dom_max-sys->dom_min+1)]->val_t->get_n_comp() ; n++) {
121 
122  Scalar so (*this) ;
123  so = 0 ;
124  so.set_domain(0) = (*sys->cst[i*(sys->dom_max-sys->dom_min+1)]->val_t->cmp[n])(0) ;
125 
126  Scalar res(*this) ;
127  res = 0 ;
128  domains[0]->update_constante(cor_inner, so, res) ;
129 
130  sys->cst[i*(sys->dom_max-sys->dom_min+1)]->val_t->cmp[n]->set_domain(0) = res(0) ;
131  }
132 
133  // Update the mapping :
134  domains[0]->update_mapping(cor_inner) ;
135 }
136 
137 }
reference set(const Index &pos)
Read/write of an element.
Definition: array.hpp:186
int get_ndim() const
Returns the number of dimensions.
Definition: array.hpp:323
int get_size(int i) const
Returns the size of a given dimension.
Definition: array.hpp:331
Class for storing the dimensions of an array.
Definition: dim_array.hpp:34
Class for a spherical compactified domain and a symmetry with respect to the plane .
Definition: spheric.hpp:1007
Class for a spherical-like domain, having a symmetry with respect to the plane .
Definition: adapted.hpp:51
void del_deriv() override
Destroys the derivated members (like coloc, cart and radius), when changing the type of colocation po...
virtual void vars_to_terms() const
The Term_eq describing the variable shape of the Domain are updated.
Class for a spherical shell and a symmetry with respect to the plane .
Definition: spheric.hpp:555
Abstract class that implements the fonctionnalities common to all the type of domains.
Definition: space.hpp:60
virtual void xx_to_ders_from_adapted(const Array< double > &xx, int &conte) const
Affects the derivative part of variable a Domain from a set of values.
Definition: space.hpp:928
virtual int nbr_unknowns_from_adapted() const
Gives the number of unknowns coming from the variable shape of the domain.
Definition: space.hpp:895
virtual void affecte_coef(int &conte, int cc, bool &found) const
The variation of the functions describing the shape of the Domain are affected from the unknowns of t...
Definition: space.hpp:906
virtual void update_variable(const Val_domain &shape, const Scalar &oldval, Scalar &newval) const
Update the value of a scalar, after the shape of the Domain has been changed by the system.
Definition: space.hpp:942
virtual void xx_to_vars_from_adapted(Val_domain &shape, const Array< double > &xx, int &conte) const
Computes the new boundary of a Domain from a set of values.
Definition: space.hpp:913
virtual void update_mapping(const Val_domain &shape)
Updates the variables parts of the Domain.
Definition: space.hpp:977
virtual void update_constante(const Val_domain &shape, const Scalar &oldval, Scalar &newval) const
Update the value of a scalar, after the shape of the Domain has been changed by the system.
Definition: space.hpp:961
The class Point is used to store the coordinates of a point.
Definition: point.hpp:30
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
virtual void xx_to_ders_variable_domains(const Array< double > &, int &) const
Update the vairable domains from a set of values.
virtual void save(FILE *) const
Saving function.
Space_adapted_bh(int base, const Point &cr, const Dim_array &nbr, const Array< double > &bounds)
virtual void affecte_coef_to_variable_domains(int &, int, Array< int > &) const
The variation of the functions describing the shape of the Domain are affected from the unknowns of t...
virtual ~Space_adapted_bh()
Destructor
virtual int nbr_unknowns_from_variable_domains() const
Gives the number of unknowns coming from the variable shape of the domain.
virtual void xx_to_vars_variable_domains(System_of_eqs *, const Array< double > &, int &) const
Update the variables of a system, from the variation of the shape of the domains.
int type_base
Type of basis used (i.e. using either Chebyshev or Legendre polynomials).
Definition: space.hpp:1367
int ndim
Number of dimensions (should be the same for all the Domains).
Definition: space.hpp:1366
Domain ** domains
Pointers on the various Domains.
Definition: space.hpp:1368
int nbr_domains
Number od Domains.
Definition: space.hpp:1365
Class used to describe and solve a system of equations.
MMPtr_array< Tensor > var
Pointer on the unknown fields.
MMPtr_array< Term_eq > cst
Pointers on the Term_eq coming from the constants passed by the user.
int dom_max
Highest domain number.
int ncst
Number of constants passed by the user.
int dom_min
Smallest domain number.
int nvar
Number of unknown fields.
Class for storing the basis of decompositions of a field and its values on both the configuration and...
Definition: val_domain.hpp:69