Skip to content

Commit

Permalink
Merge pull request #3219 from KratosMultiphysics/core/adding-paramete…
Browse files Browse the repository at this point in the history
…rs-constructor-schemes

[Core] Adding Parameters constructor to schemes
  • Loading branch information
loumalouomega committed Dec 2, 2018
2 parents acdb454 + 054743a commit b0fbbfe
Show file tree
Hide file tree
Showing 8 changed files with 198 additions and 55 deletions.
100 changes: 65 additions & 35 deletions kratos/solving_strategies/schemes/residual_based_bdf_custom_scheme.h
Expand Up @@ -94,52 +94,42 @@ class ResidualBasedBDFCustomScheme
///@name Life Cycle
///@{

/**
* @brief Constructor. The BDF method
* @param ThisParameters The parameters containing the list of variables to consider
* @todo The ideal would be to use directly the dof or the variable itself to identify the type of variable and is derivatives
*/
explicit ResidualBasedBDFCustomScheme(Parameters ThisParameters)
{
// Getting default parameters
Parameters default_parameters = GetDefaultParameters();
ThisParameters.ValidateAndAssignDefaults(default_parameters);

// Now here call the base class constructor
BDFBaseType( ThisParameters["order"].GetInt());

// Creating variables list
CreateVariablesList(ThisParameters);
}

/**
* @brief Constructor. The BDF method
* @param Order The integration order
* @param rParameters The parameters containing the list of variables to consider
* @param ThisParameters The parameters containing the list of variables to consider
* @todo The ideal would be to use directly the dof or the variable itself to identify the type of variable and is derivatives
*/
explicit ResidualBasedBDFCustomScheme(
const std::size_t Order = 2,
Parameters rParameters = Parameters(R"({})")
Parameters ThisParameters = Parameters(R"({})")
)
:BDFBaseType(Order)
{
// Getting default parameters
Parameters default_parameters = GetDefaultParameters();
rParameters.ValidateAndAssignDefaults(default_parameters);

const std::size_t n_variables = rParameters["variable"].size();
const std::size_t n_first_derivative = rParameters["first_derivative"].size();
const std::size_t n_second_derivative = rParameters["second_derivative"].size();

// Size check
KRATOS_ERROR_IF(n_variables != n_first_derivative) << "Your list of variables is not the same size as the list of first derivatives variables" << std::endl;
KRATOS_ERROR_IF(n_variables != n_second_derivative) << "Your list of variables is not the same size as the list of second derivatives variables" << std::endl;

for (unsigned int i_var = 0; i_var < n_variables; ++i_var){
const std::string& variable_name = rParameters["variable"].GetArrayItem(i_var).GetString();
const std::string& first_derivative_name = rParameters["first_derivative"].GetArrayItem(i_var).GetString();
const std::string& second_derivative_name = rParameters["second_derivative"].GetArrayItem(i_var).GetString();
ThisParameters.ValidateAndAssignDefaults(default_parameters);

if(KratosComponents<Variable<double>>::Has(variable_name)){
Variable<double> variable = KratosComponents< Variable<double> >::Get(variable_name);
Variable<double> first_derivative = KratosComponents< Variable<double> >::Get(first_derivative_name);
Variable<double> second_derivative = KratosComponents< Variable<double> >::Get(second_derivative_name);
mDoubleVariable.push_back(variable);
mFirtsDoubleDerivatives.push_back(first_derivative);
mSecondDoubleDerivatives.push_back(second_derivative);
} else if (KratosComponents< Variable< array_1d< double, 3> > >::Has(variable_name)) {
Variable<array_1d< double, 3>> variable = KratosComponents< Variable<array_1d< double, 3>> >::Get(variable_name);
Variable<array_1d< double, 3>> first_derivative = KratosComponents< Variable<array_1d< double, 3>> >::Get(first_derivative_name);
Variable<array_1d< double, 3>> second_derivative = KratosComponents< Variable<array_1d< double, 3>> >::Get(second_derivative_name);
mArrayVariable.push_back(variable);
mFirtsArrayDerivatives.push_back(first_derivative);
mSecondArrayDerivatives.push_back(second_derivative);
} else {
KRATOS_ERROR << "Only double and vector variables are allowed in the variables list." ;
}
}
// Creating variables list
CreateVariablesList(ThisParameters);
}

