KADATH
domain_shell_import.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 
22 #include "utilities.hpp"
23 #include "spheric.hpp"
24 #include "term_eq.hpp"
25 #include "scalar.hpp"
26 #include "tensor_impl.hpp"
27 
28 namespace Kadath {
29 // Tensorial parts :
30 Tensor Domain_shell::import (int numdom, int bound, int n_ope, const Array<int>& zedoms, Tensor** parts) const {
31 
32  if (parts[0]->get_valence() !=0) {
33  for (int i=0 ; i<n_ope ; i++) {
34  if (parts[i]->get_basis().get_basis(zedoms(i)) != CARTESIAN_BASIS) {
35  cerr << "Import must be called with a Cartesian tensorial basis" << endl ;
36  abort() ;
37  }
38  }
39  }
40 
41  Tensor res (*parts[0], false);
42 
43  for (int nc=0 ; nc<res.get_n_comp() ; nc++)
44  res.cmp[nc]->set_domain(numdom).allocate_conf() ;
45 
46  // Need coefficients of parts :
47  for (int i=0 ; i<n_ope ; i++)
48  for (int nc=0 ; nc<parts[i]->get_n_comp() ; nc++)
49  parts[i]->cmp[nc]->set_domain(zedoms(i)).coef() ;
50 
51  // Loop on the points of the boundary :
52  Val_domain xx (get_cart(1)) ;
53  Val_domain yy (get_cart(2)) ;
54  Val_domain zz (get_cart(3)) ;
55 
56  int index_r ;
57  switch (bound) {
58  case INNER_BC :
59  index_r = 0 ;
60  break ;
61  case OUTER_BC :
62  index_r = nbr_points(0)-1 ;
63  break ;
64  default :
65  cerr << "Unknown boundary in Domain_shell::import" << endl ;
66  }
67 
68  Index pos (get_nbr_points()) ;
69  Index pos_bound (get_nbr_points()) ;
70 
71  for (int k=0 ; k<nbr_points(2) ; k++)
72  for (int j=0 ; j<nbr_points(1) ; j++) {
73 
74  // Indices in the shell
75  pos_bound.set(0) = index_r ;
76  pos_bound.set(1) = j ;
77  pos_bound.set(2) = k ;
78 
79  // Absolute coordinates
80  Point MM (3) ;
81  MM.set(1) = xx(pos_bound) ;
82  MM.set(2) = yy(pos_bound) ;
83  MM.set(3) = zz(pos_bound) ;
84 
85  // In which other domain is it ?
86  bool found = false ;
87  int current = 0 ;
88  while ((current<n_ope) && (!found)) {
89  if (parts[0]->get_space().get_domain(zedoms(current))->is_in(MM, 1e-12))
90  found = true ;
91  else
92  current ++ ;
93  }
94  if (!found) {
95  cerr << "Point " << MM << " not found in other domains, for Domain_shell::import" << endl ;
96  abort() ;
97  }
98 
99  // Convert to numerical coordinates of the other domain
100  Point num (parts[0]->get_space().get_domain(zedoms(current))->absol_to_num(MM)) ;
101 
102  // Now loop on the components :
103  for (int nc=0 ; nc<res.get_n_comp() ; nc++) {
104  double val = ((*parts[current]->cmp[nc])(zedoms(current)).check_if_zero()) ? 0 : (*parts[current]->cmp[nc])(zedoms(current)).get_base().summation (num, *(*parts[current]->cmp[nc])(zedoms(current)).cf) ;
105  // Loop on radius :
106  for (int i=0 ; i<nbr_points(0) ; i++) {
107  pos.set(0) = i ;
108  pos.set(1) = j ;
109  pos.set(2) = k ;
110 
111  res.cmp[nc]->set_domain(numdom).set(pos) = val ;
112  }
113  }
114  }
115 
116  // Assert a std_base :
117  res.set_basis(numdom) = CARTESIAN_BASIS ; // Output in cartesian basis
118  res.std_base() ;
119 
120  return res ;
121 }}
virtual bool is_in(const Point &xx, double prec=1e-13) const
Check whether a point lies inside Domain.
virtual const Point absol_to_num(const Point &xxx) const
Computes the numerical coordinates from the physical ones.
virtual Tensor import(int, int, int, const Array< int > &, Tensor **) const
Gets the value of a Tensor by importing data from neighboring domains, on a boundary.
Dim_array const & get_nbr_points() const
Returns the number of points.
Definition: space.hpp:92
Dim_array nbr_points
Number of colocation points.
Definition: space.hpp:65
Val_domain const & get_cart(int i) const
Returns a Cartesian coordinates.
Definition: space.hpp:1471
Class that gives the position inside a multi-dimensional Array.
Definition: index.hpp:38
int & set(int i)
Read/write of the position in a given dimension.
Definition: index.hpp:72
The class Point is used to store the coordinates of a point.
Definition: point.hpp:30
double & set(int i)
Read/write of a coordinate.
Definition: point.hpp:47
Tensor handling.
Definition: tensor.hpp:149
void coef() const
Computes the coefficients.
virtual void std_base()
Sets the standard spectal bases of decomposition for each component.
Definition: tensor.cpp:385
Memory_mapped_array< Scalar * > cmp
Array of size n_comp of pointers onto the components.
Definition: tensor.hpp:179
int get_n_comp() const
Returns the number of stored components.
Definition: tensor.hpp:514
int & set_basis(int dd)
Assigns a new tensorial basis in a given domain.
Definition: tensor.hpp:331
Class for storing the basis of decompositions of a field and its values on both the configuration and...
Definition: val_domain.hpp:69