13 #if !defined(KRATOS_EDGE_BASED_GRADIENT_RECOVERY_PROCESS_INCLUDED)
14 #define KRATOS_EDGE_BASED_GRADIENT_RECOVERY_PROCESS_INCLUDED
54 template<
class TDataType,
bool TIsHistorical>
55 struct GradientDataHandler final
64 using GradientDataType =
typename std::conditional<IsDataTypeScalar, array_1d<double,3>,
Matrix>
::type;
70 static double GetOrigin(
72 const Variable<TDataType>& rOriginVar,
73 const std::size_t Component = 0);
75 static void SetGradient(
77 const Variable<GradientDataType>& rGradientVar,
78 const array_1d<double,3>& rGradientValue,
79 const std::size_t Component = 0);
85 double GradientDataHandler<double, true>::GetOrigin(
87 const Variable<double>& rOriginVar,
88 const std::size_t Component)
94 double GradientDataHandler<double, false>::GetOrigin(
96 const Variable<double>& rOriginVar,
97 const std::size_t Component)
103 double GradientDataHandler<array_1d<double,3>,
true>::GetOrigin(
105 const Variable<array_1d<double,3>>& rOriginVar,
106 const std::size_t Component)
112 double GradientDataHandler<array_1d<double,3>,
false>::GetOrigin(
114 const Variable<array_1d<double,3>>& rOriginVar,
115 const std::size_t Component)
117 return rNode.
GetValue(rOriginVar)[Component];
121 void GradientDataHandler<double, true>::SetGradient(
123 const Variable<array_1d<double,3>>& rGradientVar,
124 const array_1d<double,3>& rGradientValue,
125 const std::size_t Component)
131 void GradientDataHandler<double, false>::SetGradient(
133 const Variable<array_1d<double,3>>& rGradientVar,
134 const array_1d<double,3>& rGradientValue,
135 const std::size_t Component)
141 void GradientDataHandler<array_1d<double,3>,
true>::SetGradient(
143 const Variable<Matrix>& rGradientVar,
144 const array_1d<double,3>& rGradientComponentValue,
145 const std::size_t Component)
148 if (r_grad.size1() != 3 || r_grad.size2() != 3) {
152 for (std::size_t
i = 0;
i < 3; ++
i) {
153 r_grad(Component,
i) = rGradientComponentValue[
i];
158 void GradientDataHandler<array_1d<double,3>,
false>::SetGradient(
160 const Variable<Matrix>& rGradientVar,
161 const array_1d<double,3>& rGradientComponentValue,
162 const std::size_t Component)
164 auto &r_grad = rNode.
GetValue(rGradientVar);
165 if (r_grad.size1() != 3 || r_grad.size2() != 3) {
169 for (std::size_t
i = 0;
i < 3; ++
i) {
170 r_grad(Component,
i) = rGradientComponentValue[
i];
185 template<
class TDataType,
class TSparseSpace,
class TDenseSpace,
class TLinearSolver>
234 typename TLinearSolver::Pointer pLinearSolver,
238 auto p_builder_solver = Kratos::make_shared< ResidualBasedBlockBuilderAndSolver<TSparseSpace,TDenseSpace,TLinearSolver>>(pLinearSolver);
239 InitializeGradientRecoveryStrategy(p_builder_solver);
262 if (
mSettings[
"is_historical_origin_variable"].GetBool()) {
265 if (
mSettings[
"is_historical_gradient_variable"].GetBool()) {
295 r_process_info.
SetValue(GRADIENT_PENALTY_COEFFICIENT,
mSettings[
"gradient_penalty_coefficient"].GetDouble());
299 if (!
mSettings[
"is_historical_gradient_variable"].GetBool()) {
308 if (
mSettings[
"is_historical_origin_variable"].GetBool()) {
309 origin_value_getter = GradientDataHandler<TDataType, true>::GetOrigin;
311 origin_value_getter = GradientDataHandler<TDataType, false>::GetOrigin;
315 if (
mSettings[
"is_historical_gradient_variable"].GetBool()) {
316 gradient_value_setter = GradientDataHandler<TDataType, true>::SetGradient;
318 gradient_value_setter = GradientDataHandler<TDataType, false>::SetGradient;
322 for (std::size_t
d = 0;
d < n_components; ++
d) {
323 CalculateGradientComponent(origin_value_getter, gradient_value_setter,
d);
329 if (
mSettings[
"reform_gradient_model_part_at_each_step"].GetBool()) {
354 "model_part_name" : "",
355 "gradient_recovery_model_part_name" : "",
356 "origin_variable" : "",
357 "gradient_variable" : "",
358 "gradient_penalty_coefficient" : 1.0e-6,
359 "calculate_nodal_neighbours" : true,
360 "is_historical_origin_variable" : true,
361 "is_historical_gradient_variable": true,
362 "reform_gradient_model_part_at_each_step" : false
365 return default_parameters;
381 std::string
Info()
const override {
382 return "EdgeBasedGradientRecoveryProcess";
387 rOStream <<
"EdgeBasedGradientRecoveryProcess";
445 CheckAndAssignSettings(ThisParameters);
467 for (
const auto& r_orig_node : rOriginModelPart.
Nodes()) {
468 auto p_new_node = r_gradient_mp.
CreateNewNode(r_orig_node.Id(), r_orig_node);
479 if (
mSettings[
"calculate_nodal_neighbours"].GetBool()) {
490 const auto p_prop_0 = r_gradient_mp.CreateNewProperties(0);
492 for (std::size_t i_node = 0; i_node <
n_nodes; ++i_node) {
494 const auto it_node_orig_mp = rOriginModelPart.
NodesBegin() + i_node;
495 auto& r_orig_neigh = it_node_orig_mp->GetValue(NEIGHBOUR_NODES);
496 for (
auto& r_neigh : r_orig_neigh) {
497 if (!r_neigh.Is(VISITED)) {
498 std::vector<std::size_t> aux_ids = {it_node_orig_mp->Id(), r_neigh.Id()};
504 it_node_orig_mp->Set(VISITED,
true);
547 void CheckAndAssignSettings(
const Parameters ThisParameters)
556 KRATOS_ERROR_IF(ThisParameters[
"model_part_name"].GetString() ==
"") <<
"Empty 'model_part_name'. This needs to be provided." << std::endl;
568 "In 2D the element type is expected to be a triangle. Quadrilateral elements require extra artificial edges (not implemented yet)." << std::endl;
571 "In 3D the element type is expected to be a tetrahedra. Hexahedral elements require extra artificial edges (not implemented yet)." << std::endl;
575 if (ThisParameters[
"gradient_recovery_model_part_name"].GetString() ==
"") {
588 bool calculate_norm_dx =
false;
589 bool calculate_reactions =
false;
590 bool reform_dof_at_each_iteration =
false;
591 auto p_scheme = Kratos::make_shared<ResidualBasedIncrementalUpdateStaticScheme<TSparseSpace,TDenseSpace>>();
592 mpSolvingStrategy = Kratos::make_unique<ResidualBasedLinearStrategy<TSparseSpace,TDenseSpace,TLinearSolver>>(
597 reform_dof_at_each_iteration,
604 void CalculateGradientComponent(
607 const std::size_t Component)
611 IndexPartition<std::size_t>(
n_nodes).for_each([&](std::size_t i_node){
614 const double orig_val = rOriginValueGetter(*it_orig_node, *
mpOriginVar, Component);
615 it_grad_node->SetValue(NODAL_MAUX, orig_val);
625 IndexPartition<std::size_t>(
n_nodes).for_each([&](std::size_t i_node){
628 const array_1d<double,3>& grad_val = it_grad_node->FastGetSolutionStepValue(NODAL_VAUX);
629 rGradientValueSetter(*it_orig_node, *
mpGradientVar, grad_val, Component);
660 template <
class TDataType,
class TSparseSpace,
class TDenseSpace,
class TLinearSolver>
662 std::istream& rIStream,
666 template <
class TDataType,
class TSparseSpace,
class TDenseSpace,
class TLinearSolver>
668 std::ostream& rOStream,
672 rOStream << std::endl;
Current class provides an implementation for the base builder and solving operations.
Definition: builder_and_solver.h:64
SizeType GlobalNumberOfNodes() const
Definition: communicator.cpp:101
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
void SetValue(const Variable< TDataType > &rThisVariable, TDataType const &rValue)
Sets the value for a given variable.
Definition: data_value_container.h:320
TDataType & GetValue(const Variable< TDataType > &rThisVariable)
Gets the value associated with a given variable.
Definition: data_value_container.h:268
Edge-based gradient recovery process This process implements the edge-based gradient recovery process...
Definition: edge_based_gradient_recovery_process.h:187
KRATOS_CLASS_POINTER_DEFINITION(EdgeBasedGradientRecoveryProcess)
Pointer definition of EdgeBasedGradientRecoveryProcess.
typename ModelPart::NodeType NodeType
Definition: edge_based_gradient_recovery_process.h:197
bool mModelPartIsInitialized
Definition: edge_based_gradient_recovery_process.h:417
void PrintInfo(std::ostream &rOStream) const override
Print information about this object.
Definition: edge_based_gradient_recovery_process.h:386
std::string mGradientModelPartName
Definition: edge_based_gradient_recovery_process.h:421
virtual void InitializeGradientRecoveryModelPart(ModelPart &rOriginModelPart)
Definition: edge_based_gradient_recovery_process.h:451
void ExecuteFinalize() override
This function is designed for being called at the end of the computations.
Definition: edge_based_gradient_recovery_process.h:334
const Parameters GetDefaultParameters() const override
This method provides the defaults parameters to avoid conflicts between the different constructors.
Definition: edge_based_gradient_recovery_process.h:350
void Execute() override
Execute method is used to execute the Process algorithms.
Definition: edge_based_gradient_recovery_process.h:272
void ExecuteFinalizeSolutionStep() override
This function will be executed at every time step AFTER performing the solve phase.
Definition: edge_based_gradient_recovery_process.h:327
EdgeBasedGradientRecoveryProcess(EdgeBasedGradientRecoveryProcess const &rOther)=delete
Copy constructor.
const Variable< GradientDataType > * mpGradientVar
Definition: edge_based_gradient_recovery_process.h:415
static constexpr bool IsDataTypeScalar
Definition: edge_based_gradient_recovery_process.h:193
ModelPart * mpOriginModelPart
Definition: edge_based_gradient_recovery_process.h:409
~EdgeBasedGradientRecoveryProcess() override
Destructor.
Definition: edge_based_gradient_recovery_process.h:246
std::string Info() const override
Turn back information as a string.
Definition: edge_based_gradient_recovery_process.h:381
int Check() override
This function is designed for being called after ExecuteInitialize ONCE to verify that the input is c...
Definition: edge_based_gradient_recovery_process.h:260
Model & mrModel
Definition: edge_based_gradient_recovery_process.h:407
ModelPart * mpGradientRecoveryModelPart
Definition: edge_based_gradient_recovery_process.h:411
std::function< void(NodeType &rNode, const Variable< GradientDataType > &, const array_1d< double, 3 > &, const std::size_t)> GradientSetFunctionType
Definition: edge_based_gradient_recovery_process.h:208
EdgeBasedGradientRecoveryProcess(Model &rModel, Parameters ThisParameters)
Definition: edge_based_gradient_recovery_process.h:435
void ExecuteInitializeSolutionStep() override
This function will be executed at every time step BEFORE performing the solve phase.
Definition: edge_based_gradient_recovery_process.h:304
void Clear() override
This method clears the assignation of the conditions.
Definition: edge_based_gradient_recovery_process.h:339
const Variable< TDataType > * mpOriginVar
Definition: edge_based_gradient_recovery_process.h:413
void PrintData(std::ostream &rOStream) const override
Print object's data.
Definition: edge_based_gradient_recovery_process.h:391
typename BuilderAndSolver< TSparseSpace, TDenseSpace, TLinearSolver >::Pointer BuilderAndSolverPointerType
Definition: edge_based_gradient_recovery_process.h:212
std::string mElementRegisterName
Definition: edge_based_gradient_recovery_process.h:423
Parameters mSettings
Definition: edge_based_gradient_recovery_process.h:425
SolvingStrategyType::UniquePointer mpSolvingStrategy
Definition: edge_based_gradient_recovery_process.h:419
std::function< double(const NodeType &, const Variable< TDataType > &, const std::size_t)> OriginGetFunctionType
Definition: edge_based_gradient_recovery_process.h:202
void ExecuteInitialize() override
This function is designed for being called at the beginning of the computations right after reading t...
Definition: edge_based_gradient_recovery_process.h:286
EdgeBasedGradientRecoveryProcess(Model &rModel, typename TLinearSolver::Pointer pLinearSolver, Parameters ThisParameters)
Construct a new Edge Based Gradient Recovery Process object Level set convection proces model constru...
Definition: edge_based_gradient_recovery_process.h:232
typename std::conditional< IsDataTypeScalar, array_1d< double, 3 >, Matrix >::type GradientDataType
Definition: edge_based_gradient_recovery_process.h:195
Short class definition.
Definition: find_global_nodal_neighbours_process.h:40
void Execute() override
Execute method is used to execute the Process algorithms.
Definition: find_global_nodal_neighbours_for_entities_process.cpp:76
Implicit solving strategy base class This is the base class from which we will derive all the implici...
Definition: implicit_solving_strategy.h:61
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 different model parts across multi-physics simulations.
Definition: model.h:60
ModelPart & GetModelPart(const std::string &rFullModelPartName)
This method returns a model part given a certain name.
Definition: model.cpp:107
ModelPart & CreateModelPart(const std::string &ModelPartName, IndexType NewBufferSize=1)
This method creates a new model part contained in the current Model with a given name and buffer size...
Definition: model.cpp:37
void DeleteModelPart(const std::string &ModelPartName)
This method deletes a modelpart with a given name.
Definition: model.cpp:64
bool HasModelPart(const std::string &rFullModelPartName) const
This method checks if a certain a model part exists given a certain name.
Definition: model.cpp:178
This class aims to manage meshes for multi-physics simulations.
Definition: model_part.h:77
ElementIterator ElementsBegin(IndexType ThisIndex=0)
Definition: model_part.h:1169
NodeType::Pointer CreateNewNode(int Id, double x, double y, double z, VariablesList::Pointer pNewVariablesList, IndexType ThisIndex=0)
Definition: model_part.cpp:270
Communicator & GetCommunicator()
Definition: model_part.h:1821
std::string & Name()
Definition: model_part.h:1811
NodeIterator NodesBegin(IndexType ThisIndex=0)
Definition: model_part.h:487
void AddNodalSolutionStepVariable(VariableData const &ThisVariable)
Definition: model_part.h:532
ProcessInfo & GetProcessInfo()
Definition: model_part.h:1746
Node NodeType
Definition: model_part.h:117
void Clear()
Definition: model_part.cpp:66
SizeType NumberOfNodes(IndexType ThisIndex=0) const
Definition: model_part.h:341
NodesContainerType & Nodes(IndexType ThisIndex=0)
Definition: model_part.h:507
This class defines the node.
Definition: node.h:65
TVariableType::Type & FastGetSolutionStepValue(const TVariableType &rThisVariable)
Definition: node.h:435
TVariableType::Type & GetValue(const TVariableType &rThisVariable)
Definition: node.h:466
This class provides to Kratos a data structure for I/O based on the standard of JSON.
Definition: kratos_parameters.h:59
void ValidateAndAssignDefaults(const Parameters &rDefaultParameters)
This function is designed to verify that the parameters under testing match the form prescribed by th...
Definition: kratos_parameters.cpp:1306
std::string GetString() const
This method returns the string contained in the current Parameter.
Definition: kratos_parameters.cpp:684
The base class for all processes in Kratos.
Definition: process.h:49
Variable class contains all information needed to store and retrive data from a data container.
Definition: variable.h:63
This class implements a set of auxiliar, already parallelized, methods to perform some common tasks r...
Definition: variable_utils.h:63
int CheckVariableExists(const TVarType &rVariable, const NodesContainerType &rNodes)
Checks if all the nodes of a node set has the specified variable.
Definition: variable_utils.h:1051
void SetNonHistoricalVariableToZero(const Variable< TType > &rVariable, TContainerType &rContainer)
Sets the nodal value of any variable to zero.
Definition: variable_utils.h:724
void AddDof(const TVarType &rVar, ModelPart &rModelPart)
This function add dofs to the nodes in a model part. It is useful since addition is done in parallel.
Definition: variable_utils.h:1361
void SetFlag(const Flags &rFlag, const bool FlagValue, TContainerType &rContainer)
Sets a flag according to a given status over a given container.
Definition: variable_utils.h:900
#define KRATOS_CATCH(MoreInfo)
Definition: define.h:110
#define KRATOS_TRY
Definition: define.h:109
static constexpr bool IsDataTypeScalar
Definition: edge_based_gradient_recovery_process.h:62
#define KRATOS_ERROR_IF_NOT(conditional)
Definition: exception.h:163
#define KRATOS_ERROR_IF(conditional)
Definition: exception.h:162
REF: G. R. Cowper, GAUSSIAN QUADRATURE FORMULAS FOR TRIANGLES.
Definition: mesh_condition.cpp:21
KratosZeroMatrix< double > ZeroMatrix
Definition: amatrix_interface.h:559
Internals::Matrix< double, AMatrix::dynamic, AMatrix::dynamic > Matrix
Definition: amatrix_interface.h:470
std::istream & operator>>(std::istream &rIStream, LinearMasterSlaveConstraint &rThis)
input stream function
T & noalias(T &TheMatrix)
Definition: amatrix_interface.h:484
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
int domain_size
Definition: face_heat.py:4
type
Definition: generate_gid_list_file.py:35
int n_nodes
Definition: generate_total_lagrangian_mixed_volumetric_strain_element.py:15
int d
Definition: ode_solve.py:397
integer i
Definition: TensorModule.f:17