Documentation of CSL
pseudoIntegral.h
Go to the documentation of this file.
1 // This file is part of MARTY.
2 //
3 // MARTY is free software: you can redistribute it and/or modify
4 // it under the terms of the GNU General Public License as published by
5 // the Free Software Foundation, either version 3 of the License, or
6 // (at your option) any later version.
7 //
8 // MARTY is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 // GNU General Public License for more details.
12 //
13 // You should have received a copy of the GNU General Public License
14 // along with MARTY. If not, see <https://www.gnu.org/licenses/>.
15 
23 #ifndef PSEUDOINTEGRAL_H_INCLUDED
24 #define PSEUDOINTEGRAL_H_INCLUDED
25 
26 #include "operations.h"
27 #include "mathFunctions.h"
28 #include "indicial.h"
29 
30 namespace csl {
31 
33 {
34  public:
35 
37 
38  explicit
39  PseudoIntegral(const csl::vector_expr& terms);
40 
41  PseudoIntegral(const csl::vector_expr& t_integrals,
42  const Expr& t_argument);
43 
44  ~PseudoIntegral(){};
45 
46  void addTerm(const Expr& term);
47 
48  Expr getExpression() const;
49 
50  Expr evaluate();
51 
52  Expr applyOn(const Expr& expr) const;
53 
54  Expr const &getArgument() const;
55 
56  private:
57 
58  bool testBoundsInfinity(const Expr& inf,
59  const Expr& sup) const;
60 
61  void testIntegralDep(const Expr& term) const;
62 
63  void addSingleTerm(const Expr& term);
64 
65  void addSingleIntegral(const Expr& integral);
66 
67  void getRecursiveIntegralDependency(
68  Expr& operand,
69  const Expr& variable,
70  std::vector<Expr*>& dependencies);
71 
72  Expr getExponentialDependency(
73  std::vector<Expr*> const& dep) const;
74 
75  void expandExponentials();
76 
77  bool evaluateExpProduct(int index,
78  Expr& res,
79  std::vector<Expr*>& dependencies) const;
80 
81  bool evaluateDelta(int index,
82  Expr& res,
83  std::vector<Expr*>& dependencies) const;
84 
85  private:
86 
87  mutable
88  bool argumentUpdated = true;
89 
90  csl::vector_expr vectorIntegrals;
91 
92  csl::vector_expr argumentVector;
93 
94  mutable
95  Expr argument;
96 };
97 
98 
99 class AbstractIntegral: public Operator<AbstractFunc>{
100 
101  public:
102 
104 
105  explicit
106  AbstractIntegral(const Expr& operand);
107 
108  AbstractIntegral(const Expr& operand,
109  bool t_empty);
110 
111  AbstractIntegral(const Expr& operand,
112  const Expr& t_inf,
113  const Expr& t_sup);
114 
115  AbstractIntegral(const Expr& operand,
116  bool t_empty,
117  const Expr& t_inf,
118  const Expr& t_sup);
119 
123 
124  Expr getOperand() const override;
125 
126  bool operatorAppliesOn(Expr_info expr) const override;
127 
128  Expr getSupBoundary() const override;
129 
130  Expr getInfBoundary() const override;
131 
132  void setSupBoundary(Expr const &t_inf) override;
133 
134  void setInfBoundary(Expr const &t_sup) override;
135 
136  void setOperand(const Expr& t_operand) override;
137 
138  Expr suppressTerm(Expr_info term) const override;
139 
140  std::optional<Expr> evaluate(
141  csl::eval::mode user_mode = csl::eval::base
142  ) const override;
143 
144  std::optional<Expr> derive(Expr_info expr) const override;
145 
146  bool dependsOn(Expr_info var) const override;
147 
148  bool dependsOn(const AbstractParent* parent) const override;
149 
150  bool dependsExplicitlyOn(Expr_info var) const override;
151 
152  protected:
153 
154  Expr inf;
155 
156  Expr sup;
157 };
158 
160 
161  public:
162 
163  ScalarIntegral();
164 
165  explicit
166  ScalarIntegral(const Expr& t_variable);
167 
168  ScalarIntegral(const Expr& operand,
169  const Expr& t_variable);
170 
171  ScalarIntegral(const Expr& t_variable,
172  const Expr& t_inf,
173  const Expr& t_sup);
174 
175  ScalarIntegral(const Expr& operand,
176  const Expr& t_variable,
177  const Expr& t_inf,
178  const Expr& t_sup);
179 
180  ScalarIntegral(const Expr& operand,
181  const Expr& t_variable,
182  bool t_empty,
183  const Expr& t_inf,
184  const Expr& t_sup);
185 
189 
190  csl::Type getType() const override {
192  }
193 
194  Expr getVariable() const override;
195 
196  void setVariable(Expr const &variable) override;
197 
198  void print(int mode=0,
199  std::ostream& out=std::cout,
200  bool lib = false) const override;
201 
202  void printCode(
203  int mode = 0,
204  std::ostream &out = std::cout
205  ) const override;
206 
207  std::string printLaTeX(int mode=0) const override;
208 
209  unique_Expr copy_unique() const override;
210 
211  Expr deepCopy() const override;
212 
213  Expr refresh() const override;
214 
215  Expr deepRefresh() const override;
216 
217  bool operator==(Expr_info other) const override;
218 
219  bool operator<(const Abstract* expr) const override;
220 
221  protected:
222 
223  Expr variable;
224 };
225 
227 
228  public:
229 
230  VectorIntegral();
231 
232  explicit
233  VectorIntegral(const Tensor& t_variables);
234 
235  VectorIntegral(const Expr& operand,
236  const Tensor& t_variables);
237 
238  VectorIntegral(const Expr& operand,
239  const Tensor& t_variable,
240  bool t_empty);
241 
242  VectorIntegral(const Expr& operand,
243  const Tensor& t_variable,
244  const Expr& t_inf,
245  const Expr& t_sup);
246 
247  VectorIntegral(const Tensor& t_variable,
248  const Expr& t_inf,
249  const Expr& t_sup);
250 
251  VectorIntegral(const Expr& operand,
252  const Tensor& t_variable,
253  bool t_empty,
254  const Expr& t_inf,
255  const Expr& t_sup);
256 
257 
261 
262  csl::Type getType() const override {
264  }
265 
266  Expr getVariable() const override;
267 
268  Parent getParent() const override;
269 
270  Parent_info getParent_info() const override;
271 
272  void setParent(const Parent& t_variable) override;
273 
274  void print(int mode=0,
275  std::ostream& out=std::cout,
276  bool lib = false) const override;
277 
278  void printCode(
279  int mode = 0,
280  std::ostream &out = std::cout
281  ) const override;
282 
283  std::string printLaTeX(int mode=0) const override;
284 
285  unique_Expr copy_unique() const override;
286 
287  Expr deepCopy() const override;
288 
289  Expr refresh() const override;
290 
291  Expr deepRefresh() const override;
292 
293  bool isIndexed() const override;
294 
295  bool operatorAppliesOn(Expr_info expr) const override;
296 
297  IndexStructure getIndexStructure() const override;
298 
299  bool operator==(Expr_info other) const override;
300 
301  bool compareWithDummy(Expr_info expr,
302  std::map<Index, Index>& constraints,
303  bool keepAllCosntraints = false) const override;
304 
305  bool operator<(const Abstract* expr) const override;
306 
307  protected:
308 
309  Tensor variables;
310 };
311 
312 void MakeIntegral(Expr& init);
313 
314 template<typename ...Args>
315 Expr scalarintegral_s(Args ...args) {
316  Expr res = csl::make_shared<ScalarIntegral>(args...);
317  MakeIntegral(res);
318  return res;
319 }
320 
321 Expr vectorintegral_s(const Tensor& variables);
322 
323 template<typename ...Args>
324 Expr vectorintegral_s(const Expr& operand,
325  const Tensor& variables,
326  Args... args) {
327  Expr res = csl::make_shared<VectorIntegral>(operand, variables, args...);
328  MakeIntegral(res);
329  return res;
330 }
331 
332 template<typename ...Args>
333 Expr vectorintegral_s(const Tensor& variables,
334  Args... args) {
335  Expr res = csl::make_shared<VectorIntegral>(variables, args...);
336  MakeIntegral(res);
337  return res;
338 }
339 
340 inline Expr vectorintegral_s(const Parent& variables)
341 {
342  Tensor tensor = std::dynamic_pointer_cast<TensorParent>(variables);
343  CSL_ASSERT_SPEC(tensor,
344  CSLError::TypeError,
345  "Expected a tensor for vector integral, "
346  + toString(variables->getName()) + " given.");
347  return vectorintegral_s(tensor);
348 }
349 
350 template<typename ...Args>
351 Expr vectorintegral_s(const Expr& operand,
352  const Parent& variables,
353  Args... args) {
354  Tensor tensor = std::dynamic_pointer_cast<TensorParent>(variables);
355  CSL_ASSERT_SPEC(tensor,
356  CSLError::TypeError,
357  "Expected a tensor for vector integral, "
358  + toString(variables->getName()) + " given.");
359  return vectorintegral_s(operand, tensor, std::forward<Args>(args)...);
360 }
361 
362 template<typename ...Args>
363 Expr vectorintegral_s(const Parent& variables,
364  Args... args) {
365  Tensor tensor = std::dynamic_pointer_cast<TensorParent>(variables);
366  CSL_ASSERT_SPEC(tensor,
367  CSLError::TypeError,
368  "Expected a tensor for vector integral, "
369  + toString(variables->getName()) + " given.");
370  return vectorintegral_s(tensor, std::forward<Args>(args)...);
371 }
372 } // End of namespace csl
373 
374 #endif /* PSEUDOINTEGRAL_H_INCLUDED */
Namespace for csl library.
Definition: abreviation.h:34
Definition: parent.h:439
Parent of an indicial object, allows to generate them (TensorElement).
Definition: indicial.h:245
csl::Type getType() const override
Gives the type of Abstract.
Definition: pseudoIntegral.h:190
Type
Enum of the different types of Abstract (i.e. list of all possible specializations).
Definition: enum.h:47
Objects handling multi-argument functions, primordial operations (+,*,/,etc)
csl::Type getType() const override
Gives the type of Abstract.
Definition: pseudoIntegral.h:262
Root class of the inheritance tree of abstracts.
Definition: abstract.h:76
~AbstractIntegral()
Destructor.
Definition: pseudoIntegral.h:122
Base class for all parents (indicial, fields etc). All parents derive from this class.
Definition: parent.h:81
bool operator==(const Expr &a, const Expr &b)
see Abstract::operator==()
Definition: abstract.cpp:1398
~ScalarIntegral()
Destructor.
Definition: pseudoIntegral.h:188
Definition: pseudoIntegral.h:99
Definition: pseudoIntegral.h:32
Objects handling indexed expressions in order to perform indicial tensor calculations.
Definition: pseudoIntegral.h:226
Objects handling mathematical functions.
Definition: pseudoIntegral.h:159
bool operator<(const Expr &a, const Expr &b)
see Abstract::operator<()
Definition: abstract.cpp:1423
Definition: indicial.h:675
Linear operator O(a*X+b*Y) = a*O(X) + b*O(Y)
Definition: operator.h:38
Manages a std::vector of Index, to be used by an TensorElement.
Definition: index.h:472
Expression type/.
Definition: abstract.h:1573
~VectorIntegral()
Destructor.
Definition: pseudoIntegral.h:260