16 #if !defined(KRATOS_VARIATIONAL_DISTANCE_CALCULATION_PROCESS_INCLUDED )
17 #define KRATOS_VARIATIONAL_DISTANCE_CALCULATION_PROCESS_INCLUDED
68 template<
unsigned int TDim,
class TSparseSpace,
class TDenseSpace,
class TLinearSolver >
125 typename TLinearSolver::Pointer pLinearSolver,
126 unsigned int MaxIterations = 10,
127 Flags Options = CALCULATE_EXACT_DISTANCES_TO_PLANE.
AsFalse(),
128 std::string AuxPartName =
"RedistanceCalculationPart",
129 double Coefficient1 = 0.01,
130 double Coefficient2 = 0.1)
134 mrModel( rBaseModelPart.GetModel() ),
148 auto p_builder_solver = Kratos::make_shared<ResidualBasedBlockBuilderAndSolver<TSparseSpace, TDenseSpace, TLinearSolver> >(pLinearSolver);
166 typename TLinearSolver::Pointer pLinearSolver,
168 unsigned int MaxIterations = 10,
169 Flags Options = CALCULATE_EXACT_DISTANCES_TO_PLANE.
AsFalse(),
170 std::string AuxPartName =
"RedistanceCalculationPart",
171 double Coefficient1 = 0.01,
172 double Coefficient2 = 0.1)
176 mrModel( rBaseModelPart.GetModel() ),
232 double& d = rNode.FastGetSolutionStepValue(DISTANCE);
235 rNode.Free(DISTANCE);
237 rNode.Set(BLOCKED, false);
240 rNode.SetValue(DISTANCE, d);
244 rNode.Set(BLOCKED, true);
255 block_for_each(r_distance_model_part.Elements(), [
this](Element& rElem){
256 array_1d<double,TDim+1> distances;
257 auto& geom = rElem.GetGeometry();
259 for(unsigned int i=0; i<TDim+1; i++){
260 distances[i] = geom[i].GetValue(DISTANCE);
263 const array_1d<double,TDim+1> original_distances = distances;
266 if(this->IsSplit(distances)){
268 if (mOptions.Is(CALCULATE_EXACT_DISTANCES_TO_PLANE)) {
269 GeometryUtils::CalculateExactDistancesToPlane(geom, distances);
272 if constexpr (TDim==3){
273 GeometryUtils::CalculateTetrahedraDistances(geom, distances);
276 GeometryUtils::CalculateTriangleDistances(geom, distances);
281 for(
unsigned int i = 0;
i < TDim+1; ++
i){
282 if(original_distances[
i] < 0){
283 distances[
i] = -distances[
i];
287 for(
unsigned int i = 0;
i < TDim+1; ++
i){
288 double &
d = geom[
i].FastGetSolutionStepValue(DISTANCE);
290 if(std::abs(
d) > std::abs(distances[
i])){
293 geom[
i].Set(BLOCKED,
true);
294 geom[
i].Fix(DISTANCE);
301 this->SynchronizeFixity();
302 this->SynchronizeDistance();
305 double max_dist = 0.0;
306 double min_dist = 0.0;
307 for(
int i_node = 0; i_node <
nnodes; ++i_node){
308 auto it_node = r_distance_model_part.NodesBegin() + i_node;
309 if(it_node->IsFixed(DISTANCE)){
310 const double&
d = it_node->FastGetSolutionStepValue(DISTANCE);
321 const auto &r_communicator = r_distance_model_part.GetCommunicator().GetDataCommunicator();
322 max_dist = r_communicator.MaxAll(max_dist);
323 min_dist = r_communicator.MinAll(min_dist);
327 block_for_each(r_distance_model_part.Nodes(), [&min_dist, &max_dist](Node& rNode){
328 if(!rNode.IsFixed(DISTANCE)){
329 double& d = rNode.FastGetSolutionStepValue(DISTANCE);
337 mpSolvingStrategy->Solve();
340 r_distance_model_part.pGetProcessInfo()->SetValue(FRACTIONAL_STEP,2);
341 for(
unsigned int it = 0; it<mMaxIterations; it++){
342 mpSolvingStrategy->Solve();
346 VariableUtils().ApplyFixity(DISTANCE,
false, r_distance_model_part.Nodes());
347 VariableUtils().SetFlag(BOUNDARY,
false, r_distance_model_part.Nodes());
348 VariableUtils().SetFlag(BLOCKED,
false, r_distance_model_part.Nodes());
355 if(mrModel.HasModelPart( mAuxModelPartName ))
356 mrModel.DeleteModelPart( mAuxModelPartName );
357 mDistancePartIsInitialized =
false;
359 mpSolvingStrategy->Clear();
376 std::string
Info()
const override
378 return "VariationalDistanceCalculationProcess";
384 rOStream <<
"VariationalDistanceCalculationProcess";
433 if (num_elements > 0)
435 const auto geometry_family = mrBaseModelPart.
ElementsBegin()->GetGeometry().GetGeometryFamily();
436 KRATOS_ERROR_IF( (TDim == 2) && (geometry_family != GeometryData::KratosGeometryFamily::Kratos_Triangle) )
437 <<
"In 2D the element type is expected to be a triangle." << std::endl;
438 KRATOS_ERROR_IF( (TDim == 3) && (geometry_family != GeometryData::KratosGeometryFamily::Kratos_Tetrahedra) )
439 <<
"In 3D the element type is expected to be a tetrahedron" << std::endl;
442 KRATOS_ERROR_IF(r_comm.SumAll(num_nodes) == 0) <<
"The model part has no nodes." << std::endl;
443 KRATOS_ERROR_IF(r_comm.SumAll(num_elements) == 0) <<
"The model Part has no elements." << std::endl;
452 auto p_scheme = Kratos::make_shared< ResidualBasedIncrementalUpdateStaticScheme< TSparseSpace,TDenseSpace > >();
456 bool CalculateReactions =
false;
458 bool CalculateNormDxFlag =
false;
460 mpSolvingStrategy = Kratos::make_unique<ResidualBasedLinearStrategy<TSparseSpace, TDenseSpace, TLinearSolver> >(
461 r_distance_model_part,
466 CalculateNormDxFlag);
469 mpSolvingStrategy->Check();
485 Element::Pointer p_distance_element = Kratos::make_intrusive<DistanceCalculationElementSimplex<TDim> >();
490 modeler.
GenerateModelPart(rBaseModelPart, r_distance_model_part, *p_distance_element);
499 for(
unsigned int i=0;
i<geom.
size();
i++){
500 geom[
i].Set(BOUNDARY,
true);
506 r_distance_model_part.GetProcessInfo().SetValue(VARIATIONAL_REDISTANCE_COEFFICIENT_FIRST, mCoefficient1);
507 r_distance_model_part.GetProcessInfo().SetValue(VARIATIONAL_REDISTANCE_COEFFICIENT_SECOND, mCoefficient2);
509 mDistancePartIsInitialized =
true;
544 unsigned int positives = 0, negatives = 0;
546 for(
unsigned int i = 0;
i < TDim+1; ++
i){
547 if(rDistances[
i] >= 0){
554 if (positives > 0 && negatives > 0){
561 void SynchronizeDistance(){
566 if(r_communicator.TotalProcesses() != 1){
567 int nnodes =
static_cast<int>(r_distance_model_part.NumberOfNodes());
570 #pragma omp parallel for
571 for(
int i_node = 0; i_node <
nnodes; ++i_node){
572 auto it_node = r_distance_model_part.NodesBegin() + i_node;
573 it_node->FastGetSolutionStepValue(DISTANCE) = std::abs(it_node->FastGetSolutionStepValue(DISTANCE));
577 r_communicator.SynchronizeCurrentDataToMin(DISTANCE);
580 #pragma omp parallel for
581 for(
int i_node = 0; i_node <
nnodes; ++i_node){
582 auto it_node = r_distance_model_part.NodesBegin() + i_node;
583 if(it_node->GetValue(DISTANCE) < 0.0){
584 it_node->FastGetSolutionStepValue(DISTANCE) = -it_node->FastGetSolutionStepValue(DISTANCE);
590 void SynchronizeFixity(){
595 if(r_communicator.TotalProcesses() != 1){
596 int nnodes =
static_cast<int>(r_distance_model_part.NumberOfNodes());
600 r_communicator.SynchronizeOrNodalFlags(BLOCKED);
603 #pragma omp parallel for
604 for(
int i_node = 0; i_node <
nnodes; ++i_node){
605 auto it_node = r_distance_model_part.NodesBegin() + i_node;
606 if (it_node->Is(BLOCKED)){
607 it_node->Fix(DISTANCE);
626 VariationalDistanceCalculationProcess&
operator=(VariationalDistanceCalculationProcess
const& rOther);
635 template<
unsigned int TDim,
class TSparseSpace,
class TDenseSpace,
class TLinearSolver >
638 template<
unsigned int TDim,
class TSparseSpace,
class TDenseSpace,
class TLinearSolver >
641 template<
unsigned int TDim,
class TSparseSpace,
class TDenseSpace,
class TLinearSolver >
656 template<
unsigned int TDim,
class TSparseSpace,
class TDenseSpace,
class TLinearSolver>
661 template<
unsigned int TDim,
class TSparseSpace,
class TDenseSpace,
class TLinearSolver>
666 rOStream << std::endl;
PeriodicInterfaceProcess & operator=(const PeriodicInterfaceProcess &)=delete
Current class provides an implementation for the base builder and solving operations.
Definition: builder_and_solver.h:64
virtual bool SynchronizeOrNodalFlags(const Flags &TheFlags)
Definition: communicator.cpp:623
virtual const DataCommunicator & GetDataCommunicator() const
Definition: communicator.cpp:340
A tool to generate a copy of a ModelPart, sharing the same nodes as the original.
Definition: connectivity_preserve_modeler.h:41
void GenerateModelPart(ModelPart &OriginModelPart, ModelPart &DestinationModelPart, const Element &rReferenceElement, const Condition &rReferenceBoundaryCondition) override
Generate a copy of rOriginModelPart in rDestinationModelPart, using the given element and condtion ty...
Definition: connectivity_preserve_modeler.cpp:27
Serial (do-nothing) version of a wrapper class for MPI communication.
Definition: data_communicator.h:318
Flags AsFalse() const
Definition: flags.h:241
static Flags Create(IndexType ThisPosition, bool Value=true)
Definition: flags.h:138
Geometry base class.
Definition: geometry.h:71
SizeType size() const
Definition: geometry.h:518
Implicit solving strategy base class This is the base class from which we will derive all the implici...
Definition: implicit_solving_strategy.h:61
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
ConditionIterator ConditionsBegin(IndexType ThisIndex=0)
Definition: model_part.h:1361
ProcessInfo::Pointer pGetProcessInfo()
Definition: model_part.h:1756
Communicator & GetCommunicator()
Definition: model_part.h:1821
SizeType NumberOfElements(IndexType ThisIndex=0) const
Definition: model_part.h:1027
SizeType NumberOfNodes(IndexType ThisIndex=0) const
Definition: model_part.h:341
NodesContainerType & Nodes(IndexType ThisIndex=0)
Definition: model_part.h:507
VariablesList & GetNodalSolutionStepVariablesList()
Definition: model_part.h:549
ConditionIterator ConditionsEnd(IndexType ThisIndex=0)
Definition: model_part.h:1371
This class defines the node.
Definition: node.h:65
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
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
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 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
Short class definition.
Definition: variational_distance_calculation_process.h:70
bool mDistancePartIsInitialized
Definition: variational_distance_calculation_process.h:406
KRATOS_DEFINE_LOCAL_FLAG(DO_EXPENSIVE_CHECKS)
SolvingStrategyType::UniquePointer mpSolvingStrategy
Definition: variational_distance_calculation_process.h:417
unsigned int mMaxIterations
Definition: variational_distance_calculation_process.h:407
std::string mAuxModelPartName
Definition: variational_distance_calculation_process.h:412
void PrintData(std::ostream &rOStream) const override
Print object's data.
Definition: variational_distance_calculation_process.h:388
KRATOS_DEFINE_LOCAL_FLAG(CALCULATE_EXACT_DISTANCES_TO_PLANE)
std::string Info() const override
Turn back information as a string.
Definition: variational_distance_calculation_process.h:376
BuilderAndSolver< TSparseSpace, TDenseSpace, TLinearSolver >::Pointer BuilderSolverPointerType
Definition: variational_distance_calculation_process.h:82
Model & mrModel
Definition: variational_distance_calculation_process.h:409
VariationalDistanceCalculationProcess(ModelPart &rBaseModelPart, typename TLinearSolver::Pointer pLinearSolver, unsigned int MaxIterations=10, Flags Options=CALCULATE_EXACT_DISTANCES_TO_PLANE.AsFalse(), std::string AuxPartName="RedistanceCalculationPart", double Coefficient1=0.01, double Coefficient2=0.1)
Definition: variational_distance_calculation_process.h:123
void Execute() override
Execute method is used to execute the Process algorithms.
Definition: variational_distance_calculation_process.h:214
double mCoefficient1
Definition: variational_distance_calculation_process.h:414
void PrintInfo(std::ostream &rOStream) const override
Print information about this object.
Definition: variational_distance_calculation_process.h:382
void operator()()
Definition: variational_distance_calculation_process.h:205
virtual void ReGenerateDistanceModelPart(ModelPart &rBaseModelPart)
Definition: variational_distance_calculation_process.h:472
VariationalDistanceCalculationProcess(ModelPart &rBaseModelPart, typename TLinearSolver::Pointer pLinearSolver, BuilderSolverPointerType pBuilderAndSolver, unsigned int MaxIterations=10, Flags Options=CALCULATE_EXACT_DISTANCES_TO_PLANE.AsFalse(), std::string AuxPartName="RedistanceCalculationPart", double Coefficient1=0.01, double Coefficient2=0.1)
Constructor with custom Builder And Solver.
Definition: variational_distance_calculation_process.h:164
void ValidateInput()
Definition: variational_distance_calculation_process.h:427
Flags mOptions
Definition: variational_distance_calculation_process.h:411
~VariationalDistanceCalculationProcess() override
Destructor.
Definition: variational_distance_calculation_process.h:196
ImplicitSolvingStrategy< TSparseSpace, TDenseSpace, TLinearSolver > SolvingStrategyType
Definition: variational_distance_calculation_process.h:83
KRATOS_CLASS_POINTER_DEFINITION(VariationalDistanceCalculationProcess)
Pointer definition of VariationalDistanceCalculationProcess.
ModelPart & mrBaseModelPart
Definition: variational_distance_calculation_process.h:410
double mCoefficient2
Definition: variational_distance_calculation_process.h:415
KRATOS_DEFINE_LOCAL_FLAG(PERFORM_STEP1)
Scheme< TSparseSpace, TDenseSpace > SchemeType
Definition: variational_distance_calculation_process.h:80
void Clear() override
This method clears the assignation of the conditions.
Definition: variational_distance_calculation_process.h:353
void InitializeSolutionStrategy(BuilderSolverPointerType pBuilderAndSolver)
Definition: variational_distance_calculation_process.h:449
SchemeType::Pointer SchemePointerType
Definition: variational_distance_calculation_process.h:81
#define KRATOS_CATCH(MoreInfo)
Definition: define.h:110
#define KRATOS_TRY
Definition: define.h:109
std::ostream & operator<<(std::ostream &rOStream, const VariationalDistanceCalculationProcess< TDim, TSparseSpace, TDenseSpace, TLinearSolver > &rThis)
output stream function
Definition: variational_distance_calculation_process.h:662
std::istream & operator>>(std::istream &rIStream, VariationalDistanceCalculationProcess< TDim, TSparseSpace, TDenseSpace, TLinearSolver > &rThis)
input stream function
#define KRATOS_ERROR_IF(conditional)
Definition: exception.h:162
Kratos::ModelPart ModelPart
Definition: kratos_wrapper.h:31
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 d
Definition: ode_solve.py:397
int nnodes
Definition: sensitivityMatrix.py:24
integer i
Definition: TensorModule.f:17
ReformDofAtEachIteration
Definition: test_pureconvectionsolver_benchmarking.py:131