14 #if !defined(KRATOS_TABLE_H_INCLUDED )
15 #define KRATOS_TABLE_H_INCLUDED
64 template<
class TArgumentType,
class TResultType = TArgumentType, std::
size_t TResultsColumns = 1>
76 typedef std::pair<TArgumentType, result_row_type>
RecordType;
91 TResultType
const&
operator()(TArgumentType
const& X)
const
103 TResultType
const&
operator()(TArgumentType
const& X, std::size_t
J)
const
134 std::size_t size = mData.size();
136 KRATOS_ERROR_IF(size == 0) <<
"Get value from empty table" << std::endl;
139 return mData.begin()->second;
141 if(
X <= mData[0].first)
142 return mData[0].second;
144 for(std::size_t
i = 1 ;
i < size ;
i++)
145 if(
X <= mData[
i].first)
146 return ((
X - mData[
i-1].first) < (mData[
i].first -
X)) ? mData[
i-1].second : mData[
i].second;
149 return mData[size-1].second;
155 std::size_t size = mData.size();
157 KRATOS_ERROR_IF(size == 0) <<
"Get value from empty table" << std::endl;
160 return mData.begin()->second;
162 if(
X <= mData[0].first)
163 return mData[0].second;
165 for(std::size_t
i = 1 ;
i < size ;
i++)
166 if(
X <= mData[
i].first)
167 return ((
X - mData[
i-1].first) < (mData[
i].first -
X)) ? mData[
i-1].second : mData[
i].second;
170 return mData[size-1].second;
174 void insert(TArgumentType
const& X, TResultType
const& Y)
182 template<
class TArrayType>
183 void insert(TArgumentType
const& X, TArrayType
const& Y)
186 for(std::size_t
i = 0 ;
i < TResultsColumns ;
i++)
194 std::size_t size = mData.size();
199 else if(
X <= mData[0].first)
201 else if(
X <= mData.back().first)
204 for(std::size_t
i = 1 ;
i < size ;
i++)
205 if((
X > mData[
i-1].first) && (
X <= mData[
i].first))
216 void PushBack(TArgumentType
const& X, TResultType
const& Y)
225 template<
class TArrayType>
226 void PushBack(TArgumentType
const& X, TArrayType
const& Y)
229 for(std::size_t
i = 0 ;
i < TResultsColumns ;
i++)
236 template<
class TArrayType>
276 virtual std::string
Info()
const
366 std::string mNameOfX;
367 std::string mNameOfY;
385 virtual void save(
Serializer& rSerializer)
const
391 for(
auto i_row = mData.begin() ; i_row != mData.end() ; i_row++){
392 rSerializer.
save(
"Argument", i_row->first);
393 for(
auto j = i_row->second.begin() ;
j != i_row->second.end();
j++)
394 rSerializer.
save(
"Column",
j);
406 for(
auto i_row = mData.begin() ; i_row != mData.end() ; i_row++){
407 rSerializer.load(
"Argument", i_row->first);
408 for(
auto j = i_row->second.begin() ;
j != i_row->second.end() ;
j++)
409 rSerializer.load(
"Column",
j);
448 typedef std::pair<TArgumentType, result_row_type>
RecordType;
462 template<
class TMatrixType>
463 explicit Table(TMatrixType
const& ThisMatrix): mData()
465 for(
unsigned int i = 0 ;
i < ThisMatrix.size1() ;
i++)
504 std::size_t size = mData.size();
506 KRATOS_ERROR_IF(size == 0) <<
"Get value from empty table" << std::endl;
509 return mData.begin()->second[0];
512 if(
X <= mData[0].first)
513 return Interpolate(
X, mData[0].first, mData[0].second[0], mData[1].first, mData[1].second[0], result);
515 for(std::size_t
i = 1 ;
i < size ;
i++)
516 if(
X <= mData[
i].first)
517 return Interpolate(
X, mData[
i-1].first, mData[
i-1].second[0], mData[
i].first, mData[
i].second[0], result);
520 return Interpolate(
X, mData[size-2].first, mData[size-2].second[0], mData[size-1].first, mData[size-1].second[0], result);
526 std::size_t size = mData.size();
528 KRATOS_ERROR_IF(size == 0) <<
"Get value from empty table" << std::endl;
531 return mData.begin()->second;
533 if(
X <= mData[0].first)
534 return mData[0].second;
536 for(std::size_t
i = 1 ;
i < size ;
i++)
537 if(
X <= mData[
i].first)
538 return ((
X - mData[
i-1].first) < (mData[
i].first -
X)) ? mData[
i-1].second : mData[
i].second;
541 return mData[size-1].second;
547 std::size_t size = mData.size();
549 KRATOS_ERROR_IF(size == 0) <<
"Get value from empty table" << std::endl;
552 return mData.begin()->second[0];
554 if(
X <= mData[0].first)
555 return mData[0].second[0];
557 for(std::size_t
i = 1 ;
i < size ;
i++)
558 if(
X <= mData[
i].first)
559 return ((
X - mData[
i-1].first) < (mData[
i].first -
X)) ? mData[
i-1].second[0] : mData[
i].second[0];
562 return mData[size-1].second[0];
568 std::size_t size = mData.size();
570 KRATOS_ERROR_IF(size == 0) <<
"Get value from empty table" << std::endl;
573 return mData.begin()->second[0];
575 if(
X <= mData[0].first)
576 return mData[0].second[0];
578 for(std::size_t
i = 1 ;
i < size ;
i++)
579 if(
X <= mData[
i].first)
580 return ((
X - mData[
i-1].first) < (mData[
i].first -
X)) ? mData[
i-1].second[0] : mData[
i].second[0];
583 return mData[size-1].second[0];
588 const double epsilon = 1
e-12;
596 scale = (
X -
X1) / dx;
598 Result = Y1 + dy * scale;
615 std::size_t size = mData.size();
619 else if(
X <= mData[0].first)
621 else if(
X > mData.back().first)
624 for(std::size_t
i = 1 ;
i < size ;
i++)
625 if((
X > mData[
i-1].first) && (
X <= mData[
i].first))
643 std::size_t size = mData.size();
645 KRATOS_ERROR_IF(size == 0) <<
"Get value from empty table" << std::endl;
651 if(
X <= mData[0].first)
655 for(std::size_t
i = 1 ;
i < size ;
i++)
656 if(
X <= mData[
i].first)
657 return InterpolateDerivative( mData[
i-1].first, mData[
i-1].second[0], mData[
i].first, mData[
i].second[0], result);
664 const double epsilon = 1
e-12;
671 <<
"*******************************************\n"
672 <<
"*** ATTENTION: SMALL dX WHEN COMPUTING ***\n"
673 <<
"*** DERIVATIVE FROM TABLE. SET TO 1E-12 ***\n"
674 <<
"*******************************************" <<std::endl;
714 virtual std::string
Info()
const
716 return "Piecewise Linear Table";
728 for(std::size_t
i = 0 ;
i < mData.size() ;
i++)
729 rOStream << mData[
i].first <<
"\t\t" << mData[
i].second[0] << std::endl;
770 std::string mNameOfX;
771 std::string mNameOfY;
795 for(
auto i_row = mData.begin() ; i_row != mData.end() ; i_row++){
796 rSerializer.
save(
"Argument", i_row->first);
797 for(
auto j = i_row->second.begin() ;
j != i_row->second.end();
j++)
798 rSerializer.
save(
"Column", *
j);
810 for(
auto i_row = mData.begin() ; i_row != mData.end() ; i_row++){
811 rSerializer.load(
"Argument", i_row->first);
812 for(
auto j = i_row->second.begin() ;
j != i_row->second.end() ;
j++)
813 rSerializer.load(
"Column", *
j);
849 template<
class TArgumentType,
class TResultType>
850 inline std::istream&
operator >> (std::istream& rIStream,
851 Table<TArgumentType, TResultType>& rThis);
854 template<
class TArgumentType,
class TResultType>
855 inline std::ostream&
operator << (std::ostream& rOStream,
856 const Table<TArgumentType, TResultType>& rThis)
858 rThis.PrintInfo(rOStream);
859 rOStream << std::endl;
860 rThis.PrintData(rOStream);
The serialization consists in storing the state of an object into a storage format like data file or ...
Definition: serializer.h:123
void save(std::string const &rTag, std::array< TDataType, TDataSize > const &rObject)
Definition: serializer.h:545
Variable< TArgumentType > XVariableType
Definition: table.h:452
const std::string & NameOfY() const
Definition: table.h:737
TResultType GetValue(TArgumentType const &X) const
Definition: table.h:502
TResultType & InterpolateDerivative(TArgumentType const &X1, TResultType const &Y1, TArgumentType const &X2, TResultType const &Y2, TResultType &Result) const
Definition: table.h:662
void Clear()
This method clears database.
Definition: table.h:683
void insert(TArgumentType const &X, result_row_type const &Y)
Definition: table.h:613
Variable< TResultType > YVariableType
Definition: table.h:453
std::array< TResultType, 1 > result_row_type
Definition: table.h:446
virtual void PrintData(std::ostream &rOStream) const
Print object's data.
Definition: table.h:726
std::vector< RecordType > TableContainerType
Definition: table.h:450
void PushBack(TArgumentType const &X, TResultType const &Y)
Definition: table.h:634
TResultType operator()(TArgumentType const &X) const
Definition: table.h:480
void insert(TArgumentType const &X, TResultType const &Y)
Definition: table.h:605
KRATOS_CLASS_POINTER_DEFINITION(Table)
Pointer definition of Table.
double TResultType
Definition: table.h:443
TResultType & operator[](TArgumentType &X)
Definition: table.h:492
double TArgumentType
Definition: table.h:444
virtual std::string Info() const
Turn back information as a string.
Definition: table.h:714
void SetNameOfY(const std::string &name)
Definition: table.h:747
std::pair< TArgumentType, result_row_type > RecordType
Definition: table.h:448
const std::string & NameOfX() const
Definition: table.h:732
virtual void PrintInfo(std::ostream &rOStream) const
Print information about this object.
Definition: table.h:720
TResultType GetDerivative(TArgumentType const &X) const
Definition: table.h:641
TResultType const & operator[](TArgumentType const &X) const
Definition: table.h:486
void SetNameOfX(const std::string &name)
Definition: table.h:742
TResultType & GetNearestValue(TArgumentType const &X)
Definition: table.h:566
TableContainerType const & Data() const
Definition: table.h:698
TResultType & Interpolate(TArgumentType const &X, TArgumentType const &X1, TResultType const &Y1, TArgumentType const &X2, TResultType const &Y2, TResultType &Result) const
Definition: table.h:586
TableContainerType & Data()
Definition: table.h:693
result_row_type & GetNearestRow(TArgumentType const &X)
Definition: table.h:524
Table(TMatrixType const &ThisMatrix)
Matrix constructor. the template parameter must have (i,j) access operator and size1 methods defined.
Definition: table.h:463
TResultType const & GetNearestValue(TArgumentType const &X) const
Definition: table.h:545
This class represents the value of its variable depending to other variable.
Definition: piecewize_linear_table.h:63
std::pair< TArgumentType, result_row_type > RecordType
Definition: table.h:76
std::vector< RecordType > TableContainerType
Definition: table.h:78
void PushBack(TArgumentType const &X, TArrayType const &Y)
Definition: table.h:226
void insert(TArgumentType const &X, TResultType const &Y)
Definition: table.h:174
TResultType GetValue(TArgumentType const &X) const
Definition: piecewize_linear_table.h:138
const std::string & NameOfY() const
Definition: table.h:297
TResultType const & GetNearestValue(TArgumentType const &X) const
Definition: piecewize_linear_table.h:183
const std::string & NameOfX() const
Definition: table.h:292
void SetNameOfX(const std::string &name)
Definition: table.h:302
result_array_type & GetNearestRow(TArgumentType const &X)
Definition: piecewize_linear_table.h:161
void PushBack(TArgumentType const &X, result_row_type const &Y)
Definition: table.h:237
TResultType & Interpolate(TArgumentType const &X, TArgumentType const &X1, TResultType const &Y1, TArgumentType const &X2, TResultType const &Y2, TResultType &Result)
Definition: piecewize_linear_table.h:204
TResultType const & operator()(TArgumentType const &X) const
Definition: table.h:91
std::array< TResultType, TResultsColumns > result_row_type
Definition: table.h:74
virtual std::string Info() const
Turn back information as a string.
Definition: table.h:276
void insert(TArgumentType const &X, TArrayType const &Y)
Definition: table.h:183
std::pair< TArgumentType, result_array_type > RecordType
Definition: piecewize_linear_table.h:73
TResultType & operator()(TArgumentType const &X)
Definition: table.h:97
void insert(TArgumentType const &X, result_row_type const &Y)
Definition: table.h:192
void Clear()
This method clears database.
Definition: table.h:245
virtual void PrintData(std::ostream &rOStream) const
Print object's data.
Definition: table.h:288
KRATOS_CLASS_POINTER_DEFINITION(Table)
Pointer definition of Table.
TResultType & GetNearestRow(TArgumentType const &X)
Definition: table.h:132
result_row_type const & operator[](TArgumentType const &X) const
Definition: table.h:115
TResultType const & GetNearestRow(TArgumentType const &X) const
Definition: table.h:153
void PushBack(TArgumentType const &X, TResultType const &Y)
Definition: table.h:216
friend class Serializer
Definition: table.h:383
TResultType & operator()(TArgumentType const &X, std::size_t J)
Definition: table.h:109
virtual void PrintInfo(std::ostream &rOStream) const
Print information about this object.
Definition: table.h:282
TableContainerType const & Data() const
Definition: table.h:260
result_row_type & operator[](TArgumentType &X)
Definition: table.h:121
void SetNameOfY(const std::string &name)
Definition: table.h:307
TableContainerType & Data()
Definition: table.h:255
TResultType const & operator()(TArgumentType const &X, std::size_t J) const
Definition: table.h:103
Variable class contains all information needed to store and retrive data from a data container.
Definition: variable.h:63
#define KRATOS_ERROR_IF(conditional)
Definition: exception.h:162
#define KRATOS_WARNING(label)
Definition: logger.h:265
REF: G. R. Cowper, GAUSSIAN QUADRATURE FORMULAS FOR TRIANGLES.
Definition: mesh_condition.cpp:21
std::istream & operator>>(std::istream &rIStream, LinearMasterSlaveConstraint &rThis)
input stream function
TABLE_NUMBER_ANGULAR_VELOCITY TABLE_NUMBER_MOMENT I33 BEAM_INERTIA_ROT_UNIT_LENGHT_Y KRATOS_DEFINE_APPLICATION_VARIABLE(DEM_APPLICATION, double, BEAM_INERTIA_ROT_UNIT_LENGHT_Z) typedef std double
Definition: DEM_application_variables.h:182
std::ostream & operator<<(std::ostream &rOStream, const LinearMasterSlaveConstraint &rThis)
output stream function
Definition: linear_master_slave_constraint.h:432
X2
Definition: generate_frictional_mortar_condition.py:120
X1
Definition: generate_frictional_mortar_condition.py:119
a
Definition: generate_stokes_twofluid_element.py:77
int local_size
Definition: generate_total_lagrangian_mixed_volumetric_strain_element.py:17
def load(f)
Definition: ode_solve.py:307
int j
Definition: quadrature.py:648
J
Definition: sensitivityMatrix.py:58
integer i
Definition: TensorModule.f:17
e
Definition: run_cpp_mpi_tests.py:31