KADATH
space_spheric.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 "spheric.hpp"
22 #include <assert.h>
23 #include "scalar.hpp"
24 #include "tensor_impl.hpp"
25 namespace Kadath {
26 Space_spheric::Space_spheric(int ttype, const Point& center, const Dim_array& res, const Array<double>& bounds, bool withzec) {
27 
28  // Verif :
29  assert (bounds.get_ndim()== 1) ;
30 
31  ndim = 3 ;
32 
33  nbr_domains = (withzec) ? bounds.get_size(0)+1 : bounds.get_size(0) ;
34  type_base = ttype ;
35  domains = new Domain* [nbr_domains] ;
36  // Nucleus
37  domains[0] = new Domain_nucleus(0, ttype, bounds(0), center, res) ;
38  if (withzec) {
39  for (int i=1 ; i<nbr_domains-1 ; i++)
40  domains[i] = new Domain_shell(i, ttype, bounds(i-1), bounds(i), center, res) ;
41 
42  domains[nbr_domains-1] = new Domain_compact (nbr_domains-1, ttype, bounds(nbr_domains-2), center, res) ;
43  }
44  else {
45  for (int i=1 ; i<nbr_domains ; i++)
46  domains[i] = new Domain_shell(i, ttype, bounds(i-1), bounds(i), center, res) ;
47  }
48 }
49 
50 Space_spheric::Space_spheric(int ttype, const Point& center, Dim_array** res, const Array<double>& bounds) {
51 
52  // Verif :
53  assert (bounds.get_ndim()== 1) ;
54 
55  ndim = 3 ;
56 
57  nbr_domains = bounds.get_size(0)+1 ;
58  type_base = ttype ;
59  domains = new Domain* [nbr_domains] ;
60  // Nucleus
61  domains[0] = new Domain_nucleus(0, ttype, bounds(0), center, *res[0]) ;
62  for (int i=1 ; i<nbr_domains-1 ; i++)
63  domains[i] = new Domain_shell(i, ttype, bounds(i-1), bounds(i), center, *res[i]) ;
64 
65  domains[nbr_domains-1] = new Domain_compact (nbr_domains-1, ttype, bounds(nbr_domains-2), center, *res[nbr_domains-1]) ;
66 }
67 
68 Space_spheric::Space_spheric(int ttype, const Point& center, const Dim_array& res, const Array<double>& bounds, const Array<int>& type_shells) {
69 
70  // Verif :
71  assert (bounds.get_ndim()== 1) ;
72 
73  ndim = 3 ;
74 
75  nbr_domains = bounds.get_size(0)+1 ;
76  type_base = ttype ;
77  domains = new Domain* [nbr_domains] ;
78  // Nucleus
79  domains[0] = new Domain_nucleus(0, ttype, bounds(0), center, res) ;
80  for (int i=1 ; i<nbr_domains-1 ; i++) {
81  switch (type_shells(i-1)) {
82  case STD_TYPE :
83  domains[i] = new Domain_shell(i, ttype, bounds(i-1), bounds(i), center, res) ;
84  break ;
85  case LOG_TYPE :
86  domains[i] = new Domain_shell_log (i, ttype, bounds(i-1), bounds(i), center, res) ;
87  break ;
88  case SURR_TYPE :
89  domains[i] = new Domain_shell_surr (i, ttype, bounds(i-1), bounds(i), center, res) ;
90  break ;
91  default :
92  cerr << "Unknown type of shell" << endl ;
93  abort() ;
94  }
95  }
96 
97  domains[nbr_domains-1] = new Domain_compact (nbr_domains-1, ttype, bounds(nbr_domains-2), center, res) ;
98 }
99 
100 Space_spheric::Space_spheric(FILE* fd, bool withzec) {
101  fread_be (&nbr_domains, sizeof(int), 1, fd) ;
102  fread_be (&ndim, sizeof(int), 1, fd) ;
103  fread_be (&type_base, sizeof(int), 1, fd) ;
104  domains = new Domain* [nbr_domains] ;
105  //nucleus :
106  domains[0] = new Domain_nucleus(0, fd) ;
107 
108  if (withzec) {
109  //Shells :
110  for (int i=1 ; i<nbr_domains-1 ; i++)
111  domains[i] = new Domain_shell(i, fd) ;
112  // Compactified
114  }
115  else {
116  //Shells :
117  for (int i=1 ; i<nbr_domains ; i++)
118  domains[i] = new Domain_shell(i, fd) ;
119  }
120 }
121 
123 }
124 
125 void Space_spheric::save (FILE* fd) const {
126  fwrite_be (&nbr_domains, sizeof(int), 1, fd) ;
127  fwrite_be (&ndim, sizeof(int), 1, fd) ;
128  fwrite_be (&type_base, sizeof(int), 1, fd) ;
129  for (int i=0 ; i<nbr_domains ; i++)
130  domains[i]->save(fd) ;
131 }
132 
134 
135  assert ((dom>=0) && (dom<nbr_domains)) ;
136  Array<int> res (2, 1) ;
137  switch (bound) {
138  case OUTER_BC :
139  res.set(0,0) = dom+1 ;
140  res.set(1,0) = INNER_BC ;
141  break ;
142  case INNER_BC :
143  res.set(0,0) = dom-1 ;
144  res.set(1,0) = OUTER_BC ;
145  break ;
146  default :
147  cerr << "Unknown boundary in " << endl ;
148  cerr << *this << endl ;
149  abort() ;
150  }
151  return res ;
152 }
153 
154 double Space_spheric::int_inf (const Scalar& so) const {
155 
156  const Domain_compact* p_cmp = dynamic_cast <const Domain_compact*> (domains[nbr_domains-1]) ;
157  if (p_cmp==0x0) {
158  cerr << "No compactified domain in Space_spheric::int_inf" << endl ;
159  abort() ;
160  }
161  return p_cmp->integ (so(nbr_domains-1), OUTER_BC) ;
162 }}
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
virtual double integ(const Val_domain &, int) const
Surface integral on a given boundary.
Class for a spherical domain containing the origin and a symmetry with respect to the plane .
Definition: spheric.hpp:66
Class for a spherical shell and a symmetry with respect to the plane .
Definition: spheric.hpp:1507
Class for a spherical shell and a symmetry with respect to the plane .
Definition: spheric.hpp:1597
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
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
virtual Array< int > get_indices_matching_non_std(int, int) const
Gives the number of the other domains, touching a given boundary.
double int_inf(const Scalar &) const
Computes the surface integral at infinity.
Space_spheric(int ttype, const Point &cr, const Dim_array &nbr, const Array< double > &bounds, bool withzec=true)
Standard constructor.
virtual void save(FILE *) const
Saving function.
virtual ~Space_spheric()
Destructor
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