14 #if !defined(KRATOS_RESIDUAL_BASED_BDF_CUSTOM_SCHEME )
15 #define KRATOS_RESIDUAL_BASED_BDF_CUSTOM_SCHEME
54 template<
class TSparseSpace,
class TDenseSpace>
110 CreateVariablesList(ThisParameters);
120 const std::size_t Order = 2,
130 CreateVariablesList(ThisParameters);
170 return Kratos::make_shared<ClassType>(ThisParameters);
188 KRATOS_WARNING_IF(
"ResidualBasedBDFCustomScheme", !r_current_process_info.
Has(DOMAIN_SIZE)) <<
"DOMAIN_SIZE not defined. Please define DOMAIN_SIZE. 3D case will be assumed" << std::endl;
189 const std::size_t
domain_size = r_current_process_info.
Has(DOMAIN_SIZE) ? r_current_process_info.
GetValue(DOMAIN_SIZE) : 3;
195 const std::size_t number_variables_added = total_number_of_variables/3;
196 for (std::size_t
i = 0;
i < number_variables_added; ++
i) {
202 const std::size_t number_variables_added = total_number_of_variables/2;
203 for (std::size_t
i = 0;
i < number_variables_added; ++
i) {
204 const std::string variable_name = ((*(
mDoubleVariable.begin() + 2 *
i))->GetSourceVariable()).
Name();
239 const int num_nodes =
static_cast<int>( rModelPart.
Nodes().size() );
240 const auto it_node_begin = rModelPart.
Nodes().begin();
246 auto it_node = it_node_begin +
Index;
257 if (it_node->HasDofFor(d2var)) {
258 if (it_node->IsFixed(d2var)) {
259 it_node->Fix(*p_var);
264 if (it_node->HasDofFor(dvar)) {
265 if (it_node->IsFixed(dvar) && !fixed) {
266 it_node->Fix(*p_var);
274 KRATOS_CATCH(
"ResidualBasedBDFCustomScheme.InitializeSolutionStep");
300 const double delta_time = r_current_process_info[DELTA_TIME];
303 const int num_nodes =
static_cast<int>( rModelPart.
Nodes().size() );
306 const auto it_node_begin = rModelPart.
Nodes().begin();
309 auto it_node = it_node_begin +
Index;
312 for (
auto p_var : mDoubleVariable) {
314 const auto& dvar = *mFirstDoubleDerivatives[
counter];
315 const auto& d2var = *mSecondDoubleDerivatives[
counter];
317 ComputePredictComponent(it_node, *p_var, dvar, d2var,
delta_time);
323 UpdateFirstDerivative(it_node);
324 UpdateSecondDerivative(it_node);
343 const int err = BDFBaseType::Check(rModelPart);
344 if(err!=0)
return err;
347 for(
auto& r_node : rModelPart.
Nodes()) {
348 for (
auto p_var : mDoubleVariable)
350 for (
auto p_var : mFirstDoubleDerivatives)
352 for (
auto p_var : mSecondDoubleDerivatives)
355 for (
auto p_var : mDoubleVariable)
372 "name" : "bdf_scheme",
374 "integration_order" : 2,
375 "solution_variables" : ["DISPLACEMENT"]
379 const Parameters base_default_parameters = BDFBaseType::GetDefaultParameters();
381 return default_parameters;
406 std::string
Info()
const override
408 return "ResidualBasedBDFCustomScheme";
456 for (
auto p_var : mDoubleVariable) {
457 double& dotun0 = itNode->FastGetSolutionStepValue(*mFirstDoubleDerivatives[
counter]);
458 dotun0 = BDFBaseType::mBDF[0] * itNode->FastGetSolutionStepValue(*p_var);
459 for (std::size_t i_order = 1; i_order < BDFBaseType::mOrder + 1; ++i_order)
460 dotun0 += BDFBaseType::mBDF[i_order] * itNode->FastGetSolutionStepValue(*p_var, i_order);
473 for (
auto p_var : mFirstDoubleDerivatives) {
474 double& dot2un0 = itNode->FastGetSolutionStepValue(*mSecondDoubleDerivatives[
counter]);
475 dot2un0 = BDFBaseType::mBDF[0] * itNode->FastGetSolutionStepValue(*p_var);
476 for (std::size_t i_order = 1; i_order < BDFBaseType::mOrder + 1; ++i_order)
477 dot2un0 += BDFBaseType::mBDF[i_order] * itNode->FastGetSolutionStepValue(*p_var, i_order);
504 std::size_t mDomainSize = 3;
522 template<
class TClassVar>
523 void ComputePredictComponent(
525 const TClassVar& rVariable,
526 const TClassVar& rDerivedVariable,
527 const TClassVar& rDerived2Variable,
528 const double DeltaTime
532 const double dot2un1 = itNode->FastGetSolutionStepValue(rDerived2Variable, 1);
533 const double dotun1 = itNode->FastGetSolutionStepValue(rDerivedVariable, 1);
534 const double un1 = itNode->FastGetSolutionStepValue(rVariable, 1);
535 const double dot2un0 = itNode->FastGetSolutionStepValue(rDerived2Variable);
536 double& dotun0 = itNode->FastGetSolutionStepValue(rDerivedVariable);
537 double& un0 = itNode->FastGetSolutionStepValue(rVariable);
539 if (itNode->HasDofFor(rDerived2Variable) && itNode->IsFixed(rDerived2Variable)) {
541 for (std::size_t i_order = 1; i_order < BDFBaseType::mOrder + 1; ++i_order)
542 dotun0 -= BDFBaseType::mBDF[i_order] * itNode->FastGetSolutionStepValue(rDerivedVariable, i_order);
543 dotun0 /= BDFBaseType::mBDF[0];
546 for (std::size_t i_order = 1; i_order < BDFBaseType::mOrder + 1; ++i_order)
547 un0 -= BDFBaseType::mBDF[i_order] * itNode->FastGetSolutionStepValue(rVariable, i_order);
548 un0 /= BDFBaseType::mBDF[0];
549 }
else if (itNode->HasDofFor(rDerivedVariable) && itNode->IsFixed(rDerivedVariable)) {
551 for (std::size_t i_order = 1; i_order < BDFBaseType::mOrder + 1; ++i_order)
552 un0 -= BDFBaseType::mBDF[i_order] * itNode->FastGetSolutionStepValue(rVariable, i_order);
553 un0 /= BDFBaseType::mBDF[0];
554 }
else if (!itNode->IsFixed(rVariable)) {
555 un0 = un1 + DeltaTime * dotun1 + 0.5 * std::pow(DeltaTime, 2) * dot2un1;
563 void CreateVariablesList(Parameters ThisParameters)
565 const std::size_t n_variables = ThisParameters[
"solution_variables"].size();
568 mDomainSize = ThisParameters[
"domain_size"].GetInt();
570 const auto variable_names = ThisParameters[
"solution_variables"].GetStringArray();
572 for (std::size_t p_var = 0; p_var < n_variables; ++p_var){
573 const std::string& variable_name = variable_names[p_var];
575 if(KratosComponents<Variable<double>>::
Has(variable_name)){
576 const auto& r_var = KratosComponents<Variable<double>>::Get(variable_name);
577 mDoubleVariable.push_back(&r_var);
578 mFirstDoubleDerivatives.push_back(&(r_var.GetTimeDerivative()));
579 mSecondDoubleDerivatives.push_back(&((r_var.GetTimeDerivative()).GetTimeDerivative()));
580 }
else if (KratosComponents< Variable< array_1d< double, 3> > >::
Has(variable_name)) {
582 const auto& r_var_x = KratosComponents<Variable<double>>::Get(variable_name+
"_X");
583 const auto& r_var_y = KratosComponents<Variable<double>>::Get(variable_name+
"_Y");
584 mDoubleVariable.push_back(&r_var_x);
585 mDoubleVariable.push_back(&r_var_y);
586 mFirstDoubleDerivatives.push_back(&(r_var_x.GetTimeDerivative()));
587 mFirstDoubleDerivatives.push_back(&(r_var_y.GetTimeDerivative()));
588 mSecondDoubleDerivatives.push_back(&((r_var_x.GetTimeDerivative()).GetTimeDerivative()));
589 mSecondDoubleDerivatives.push_back(&((r_var_y.GetTimeDerivative()).GetTimeDerivative()));
590 if (mDomainSize == 3) {
591 const auto& r_var_z = KratosComponents<Variable<double>>::Get(variable_name+
"_Z");
592 mDoubleVariable.push_back(&r_var_z);
593 mFirstDoubleDerivatives.push_back(&(r_var_z.GetTimeDerivative()));
594 mSecondDoubleDerivatives.push_back(&((r_var_z.GetTimeDerivative()).GetTimeDerivative()));
597 KRATOS_ERROR <<
"Only double and vector variables are allowed in the variables list." ;
std::string Info() const override
Turn back information as a string.
Definition: periodic_interface_process.hpp:93
bool Has(const Variable< TDataType > &rThisVariable) const
Checks if the data container has a value associated with a given variable.
Definition: data_value_container.h:382
TDataType & GetValue(const Variable< TDataType > &rThisVariable)
Gets the value associated with a given variable.
Definition: data_value_container.h:268
std::vector< DofType::Pointer > DofsVectorType
Definition: element.h:100
This class is useful for index iteration over containers.
Definition: parallel_utilities.h:451
void for_each(TUnaryFunction &&f)
Definition: parallel_utilities.h:514
KratosComponents class encapsulates a lookup table for a family of classes in a generic way.
Definition: kratos_components.h:49
This class aims to manage meshes for multi-physics simulations.
Definition: model_part.h:77
ProcessInfo & GetProcessInfo()
Definition: model_part.h:1746
NodesContainerType & Nodes(IndexType ThisIndex=0)
Definition: model_part.h:507
This class provides to Kratos a data structure for I/O based on the standard of JSON.
Definition: kratos_parameters.h:59
void RecursivelyAddMissingParameters(const Parameters &rDefaultParameters)
This function is designed to verify that the parameters under testing contain at least all parameters...
Definition: kratos_parameters.cpp:1457
A sorted associative container similar to an STL set, but uses a vector to store pointers to its data...
Definition: pointer_vector_set.h:72
boost::indirect_iterator< typename TContainerType::iterator > iterator
Definition: pointer_vector_set.h:95
ProcessInfo holds the current value of different solution parameters.
Definition: process_info.h:59
BDF integration scheme (for dynamic problems)
Definition: residual_based_bdf_custom_scheme.h:57
ModelPart::NodesContainerType NodesArrayType
Definition: residual_based_bdf_custom_scheme.h:85
ImplicitBaseType::TSystemMatrixType TSystemMatrixType
Definition: residual_based_bdf_custom_scheme.h:77
Scheme< TSparseSpace, TDenseSpace > BaseType
Definition: residual_based_bdf_custom_scheme.h:63
ResidualBasedImplicitTimeScheme< TSparseSpace, TDenseSpace > ImplicitBaseType
Definition: residual_based_bdf_custom_scheme.h:65
ImplicitBaseType::DofsArrayType DofsArrayType
Definition: residual_based_bdf_custom_scheme.h:73
std::vector< const Variable< double > * > mFirstDoubleDerivatives
The double variables.
Definition: residual_based_bdf_custom_scheme.h:437
void PrintData(std::ostream &rOStream) const override
Print object's data.
Definition: residual_based_bdf_custom_scheme.h:418
ResidualBasedBDFCustomScheme(const std::size_t Order=2, Parameters ThisParameters=Parameters(R"({})"))
Constructor. The BDF method.
Definition: residual_based_bdf_custom_scheme.h:119
void UpdateSecondDerivative(NodesArrayType::iterator itNode) override
Updating second time derivative (acceleration)
Definition: residual_based_bdf_custom_scheme.h:469
ImplicitBaseType::LocalSystemVectorType LocalSystemVectorType
Definition: residual_based_bdf_custom_scheme.h:81
ResidualBasedBDFCustomScheme(ResidualBasedBDFCustomScheme &rOther)
Definition: residual_based_bdf_custom_scheme.h:135
ModelPart::ElementsContainerType ElementsArrayType
Definition: residual_based_bdf_custom_scheme.h:87
KRATOS_CLASS_POINTER_DEFINITION(ResidualBasedBDFCustomScheme)
BaseType::Pointer BaseTypePointer
Definition: residual_based_bdf_custom_scheme.h:91
static std::string Name()
Returns the name of the class as used in the settings (snake_case format)
Definition: residual_based_bdf_custom_scheme.h:388
void Predict(ModelPart &rModelPart, DofsArrayType &rDofSet, TSystemMatrixType &A, TSystemVectorType &Dx, TSystemVectorType &b) override
Performing the prediction of the solution.
Definition: residual_based_bdf_custom_scheme.h:286
~ResidualBasedBDFCustomScheme() override
Definition: residual_based_bdf_custom_scheme.h:154
BaseType::Pointer Create(Parameters ThisParameters) const override
Create method.
Definition: residual_based_bdf_custom_scheme.h:168
ResidualBasedBDFCustomScheme< TSparseSpace, TDenseSpace > ClassType
Definition: residual_based_bdf_custom_scheme.h:69
ImplicitBaseType::TDataType TDataType
Definition: residual_based_bdf_custom_scheme.h:71
int Check(const ModelPart &rModelPart) const override
This function is designed to be called once to perform all the checks needed on the input provided.
Definition: residual_based_bdf_custom_scheme.h:339
std::vector< const Variable< double > * > mSecondDoubleDerivatives
The first derivative double variable to compute.
Definition: residual_based_bdf_custom_scheme.h:438
BaseTypePointer Clone() override
Definition: residual_based_bdf_custom_scheme.h:146
void InitializeSolutionStep(ModelPart &rModelPart, TSystemMatrixType &rA, TSystemVectorType &rDx, TSystemVectorType &rb) override
It initializes time step solution. Only for reasons if the time step solution is restarted.
Definition: residual_based_bdf_custom_scheme.h:227
void Initialize(ModelPart &rModelPart) override
This is the place to initialize the Scheme.
Definition: residual_based_bdf_custom_scheme.h:178
Element::DofsVectorType DofsVectorType
Definition: residual_based_bdf_custom_scheme.h:75
void PrintInfo(std::ostream &rOStream) const override
Print information about this object.
Definition: residual_based_bdf_custom_scheme.h:412
void UpdateFirstDerivative(NodesArrayType::iterator itNode) override
Updating first time derivative (velocity)
Definition: residual_based_bdf_custom_scheme.h:452
std::string Info() const override
Turn back information as a string.
Definition: residual_based_bdf_custom_scheme.h:406
ImplicitBaseType::TSystemVectorType TSystemVectorType
Definition: residual_based_bdf_custom_scheme.h:79
ImplicitBaseType::LocalSystemMatrixType LocalSystemMatrixType
Definition: residual_based_bdf_custom_scheme.h:83
ResidualBasedBDFCustomScheme(Parameters ThisParameters)
Constructor. The BDF method.
Definition: residual_based_bdf_custom_scheme.h:102
std::vector< const Variable< double > * > mDoubleVariable
Definition: residual_based_bdf_custom_scheme.h:436
ModelPart::ConditionsContainerType ConditionsArrayType
Definition: residual_based_bdf_custom_scheme.h:89
Parameters GetDefaultParameters() const override
This method provides the defaults parameters to avoid conflicts between the different constructors.
Definition: residual_based_bdf_custom_scheme.h:368
ResidualBasedBDFScheme< TSparseSpace, TDenseSpace > BDFBaseType
Definition: residual_based_bdf_custom_scheme.h:67
BDF integration scheme (for dynamic problems)
Definition: residual_based_bdf_scheme.h:83
void InitializeSolutionStep(ModelPart &rModelPart, TSystemMatrixType &rA, TSystemVectorType &rDx, TSystemVectorType &rb) override
It initializes time step solution. Only for reasons if the time step solution is restarted.
Definition: residual_based_bdf_scheme.h:236
This is the base class for the implicit time schemes.
Definition: residual_based_implicit_time_scheme.h:55
BaseType::TDataType TDataType
Data type definition.
Definition: residual_based_implicit_time_scheme.h:71
BaseType::TSystemMatrixType TSystemMatrixType
Matrix type definition.
Definition: residual_based_implicit_time_scheme.h:73
BaseType::LocalSystemMatrixType LocalSystemMatrixType
Local system vector type definition.
Definition: residual_based_implicit_time_scheme.h:79
BaseType::LocalSystemVectorType LocalSystemVectorType
Local system matrix type definition.
Definition: residual_based_implicit_time_scheme.h:77
BaseType::TSystemVectorType TSystemVectorType
Vector type definition.
Definition: residual_based_implicit_time_scheme.h:75
This class provides the implementation of the basic tasks that are needed by the solution strategy.
Definition: scheme.h:56
virtual Parameters ValidateAndAssignParameters(Parameters ThisParameters, const Parameters DefaultParameters) const
This method validate and assign default parameters.
Definition: scheme.h:773
virtual void Initialize(ModelPart &rModelPart)
This is the place to initialize the Scheme.
Definition: scheme.h:168
virtual void AssignSettings(const Parameters ThisParameters)
This method assigns settings to member variables.
Definition: scheme.h:786
#define KRATOS_CATCH(MoreInfo)
Definition: define.h:110
#define KRATOS_TRY
Definition: define.h:109
#define KRATOS_ERROR
Definition: exception.h:161
#define KRATOS_CHECK_DOF_IN_NODE(TheVariable, TheNode)
Definition: checks.h:176
#define KRATOS_CHECK_VARIABLE_IN_NODAL_DATA(TheVariable, TheNode)
Definition: checks.h:171
#define KRATOS_WARNING_IF(label, conditional)
Definition: logger.h:266
bool Has(const std::string &ModelerName)
Checks if the modeler is registered.
Definition: modeler_factory.cpp:24
REF: G. R. Cowper, GAUSSIAN QUADRATURE FORMULAS FOR TRIANGLES.
Definition: mesh_condition.cpp:21
int domain_size
Definition: face_heat.py:4
delta_time
Definition: generate_frictional_mortar_condition.py:130
b
Definition: generate_total_lagrangian_mixed_volumetric_strain_element.py:31
int counter
Definition: script_THERMAL_CORRECT.py:218
A
Definition: sensitivityMatrix.py:70
integer i
Definition: TensorModule.f:17