/** Copy Constructor.
Expand Down Expand Up @@ -504,15 +494,55 @@ class ResidualBasedBDFCustomScheme
}
}

/**
* @brief This method creates the list of variables
* @param ThisParameters The configuration parameters
*/
void CreateVariablesList(Parameters ThisParameters)
{
const std::size_t n_variables = ThisParameters["variable"].size();
const std::size_t n_first_derivative = ThisParameters["first_derivative"].size();
const std::size_t n_second_derivative = ThisParameters["second_derivative"].size();

// Size check
KRATOS_ERROR_IF(n_variables != n_first_derivative) << "Your list of variables is not the same size as the list of first derivatives variables" << std::endl;
KRATOS_ERROR_IF(n_variables != n_second_derivative) << "Your list of variables is not the same size as the list of second derivatives variables" << std::endl;

for (unsigned int i_var = 0; i_var < n_variables; ++i_var){
const std::string& variable_name = ThisParameters["variable"].GetArrayItem(i_var).GetString();
const std::string& first_derivative_name = ThisParameters["first_derivative"].GetArrayItem(i_var).GetString();
const std::string& second_derivative_name = ThisParameters["second_derivative"].GetArrayItem(i_var).GetString();

if(KratosComponents<Variable<double>>::Has(variable_name)){
Variable<double> variable = KratosComponents< Variable<double> >::Get(variable_name);
Variable<double> first_derivative = KratosComponents< Variable<double> >::Get(first_derivative_name);
Variable<double> second_derivative = KratosComponents< Variable<double> >::Get(second_derivative_name);
mDoubleVariable.push_back(variable);
mFirtsDoubleDerivatives.push_back(first_derivative);
mSecondDoubleDerivatives.push_back(second_derivative);
} else if (KratosComponents< Variable< array_1d< double, 3> > >::Has(variable_name)) {
Variable<array_1d< double, 3>> variable = KratosComponents< Variable<array_1d< double, 3>> >::Get(variable_name);
Variable<array_1d< double, 3>> first_derivative = KratosComponents< Variable<array_1d< double, 3>> >::Get(first_derivative_name);
Variable<array_1d< double, 3>> second_derivative = KratosComponents< Variable<array_1d< double, 3>> >::Get(second_derivative_name);
mArrayVariable.push_back(variable);
mFirtsArrayDerivatives.push_back(first_derivative);
mSecondArrayDerivatives.push_back(second_derivative);
} else {
KRATOS_ERROR << "Only double and vector variables are allowed in the variables list." ;
}
}
}

/**
* @brief This method returns the defaulr parameters in order to avoid code duplication
* @return Returns the default parameters
*/

