KADATH
bispheric_add_eq.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 "bispheric.hpp"
23 #include "system_of_eqs.hpp"
24 #include "name_tools.hpp"
25 namespace Kadath {
26 void Space_bispheric::add_bc_sphere_one (System_of_eqs& sys, const char* name, int nused, Array<int>** pused) {
27 
28  if (ndom_minus==1) {
29  // BC in domain 2 and 3
30  sys.add_eq_bc (ndom_minus+ndom_plus, INNER_BC, name, nused, pused) ;
31  sys.add_eq_bc (ndom_minus+ndom_plus+1, INNER_BC, name, nused, pused) ;
32  }
33  else {
34  sys.add_eq_bc (2, INNER_BC, name, nused, pused) ;
35  }
36 }
37 
38 void Space_bispheric::add_bc_sphere_two (System_of_eqs& sys, const char* name, int nused, Array<int>** pused) {
39  if (ndom_plus==1) {
40  // BC in domain 5 and 6
41  sys.add_eq_bc (ndom_minus+ndom_plus+3, INNER_BC, name, nused, pused) ;
42  sys.add_eq_bc (ndom_minus+ndom_plus+4, INNER_BC, name, nused, pused) ;
43  }
44  else {
45  sys.add_eq_bc (ndom_minus+1, INNER_BC, name, nused, pused) ;
46  }
47 }
48 
49 void Space_bispheric::add_bc_outer_sphere (System_of_eqs& sys, const char* name, int nused, Array<int>** pused) {
50  // All domains :
51  for (int dd=ndom_minus+ndom_plus ; dd<ndom_minus+ndom_plus+5 ; dd++)
52  sys.add_eq_bc(dd, OUTER_BC, name, nused, pused) ;
53 }
54 
55 void Space_bispheric::add_bc_outer (System_of_eqs& sys, const char* name, int nused, Array<int>** pused) {
56  sys.add_eq_bc (nbr_domains-1, OUTER_BC, name, nused, pused) ;
57 }
58 
59 void Space_bispheric::add_eq (System_of_eqs& sys, const char* name, int nused, Array<int>** pused) {
60  for (int dd=sys.get_dom_min() ; dd<=sys.get_dom_max() ; dd++)
61  sys.add_eq_inside (dd, name, nused, pused) ;
62 }
63 
64 void Space_bispheric::add_eq_full (System_of_eqs& sys, const char* name, int nused, Array<int>** pused) {
65  for (int dd=sys.get_dom_min() ; dd<=sys.get_dom_max() ; dd++)
66  sys.add_eq_full (dd, name, nused, pused) ;
67 }
68 
69 void Space_bispheric::add_eq_one_side (System_of_eqs& sys, const char* name, int nused, Array<int>** pused) {
70  for (int dd=sys.get_dom_min() ; dd<=sys.get_dom_max() ; dd++)
71  sys.add_eq_one_side (dd, name, nused, pused) ;
72 }
73 
74 void Space_bispheric::add_matching (System_of_eqs& sys, const char* name, int nused, Array<int>** pused) {
75  sys.add_eq_matching (ndom_minus+ndom_plus, CHI_ONE_BC, name, nused, pused) ;
76  sys.add_eq_matching (ndom_minus+ndom_plus+1, ETA_PLUS_BC, name, nused, pused) ;
77  sys.add_eq_matching (ndom_minus+ndom_plus+2, ETA_PLUS_BC, name, nused, pused) ;
78  sys.add_eq_matching (ndom_minus+ndom_plus+3, CHI_ONE_BC, name, nused, pused) ;
79 }
80 
81 void Space_bispheric::add_matching (System_of_eqs& sys, const char* name, const List_comp& list) {
82  add_matching (sys, name, list.get_ncomp(), list.get_pcomp()) ;
83 }
84 
85 void Space_bispheric::add_matching_one_side (System_of_eqs& sys, const char* name, int nused, Array<int>** pused) {
86  sys.add_eq_matching_one_side (ndom_minus+ndom_plus, CHI_ONE_BC, name, nused, pused) ;
87  sys.add_eq_matching_one_side (ndom_minus+ndom_plus+1, ETA_PLUS_BC, name, nused, pused) ;
88  sys.add_eq_matching_one_side (ndom_minus+ndom_plus+2, ETA_PLUS_BC, name, nused, pused) ;
89  sys.add_eq_matching_one_side (ndom_minus+ndom_plus+3, CHI_ONE_BC, name, nused, pused) ;
90 }
91 
92 void Space_bispheric::add_eq (System_of_eqs& sys, const char* eq, const char* rac, const char* rac_der, int nused, Array<int>** pused) {
93 
94  // First NS
95  sys.add_eq_inside (0, eq, nused, pused) ;
96  sys.add_eq_matching (0, OUTER_BC, rac, nused, pused) ;
97  sys.add_eq_matching (0, OUTER_BC, rac_der, nused, pused) ;
98  sys.add_eq_inside (1, eq, nused, pused) ;
99  sys.add_eq_matching (1, OUTER_BC, rac, nused, pused) ;
100  sys.add_eq_matching (1, OUTER_BC, rac_der, nused, pused) ;
101  sys.add_eq_inside (2, eq, nused, pused) ;
102 
103 
104  // Matching with bispheric :
105  sys.add_eq_matching_import (2, OUTER_BC, rac, nused, pused) ;
106  sys.add_eq_matching_import (6, INNER_BC, rac_der, nused, pused) ;
107  sys.add_eq_matching_import (7, INNER_BC, rac_der, nused, pused) ;
108 
109  // Second NS :
110  sys.add_eq_inside (3, eq, nused, pused) ;
111  sys.add_eq_matching (3, OUTER_BC, rac, nused, pused) ;
112  sys.add_eq_matching (3, OUTER_BC, rac_der, nused, pused) ;
113  sys.add_eq_inside (4, eq, nused, pused) ;
114  sys.add_eq_matching (4, OUTER_BC, rac, nused, pused) ;
115  sys.add_eq_matching (4, OUTER_BC, rac_der, nused, pused) ;
116  sys.add_eq_inside (5, eq, nused, pused) ;
117 
118  // Matching with bispheric :
119  sys.add_eq_matching_import (5, OUTER_BC, rac, nused, pused) ;
120  sys.add_eq_matching_import (9, INNER_BC, rac_der, nused, pused) ;
121  sys.add_eq_matching_import (10, INNER_BC, rac_der, nused, pused) ;
122 
123  // Chi first
124  sys.add_eq_inside (6, eq, nused, pused) ;
125  sys.add_eq_matching (6, CHI_ONE_BC, rac, nused, pused) ;
126  sys.add_eq_matching (6, CHI_ONE_BC, rac_der, nused, pused) ;
127 
128  // Rect :
129  sys.add_eq_inside (7, eq, nused, pused) ;
130  sys.add_eq_matching (7, ETA_PLUS_BC, rac, nused, pused) ;
131  sys.add_eq_matching (7, ETA_PLUS_BC, rac_der, nused, pused) ;
132 
133  // Eta first
134  sys.add_eq_inside (8, eq, nused, pused) ;
135  sys.add_eq_matching (8, ETA_PLUS_BC, rac, nused, pused) ;
136  sys.add_eq_matching (8, ETA_PLUS_BC, rac_der, nused, pused) ;
137 
138  // Rect
139  sys.add_eq_inside (9, eq, nused, pused) ;
140  sys.add_eq_matching (9, CHI_ONE_BC, rac, nused, pused) ;
141  sys.add_eq_matching (9, CHI_ONE_BC, rac_der, nused, pused) ;
142 
143 
144  // chi first :
145  sys.add_eq_inside (10, eq, nused, pused) ;
146 
147  // Matching outer domain :
148  for (int d=6 ; d<=10 ; d++)
149  sys.add_eq_matching_import (d, OUTER_BC, rac, nused, pused) ;
150  sys.add_eq_matching_import (11, INNER_BC, rac_der, nused, pused) ;
151 
152  //Compactified domain
153  sys.add_eq_inside (11, eq, nused, pused) ;
154 }
155 
156 void Space_bispheric::add_eq (System_of_eqs& sys, const char* eq, const char* rac, const char* rac_der, const List_comp& list) {
157  add_eq (sys, eq, rac, rac_der, list.get_ncomp(), list.get_pcomp()) ;
158 }
159 
160 void Space_bispheric::add_eq_no_nucleus (System_of_eqs& sys, const char* eq, const char* rac, const char* rac_der, int nused, Array<int>** pused) {
161 
162  // Shell 1
163  sys.add_eq_inside (0, eq, nused, pused) ;
164 
165  // Matching with bispheric :
166  sys.add_eq_matching_import (0, OUTER_BC, rac, nused, pused) ;
167  sys.add_eq_matching_import (2, INNER_BC, rac_der, nused, pused) ;
168  sys.add_eq_matching_import (3, INNER_BC, rac_der, nused, pused) ;
169 
170  // Shell 2
171  sys.add_eq_inside (1, eq, nused, pused) ;
172 
173  // Matching with bispheric :
174  sys.add_eq_matching_import (1, OUTER_BC, rac, nused, pused) ;
175  sys.add_eq_matching_import (5, INNER_BC, rac_der, nused, pused) ;
176  sys.add_eq_matching_import (6, INNER_BC, rac_der, nused, pused) ;
177 
178  // Chi first
179  sys.add_eq_inside (2, eq, nused, pused) ;
180  sys.add_eq_matching (2, CHI_ONE_BC, rac, nused, pused) ;
181  sys.add_eq_matching (2, CHI_ONE_BC, rac_der, nused, pused) ;
182 
183  // Rect :
184  sys.add_eq_inside (3, eq, nused, pused) ;
185  sys.add_eq_matching (3, ETA_PLUS_BC, rac, nused, pused) ;
186  sys.add_eq_matching (3, ETA_PLUS_BC, rac_der, nused, pused) ;
187 
188  // Eta first
189  sys.add_eq_inside (4, eq, nused, pused) ;
190  sys.add_eq_matching (4, ETA_PLUS_BC, rac, nused, pused) ;
191  sys.add_eq_matching (4, ETA_PLUS_BC, rac_der, nused, pused) ;
192 
193  // Rect
194  sys.add_eq_inside (5, eq, nused, pused) ;
195  sys.add_eq_matching (5, CHI_ONE_BC, rac, nused, pused) ;
196  sys.add_eq_matching (5, CHI_ONE_BC, rac_der, nused, pused) ;
197 
198 
199  // chi first :
200  sys.add_eq_inside (6, eq, nused, pused) ;
201 
202  // Matching outer domain :
203  for (int d=2 ; d<=6 ; d++)
204  sys.add_eq_matching_import (d, OUTER_BC, rac, nused, pused) ;
205  sys.add_eq_matching_import (7, INNER_BC, rac_der, nused, pused) ;
206 
207  //Compactified domain
208  sys.add_eq_inside (7, eq, nused, pused) ;
209 }
210 
211 void Space_bispheric::add_eq_no_nucleus (System_of_eqs& sys, const char* eq, const char* rac, const char* rac_der, const List_comp& list) {
212  add_eq (sys, eq, rac, rac_der, list.get_ncomp(), list.get_pcomp()) ;
213 }
214 void Space_bispheric::add_eq_int_inf (System_of_eqs& sys, const char* nom) {
215 
216  // Check the last domain is of the right type :
217  const Domain_compact* pcomp = dynamic_cast <const Domain_compact*> (domains[nbr_domains-1]) ;
218  if (pcomp==0x0) {
219  cerr << "add_eq_int_inf requires a compactified domain" << endl ;
220  abort() ;
221  }
222  int dom = nbr_domains-1 ;
223 
224  // Get the lhs and rhs
225  char p1[LMAX] ;
226  char p2[LMAX] ;
227  bool indic = sys.is_ope_bin(nom, p1, p2, '=') ;
228  if (!indic) {
229  cerr << "= needed for equations" << endl ;
230  abort() ;
231  }
232  else {
233  // Verif lhs = 0 ?
234  indic = ((p2[0]=='0') && (p2[1]==' ') && (p2[2]=='\0')) ?
235  true : false ;
236 
237  // Construction of the equation
238  sys.eq_int[sys.neq_int] = new Eq_int(1) ;
239 
240  // Affectation :
241  // no lhs :
242  if (indic)
243  sys.eq_int[sys.neq_int]->set_part(0, sys.give_ope(dom, p1, OUTER_BC)) ;
244 
245  else
246  sys.eq_int[sys.neq_int]->set_part(0, new Ope_sub(&sys, sys.give_ope(dom, p1, OUTER_BC), sys.give_ope(dom, p2, OUTER_BC))) ;
247  sys.neq_int ++ ;
248  }
249  sys.nbr_conditions = -1 ;
250 }
251 
253 
254  // Get the lhs and rhs
255  char p1[LMAX] ;
256  char p2[LMAX] ;
257  bool indic = sys.is_ope_bin(nom, p1, p2, '=') ;
258  if (!indic) {
259  cerr << "= needed for equations" << endl ;
260  abort() ;
261  }
262  else {
263 
264  // Verif lhs = 0 ?
265  indic = ((p2[0]=='0') && (p2[1]==' ') && (p2[2]=='\0')) ?
266  true : false ;
267 
268  if (ndom_minus==1) {
269  // Construction of the equation
270  sys.eq_int[sys.neq_int] = new Eq_int(2) ;
271 
272  // Affectation :
273  // no lhs :
274  if (indic) {
275  sys.eq_int[sys.neq_int]->set_part(0, sys.give_ope(ndom_minus+ndom_plus, p1, INNER_BC)) ;
276  sys.eq_int[sys.neq_int]->set_part(1, sys.give_ope(ndom_minus+ndom_plus+1, p1, INNER_BC)) ;
277  }
278  else {
279  sys.eq_int[sys.neq_int]->set_part(0,
280  new Ope_sub(&sys, sys.give_ope(ndom_minus+ndom_plus, p1, INNER_BC), sys.give_ope(ndom_minus+ndom_plus, p2, INNER_BC))) ;
281  sys.eq_int[sys.neq_int]->set_part(1,
282  new Ope_sub(&sys, sys.give_ope(ndom_minus+ndom_plus+1, p1, INNER_BC), sys.give_ope(ndom_minus+ndom_plus+1, p2, INNER_BC))) ;
283  }
284  }
285  else {
286  // Construction of the equation
287  sys.eq_int[sys.neq_int] = new Eq_int(1) ;
288 
289  // Affectation :
290  // no lhs :
291  if (indic) {
292  sys.eq_int[sys.neq_int]->set_part(0, sys.give_ope(1, p1, INNER_BC)) ;
293  }
294  else {
295  sys.eq_int[sys.neq_int]->set_part(0,
296  new Ope_sub(&sys, sys.give_ope(1, p1, INNER_BC), sys.give_ope(1, p2, INNER_BC))) ;
297  }
298  }
299  sys.neq_int ++ ;
300  }
301  sys.nbr_conditions = -1 ;
302 }
303 
304 
306 
307  // Get the lhs and rhs
308  char p1[LMAX] ;
309  char p2[LMAX] ;
310  bool indic = sys.is_ope_bin(nom, p1, p2, '=') ;
311  if (!indic) {
312  cerr << "= needed for equations" << endl ;
313  abort() ;
314  }
315  else {
316  // Verif lhs = 0 ?
317  indic = ((p2[0]=='0') && (p2[1]==' ') && (p2[2]=='\0')) ?
318  true : false ;
319 
320  if (ndom_plus==1) {
321  // Construction of the equation
322  sys.eq_int[sys.neq_int] = new Eq_int(2) ;
323 
324  // Affectation :
325  // no lhs :
326  if (indic) {
327  sys.eq_int[sys.neq_int]->set_part(0, sys.give_ope(ndom_minus+ndom_plus+3, p1, INNER_BC)) ;
328  sys.eq_int[sys.neq_int]->set_part(1, sys.give_ope(ndom_minus+ndom_plus+4, p1, INNER_BC)) ;
329  }
330  else {
331  sys.eq_int[sys.neq_int]->set_part(0,
332  new Ope_sub(&sys, sys.give_ope(ndom_minus+ndom_plus+3, p1, INNER_BC), sys.give_ope(ndom_minus+ndom_plus+3, p2, INNER_BC))) ;
333  sys.eq_int[sys.neq_int]->set_part(1,
334  new Ope_sub(&sys, sys.give_ope(ndom_minus+ndom_plus+4, p1, INNER_BC), sys.give_ope(ndom_minus+ndom_plus+4, p2, INNER_BC))) ;
335  }
336  }
337  else {
338  // Construction of the equation
339  sys.eq_int[sys.neq_int] = new Eq_int(1) ;
340 
341  // Affectation :
342  // no lhs :
343  if (indic) {
344  sys.eq_int[sys.neq_int]->set_part(0, sys.give_ope(ndom_minus+1, p1, INNER_BC)) ;
345  }
346  else {
347  sys.eq_int[sys.neq_int]->set_part(0,
348  new Ope_sub(&sys, sys.give_ope(ndom_minus+1, p1, INNER_BC), sys.give_ope(ndom_minus+1, p2, INNER_BC))) ;
349  }
350  }
351 
352  sys.neq_int ++ ;
353  }
354  sys.nbr_conditions = -1 ;
355 }
356 
357 
358 void Space_bispheric::add_eq_zero_mode_inf (System_of_eqs& sys, const char* name, int j, int k) {
359 
360  Index pos_cf (domains[nbr_domains-1]->get_nbr_coefs()) ;
361  pos_cf.set(1) = j ;
362  pos_cf.set(2) = k ;
363  double value = 0. ;
364  char auxi[LMAX] ;
365  trim_spaces (auxi, name) ;
366  sys.add_eq_mode (nbr_domains-1, OUTER_BC, auxi, pos_cf, value) ;
367 }
368 }
Class for a spherical compactified domain and a symmetry with respect to the plane .
Definition: spheric.hpp:1007
Class implementing an integral equation.
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
Class for storing a list of tensorial components.
Definition: list_comp.hpp:33
int get_ncomp() const
Returns the number of components.
Definition: list_comp.hpp:64
Array< int > ** get_pcomp() const
Returns a pointer of the liste.
Definition: list_comp.hpp:69
The operator substraction.
Definition: ope_eq.hpp:165
void add_eq_full(System_of_eqs &syst, const char *eq, int nused=-1, Array< int > **pused=0x0)
Sets an equation inside every domains (assumed to be zeroth order).
void add_bc_outer_sphere(System_of_eqs &syst, const char *eq, int nused=-1, Array< int > **pused=0x0)
Sets a boundary condition at the outer sphere of the bispheric coordinates.
void add_eq_zero_mode_inf(System_of_eqs &syst, const char *f, int jtarget, int ktarget)
Adds an equation saying that one coefficient of a field is zero (at infinity)
int ndom_minus
Number of spherical domains inside the first sphere.
Definition: bispheric.hpp:1245
void add_eq_one_side(System_of_eqs &syst, const char *eq, int nused=-1, Array< int > **pused=0x0)
Sets an equation inside every domains (assumed to be first order).
int ndom_plus
Number of spherical domains inside the second sphere.
Definition: bispheric.hpp:1246
void add_bc_outer(System_of_eqs &syst, const char *eq, int nused=-1, Array< int > **pused=0x0)
Sets a boundary condition at the outer boundary.
void add_bc_sphere_one(System_of_eqs &syst, const char *eq, int nused=-1, Array< int > **pused=0x0)
Sets a boundary condition at the inner radius of the first sphere.
void add_eq(System_of_eqs &syst, const char *eq, int nused=-1, Array< int > **pused=0x0)
Sets an equation inside every domains (assumed to be second order).
void add_eq_int_inf(System_of_eqs &syst, const char *eq)
Adds an equation being a surface integral at infinity.
void add_bc_sphere_two(System_of_eqs &syst, const char *eq, int nused=-1, Array< int > **pused=0x0)
Sets a boundary condition at the inner radius of the second sphere.
void add_matching(System_of_eqs &syst, const char *rac, const List_comp &list)
Sets a matching condition accross all the bispheric domain (intended for a second order equation).
void add_eq_int_sphere_one(System_of_eqs &syst, const char *eq)
Adds an equation being a surface integral on the first sphere.
void add_eq_no_nucleus(System_of_eqs &syst, const char *eq, const char *rac, const char *rac_der, int nused=-1, Array< int > **pused=0x0)
Adds a bulk equation and two matching conditions for a space without nucleii.
void add_matching_one_side(System_of_eqs &syst, const char *rac, int nused=-1, Array< int > **pused=0x0)
Sets a matching condition accross all the bispheric domain (intended for a first order equation).
void add_eq_int_sphere_two(System_of_eqs &syst, const char *eq)
Adds an equation being a surface integral on the second sphere.
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.
virtual void add_eq_inside(int dom, const char *eq, int n_cmp=-1, Array< int > **p_cmp=nullptr)
Addition of an equation to be solved inside a domain (assumed to be second order).
Definition: add_eq.cpp:26
virtual void add_eq_full(int dom, const char *eq, int n_cmp=-1, Array< int > **p_cmp=nullptr)
Addition of an equation to be solved inside a domain (assumed to be zeroth order i....
Definition: add_eq.cpp:374
virtual void add_eq_matching_import(int dom, int bb, const char *eq, int n_cmp=-1, Array< int > **p_cmp=nullptr)
Addition of an equation describing a matching condition between domains using the ("import" setting) ...
Definition: add_eq.cpp:344
virtual void add_eq_mode(int dom, int bb, const char *eq, const Index &pos_cf, double val)
Addition of an equation prescribing the value of one coefficient of a scalar field,...
Definition: add_eq.cpp:438
virtual void add_eq_matching(int dom, int bb, const char *eq, int n_cmp=-1, Array< int > **p_cmp=nullptr)
Addition of an equation describing a matching condition between two domains (standard setting)
Definition: add_eq.cpp:198
int neq_int
Number of integral equations (i.e. which are doubles)
virtual void add_eq_bc(int dom, int bb, const char *eq, int n_cmp=-1, Array< int > **p_cmp=nullptr)
Addition of an equation describing a boundary condition.
Definition: add_eq.cpp:168
bool is_ope_bin(const char *input, char *p1, char *p2, char symb) const
Checks if a string represents an operator of the type "a + b".
Definition: give_ope.cpp:276
virtual void add_eq_matching_one_side(int dom, int bb, const char *eq, int n_cmp=-1, Array< int > **p_cmp=nullptr)
Addition of an equation describing a matching condition between two domains (specialized function for...
Definition: add_eq.cpp:270
Ope_eq * give_ope(int dom, const char *name, int bb=0) const
Function that reads a string and returns a pointer on the generated Ope_eq.
Definition: give_ope.cpp:559
int get_dom_max() const
Returns the highest index of the domains.
int nbr_conditions
Total number of conditions (the number of coefficients of all the equations, once regularities are ta...
virtual void add_eq_one_side(int dom, const char *eq, int n_cmp=-1, Array< int > **p_cmp=nullptr)
Addition of an equation to be solved inside a domain (assumed to be first order).
Definition: add_eq.cpp:407
int get_dom_min() const
Returns the smallest index of the domains.
MMPtr_array< Eq_int > eq_int
Pointers onto the integral equations.