2 #ifndef INMOST_AUTODIFF_ETBVAR_H_INCLUDED
3 #define INMOST_AUTODIFF_ETBVAR_H_INCLUDED
4 #include "inmost_common.h"
5 #include "inmost_expression.h"
6 #include "inmost_mesh.h"
7 #include "inmost_autodiff.h"
8 #include "inmost_solver.h"
9 #include "inmost_variable.h"
13 #if defined(USE_AUTODIFF) && defined(USE_MESH)
21 #pragma warning(disable : 4503)
38 template<
typename RetType>
42 virtual RetType operator()(
const Storage & e)
const = 0;
52 vMatrix operator()(
const Storage & e)
const {
return var.Variable(e);}
77 vMatrix Variable(
const Storage & e)
const {
return var->Variable(e);}
106 bool isUnknown(
const Storage & e)
const {
return entry->
isValid(e)?
true:
false;}
123 vMatrix Variable(
const Storage & e)
const {(void)e;
return value;}
131 INMOST_DATA_ENUM_TYPE n,m;
134 : value_tag(t), n(t.GetSize()), m(1) {assert(t.GetDataType() == DATA_REAL);}
136 : value_tag(t), n(pn), m(pm) {assert(t.GetDataType() == DATA_REAL);}
138 : value_tag(other.value_tag), n(other.n), m(other.m) {}
141 value_tag = other.value_tag;
147 vMatrix Variable(
const Storage & e)
const {
return value_tag(e,n,m);}
149 bool isUnknown(
const Storage & e)
const {(void)e;
return false;}
157 INMOST_DATA_ENUM_TYPE n,m;
160 : variable_tag(t), n(t.GetSize()), m(1) {}
162 : variable_tag(t), n(pn), m(pm) {assert(t.GetDataType() == DATA_VARIABLE);}
164 : variable_tag(other.variable_tag), n(other.n), m(other.m) {}
167 variable_tag = other.variable_tag;
172 rMatrix Value(
const Storage & e)
const {
return variable_tag(e,n,m);}
173 vMatrix Variable(
const Storage & e)
const {
return variable_tag(e,n,m);}
175 bool isUnknown(
const Storage & e)
const {(void)e;
return false;}
189 : tag_elems(tag_elems), tag_coefs(tag_coefs), Arg(parg) {}
191 : tag_elems(other.tag_elems), tag_coefs(other.tag_coefs), Arg(other.Arg) {}
194 tag_elems = other.tag_elems;
195 tag_coefs = other.tag_coefs;
203 assert(coefs.size() == elems.size());
204 rMatrix ret = coefs[0]*Arg.Value(elems[0]);
205 for(INMOST_DATA_ENUM_TYPE k = 1; k < elems.size(); ++k)
206 ret += coefs[k]*Arg.Value(elems[k]);
213 assert(coefs.size() == elems.size());
214 vMatrix ret = coefs[0]*Arg.Variable(elems[0]);
215 for(INMOST_DATA_ENUM_TYPE k = 1; k < elems.size(); ++k)
216 ret += coefs[k]*Arg.Variable(elems[k]);
234 for(INMOST_DATA_ENUM_TYPE k = 0; k < ret.
Rows(); ++k)
235 for(INMOST_DATA_ENUM_TYPE l = 0; l < ret.
Cols(); ++l)
236 ret(k,l) = get_table(ret(k,l),Table);
242 for(INMOST_DATA_ENUM_TYPE k = 0; k < ret.
Rows(); ++k)
243 for(INMOST_DATA_ENUM_TYPE l = 0; l < ret.
Cols(); ++l)
244 ret(k,l) = get_table(ret(k,l),Table);
257 ElementType types_true;
261 : ArgA(_ArgA), ArgB(_ArgB), types_true(_types_true) {}
264 : ArgA(other.ArgA), ArgB(other.ArgB), types_true(other.types_true) {}
268 types_true = other.types_true;
275 {
return (e->GetElementType() & types_true) ? ArgA.Value(e) : ArgB.Value(e);}
279 {
return (e->GetElementType() & types_true) ? ArgA.Variable(e) : ArgB.Variable(e);}
301 marker = other.marker;
308 {
return ( isPrivate(marker) ? e->GetPrivateMarker(marker) : e->GetMarker(marker) ) ? ArgA.Value(e) : ArgB.Value(e);}
312 {
return ( isPrivate(marker) ? e->GetPrivateMarker(marker) : e->GetMarker(marker) ) ? ArgA.Variable(e) : ArgB.Variable(e);}
327 : ArgA(_ArgA), ArgB(_ArgB) {}
330 : ArgA(other.ArgA), ArgB(other.ArgB) {}
340 {
return ArgA.Value(e) + ArgB.Value(e);}
344 {
return ArgA.Variable(e) + ArgB.Variable(e);}
359 : ArgA(_ArgA), ArgB(_ArgB) {}
362 : ArgA(other.ArgA), ArgB(other.ArgB) {}
372 {
return ArgA.Value(e) - ArgB.Value(e);}
376 {
return ArgA.Variable(e) - ArgB.Variable(e);}
391 : ArgA(_ArgA), ArgB(_ArgB) {}
394 : ArgA(other.ArgA), ArgB(other.ArgB) {}
404 {
return ArgA.Value(e)*ArgB.Value(e);}
408 {
return ArgA.Variable(e)*ArgB.Variable(e);}
423 : ArgA(_ArgA), ArgB(_ArgB) {}
426 : ArgA(other.ArgA), ArgB(other.ArgB) {}
436 {
return (ArgA.Value(e)/ArgB.Value(e));}
440 {
return (ArgA.Variable(e)/ArgB.Variable(e));}
455 : ArgA(_ArgA), ArgB(_ArgB) {}
458 : ArgA(other.ArgA), ArgB(other.ArgB) {}
468 {
return ArgA.Value(e).
ConcatCols(ArgB.Value(e));}
472 {
return ArgA.Variable(e).
ConcatCols(ArgB.Variable(e));}
487 : ArgA(_ArgA), ArgB(_ArgB) {}
490 : ArgA(other.ArgA), ArgB(other.ArgB) {}
500 {
return ArgA.Value(e).
ConcatRows(ArgB.Value(e));}
504 {
return ArgA.Variable(e).
ConcatRows(ArgB.Variable(e));}
522 : ArgA(other.ArgA) {}
545 INMOST_DATA_ENUM_TYPE row1,row2,col1,col2;
549 INMOST_DATA_ENUM_TYPE row1,
550 INMOST_DATA_ENUM_TYPE row2,
551 INMOST_DATA_ENUM_TYPE col1,
552 INMOST_DATA_ENUM_TYPE col2)
553 : ArgA(_ArgA), row1(row1), row2(row2), col1(col1), col2(col2) {}
556 : ArgA(b.ArgA), row1(b.row1), row2(b.row2), col1(b.col1), col2(b.col2) {}
569 {
return ArgA.Value(e)(row1,row2,col1,col2);}
573 {
return ArgA.Variable(e)(row1,row2,col1,col2);}
583 INMOST_DATA_REAL_TYPE value;
587 INMOST_DATA_REAL_TYPE val)
588 : ArgA(_ArgA), value(val) {}
591 : ArgA(b.ArgA), value(b.value) {}
601 {
return ArgA.Value(e)*value;}
605 {
return ArgA.Variable(e)*value;}
622 : ArgA(_ArgA), ArgB(_ArgB), ArgC(_ArgC) {}
625 : ArgA(b.ArgA), ArgB(b.ArgB), ArgC(b.ArgC) {}
636 {
return ArgC.Value(e) > 0.0 ? ArgA.Value(e) : ArgB.Value(e);}
640 {
return ArgC.Value(e) > 0.0 ? ArgA.Variable(e) : ArgB.Variable(e);}
655 : ArgA(_ArgA), ArgB(_ArgB) {}
658 : ArgA(b.ArgA), ArgB(b.ArgB) {}
668 {
return ArgA.Value(e)*ArgB.Value(e);}
672 {
return ArgA.Variable(e)*ArgB.Variable(e);}
688 : ArgA(other.ArgA) {}
697 {
return ArgA.Value(e).
Invert();}
701 {
return ArgA.Variable(e).
Invert();}
715 : ArgA(_ArgA), eps(_eps) {}
718 : ArgA(other.ArgA), eps(other.eps) {}
740 typedef abstract_dynamic_block_variable abstract_block_variable;
805 INMOST_DATA_ENUM_TYPE row1,
806 INMOST_DATA_ENUM_TYPE row2,
807 INMOST_DATA_ENUM_TYPE col1,
808 INMOST_DATA_ENUM_TYPE col2)
814 INMOST_DATA_REAL_TYPE Right)
819 operator *(INMOST_DATA_REAL_TYPE Left,
826 INMOST_DATA_REAL_TYPE Right)
862 etype_branch(INMOST::ElementType true_type,
869 marker_branch(INMOST::MarkerType marker,
This class is used to organize unknowns in abstract way, it should be registered with and managed by ...
virtual unknown Unknown(const Storage &e, INMOST_DATA_ENUM_TYPE pos) const =0
Return unknown in vector of variables of the block at certain position.
virtual INMOST_DATA_REAL_TYPE Value(const Storage &e, INMOST_DATA_ENUM_TYPE pos) const =0
Return value in vector of unknowns of the block at certain position.
bool isValid(const Storage &e) const
Check that the block is valid on given element.
Matrix< Var > Invert(int *ierr=NULL) const
Inverts matrix using Crout-LU decomposition with full pivoting for maximum element.
Matrix< Var > PseudoInvert(INMOST_DATA_REAL_TYPE tol=0, int *ierr=NULL) const
Calculates Moore-Penrose pseudo-inverse of the matrix.
MatrixConcatCols< Var > ConcatCols(AbstractMatrix< Var > &B)
Concatenate B matrix as columns of current matrix.
MatrixTranspose< Var > Transpose()
Transpose the current matrix with access to elements.
MatrixConcatRows< Var > ConcatRows(AbstractMatrix< Var > &B)
Concatenate B matrix as rows of current matrix.
The Automatizator class helps in defining primary unknowns of the model and enhances user experience ...
AbstractEntry & GetEntry(INMOST_DATA_ENUM_TYPE ind)
Retrieve the block from automatizator by index.
__INLINE enumerator Cols() const
Obtain number of columns.
__INLINE enumerator Rows() const
Obtain number of rows.
Storage type for representing arrays of Element references.
Base class for Mesh, Element, and ElementSet classes.
This class provides the access to the individual mesh datum and general information about it.
This class represents addition of two matrices.
vMatrix Variable(const Storage &e) const
Get value with derivatives of variable expression on provided element e.
addition_block_variable(const abstract_dynamic_block_variable &_ArgA, const abstract_dynamic_block_variable &_ArgB)
Constructor.
addition_block_variable & operator=(addition_block_variable const &other)
Assignment operator.
addition_block_variable(const addition_block_variable &other)
Copy constructor.
abstract_dynamic_block_variable * Copy() const
Make a copy of this class, used to reproduce and store a tree of variable expressions.
rMatrix Value(const Storage &e) const
Get value of variable expression on provided element e.
This class represents division of two matrices, this is technically B^{-1}A.
concat_cols_block_variable(const abstract_dynamic_block_variable &_ArgA, const abstract_dynamic_block_variable &_ArgB)
Constructor.
rMatrix Value(const Storage &e) const
Get value of variable expression on provided element e.
abstract_dynamic_block_variable * Copy() const
Make a copy of this class, used to reproduce and store a tree of variable expressions.
vMatrix Variable(const Storage &e) const
Get value with derivatives of variable expression on provided element e.
concat_cols_block_variable(const concat_cols_block_variable &other)
Copy constructor.
concat_cols_block_variable & operator=(concat_cols_block_variable const &other)
Assignment operator.
This class represents division of two matrices, this is technically B^{-1}A.
rMatrix Value(const Storage &e) const
Get value of variable expression on provided element e.
concat_rows_block_variable(const concat_rows_block_variable &other)
Copy constructor.
abstract_dynamic_block_variable * Copy() const
Make a copy of this class, used to reproduce and store a tree of variable expressions.
concat_rows_block_variable(const abstract_dynamic_block_variable &_ArgA, const abstract_dynamic_block_variable &_ArgB)
Constructor.
concat_rows_block_variable & operator=(concat_rows_block_variable const &other)
Assignment operator.
vMatrix Variable(const Storage &e) const
Get value with derivatives of variable expression on provided element e.
This class represents multiplication of the matrix by the variable.
condition_block_variable(const condition_block_variable &b)
Copy constructor.
vMatrix Variable(const Storage &e) const
Get value with derivatives of variable expression on provided element e.
rMatrix Value(const Storage &e) const
Get value of variable expression on provided element e.
abstract_dynamic_block_variable * Copy() const
Make a copy of this class, used to reproduce and store a tree of variable expressions.
condition_block_variable(const abstract_dynamic_variable &_ArgC, const abstract_dynamic_block_variable &_ArgA, const abstract_dynamic_block_variable &_ArgB)
Constructor.
condition_block_variable & operator=(condition_block_variable const &b)
Assignment operator.
This class represents division of two matrices, this is technically B^{-1}A.
division_block_variable & operator=(division_block_variable const &other)
Assignment operator.
rMatrix Value(const Storage &e) const
Get value of variable expression on provided element e.
abstract_dynamic_block_variable * Copy() const
Make a copy of this class, used to reproduce and store a tree of variable expressions.
division_block_variable(const division_block_variable &other)
Copy constructor.
vMatrix Variable(const Storage &e) const
Get value with derivatives of variable expression on provided element e.
division_block_variable(const abstract_dynamic_block_variable &_ArgA, const abstract_dynamic_block_variable &_ArgB)
Constructor.
This class makes possible to evaluate different expressions on different element types.
etype_branch_block_variable(ElementType _types_true, const abstract_dynamic_block_variable &_ArgA, const abstract_dynamic_block_variable &_ArgB)
Constructor. Used by etype_branch function.
etype_branch_block_variable(const etype_branch_block_variable &other)
Copy constructor.
etype_branch_block_variable & operator=(etype_branch_block_variable const &other)
Assignment operator.
vMatrix Variable(const Storage &e) const
Get value with derivatives of variable expression on provided element e.
abstract_dynamic_block_variable * Copy() const
Make a copy of this class, used to reproduce and store a tree of variable expressions.
rMatrix Value(const Storage &e) const
Get value of variable expression on provided element e.
This class represents inverse of the matrix, this is A^{-1}.
inverse_block_variable & operator=(inverse_block_variable const &other)
Assignment operator.
rMatrix Value(const Storage &e) const
Get value of variable expression on provided element e.
inverse_block_variable(const abstract_dynamic_block_variable &_ArgA)
Constructor.
inverse_block_variable(const inverse_block_variable &other)
Copy constructor.
vMatrix Variable(const Storage &e) const
Get value with derivatives of variable expression on provided element e.
abstract_dynamic_block_variable * Copy() const
Make a copy of this class, used to reproduce and store a tree of variable expressions.
This class makes possible to evaluate different expressions depending on the markers.
rMatrix Value(const Storage &e) const
Get value of variable expression on provided element e.
abstract_dynamic_block_variable * Copy() const
Make a copy of this class, used to reproduce and store a tree of variable expressions.
marker_branch_block_variable(const marker_branch_block_variable &other)
Copy constructor.
marker_branch_block_variable(MarkerType _marker, const abstract_dynamic_block_variable &_ArgA, const abstract_dynamic_block_variable &_ArgB)
Constructor. Used by marker_branch function.
marker_branch_block_variable & operator=(marker_branch_block_variable const &other)
Assignment operator.
vMatrix Variable(const Storage &e) const
Get value with derivatives of variable expression on provided element e.
This class represents multiplication of two matrices.
rMatrix Value(const Storage &e) const
Get value of variable expression on provided element e.
abstract_dynamic_block_variable * Copy() const
Make a copy of this class, used to reproduce and store a tree of variable expressions.
vMatrix Variable(const Storage &e) const
Get value with derivatives of variable expression on provided element e.
multiplication_block_variable & operator=(multiplication_block_variable const &other)
Assignment operator.
multiplication_block_variable(const abstract_dynamic_block_variable &_ArgA, const abstract_dynamic_block_variable &_ArgB)
Constructor.
multiplication_block_variable(const multiplication_block_variable &other)
Copy constructor.
This class represents multiplication of the matrix by the constant.
rMatrix Value(const Storage &e) const
Get value of variable expression on provided element e.
multiply_const_block_variable(const multiply_const_block_variable &b)
Copy constructor.
multiply_const_block_variable & operator=(multiply_const_block_variable const &b)
Assignment operator.
multiply_const_block_variable(const abstract_dynamic_block_variable &_ArgA, INMOST_DATA_REAL_TYPE val)
Constructor.
abstract_dynamic_block_variable * Copy() const
Make a copy of this class, used to reproduce and store a tree of variable expressions.
vMatrix Variable(const Storage &e) const
Get value with derivatives of variable expression on provided element e.
This class represents multiplication of the matrix by the variable.
rMatrix Value(const Storage &e) const
Get value of variable expression on provided element e.
multiply_variable_block_variable(const abstract_dynamic_block_variable &_ArgA, const abstract_dynamic_variable &_ArgB)
Constructor.
multiply_variable_block_variable & operator=(multiply_variable_block_variable const &b)
Assignment operator.
multiply_variable_block_variable(const multiply_variable_block_variable &b)
Copy constructor.
abstract_dynamic_block_variable * Copy() const
Make a copy of this class, used to reproduce and store a tree of variable expressions.
vMatrix Variable(const Storage &e) const
Get value with derivatives of variable expression on provided element e.
This class represents pseudo-inverse of the matrix, this is A^{+}.
pseudo_inverse_block_variable(const pseudo_inverse_block_variable &other)
Copy constructor.
pseudo_inverse_block_variable & operator=(pseudo_inverse_block_variable const &other)
Assignment operator.
vMatrix Variable(const Storage &e) const
Get value with derivatives of variable expression on provided element e.
rMatrix Value(const Storage &e) const
Get value of variable expression on provided element e.
pseudo_inverse_block_variable(const abstract_dynamic_block_variable &_ArgA, double _eps=1.0e-13)
Constructor.
abstract_dynamic_block_variable * Copy() const
Make a copy of this class, used to reproduce and store a tree of variable expressions.
bool isDefined() const
Checks that the stored expresison was defined.
This class represents submatrix of the matrix.
rMatrix Value(const Storage &e) const
Get value of variable expression on provided element e.
submatrix_block_variable(const submatrix_block_variable &b)
Copy constructor.
submatrix_block_variable & operator=(submatrix_block_variable const &b)
Assignment operator.
submatrix_block_variable(const abstract_dynamic_block_variable &_ArgA, INMOST_DATA_ENUM_TYPE row1, INMOST_DATA_ENUM_TYPE row2, INMOST_DATA_ENUM_TYPE col1, INMOST_DATA_ENUM_TYPE col2)
Constructor.
abstract_dynamic_block_variable * Copy() const
Make a copy of this class, used to reproduce and store a tree of variable expressions.
vMatrix Variable(const Storage &e) const
Get value with derivatives of variable expression on provided element e.
This class represents subtraction of two matrices.
abstract_dynamic_block_variable * Copy() const
Make a copy of this class, used to reproduce and store a tree of variable expressions.
subtraction_block_variable(const abstract_dynamic_block_variable &_ArgA, const abstract_dynamic_block_variable &_ArgB)
Constructor.
vMatrix Variable(const Storage &e) const
Get value with derivatives of variable expression on provided element e.
rMatrix Value(const Storage &e) const
Get value of variable expression on provided element e.
subtraction_block_variable(const subtraction_block_variable &other)
Copy constructor.
subtraction_block_variable & operator=(subtraction_block_variable const &other)
Assignment operator.
Apply table component-wise on argument matrix.
This class represents transposition of the matrix, this is A^T.
vMatrix Variable(const Storage &e) const
Get value with derivatives of variable expression on provided element e.
transpose_block_variable(const abstract_dynamic_block_variable &_ArgA)
Constructor.
abstract_dynamic_block_variable * Copy() const
Make a copy of this class, used to reproduce and store a tree of variable expressions.
rMatrix Value(const Storage &e) const
Get value of variable expression on provided element e.
transpose_block_variable(const transpose_block_variable &other)
Copy constructor.
transpose_block_variable & operator=(transpose_block_variable const &other)
Assignment operator.