Parameters GetDefaultParameters()
{
Parameters default_parameters = Parameters(R"(
{
"scheme_type" : "ResidualBasedBDFCustomScheme",
"integration_order" : 2,
"variable" : ["DISPLACEMENT"],
"first_derivative" : ["VELOCITY"],
"second_derivative" : ["ACCELERATION"]
Expand Down
Expand Up @@ -92,6 +92,21 @@ class ResidualBasedBDFDisplacementScheme
///@name Life Cycle
///@{

/**
* @brief Constructor. The BDF method (parameters)
* @param ThisParameters Parameters with the integration order
*/
explicit ResidualBasedBDFDisplacementScheme(Parameters ThisParameters)
: ResidualBasedBDFDisplacementScheme(ThisParameters.Has("integration_order") ? static_cast<std::size_t>(ThisParameters["integration_order"].GetInt()) : 2)
{
// Validate default parameters
Parameters default_parameters = Parameters(R"(
{
"integration_order" : 2
})" );
ThisParameters.ValidateAndAssignDefaults(default_parameters);
}

/**
* @brief Constructor. The BDF method
* @param Order The integration order
Expand Down
Expand Up @@ -86,10 +86,26 @@ class ResidualBasedBossakDisplacementScheme
///@name Life Cycle
///@{

/**
* @brief Constructor. (with parameters)
* @detail The bossak method
* @param ThisParameters The parameters containing the configuration
*/
explicit ResidualBasedBossakDisplacementScheme(Parameters ThisParameters)
: ResidualBasedBossakDisplacementScheme(ThisParameters.Has("damp_factor_m") ? ThisParameters["damp_factor_m"].GetDouble() : -0.3)
{
// Validate default parameters
Parameters default_parameters = Parameters(R"(
{
"damp_factor_m" : -0.3
})" );
ThisParameters.ValidateAndAssignDefaults(default_parameters);
}

/**
* @brief Constructor.
* @detail The bossak method
* @rAlpham The Bossak parameter. Default value is 0, which is the Newmark method
* @param rAlpham The Bossak parameter. Default value is 0, which is the Newmark method
*/
explicit ResidualBasedBossakDisplacementScheme(const double rAlpham = 0.0)
:ImplicitBaseType()
Expand Down
Expand Up @@ -82,6 +82,24 @@ class ResidualBasedNewmarkDisplacementScheme
///@}
///@name Life Cycle
///@{

/**
* @brief Constructor. The Newmark method (parameters)
* @param ThisParameters Dummy parameters
*/
explicit ResidualBasedNewmarkDisplacementScheme(Parameters ThisParameters)
:DerivedBaseType(0.0)
{
// Validate default parameters
Parameters default_parameters = Parameters(R"(
{
})" );
ThisParameters.ValidateAndAssignDefaults(default_parameters);
}

/**
* @brief Default constructor. The Newmark method
*/
explicit ResidualBasedNewmarkDisplacementScheme()
:DerivedBaseType(0.0)
{
Expand Down
Expand Up @@ -83,6 +83,27 @@ class ResidualBasedPseudoStaticDisplacementScheme
///@}
///@name Life Cycle
///@{

/**
* @brief Constructor. The pseudo static scheme (parameters)
* @param ThisParameters Parameters with the Rayleigh variable
*/
explicit ResidualBasedPseudoStaticDisplacementScheme(Parameters ThisParameters)
:DerivedBaseType(0.0)
{
// Validate default parameters
Parameters default_parameters = Parameters(R"(
{
"rayleigh_beta_variable" : "RAYLEIGH_BETA"
})" );
ThisParameters.ValidateAndAssignDefaults(default_parameters);

mRayleighBeta = KratosComponents<Variable<double>>::Get(ThisParameters["rayleigh_beta_variable"].GetString());
}

/**
* @brief Default constructor. The pseudo static scheme
*/
explicit ResidualBasedPseudoStaticDisplacementScheme(const Variable<double> RayleighBetaVariable)
:DerivedBaseType(0.0),
mRayleighBeta(RayleighBetaVariable)
Expand Down
Expand Up @@ -10,25 +10,19 @@
// Main authors: Riccardo Rossi
//


#if !defined( KRATOS_RESIDUALBASED_INCREMENTAL_AITKEN_STATIC_SCHEME_H_INCLUDED )
#define KRATOS_RESIDUALBASED_INCREMENTAL_AITKEN_STATIC_SCHEME_H_INCLUDED



// System includes
#include <string>
#include <iostream>


// External includes


// Project includes
#include "includes/define.h"
#include "solving_strategies/schemes/residualbased_incrementalupdate_static_scheme.h"


namespace Kratos
{
///@addtogroup KratosCore
Expand Down Expand Up @@ -76,17 +70,32 @@ class ResidualBasedIncrementalAitkenStaticScheme : public ResidualBasedIncrement

typedef typename BaseType::TSystemVectorType TSystemVectorType;

//typedef typename BaseType::LocalSystemVectorType LocalSystemVectorType;
//typedef typename BaseType::LocalSystemMatrixType LocalSystemMatrixType;

///@}
///@name Life Cycle
///@{

/// Default constructor.
/** @param DefaultOmega Default relaxation factor to use in the first iteration, where Aitken's factor cannot be computed. Use a value between 0 and 1.
*/
ResidualBasedIncrementalAitkenStaticScheme(double DefaultOmega):
/**
* @brief Default constructor. (with parameters)
* @param ThisParameters Default relaxation factor to use in the first iteration, where Aitken's factor cannot be computed. Use a value between 0 and 1.
*/
explicit ResidualBasedIncrementalAitkenStaticScheme(Parameters ThisParameters)
{
// Validate default parameters
Parameters default_parameters = Parameters(R"(
{
"default_omega" : 0.0
})" );
ThisParameters.ValidateAndAssignDefaults(default_parameters);

mDefaultOmega = ThisParameters["default_omega"].GetDouble();
mOldOmega = ThisParameters["default_omega"].GetDouble();
}

/**
* @brief Default constructor.
* @param DefaultOmega Default relaxation factor to use in the first iteration, where Aitken's factor cannot be computed. Use a value between 0 and 1.
*/
explicit ResidualBasedIncrementalAitkenStaticScheme(double DefaultOmega):
mDefaultOmega(DefaultOmega),
mOldOmega(DefaultOmega)
{}
Expand Down
Expand Up @@ -91,10 +91,24 @@ class ResidualBasedIncrementalUpdateStaticScheme
///@name Life Cycle
///@{

/** Constructor.
/**
* @brief Constructor. The pseudo static scheme (parameters)
* @param ThisParameters Dummy parameters
*/
explicit ResidualBasedIncrementalUpdateStaticScheme(Parameters ThisParameters)
: BaseType()
{
// Validate default parameters
Parameters default_parameters = Parameters(R"(
{
})" );
ThisParameters.ValidateAndAssignDefaults(default_parameters);
}

/** Default onstructor.
*/
explicit ResidualBasedIncrementalUpdateStaticScheme()
: Scheme<TSparseSpace,TDenseSpace>()
: BaseType()
{}

/** Copy Constructor.
Expand Down
Expand Up @@ -94,22 +94,42 @@ class ResidualBasedIncrementalUpdateStaticSchemeSlip : public ResidualBasedIncre
///@name Life Cycle
///@{

/**
* @brief Constructor. The pseudo static scheme (parameters)
* @param ThisParameters Configuration parameters
*/
explicit ResidualBasedIncrementalUpdateStaticSchemeSlip(Parameters ThisParameters)
: BaseType()
{
// Validate default parameters
Parameters default_parameters = Parameters(R"(
{
"domain_size" : 3,
"block_size" : 3
})" );
ThisParameters.ValidateAndAssignDefaults(default_parameters);

const int domain_size = ThisParameters["domain_size"].GetInt();
const int block_size = ThisParameters["block_size"].GetInt();
mpRotationTool = Kratos::make_shared<RotationToolType>(domain_size, block_size, IS_STRUCTURE, 0.0);
}

/// Constructor.
/** @param DomainSize Number of spatial dimensions (2 or 3).
* @param BlockSize Number of matrix and vector rows associated to each node. Only the first DomainSize rows will be rotated.
*/
ResidualBasedIncrementalUpdateStaticSchemeSlip(unsigned int DomainSize,
explicit ResidualBasedIncrementalUpdateStaticSchemeSlip(unsigned int DomainSize,
unsigned int BlockSize):
ResidualBasedIncrementalUpdateStaticScheme<TSparseSpace,TDenseSpace>(),
BaseType(),
mpRotationTool(Kratos::make_shared<RotationToolType>(DomainSize,BlockSize,IS_STRUCTURE,0.0))
{}

/// Constructor providing a custom rotation tool.

/** @param pRotationTool a pointer to the helper class that manages DOF rotation.
*/
ResidualBasedIncrementalUpdateStaticSchemeSlip(RotationToolPointerType pRotationTool):
ResidualBasedIncrementalUpdateStaticScheme<TSparseSpace,TDenseSpace>(),
explicit ResidualBasedIncrementalUpdateStaticSchemeSlip(RotationToolPointerType pRotationTool):
BaseType(),
mpRotationTool(pRotationTool)
{}

Expand Down

0 comments on commit b0fbbfe

Please sign in to comment.