KADATH
polar_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 #include "polar.hpp"
22 #include "system_of_eqs.hpp"
23 #include "name_tools.hpp"
24 #include "ope_eq.hpp"
25 namespace Kadath {
26 void Space_polar::add_inner_bc (System_of_eqs& sys, const char* name, int nused, Array<int>** pused) const {
27  // BC in domain 5 and 6
28  sys.add_eq_bc (sys.get_dom_min(), INNER_BC, name, nused, pused) ;
29 }
30 
31 void Space_polar::add_outer_bc (System_of_eqs& sys, const char* name, int nused, Array<int>** pused) const {
32  sys.add_eq_bc (sys.get_dom_max(), OUTER_BC, name, nused, pused) ;
33 }
34 
35 void Space_polar::add_eq (System_of_eqs& sys, const char* name, int nused, Array<int>** pused) const {
36  for (int dd=sys.get_dom_min() ; dd<=sys.get_dom_max() ; dd++)
37  sys.add_eq_inside (dd, name, nused, pused) ;
38 }
39 
40 void Space_polar::add_eq_full (System_of_eqs& sys, const char* name, int nused, Array<int>** pused) const {
41  for (int dd=sys.get_dom_min() ; dd<=sys.get_dom_max() ; dd++)
42  sys.add_eq_full (dd, name, nused, pused) ;
43 }
44 
45 void Space_polar::add_matching (System_of_eqs& sys, const char* name, int nused, Array<int>** pused) const {
46  for (int dd=sys.get_dom_min() ; dd<sys.get_dom_max() ; dd++)
47  sys.add_eq_matching (dd, OUTER_BC, name, nused, pused) ;
48 }
49 
50 void Space_polar::add_eq (System_of_eqs& sys, const char* eq, const char* rac, const char* rac_der, int nused, Array<int>** pused) const {
51  for (int dd=sys.get_dom_min() ; dd<sys.get_dom_max(); dd++) {
52  sys.add_eq_inside (dd, eq, nused, pused) ;
53  sys.add_eq_matching (dd, OUTER_BC, rac, nused, pused) ;
54  sys.add_eq_matching (dd, OUTER_BC, rac_der, nused, pused) ;
55  }
56  sys.add_eq_inside (sys.get_dom_max(), eq, nused, pused) ;
57 }
58 
59 void Space_polar::add_eq_int_volume (System_of_eqs& sys, const char* nom) {
60 
61  // Get the lhs and rhs
62  char p1[LMAX] ;
63  char p2[LMAX] ;
64  bool indic = sys.is_ope_bin(nom, p1, p2, '=') ;
65  if (!indic) {
66  cerr << "= needed for equations" << endl ;
67  abort() ;
68  }
69  else {
70  // Construction of the equation
71  sys.eq_int[sys.neq_int] = new Eq_int(nbr_domains+1) ;
72 
73  // Affectation of the intregrale parts
74  for (int d=0 ; d<nbr_domains ; d++)
75  sys.eq_int[sys.neq_int]->set_part(d, sys.give_ope(d, p1)) ;
76  // Affectation of the second member (constant value)
77  sys.eq_int[sys.neq_int]->set_part(nbr_domains, new Ope_minus(&sys, sys.give_ope(0, p2))) ;
78  sys.neq_int ++ ;
79  }
80  sys.nbr_conditions = -1 ;
81 }
82 
83 
84 void Space_polar::add_eq_int_inf (System_of_eqs& sys, const char* nom) {
85 
86  // Check the last domain is of the right type :
87  const Domain_polar_compact* pcomp = dynamic_cast <const Domain_polar_compact*> (domains[nbr_domains-1]) ;
88  if (pcomp==0x0) {
89  cerr << "add_eq_int_inf requires a compactified domain" << endl ;
90  abort() ;
91  }
92  int dom = nbr_domains-1 ;
93 
94  // Get the lhs and rhs
95  char p1[LMAX] ;
96  char p2[LMAX] ;
97  bool indic = sys.is_ope_bin(nom, p1, p2, '=') ;
98  if (!indic) {
99  cerr << "= needed for equations" << endl ;
100  abort() ;
101  }
102  else {
103  // Verif lhs = 0 ?
104  indic = ((p2[0]=='0') && (p2[1]==' ') && (p2[2]=='\0')) ?
105  true : false ;
106 
107  // Construction of the equation
108  sys.eq_int[sys.neq_int] = new Eq_int(1) ;
109 
110  // Affectation :
111  // no lhs :
112  if (indic)
113  sys.eq_int[sys.neq_int]->set_part(0, sys.give_ope(dom, p1, OUTER_BC)) ;
114 
115  else
116  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))) ;
117  sys.neq_int ++ ;
118  }
119  sys.nbr_conditions = -1 ;
120 }
121 
122 void Space_polar::add_eq_int_inner (System_of_eqs& sys, const char* nom) {
123 
124  // Check the last domain is of the right type :
125  const Domain_polar_shell* pshell = dynamic_cast <const Domain_polar_shell*> (domains[1]) ;
126  if (pshell==0x0) {
127  cerr << "add_eq_int_inner requires that the domain 1 is a shell" << endl ;
128  abort() ;
129  }
130  int dom = 1 ;
131 
132  // Get the lhs and rhs
133  char p1[LMAX] ;
134  char p2[LMAX] ;
135  bool indic = sys.is_ope_bin(nom, p1, p2, '=') ;
136  if (!indic) {
137  cerr << "= needed for equations" << endl ;
138  abort() ;
139  }
140  else {
141  // Verif lhs = 0 ?
142  indic = ((p2[0]=='0') && (p2[1]==' ') && (p2[2]=='\0')) ?
143  true : false ;
144 
145  // Construction of the equation
146  sys.eq_int[sys.neq_int] = new Eq_int(1) ;
147 
148  // Affectation :
149  // no lhs :
150  if (indic)
151  sys.eq_int[sys.neq_int]->set_part(0, sys.give_ope(dom, p1, OUTER_BC)) ;
152 
153  else
154  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))) ;
155  sys.neq_int ++ ;
156  }
157  sys.nbr_conditions = -1 ;
158 }
159 
160 
161 void Space_polar::add_eq_mode (System_of_eqs& sys, const char* name, int domtarget, int itarget, int jtarget) {
162 
163  Index pos_cf (domains[domtarget]->get_nbr_coefs()) ;
164  pos_cf.set(0) = itarget ;
165  pos_cf.set(1) = jtarget ;
166  double value = 1. ;
167  char auxi[LMAX] ;
168  trim_spaces (auxi, name) ;
169  sys.add_eq_val_mode (domtarget, auxi, pos_cf, value) ;
170 }
171 
172 void Space_polar::add_eq_ori (System_of_eqs& sys, const char* name) {
173 
174  Index pos (domains[0]->get_nbr_points()) ;
175  char auxi[LMAX] ;
176  trim_spaces (auxi, name) ;
177  sys.add_eq_val (0, auxi, pos) ;
178 }
179 
180 void Space_polar::add_eq_point (System_of_eqs& sys, const Point& MM, const char* name) {
181 
182  // Get the domain and num coordinates :
183  int ld = -1;
184  bool* inside = new bool[nbr_domains] ;
185  for (int l=0 ; l<nbr_domains; l++)
186  inside[l] = get_domain(l)->is_in(MM) ;
187  for (int l=0 ; l<nbr_domains ; l++)
188  if ((ld==-1) && (inside[l]))
189  ld = l ;
190  Point num (get_domain(ld)->absol_to_num(MM)) ;
191 
192  char auxi[LMAX] ;
193  trim_spaces (auxi, name) ;
194  sys.add_eq_point (ld, auxi, num) ;
195 }
196 }
Class for a 2-dimensional spherical shell and a symmetry with respect to the plane .
Definition: polar.hpp:408
Class for a 2-dimensional spherical shell and a symmetry with respect to the plane .
Definition: polar.hpp:221
virtual bool is_in(const Point &xx, double prec=1e-13) const
Check whether a point lies inside Domain.
Definition: domain.cpp:942
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
The operator minus.
Definition: ope_eq.hpp:128
The operator substraction.
Definition: ope_eq.hpp:165
The class Point is used to store the coordinates of a point.
Definition: point.hpp:30
void add_outer_bc(System_of_eqs &syst, const char *eq, int nused=-1, Array< int > **pused=0x0) const
Sets a boundary condition at the outer radius of the compactified polar domain.
void add_inner_bc(System_of_eqs &syst, const char *eq, int nused=-1, Array< int > **pused=0x0) const
Sets a boundary condition at the inner radius of the innermost polar shell.
void add_eq_point(System_of_eqs &syst, const Point &pp, const char *eq)
Adds an equation being the value of some field at a given point.
void add_eq(System_of_eqs &syst, const char *eq, int nused=-1, Array< int > **pused=0x0) const
Adds a bulk equation in all the domains of a given system (equation is assumed to be second order)
void add_eq_full(System_of_eqs &syst, const char *eq, int nused=-1, Array< int > **pused=0x0) const
Adds a bulk equation in all the domains of a given system (equation is assumed to be 0th order)
void add_eq_mode(System_of_eqs &syst, const char *f, int domtarget, int itarget, int jtarget)
Adds an equation saying that one coefficient of a field is zero in a given domain.
void add_eq_int_volume(System_of_eqs &syst, const char *eq)
Adds an equation being a volume integral in the whole computational space.
void add_eq_int_inf(System_of_eqs &syst, const char *eq)
Adds an equation being a surface integral at infinity.
void add_matching(System_of_eqs &syst, const char *eq, int nused=-1, Array< int > **pused=0x0) const
Adds a matching condition, at all the interface present in a given system.
void add_eq_int_inner(System_of_eqs &syst, const char *eq)
Adds an equation being a surface integral in the innermost shell.
void add_eq_ori(System_of_eqs &syst, const char *eq)
Adds an equation being the value of some field at the origin.
const Domain * get_domain(int i) const
returns a pointer on the domain.
Definition: space.hpp:1385
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(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_point(int dom, const char *eq, const Point &MM)
Addition of an equation saying that the value of a field must be zero at one point (arbitrary).
Definition: add_eq.cpp:473
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
virtual void add_eq_val(int dom, const char *eq, const Index &pos)
Addition of an equation saying that the value of a field must be zero at one collocation point.
Definition: add_eq.cpp:462
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...
int get_dom_min() const
Returns the smallest index of the domains.
MMPtr_array< Eq_int > eq_int
Pointers onto the integral equations.
virtual void add_eq_val_mode(int dom, 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:450