13 #ifndef KRATOS_DISTANCE_SMOOTHING_H
14 #define KRATOS_DISTANCE_SMOOTHING_H
73 template<
unsigned int TDim,
class TSparseSpace,
class TDenseSpace,
class TLinearSolver>
96 typename TLinearSolver::Pointer pLinearSolver,
97 const bool AllConditionsAsBoundary =
true)
99 mrModelPart(rModelPart),
100 mrModel(rModelPart.GetModel()),
101 mAuxModelPartName(
"smoothing_model_part"),
102 mAllConditionsAsBoundary(AllConditionsAsBoundary),
103 mAuxModelPartIsInitialized(false)
106 CreateAuxModelPart();
108 auto p_builder_solver = Kratos::make_shared<ResidualBasedBlockBuilderAndSolver<TSparseSpace, TDenseSpace, TLinearSolver> >(pLinearSolver);
110 CreateSolutionStrategy(p_builder_solver);
116 typename TLinearSolver::Pointer pLinearSolver,
118 const bool AllConditionsAsBoundary =
true)
120 mrModelPart(rModelPart),
121 mrModel(rModelPart.GetModel()),
122 mAuxModelPartName(
"smoothing_model_part"),
123 mAllConditionsAsBoundary(AllConditionsAsBoundary),
124 mAuxModelPartIsInitialized(false)
127 CreateAuxModelPart();
129 CreateSolutionStrategy(pBuilderAndSolver);
139 Parameters[
"all_conditions_as_boundaries"].GetBool()
147 rModel.GetModelPart(
Parameters[
"model_part_name"].GetString()),
165 if(mAuxModelPartIsInitialized ==
false){
166 CreateAuxModelPart();
169 auto& r_smoothing_model_part = mrModel.GetModelPart( mAuxModelPartName );
172 rNode.Free(DISTANCE);
173 const double distance = rNode.FastGetSolutionStepValue(DISTANCE);
174 rNode.FastGetSolutionStepValue(DISTANCE, 1) = distance;
177 mp_solving_strategy->Solve();
180 rNode.SetValue( DISTANCE, rNode.FastGetSolutionStepValue(DISTANCE)
181 - rNode.FastGetSolutionStepValue(DISTANCE, 1) );
184 auto& r_data_comm = r_smoothing_model_part.GetCommunicator().GetDataCommunicator();
187 const unsigned int num_nodes = r_smoothing_model_part.NumberOfNodes();
189 for (
unsigned int i_node = 0; i_node < num_nodes; ++i_node){
190 auto it_node = r_smoothing_model_part.NodesBegin() + i_node;
191 auto& global_pointer_list = it_node->GetValue(NEIGHBOUR_NODES);
193 for (
unsigned int j = 0;
j< global_pointer_list.size(); ++
j)
195 auto& global_pointer = global_pointer_list(
j);
202 auto combined_proxy = pointer_comm.
Apply(
204 return std::make_pair(
205 global_pointer->GetValue(DISTANCE),
206 global_pointer->Coordinates());
209 auto contact_proxy = pointer_comm.
Apply(
212 return global_pointer->Is(CONTACT);
216 auto &r_communicator = r_smoothing_model_part.GetCommunicator();
217 r_communicator.GetDataCommunicator().Barrier();
220 const array_1d<double,3>& x_i = rNode.Coordinates();
223 double dist_diff_avg = 0.0;
225 GlobalPointersVector< Node >& global_pointer_list = rNode.GetValue(NEIGHBOUR_NODES);
226 array_1d<double,3> dx;
228 for (unsigned int j = 0; j< global_pointer_list.size(); ++j)
230 auto& global_pointer = global_pointer_list(j);
232 if (contact_proxy.Get(global_pointer) == rNode.Is(CONTACT)){
234 auto result = combined_proxy.Get(global_pointer);
235 const array_1d<double,3>& x_j = std::get<1>(result);
239 const double distance_ij = norm_2(dx);
242 KRATOS_WARNING_IF(
"DistanceSmoothingProcess", distance_ij < 1.0e-12)
243 <<
"WARNING: Neighbouring nodes are almost coinciding" << std::endl;
246 if (distance_ij > 1.0e-12){
247 weight += 1.0/distance_ij;
248 const double distance_j = std::get<0>(result);
249 dist_diff_avg += distance_j/distance_ij;
256 <<
"WARNING: Correction is not done due to a zero weight" <<std::endl;
259 if (weight > 1.0e-12)
263 r_communicator.SynchronizeCurrentDataToMin(DISTANCE);
270 if(mrModel.HasModelPart( mAuxModelPartName ))
271 mrModel.DeleteModelPart( mAuxModelPartName );
272 mAuxModelPartIsInitialized =
false;
274 mp_solving_strategy->Clear();
294 std::string
Info()
const override
296 std::stringstream buffer;
297 buffer <<
"Distance Smoothing Process" ;
302 void PrintInfo(std::ostream& rOStream)
const override {rOStream <<
"Distance Smoothing Process";}
305 void PrintData(std::ostream& rOStream)
const override {}
323 std::string mAuxModelPartName;
324 bool mAllConditionsAsBoundary;
325 bool mAuxModelPartIsInitialized;
327 typename SolvingStrategyType::UniquePointer mp_solving_strategy;
342 void CreateSolutionStrategy(BuilderSolverPointerType pBuilderAndSolver)
345 auto p_scheme = Kratos::make_shared< ResidualBasedIncrementalUpdateStaticScheme< TSparseSpace,TDenseSpace > >();
347 auto& r_smoothing_model_part = mrModel.
GetModelPart( mAuxModelPartName );
349 const bool calculate_reactions =
false;
350 const bool reform_dof_at_each_iteration =
false;
351 const bool calculate_norm_dx_flag =
false;
353 mp_solving_strategy = Kratos::make_unique<ResidualBasedLinearStrategy<TSparseSpace, TDenseSpace, TLinearSolver> >(
354 r_smoothing_model_part,
358 reform_dof_at_each_iteration,
359 calculate_norm_dx_flag);
361 mp_solving_strategy->Initialize();
362 mp_solving_strategy->SetEchoLevel(0);
363 mp_solving_strategy->
Check();
370 void CreateAuxModelPart()
378 VariableUtils().AddDof<Variable<double> >(DISTANCE, mrModelPart);
381 auto& r_smoothing_model_part = mrModel.
CreateModelPart( mAuxModelPartName );
383 auto p_smoothing_element = Kratos::make_intrusive<DistanceSmoothingElement<TDim>>();
387 ConnectivityPreserveModeler modeler;
388 modeler.GenerateModelPart(mrModelPart, r_smoothing_model_part, *p_smoothing_element);
390 const unsigned int buffer_size = r_smoothing_model_part.GetBufferSize();
391 KRATOS_ERROR_IF(buffer_size < 2) <<
"Buffer size should be at least 2" << std::endl;
393 FindGlobalNodalNeighboursProcess nodal_neighbour_process_new(r_smoothing_model_part);
394 nodal_neighbour_process_new.Execute();
396 GenericFindElementalNeighboursProcess neighbour_elements_finder_new(r_smoothing_model_part);
397 neighbour_elements_finder_new.ExecuteInitialize();
399 if (mAllConditionsAsBoundary)
401 VariableUtils().SetFlag(CONTACT,
true, r_smoothing_model_part.Conditions());
404 mAuxModelPartIsInitialized =
true;
424 DistanceSmoothingProcess() =
delete;
427 DistanceSmoothingProcess&
operator=(DistanceSmoothingProcess
const& rOther) =
delete;
430 DistanceSmoothingProcess(DistanceSmoothingProcess
const& rOther) =
delete;
PeriodicInterfaceProcess & operator=(const PeriodicInterfaceProcess &)=delete
Current class provides an implementation for the base builder and solving operations.
Definition: builder_and_solver.h:64
Definition: distance_smoothing_process.h:75
ImplicitSolvingStrategy< TSparseSpace, TDenseSpace, TLinearSolver > SolvingStrategyType
Definition: distance_smoothing_process.h:86
DistanceSmoothingProcess(ModelPart &rModelPart, typename TLinearSolver::Pointer pLinearSolver, BuilderSolverPointerType pBuilderAndSolver, const bool AllConditionsAsBoundary=true)
Constructor.
Definition: distance_smoothing_process.h:114
DistanceSmoothingProcess(Model &rModel, Parameters Parameters)
Constructor with Kratos model.
Definition: distance_smoothing_process.h:143
DistanceSmoothingProcess(ModelPart &rModelPart, Parameters Parameters)
Constructor with Kratos parameters.
Definition: distance_smoothing_process.h:133
~DistanceSmoothingProcess() override
Destructor.
Definition: distance_smoothing_process.h:152
BuilderAndSolver< TSparseSpace, TDenseSpace, TLinearSolver >::Pointer BuilderSolverPointerType
Definition: distance_smoothing_process.h:85
SchemeType::Pointer SchemePointerType
Definition: distance_smoothing_process.h:84
std::string Info() const override
Turn back information as a string.
Definition: distance_smoothing_process.h:294
void PrintData(std::ostream &rOStream) const override
Print object's data.
Definition: distance_smoothing_process.h:305
Scheme< TSparseSpace, TDenseSpace > SchemeType
Definition: distance_smoothing_process.h:83
KRATOS_CLASS_POINTER_DEFINITION(DistanceSmoothingProcess)
Pointer definition of DistanceSmoothingProcess.
void Execute() override
Execute method is used to execute the Process algorithms.
Definition: distance_smoothing_process.h:161
DistanceSmoothingProcess(ModelPart &rModelPart, typename TLinearSolver::Pointer pLinearSolver, const bool AllConditionsAsBoundary=true)
Constructor.
Definition: distance_smoothing_process.h:94
void PrintInfo(std::ostream &rOStream) const override
Print information about this object.
Definition: distance_smoothing_process.h:302
void Clear() override
This method clears the assignation of the conditions.
Definition: distance_smoothing_process.h:268
A template class for handling communication related to global pointers.
Definition: pointer_communicator.h:178
ResultsProxy< TPointerDataType, TFunctorType > Apply(TFunctorType &&UserFunctor)
Applies a user-provided function to the global pointers and return a proxy to the results.
Definition: pointer_communicator.h:266
This class is a wrapper for a pointer to a data that is located in a different rank.
Definition: global_pointer.h:44
This class is a vector which stores global pointers.
Definition: global_pointers_vector.h:61
void push_back(TPointerType x)
Definition: global_pointers_vector.h:322
Implicit solving strategy base class This is the base class from which we will derive all the implici...
Definition: implicit_solving_strategy.h:61
Here we add the functions needed for the registration of linear solvers.
Definition: linear_solver_factory.h:62
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
virtual int Check() const
run input validation
Definition: model_part.cpp:2204
VariablesList & GetNodalSolutionStepVariablesList()
Definition: model_part.h:549
This class defines the node.
Definition: node.h:65
TVariableType::Type & FastGetSolutionStepValue(const TVariableType &rThisVariable)
Definition: node.h:435
This class provides to Kratos a data structure for I/O based on the standard of JSON.
Definition: kratos_parameters.h:59
The base class for all processes in Kratos.
Definition: process.h:49
This class provides the implementation of the basic tasks that are needed by the solution strategy.
Definition: scheme.h:56
#define KRATOS_CATCH(MoreInfo)
Definition: define.h:110
#define KRATOS_TRY
Definition: define.h:109
#define KRATOS_ERROR_IF(conditional)
Definition: exception.h:162
#define KRATOS_WARNING_IF(label, conditional)
Definition: logger.h:266
Modeler::Pointer Create(const std::string &ModelerName, Model &rModel, const Parameters ModelParameters)
Checks if the modeler is registered.
Definition: modeler_factory.cpp:30
REF: G. R. Cowper, GAUSSIAN QUADRATURE FORMULAS FOR TRIANGLES.
Definition: mesh_condition.cpp:21
void block_for_each(TIterator itBegin, TIterator itEnd, TFunction &&rFunction)
Execute a functor on all items of a range in parallel.
Definition: parallel_utilities.h:299
int j
Definition: quadrature.py:648