KADATH
space_polar_periodic.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 "polar_periodic.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 
28 namespace Kadath {
29 Space_polar_periodic::Space_polar_periodic(int ttype, double omega, 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  // Nucleus
40  domains[0] = new Domain_polar_periodic_nucleus(0, ttype, bounds(0), omega, res) ;
41  for (int i=1 ; i<nbr_domains ; i++)
42  domains[i] = new Domain_polar_periodic_shell(i, ttype, bounds(i-1), bounds(i), omega, res) ;
43 
44 }
45 
47  fread_be (&nbr_domains, sizeof(int), 1, fd) ;
48  fread_be (&ndim, sizeof(int), 1, fd) ;
49  fread_be (&type_base, sizeof(int), 1, fd) ;
50  domains = new Domain* [nbr_domains] ;
51  //nucleus :
52  domains[0] = new Domain_polar_periodic_nucleus(0, fd) ;
53  //Shells :
54  for (int i=1 ; i<nbr_domains ; i++)
55  domains[i] = new Domain_polar_periodic_shell(i, fd) ;
56 }
57 
58 Space_polar_periodic::~Space_polar_periodic() {
59 }
60 
61 void Space_polar_periodic::save (FILE* fd) const {
62  fwrite_be (&nbr_domains, sizeof(int), 1, fd) ;
63  fwrite_be (&ndim, sizeof(int), 1, fd) ;
64  fwrite_be (&type_base, sizeof(int), 1, fd) ;
65  for (int i=0 ; i<nbr_domains ; i++)
66  domains[i]->save(fd) ;
67 }
68 
69 /*
70 int Space_polar_periodic::nbr_unknowns_from_variable_domains () const {
71 
72  return domains[0]->nbr_unknowns_from_adapted() ;
73 }
74 
75 void Space_polar_periodic::affecte_coef_to_variable_domains (int& pos, int cc, Array<int>& zedoms) const {
76  int old_pos = pos ;
77  bool indic = false ;
78  bool firstindic ;
79  for (int d=0 ; d<nbr_domains ; d++) {
80  pos = old_pos ;
81  domains[d]->affecte_coef(pos, cc, indic) ;
82  if (d==0)
83  firstindic = indic ;
84  assert(indic==firstindic) ;
85  if (indic)
86  zedoms.set(d) = d ;
87  else
88  zedoms.set(d) = -1 ;
89  }
90 }
91 
92 
93 void Space_polar_periodic::xx_to_ders_variable_domains (const Array<double>& xx, int& conte) const {
94 
95  int old_conte = conte ;
96  for (int d=0 ; d<nbr_domains ; d++) {
97  conte = old_conte ;
98  domains[d]->xx_to_ders_from_adapted(xx, conte) ;
99  }
100 }
101 
102 
103 void Space_polar_periodic::xx_to_vars_variable_domains (System_of_eqs* sys, const Array<double>& xx, int& pos) const {
104 
105  // First get the correction :
106  int old_pos = pos ;
107  double cor_ome ;
108  domains[0]->xx_to_vars_from_adapted(cor_ome, xx, pos) ;
109 
110  // Now update the variables :
111  for (int i=0 ; i<sys->nvar ; i++) {
112  for (int n=0 ; n<sys->var[i]->get_n_comp() ; n++) {
113  Scalar res(*this) ;
114  for (int d=0 ; d<nbr_domains ; d++)
115  domains[d]->update_variable(cor_ome, *sys->var[i]->cmp[n], res) ;
116 
117  for (int d=0 ; d<nbr_domains ; d++)
118  sys->var[i]->cmp[n]->set_domain(d) = res(d) ;
119  }
120  }
121 
122  // Now the constants :
123  for (int i=0 ; i<sys->ncst ; i++)
124  if (sys->cst[i*(sys->dom_max-sys->dom_min+1)]->get_type_data()==TERM_T)
125  for (int n=0 ; n<sys->cst[i*(sys->dom_max-sys->dom_min+1)]->val_t->get_n_comp() ; n++) {
126 
127  Scalar so (*this) ;
128  so = 0 ;
129  for (int d=0 ; d<nbr_domains ; d++)
130  so.set_domain(d) = (*sys->cst[i*(sys->dom_max-sys->dom_min+1)+d]->val_t->cmp[n])(d) ;
131 
132  Scalar res(*this) ;
133  res = 0 ;
134  for (int d=0 ; d<nbr_domains ; d++)
135  domains[d]->update_constante(cor_ome, so, res) ;
136  for (int d=0 ; d<nbr_domains ; d++)
137  sys->cst[i*(sys->dom_max-sys->dom_min+1)+1+d]->val_t->cmp[n]->set_domain(d) = res(d) ;
138  }
139 
140  // Update the mapping :
141  for (int d=0 ; d<nbr_domains ; d++)
142  domains[d]->update_mapping(cor_ome) ;
143 }
144 */
145 
147  const Domain_polar_periodic_nucleus* polarperiodicnuc = dynamic_cast<const Domain_polar_periodic_nucleus*>(domains[0]) ;
148  return polarperiodicnuc->get_ome() ;
149 
150 }
151 }
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 nucleus with a symmetry in .
double get_ome() const
Returns omega.
Class for a spherical shell with a symmetry in .
Abstract class that implements the fonctionnalities common to all the type of domains.
Definition: space.hpp:60
double get_omega() const
Returns omega.
Space_polar_periodic(int ttype, double omega, const Dim_array &nbr, const Array< double > &bounds)
Standard constructor.
virtual void save(FILE *) const
Saving function.
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