codac 1.5.6
Loading...
Searching...
No Matches
codac2_analytic_variables.h
Go to the documentation of this file.
1
9
10#pragma once
11
12#include <iostream>
13#include "codac2_AnalyticExpr.h"
14#include "codac2_VarBase.h"
15#include "codac2_component.h"
16
17namespace codac2
18{
19 template<typename T>
20 struct AnalyticExprWrapper;
21
22 template<typename T>
23 class AnalyticVarExpr : public AnalyticExpr<T>, public VarBase
24 {
25 public:
26
27 AnalyticVarExpr()
28 { }
29
30 virtual const ExprID& unique_id() const
31 {
32 return AnalyticExpr<T>::unique_id();
33 }
34
35 T fwd_eval(ValuesMap& v, [[maybe_unused]] Index total_input_size, [[maybe_unused]] bool natural_eval) const
36 {
37 return AnalyticExpr<T>::value(v);
38 }
39
40 void bwd_eval([[maybe_unused]] ValuesMap& v) const
41 { }
42
43 void replace_expr([[maybe_unused]] const ExprID& old_expr_id, [[maybe_unused]] const std::shared_ptr<ExprBase>& new_expr)
44 { }
45
46 virtual bool belongs_to_args_list(const FunctionArgsList& args) const
47 {
48 for(const auto& xi : args)
49 if(xi->unique_id() == this->unique_id())
50 return true;
51 return false;
52 }
53 };
54
55 class ScalarVar : public AnalyticVarExpr<ScalarType>
56 {
57 public:
58
59 ScalarVar();
60
61 std::shared_ptr<VarBase> arg_copy() const;
62 std::shared_ptr<ExprBase> copy() const;
63 Index size() const;
64
65 AnalyticExprWrapper<ScalarType> operator-() const;
66 };
67
68 class VectorVar : public AnalyticVarExpr<VectorType>
69 {
70 public:
71
72 explicit VectorVar(Index n);
73
74 std::shared_ptr<VarBase> arg_copy() const;
75 std::shared_ptr<ExprBase> copy() const;
76 Index size() const;
77
78 AnalyticExprWrapper<ScalarType> operator[](Index i) const;
79 AnalyticExprWrapper<VectorType> subvector(Index i, Index j) const;
80
81 protected:
82
83 Index _n;
84 };
85
86 class MatrixVar : public AnalyticVarExpr<MatrixType>
87 {
88 public:
89
90 explicit MatrixVar(Index r, Index c);
91
92 std::shared_ptr<VarBase> arg_copy() const;
93 std::shared_ptr<ExprBase> copy() const;
94 Index size() const;
95 Index rows() const;
96 Index cols() const;
97
98 AnalyticExprWrapper<ScalarType> operator()(Index i, Index j) const;
99 //AnalyticExprWrapper<VectorType> col(Index i) const;
100
101 protected:
102
103 Index _r, _c;
104 };
105}