-
Notifications
You must be signed in to change notification settings - Fork 244
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #11217 from KratosMultiphysics/core-adding-table-a…
…ccessor
- Loading branch information
Showing
8 changed files
with
683 additions
and
116 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,177 @@ | ||
// | / | | ||
// ' / __| _` | __| _ \ __| | ||
// . \ | ( | | ( |\__ ` | ||
// _|\_\_| \__,_|\__|\___/ ____/ | ||
// Multi-Physics | ||
// | ||
// License: BSD License | ||
// Kratos default license: kratos/license.txt | ||
// | ||
// Main authors: Alejandro Cornejo | ||
// Riccardo Rossi | ||
// Carlos Roig | ||
// Ruben Zorrilla | ||
// | ||
|
||
# pragma once | ||
|
||
// System includes | ||
|
||
// External includes | ||
|
||
// Project includes | ||
#include "includes/accessor.h" | ||
|
||
namespace Kratos | ||
{ | ||
///@addtogroup KratosCore | ||
///@{ | ||
|
||
///@name Kratos Classes | ||
///@{ | ||
|
||
/** | ||
* @class TableAccessor | ||
* @ingroup Kratos Core | ||
* @brief This class defines the way a certain property is accessed according to a table. | ||
* @brief The tables are supposed to relate double <-> double type entities. | ||
* @brief The input variable is suposed to be a nodally accesible one (either historical or not) | ||
* @author Alejandro Cornejo, Riccardo Rossi, Carlos Roig and Ruben Zorrilla | ||
*/ | ||
class KRATOS_API(KRATOS_CORE) TableAccessor : public Accessor | ||
{ | ||
public: | ||
///@name Type Definitions | ||
///@{ | ||
|
||
/// Geometry type definition | ||
using GeometryType = Geometry<Node>; | ||
|
||
/// Variable type | ||
using VariableType = Variable<double>; | ||
|
||
/// BaseType | ||
using BaseType = Accessor; | ||
|
||
using DataLocation = Globals::DataLocation; | ||
|
||
using SizeType = std::size_t; | ||
|
||
/// Pointer definition of TableAccessor | ||
KRATOS_CLASS_POINTER_DEFINITION(TableAccessor); | ||
|
||
///@} | ||
///@name Life Cycle | ||
///@{ | ||
TableAccessor() | ||
{} | ||
|
||
/// Custom constructor | ||
TableAccessor(VariableType& rInputVariable, const std::string& rInputVariableType = "node_historical") | ||
: mpInputVariable(&rInputVariable) | ||
{ | ||
// We initialize the variable type only once | ||
if (rInputVariableType == "node_historical") { | ||
mInputVariableType = Globals::DataLocation::NodeHistorical; | ||
} else if (rInputVariableType == "node_non_historical") { | ||
mInputVariableType = Globals::DataLocation::NodeNonHistorical; | ||
} else if (rInputVariableType == "element") { | ||
mInputVariableType = Globals::DataLocation::Element; | ||
} else { | ||
KRATOS_ERROR << "The table_input_variable_type is incorrect or not supported. Types available are : 'node_historical', 'node_non_historical' and 'element'" << std::endl; | ||
} | ||
} | ||
|
||
/// Copy constructor | ||
TableAccessor(const TableAccessor& rOther) | ||
: BaseType(rOther), | ||
mpInputVariable(rOther.mpInputVariable), | ||
mInputVariableType(rOther.mInputVariableType) | ||
{} | ||
|
||
///@} | ||
///@name Operations | ||
///@{ | ||
|
||
/** | ||
* @brief Custom method to retrieve double type properties | ||
* @param rVariable The variable considered (double type properties) | ||
* @param rProperties The properties considered | ||
* @param rGeometry The geometry considered | ||
* @param rShapeFunctionVector The shape function of the GP considered | ||
* @param rProcessInfo The process info considered | ||
* @return The double type properties | ||
*/ | ||
double GetValue( | ||
const Variable<double>& rVariable, | ||
const Properties& rProperties, | ||
const GeometryType& rGeometry, | ||
const Vector& rShapeFunctionVector, | ||
const ProcessInfo& rProcessInfo | ||
) const override; | ||
|
||
/** | ||
* @brief This computes a material property according to a certain | ||
* nodal Variable<double> table | ||
*/ | ||
double GetValueFromTable( | ||
const Variable<double>& rIndependentVariable, | ||
const Variable<double>& rDependentVariable, | ||
const Properties& rProperties, | ||
const GeometryType& rGeometry, | ||
const Vector& rShapeFunctionVector, | ||
const ProcessInfo& rProcessInfo) const; | ||
|
||
|
||
/** | ||
* @brief Returns the member input variable | ||
*/ | ||
VariableType& GetInputVariable() const | ||
{ | ||
return *mpInputVariable; | ||
} | ||
|
||
// Getting a pointer to the class | ||
Accessor::UniquePointer Clone() const override; | ||
|
||
///@} | ||
///@name Input and output | ||
///@{ | ||
|
||
/// Turn back information as a string. | ||
std::string Info() const override | ||
{ | ||
std::stringstream buffer; | ||
buffer << "TableAccessor" ; | ||
|
||
return buffer.str(); | ||
} | ||
|
||
/// Print information about this object. | ||
void PrintInfo(std::ostream& rOStream) const override {rOStream << "TableAccessor";} | ||
|
||
/// Print object's data. | ||
void PrintData(std::ostream& rOStream) const override {rOStream << "TableAccessor class";} | ||
|
||
///@} | ||
|
||
private: | ||
|
||
///@name Member Variables | ||
///@{ | ||
|
||
VariableType* mpInputVariable; | ||
Globals::DataLocation mInputVariableType = Globals::DataLocation::NodeHistorical; // NodalHistorical by default | ||
|
||
friend class Serializer; | ||
|
||
void save(Serializer &rSerializer) const override; | ||
|
||
void load(Serializer &rSerializer) override; | ||
|
||
}; // class | ||
///@} | ||
|
||
///@} addtogroup block | ||
|
||
} // namespace Kratos |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
// | / | | ||
// ' / __| _` | __| _ \ __| | ||
// . \ | ( | | ( |\__ ` | ||
// _|\_\_| \__,_|\__|\___/ ____/ | ||
// Multi-Physics | ||
// | ||
// License: BSD License | ||
// Kratos default license: kratos/license.txt | ||
// | ||
// Main authors: Alejandro Cornejo | ||
// Riccardo Rossi | ||
// Carlos Roig | ||
// | ||
// | ||
|
||
// System includes | ||
|
||
// External includes | ||
|
||
// Project includes | ||
#include "includes/table_accessor.h" | ||
#include "includes/properties.h" | ||
|
||
namespace Kratos | ||
{ | ||
|
||
/***********************************************************************************/ | ||
/***********************************************************************************/ | ||
|
||
double TableAccessor::GetValue( | ||
const Variable<double>& rVariable, | ||
const Properties& rProperties, | ||
const GeometryType& rGeometry, | ||
const Vector& rShapeFunctionVector, | ||
const ProcessInfo& rProcessInfo | ||
) const | ||
{ | ||
return GetValueFromTable(*mpInputVariable, rVariable, rProperties, rGeometry, rShapeFunctionVector, rProcessInfo); | ||
} | ||
|
||
/***********************************************************************************/ | ||
/***********************************************************************************/ | ||
|
||
double TableAccessor::GetValueFromTable( | ||
const Variable<double> &rIndependentVariable, | ||
const Variable<double> &rDependentVariable, | ||
const Properties& rProperties, | ||
const GeometryType& rGeometry, | ||
const Vector& rShapeFunctionVector, | ||
const ProcessInfo& rProcessInfo) const | ||
{ | ||
double independent_at_gauss = 0.0; | ||
if (mInputVariableType == Globals::DataLocation::NodeHistorical) { | ||
for (SizeType i = 0; i < rShapeFunctionVector.size(); ++i) { | ||
KRATOS_DEBUG_ERROR_IF_NOT(rGeometry[i].SolutionStepsDataHas(rIndependentVariable)) << "The Variable " << rIndependentVariable.Name() << " is not available at the nodes of the Geometry to retrieve Table values." << std::endl; | ||
const double nodal_value = rGeometry[i].FastGetSolutionStepValue(rIndependentVariable); | ||
independent_at_gauss += nodal_value * rShapeFunctionVector[i]; | ||
} | ||
} else if (mInputVariableType == Globals::DataLocation::NodeNonHistorical) { | ||
for (SizeType i = 0; i < rShapeFunctionVector.size(); ++i) { | ||
KRATOS_DEBUG_ERROR_IF_NOT(rGeometry[i].Has(rIndependentVariable)) << "The Variable " << rIndependentVariable.Name() << " is not available at the nodes of the Geometry to retrieve Table values." << std::endl; | ||
const double nodal_value = rGeometry[i].GetValue(rIndependentVariable); | ||
independent_at_gauss += nodal_value * rShapeFunctionVector[i]; | ||
} | ||
} else if (mInputVariableType == Globals::DataLocation::Element) { | ||
KRATOS_DEBUG_ERROR_IF_NOT(rGeometry.Has(rIndependentVariable)) << "The Variable " << rIndependentVariable.Name() << " is not available at the Geometry to retrieve Table values." << std::endl; | ||
independent_at_gauss = rGeometry.GetValue(rIndependentVariable); | ||
} else { | ||
KRATOS_ERROR << "The table_input_variable_type is incorrect or not supported. Types available are : nodal_historical, nodal_non_historical and elemental_non_historical" << std::endl; | ||
} | ||
|
||
// Retrieve the dependent variable from the table | ||
const auto& r_table = rProperties.GetTable(rIndependentVariable, rDependentVariable); | ||
return r_table.GetValue(independent_at_gauss); | ||
} | ||
|
||
/***********************************************************************************/ | ||
/***********************************************************************************/ | ||
|
||
void TableAccessor::save(Serializer& rSerializer) const | ||
{ | ||
rSerializer.save("InputVariable", mpInputVariable->Name()); | ||
// // we must do the int cast to be able to compile | ||
rSerializer.save("InputVariableType", static_cast<int>(mInputVariableType)); | ||
} | ||
void TableAccessor::load(Serializer& rSerializer) | ||
{ | ||
std::string variable_name; | ||
rSerializer.load("InputVariable", variable_name); | ||
mpInputVariable = static_cast<Variable<double> *>(KratosComponents<VariableData>::pGet(variable_name)); | ||
|
||
// // we must do the int cast to be able to compile | ||
int enum_value; | ||
rSerializer.load("InputVariableType", enum_value); | ||
mInputVariableType = static_cast<Globals::DataLocation>(enum_value); | ||
} | ||
|
||
/***********************************************************************************/ | ||
/***********************************************************************************/ | ||
|
||
Accessor::UniquePointer TableAccessor::Clone() const | ||
{ | ||
return Kratos::make_unique<TableAccessor>(*this); | ||
} | ||
|
||
} // namespace Kratos |
Oops, something went wrong.