KADATH
space_spheric_adapted.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.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_spheric_adapted::Space_spheric_adapted (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)+1 ;
37  assert (nbr_domains>=4) ;
38  type_base = ttype ;
39  domains = new Domain* [nbr_domains] ;
40 
41  // Nucleus
42  domains[0] = new Domain_nucleus (0, ttype, bounds(0), center, res) ;
43  domains[1] = new Domain_shell_outer_adapted (*this, 1, ttype, bounds(0), bounds(1), center, res) ;
44  domains[2] = new Domain_shell_inner_adapted (*this, 2, ttype, bounds(1), bounds(2), center, res) ;
45  for (int i=3 ; i<nbr_domains-1 ; i++)
46  domains[i] = new Domain_shell(i, ttype, bounds(i-1), bounds(i), center, res) ;
47 
48  domains[nbr_domains-1] = new Domain_compact (nbr_domains-1, ttype, bounds(nbr_domains-2), center, res) ;
49 
50  const Domain_shell_outer_adapted* pshell_outer = dynamic_cast<const Domain_shell_outer_adapted*> (domains[1]) ;
51  pshell_outer->vars_to_terms() ;
52  const Domain_shell_inner_adapted* pshell_inner = dynamic_cast<const Domain_shell_inner_adapted*> (domains[2]) ;
53  pshell_inner->vars_to_terms() ;
54 }
55 
56 
58  fread_be (&nbr_domains, sizeof(int), 1, fd) ;
59  fread_be (&ndim, sizeof(int), 1, fd) ;
60  fread_be (&type_base, sizeof(int), 1, fd) ;
61  domains = new Domain* [nbr_domains] ;
62  //nucleus :
63  domains[0] = new Domain_nucleus (0, fd) ;
64  domains[1] = new Domain_shell_outer_adapted (*this, 1, fd) ;
65  domains[2] = new Domain_shell_inner_adapted (*this, 2, fd) ;
66  //Shells :
67  for (int i=3 ; i<nbr_domains-1 ; i++)
68  domains[i] = new Domain_shell(i, fd) ;
69  // Compactified
71 
72  const Domain_shell_outer_adapted* pshell_outer = dynamic_cast<const Domain_shell_outer_adapted*> (domains[1]) ;
73  pshell_outer->vars_to_terms() ;
74  const Domain_shell_inner_adapted* pshell_inner = dynamic_cast<const Domain_shell_inner_adapted*> (domains[2]) ;
75  pshell_inner->vars_to_terms() ;
76 }
77 
79  Domain_shell_outer_adapted* pshell_outer = dynamic_cast<Domain_shell_outer_adapted*> (domains[1]) ;
80  pshell_outer->del_deriv() ;
81  Domain_shell_inner_adapted* pshell_inner = dynamic_cast<Domain_shell_inner_adapted*> (domains[2]) ;
82  pshell_inner->del_deriv() ;
83 }
84 
85 void Space_spheric_adapted::save (FILE* fd) const {
86  fwrite_be (&nbr_domains, sizeof(int), 1, fd) ;
87  fwrite_be (&ndim, sizeof(int), 1, fd) ;
88  fwrite_be (&type_base, sizeof(int), 1, fd) ;
89  for (int i=0 ; i<nbr_domains ; i++)
90  domains[i]->save(fd) ;
91 }
92 
94 
95  return domains[1]->nbr_unknowns_from_adapted() ;
96 }
97 
99 
100  bool found_outer = false ;
101  int old_pos = pos ;
102  domains[1]->affecte_coef(pos, cc, found_outer) ;
103  pos = old_pos ;
104  bool found_inner = false ;
105  domains[2]->affecte_coef(pos, cc, found_inner) ;
106  assert (found_outer == found_inner) ;
107  if (found_outer) {
108  zedoms.set(0) = 1 ;
109  zedoms.set(1) = 2 ;
110  }
111  else {
112  zedoms.set(0) = -1 ;
113  zedoms.set(1) = -1 ;
114  }
115 }
116 
118 
119  int old_conte = conte ;
120  domains[1]->xx_to_ders_from_adapted(xx, conte) ;
121  conte = old_conte ;
122  domains[2]->xx_to_ders_from_adapted(xx, conte) ;
123 }
124 
126 
127  // First get the corrections :
128  int old_pos = pos ;
129  Val_domain cor_outer (domains[1]) ;
130  domains[1]->xx_to_vars_from_adapted(cor_outer, xx, pos) ;
131  pos = old_pos ;
132  Val_domain cor_inner (domains[2]) ;
133  domains[2]->xx_to_vars_from_adapted(cor_inner, xx, pos) ;
134 
135  // Now update the variables :
136  for (int i=0 ; i<sys->nvar ; i++) {
137  for (int n=0 ; n<sys->var[i]->get_n_comp() ; n++) {
138  Scalar res(*this) ;
139  domains[1]->update_variable(cor_outer, *sys->var[i]->cmp[n], res) ;
140  domains[2]->update_variable(cor_inner, *sys->var[i]->cmp[n], res) ;
141 
142  sys->var[i]->cmp[n]->set_domain(1) = res(1) ;
143  sys->var[i]->cmp[n]->set_domain(2) = res(2) ;
144 
145  }
146  }
147 
148  // Now the constants :
149  for (int i=0 ; i<sys->ncst ; i++)
150  if (sys->cst[i*(sys->dom_max-sys->dom_min+1)]->get_type_data()==TERM_T)
151  for (int n=0 ; n<sys->cst[i*(sys->dom_max-sys->dom_min+1)]->val_t->get_n_comp() ; n++) {
152 
153  Scalar so (*this) ;
154  so = 0 ;
155  for (int d=1 ; d<=2 ; d++)
156  so.set_domain(d) = (*sys->cst[i*(sys->dom_max-sys->dom_min+1)+d-sys->dom_min]->val_t->cmp[n])(d) ;
157 
158  Scalar res(*this) ;
159  res = 0 ;
160  domains[1]->update_constante(cor_outer, so, res) ;
161  domains[2]->update_constante(cor_inner, so, res) ;
162 
163  sys->cst[i*(sys->dom_max-sys->dom_min+1)+1-sys->dom_min]->val_t->cmp[n]->set_domain(1) = res(1) ;
164  sys->cst[i*(sys->dom_max-sys->dom_min+1)+2-sys->dom_min]->val_t->cmp[n]->set_domain(2) = res(2) ;
165 
166  }
167 
168  // Update the mapping :
169  domains[1]->update_mapping(cor_outer) ;
170  domains[2]->update_mapping(cor_inner) ;
171 }
172 
173 
175 
176  assert ((dom>=0) && (dom<nbr_domains)) ;
177  Array<int> res (2, 1) ;
178  switch (bound) {
179  case OUTER_BC :
180  res.set(0,0) = dom+1 ;
181  res.set(1,0) = INNER_BC ;
182  break ;
183  case INNER_BC :
184  res.set(0,0) = dom-1 ;
185  res.set(1,0) = OUTER_BC ;
186  break ;
187  default :
188  cerr << "Unknown boundary in " << endl ;
189  cerr << *this << endl ;
190  abort() ;
191  }
192  return res ;
193 }
194 
195 void Space_spheric_adapted::add_eq_ori (System_of_eqs& sys, const char* name) {
196 
197  Index pos (domains[0]->get_nbr_points()) ;
198  char auxi[LMAX] ;
199  trim_spaces (auxi, name) ;
200  sys.add_eq_val (0, auxi, pos) ;
201 }
202 }
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 domain containing the origin and a symmetry with respect to the plane .
Definition: spheric.hpp:66
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-like domain, having a symmetry with respect to the plane .
Definition: adapted.hpp:367
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
Class that gives the position inside a multi-dimensional Array.
Definition: index.hpp:38
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
void add_eq_ori(System_of_eqs &syst, const char *eq)
Adds an equation being the value of some field at the origin.
virtual void xx_to_ders_variable_domains(const Array< double > &, int &) const
Update the vairable domains from a set of values.
virtual ~Space_spheric_adapted()
Destructor
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 Array< int > get_indices_matching_non_std(int, int) const
Gives the number of the other domains, touching a given boundary.
virtual void save(FILE *) const
Saving function.
Space_spheric_adapted(int ttyp, const Point &cr, const Dim_array &nbr, const Array< double > &bounds)
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.
virtual void add_eq_val(int dom, const char *eq, const Index &pos)
Addition of an equation saying that the value of a field must be zero at one collocation point.
Definition: add_eq.cpp:462
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