KADATH
domain_shell_outer_adapted_import.cpp
1 /*
2  Copyright 2018 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 "utilities.hpp"
22 #include "adapted.hpp"
23 #include "point.hpp"
24 #include "array_math.hpp"
25 #include "term_eq.hpp"
26 #include "scalar.hpp"
27 #include "tensor_impl.hpp"
28 
29 namespace Kadath {
30 // Tensorial parts :
31 Tensor Domain_shell_outer_adapted::import (int numdom, int bound, int n_ope, const Array<int>& zedoms, Tensor** parts) const {
32 
33 #ifndef REMOVE_ALL_CHECKS
34  if (parts[0]->get_valence() !=0) {
35  for (int i=0 ; i<n_ope ; i++) {
36  if (parts[i]->get_basis().get_basis(zedoms(i)) != CARTESIAN_BASIS) {
37  cerr << "Import must be called with a Cartesian tensorial basis" << endl ;
38  abort() ;
39  }
40  }
41  }
42 #endif
43 
44  Tensor res (*parts[0], false);
45 
46  for (int nc=0 ; nc<res.get_n_comp() ; nc++)
47  res.cmp[nc]->set_domain(numdom).allocate_conf() ;
48 
49  // Need coefficients of parts :
50  for (int i=0 ; i<n_ope ; i++)
51  for (int nc=0 ; nc<parts[i]->get_n_comp() ; nc++)
52  parts[i]->cmp[nc]->set_domain(zedoms(i)).coef() ;
53 
54  // Loop on the points of the boundary :
55  Val_domain xx (get_cart(1)) ;
56  Val_domain yy (get_cart(2)) ;
57  Val_domain zz (get_cart(3)) ;
58 
59  int index_r ;
60  switch (bound) {
61  case INNER_BC :
62  index_r = 0 ;
63  break ;
64  case OUTER_BC :
65  index_r = nbr_points(0)-1 ;
66  break ;
67  default :
68  cerr << "Unknown boundary in Domain_shell_outer_adapted::import" << endl ;
69  }
70 
71  Index pos (get_nbr_points()) ;
72  Index pos_bound (get_nbr_points()) ;
73 
74  for (int k=0 ; k<nbr_points(2) ; k++)
75  for (int j=0 ; j<nbr_points(1) ; j++) {
76 
77  // Indices in the shell
78  pos_bound.set(0) = index_r ;
79  pos_bound.set(1) = j ;
80  pos_bound.set(2) = k ;
81 
82  // Absolute coordinates
83  Point MM (3) ;
84  MM.set(1) = xx(pos_bound) ;
85  MM.set(2) = yy(pos_bound) ;
86  MM.set(3) = zz(pos_bound) ;
87 
88  // In which other domain is it ?
89  bool found = false ;
90  int current = 0 ;
91  while ((current<n_ope) && (!found)) {
92  if (parts[0]->get_space().get_domain(zedoms(current))->is_in(MM))
93  found = true ;
94  else
95  current ++ ;
96  }
97 #ifndef REMOVE_ALL_CHECKS
98  if (!found) {
99  cerr << "Point " << MM << " not found in other domains, for Domain_shell_outer_adapted::import" << endl ;
100  abort() ;
101  }
102 #endif
103 
104  // Convert to numerical coordinates of the other domain
105  Point num (parts[0]->get_space().get_domain(zedoms(current))->absol_to_num(MM)) ;
106 
107  // Now loop on the components :
108  for (int nc=0 ; nc<res.get_n_comp() ; nc++) {
109  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) ;
110  // Loop on radius :
111  for (int i=0 ; i<nbr_points(0) ; i++) {
112  pos.set(0) = i ;
113  pos.set(1) = j ;
114  pos.set(2) = k ;
115 
116  res.cmp[nc]->set_domain(numdom).set(pos) = val ;
117  }
118  }
119  }
120 
121  // Assert a std_base :
122  res.set_basis(numdom) = CARTESIAN_BASIS ; // Output in cartesian basis
123  res.std_base() ;
124 
125  return res ;
126 }
127 }
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.
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 &) const
Computes the numerical coordinates from the physical ones.
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