Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Core] Fix Extrapolation in Table::GetDerivative #12471

Closed
wants to merge 3 commits into from
Closed
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 22 additions & 28 deletions kratos/includes/table.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@
// Riccardo Rossi
//

#if !defined(KRATOS_TABLE_H_INCLUDED )
#define KRATOS_TABLE_H_INCLUDED
#pragma once

// System includes
#include <string>
Expand Down Expand Up @@ -48,8 +47,8 @@ namespace Kratos
///@}
///@name Kratos Classes
///@{
/**

/**
* @class Table
* @ingroup KratosCore
* @brief This class represents the value of its variable depending to other variable.
Expand All @@ -71,11 +70,11 @@ class Table
/// Pointer definition of Table
KRATOS_CLASS_POINTER_DEFINITION(Table);

typedef std::array<TResultType, TResultsColumns> result_row_type;
using result_row_type = std::array<TResultType, TResultsColumns>;

typedef std::pair<TArgumentType, result_row_type> RecordType;
using RecordType = std::pair<TArgumentType, result_row_type>;

typedef std::vector<RecordType> TableContainerType;
using TableContainerType = std::vector<RecordType>;

///@}
///@name Life Cycle
Expand Down Expand Up @@ -238,7 +237,7 @@ class Table
{
mData.push_back(RecordType(X,Y));
}

/**
* @brief This method clears database
*/
Expand Down Expand Up @@ -440,17 +439,18 @@ class Table<double, double>
/// Pointer definition of Table
KRATOS_CLASS_POINTER_DEFINITION(Table);

typedef double TResultType;
typedef double TArgumentType;

typedef std::array<TResultType, 1> result_row_type;
using TResultType = double;
using TArgumentType = double;

typedef std::pair<TArgumentType, result_row_type> RecordType;
using result_row_type = std::array<TResultType, 1>;
using RecordType = std::pair<TArgumentType, result_row_type>;
using TableContainerType = std::vector<RecordType>;

typedef std::vector<RecordType> TableContainerType;
template <typename T>
using Variable = Variable<T>;

typedef Variable<TArgumentType> XVariableType;
typedef Variable<TResultType> YVariableType;
using XVariableType = Variable<TArgumentType>;
using YVariableType = Variable<TResultType>;

///@}
///@name Life Cycle
Expand Down Expand Up @@ -649,15 +649,13 @@ class Table<double, double>

TResultType result;
if(X <= mData[0].first)
//return Interpolate(X, mData[0].first, mData[0].second[0], mData[1].first, mData[1].second[0], result);
return 0.0;
return InterpolateDerivative(mData[0].first, mData[0].second[0], mData[1].first, mData[1].second[0], result);

for(std::size_t i = 1 ; i < size ; i++)
if(X <= mData[i].first)
return InterpolateDerivative( mData[i-1].first, mData[i-1].second[0], mData[i].first, mData[i].second[0], result);

// If it lies outside the table values we will return 0.0.
return 0.0;
return InterpolateDerivative(mData[size-2].first, mData[size-2].second[0], mData[size-1].first, mData[size-1].second[0], result);
}
TResultType& InterpolateDerivative( TArgumentType const& X1, TResultType const& Y1, TArgumentType const& X2, TResultType const& Y2, TResultType& Result) const
{
Expand All @@ -667,7 +665,7 @@ class Table<double, double>
if (dx < epsilon)
{
dx=epsilon;
KRATOS_WARNING("")
KRATOS_WARNING("")
<< "*******************************************\n"
<< "*** ATTENTION: SMALL dX WHEN COMPUTING ***\n"
<< "*** DERIVATIVE FROM TABLE. SET TO 1E-12 ***\n"
Expand All @@ -676,15 +674,15 @@ class Table<double, double>
Result= dy/dx;
return Result;
}

/**
* @brief This method clears database
*/
void Clear()
{
mData.clear();
}

///@}
///@name Access
///@{
Expand Down Expand Up @@ -812,7 +810,7 @@ class Table<double, double>
for(auto j = i_row->second.begin() ; j != i_row->second.end() ; j++)
rSerializer.load("Column", *j);
}
}
}


///@}
Expand Down Expand Up @@ -867,7 +865,3 @@ inline std::ostream& operator << (std::ostream& rOStream,
///@} addtogroup block

} // namespace Kratos.

#endif // KRATOS_TABLE_H_INCLUDED defined


Loading