10 #if !defined(KRATOS_ADAPTIVE_TIME_INTERVAL_PROCESS_H_INCLUDED )
11 #define KRATOS_ADAPTIVE_TIME_INTERVAL_PROCESS_H_INCLUDED
73 : mrModelPart(rModelPart)
100 const double initialTimeInterval = rCurrentProcessInfo[INITIAL_DELTA_TIME];
101 const double currentTimeInterval = rCurrentProcessInfo[CURRENT_DELTA_TIME];
103 double updatedTime = rCurrentProcessInfo[TIME];
104 double updatedTimeInterval = rCurrentProcessInfo[DELTA_TIME];
106 double deltaTimeToNewMilestone = initialTimeInterval;
107 double minimumTimeInterval = initialTimeInterval*0.0001;
109 rCurrentProcessInfo.
SetValue(PREVIOUS_DELTA_TIME,currentTimeInterval);
110 rCurrentProcessInfo.SetValue(TIME_INTERVAL_CHANGED,
false);
112 bool milestoneTimeReached=
true;
113 bool increaseTimeInterval=
true;
114 bool timeIntervalReduced=
false;
116 double tolerance=0.0001;
117 updatedTime -= initialTimeInterval;
118 unsigned int previousMilestoneStep=updatedTime/initialTimeInterval;
119 deltaTimeToNewMilestone=initialTimeInterval*(previousMilestoneStep+1)-updatedTime;
121 updatedTimeInterval =currentTimeInterval;
123 bool badVelocityConvergence=rCurrentProcessInfo[BAD_VELOCITY_CONVERGENCE];
124 bool badPressureConvergence=rCurrentProcessInfo[BAD_PRESSURE_CONVERGENCE];
126 if(updatedTimeInterval<2.0*minimumTimeInterval && mEchoLevel > 0 && mrModelPart.
GetCommunicator().
MyPID() == 0){
127 std::cout<<
"ATTENTION! time step much smaller than initial time step, I'll not reduce it"<<std::endl;
130 if((badPressureConvergence==
true || badVelocityConvergence==
true) && updatedTimeInterval>(2.0*minimumTimeInterval)){
131 updatedTimeInterval *=0.5;
133 rCurrentProcessInfo.SetValue(TIME_INTERVAL_CHANGED,
true);
134 timeIntervalReduced=
true;
137 if(deltaTimeToNewMilestone<(1.0+tolerance)*updatedTimeInterval && deltaTimeToNewMilestone>initialTimeInterval*tolerance){
138 rCurrentProcessInfo.SetValue(DELTA_TIME,deltaTimeToNewMilestone);
139 if(deltaTimeToNewMilestone<0.75*updatedTimeInterval){
140 timeIntervalReduced=
true;
141 rCurrentProcessInfo.SetValue(TIME_INTERVAL_CHANGED,
true);
143 updatedTimeInterval =deltaTimeToNewMilestone;
144 milestoneTimeReached=
true;
146 milestoneTimeReached=
false;
147 rCurrentProcessInfo.SetValue(DELTA_TIME,updatedTimeInterval);
150 if(timeIntervalReduced==
false){
152 if(updatedTimeInterval>(2.0*minimumTimeInterval)){
157 if(timeIntervalReduced==
false){
164 if(increaseTimeInterval==
true && initialTimeInterval>(1.0+tolerance)*updatedTimeInterval && badVelocityConvergence==
false ){
165 IncreaseTimeInterval(updatedTimeInterval,deltaTimeToNewMilestone,tolerance,increaseTimeInterval);
168 increaseTimeInterval=
false;
173 double newTimeInterval = rCurrentProcessInfo[DELTA_TIME];
174 double milestoneGap=fabs(newTimeInterval-deltaTimeToNewMilestone);
176 if(milestoneGap<0.49*newTimeInterval && milestoneTimeReached==
false){
178 newTimeInterval+=milestoneGap;
179 rCurrentProcessInfo.SetValue(DELTA_TIME,newTimeInterval);
180 milestoneTimeReached=
true;
183 updatedTime+=newTimeInterval;
184 rCurrentProcessInfo.SetValue(TIME,updatedTime);
185 rCurrentProcessInfo.SetValue(CURRENT_DELTA_TIME,newTimeInterval);
191 if(increaseTimeInterval==
false && milestoneTimeReached==
true && fabs(newTimeInterval-initialTimeInterval)>tolerance && !(deltaTimeToNewMilestone>newTimeInterval*(1.0+tolerance))){
192 rCurrentProcessInfo.SetValue(CURRENT_DELTA_TIME,currentTimeInterval);
196 if (newTimeInterval<initialTimeInterval){
197 std::cout<<
"current time "<<updatedTime<<
" time step: new "<<newTimeInterval<<
" previous "<<currentTimeInterval<<
" initial "<<initialTimeInterval<<
"\n"<<std::endl;
207 bool &increaseTimeInterval,
208 bool &timeIntervalReduced)
220 if(itNode->IsNot(TO_ERASE) && itNode->IsNot(ISOLATED) && itNode->IsNot(SOLID)){
222 double NormVelNode=0;
223 for (
unsigned int d = 0;
d < 3; ++
d){
224 NormVelNode+=Vel[
d] * Vel[
d];
226 double motionInStep=sqrt(NormVelNode)*updatedTimeInterval;
227 double unsafetyFactor=0;
229 for(
auto i_nnode : nNodes)
232 double squaredDistance=0;
233 for (
unsigned int d = 0;
d < 3; ++
d){
234 squaredDistance+=CoorNeighDifference[
d]*CoorNeighDifference[
d];
236 double nodeDistance=sqrt(squaredDistance);
237 double tempUnsafetyFactor=motionInStep/nodeDistance;
238 if(tempUnsafetyFactor>unsafetyFactor){
239 unsafetyFactor=tempUnsafetyFactor;
243 if(unsafetyFactor>0.35){
244 increaseTimeInterval=
false;
245 if(unsafetyFactor>1.0){
246 double temporaryTimeInterval = rCurrentProcessInfo[DELTA_TIME];
247 double reducedTimeInterval=0.5*updatedTimeInterval;
248 if(reducedTimeInterval<temporaryTimeInterval){
249 rCurrentProcessInfo.
SetValue(DELTA_TIME,reducedTimeInterval);
251 rCurrentProcessInfo.
SetValue(TIME_INTERVAL_CHANGED,
true);
252 timeIntervalReduced=
true;
276 double temporaryTimeInterval=rCurrentProcessInfo[DELTA_TIME];
277 double currentElementalArea = 0;
278 const unsigned int dimension = (itElem)->GetGeometry().WorkingSpaceDimension();
280 currentElementalArea = (itElem)->GetGeometry().Area();
282 bool solidElement=
false;
283 for(
unsigned int i=0;
i<itElem->GetGeometry().size(); ++
i)
285 if(itElem->GetGeometry()[
i].Is(SOLID) || itElem->GetGeometry()[
i].Is(TO_ERASE) || itElem->IsNot(ACTIVE)){
289 const array_1d<double,3> &Vel = itElem->GetGeometry()[
i].FastGetSolutionStepValue(VELOCITY);
290 Point updatedNodalCoordinates=itElem->GetGeometry()[
i].
Coordinates()+Vel*temporaryTimeInterval;
291 updatedElementCoordinates.
push_back(Kratos::make_shared<Node >(
i,updatedNodalCoordinates.
X(),updatedNodalCoordinates.
Y(),updatedNodalCoordinates.
Z()));
295 if(itElem->GetGeometry().size()==3){
297 newArea=myGeometry.
Area();
298 }
else if(itElem->GetGeometry().size()==6){
300 newArea=myGeometry.
Area();
302 std::cout<<
"GEOMETRY NOT DEFINED"<<std::endl;
305 if(solidElement==
true){
306 newArea=currentElementalArea;
309 if(newArea<0.001*currentElementalArea && currentElementalArea>0){
310 double reducedTimeInterval=0.5*temporaryTimeInterval;
312 if(reducedTimeInterval<temporaryTimeInterval){
313 rCurrentProcessInfo.
SetValue(DELTA_TIME,reducedTimeInterval);
315 rCurrentProcessInfo.
SetValue(TIME_INTERVAL_CHANGED,
true);
316 increaseTimeInterval=
false;
322 for(
unsigned int i=0;
i<itElem->GetGeometry().size(); ++
i)
324 const array_1d<double,3> &Vel = itElem->GetGeometry()[
i].FastGetSolutionStepValue(VELOCITY);
325 Point updatedNodalCoordinates=itElem->GetGeometry()[
i].
Coordinates()+Vel*temporaryTimeInterval*2.5;
326 updatedEnlargedElementCoordinates.
push_back(Kratos::make_shared<Node >(
i,updatedNodalCoordinates.
X(),updatedNodalCoordinates.
Y(),updatedNodalCoordinates.
Z()));
330 if(itElem->GetGeometry().size()==3){
332 newArea=myGeometry.
Area();
333 }
else if(itElem->GetGeometry().size()==6){
335 newArea=myGeometry.
Area();
337 std::cout<<
"GEOMETRY NOT DEFINED"<<std::endl;
340 if(newArea<0.001*currentElementalArea && currentElementalArea>0){
341 increaseTimeInterval=
false;
348 double currentElementalVolume = (itElem)->GetGeometry().Volume();
350 bool solidElement=
false;
351 for(
unsigned int i=0;
i<itElem->GetGeometry().size(); ++
i)
353 if(itElem->GetGeometry()[
i].Is(SOLID) || itElem->IsNot(ACTIVE)){
356 const array_1d<double,3> &Vel = itElem->GetGeometry()[
i].FastGetSolutionStepValue(VELOCITY);
357 Point updatedNodalCoordinates=itElem->GetGeometry()[
i].
Coordinates()+Vel*temporaryTimeInterval;
358 updatedElementCoordinates.
push_back(Kratos::make_shared<Node >(
i,updatedNodalCoordinates.
X(),updatedNodalCoordinates.
Y(),updatedNodalCoordinates.
Z()));
362 if(itElem->GetGeometry().size()==4){
364 newVolume=myGeometry.
Volume();
365 }
else if(itElem->GetGeometry().size()==10){
367 newVolume=myGeometry.
Volume();
369 std::cout<<
"GEOMETRY NOT DEFINED"<<std::endl;
372 if(solidElement==
true){
373 newVolume=currentElementalVolume;
376 if(newVolume<0.001*currentElementalVolume && currentElementalVolume>0){
377 double reducedTimeInterval=0.5*temporaryTimeInterval;
379 if(reducedTimeInterval<temporaryTimeInterval){
380 rCurrentProcessInfo.
SetValue(DELTA_TIME,reducedTimeInterval);
382 rCurrentProcessInfo.
SetValue(TIME_INTERVAL_CHANGED,
true);
383 increaseTimeInterval=
false;
389 for(
unsigned int i=0;
i<itElem->GetGeometry().size(); ++
i)
391 const array_1d<double,3> &Vel = itElem->GetGeometry()[
i].FastGetSolutionStepValue(VELOCITY);
392 Point updatedNodalCoordinates=itElem->GetGeometry()[
i].
Coordinates()+Vel*temporaryTimeInterval*2.5;
393 updatedEnlargedElementCoordinates.
push_back(Kratos::make_shared<Node >(
i,updatedNodalCoordinates.
X(),updatedNodalCoordinates.
Y(),updatedNodalCoordinates.
Z()));
396 if(itElem->GetGeometry().size()==4){
398 newVolume=myGeometry.
Volume();
399 }
else if(itElem->GetGeometry().size()==10){
401 newVolume=myGeometry.
Volume();
403 std::cout<<
"GEOMETRY NOT DEFINED"<<std::endl;
406 if(newVolume<0.001*currentElementalVolume && currentElementalVolume>0){
407 increaseTimeInterval=
false;
424 double deltaTimeToNewMilestone,
426 bool &increaseTimeInterval)
430 double increasedTimeInterval = 2.0 * updatedTimeInterval;
432 if(increasedTimeInterval<deltaTimeToNewMilestone*(1.0+tolerance))
434 rCurrentProcessInfo.
SetValue(DELTA_TIME,increasedTimeInterval);
435 rCurrentProcessInfo.
SetValue(TIME_INTERVAL_CHANGED,
true);
438 increaseTimeInterval=
false;
464 std::string
Info()
const override
466 return "AdaptiveTimeIntervalProcess";
472 rOStream <<
"AdaptiveTimeIntervalProcess";
557 rOStream << std::endl;
Short class definition.
Definition: adaptive_time_interval_process.hpp:58
AdaptiveTimeIntervalProcess(ModelPart &rModelPart, int EchoLevel)
Default constructor.
Definition: adaptive_time_interval_process.hpp:71
void CheckElementalConditionForTimeStepReduction(bool &increaseTimeInterval)
Definition: adaptive_time_interval_process.hpp:264
void PrintInfo(std::ostream &rOStream) const override
Print information about this object.
Definition: adaptive_time_interval_process.hpp:470
std::string Info() const override
Turn back information as a string.
Definition: adaptive_time_interval_process.hpp:464
KRATOS_CLASS_POINTER_DEFINITION(AdaptiveTimeIntervalProcess)
Pointer definition of AdaptiveTimeIntervalProcess.
void IncreaseTimeInterval(double updatedTimeInterval, double deltaTimeToNewMilestone, double tolerance, bool &increaseTimeInterval)
Definition: adaptive_time_interval_process.hpp:423
void CheckNodalConditionForTimeStepReduction(double updatedTimeInterval, bool &increaseTimeInterval, bool &timeIntervalReduced)
Definition: adaptive_time_interval_process.hpp:206
void operator()()
Definition: adaptive_time_interval_process.hpp:83
virtual ~AdaptiveTimeIntervalProcess()
Destructor.
Definition: adaptive_time_interval_process.hpp:79
void Execute() override
Execute method is used to execute the Process algorithms.
Definition: adaptive_time_interval_process.hpp:93
virtual int MyPID() const
Definition: communicator.cpp:91
void SetValue(const Variable< TDataType > &rThisVariable, TDataType const &rValue)
Sets the value for a given variable.
Definition: data_value_container.h:320
Geometry base class.
Definition: geometry.h:71
void push_back(PointPointerType x)
Definition: geometry.h:548
PointerVector< TPointType > PointsArrayType
Definition: geometry.h:118
This class is a vector which stores global pointers.
Definition: global_pointers_vector.h:61
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
MeshType::ElementsContainerType ElementsContainerType
Element container. A vector set of Elements with their Id's as key.
Definition: model_part.h:168
Communicator & GetCommunicator()
Definition: model_part.h:1821
ProcessInfo & GetProcessInfo()
Definition: model_part.h:1746
MeshType::NodeIterator NodeIterator
Definition: model_part.h:134
ElementsContainerType & Elements(IndexType ThisIndex=0)
Definition: model_part.h:1189
MeshType::NodesContainerType NodesContainerType
Nodes container. Which is a vector set of nodes with their Id's as key.
Definition: model_part.h:128
MeshType::ElementIterator ElementIterator
Definition: model_part.h:174
NodesContainerType & Nodes(IndexType ThisIndex=0)
Definition: model_part.h:507
static void PartitionedIterators(TVector &rVector, typename TVector::iterator &rBegin, typename TVector::iterator &rEnd)
Generate a partition for an std::vector-like array, providing iterators to the begin and end position...
Definition: openmp_utils.h:179
Point class.
Definition: point.h:59
CoordinatesArrayType const & Coordinates() const
Definition: point.h:215
double Y() const
Definition: point.h:187
double Z() const
Definition: point.h:193
double X() const
Definition: point.h:181
The base class for all processes in Kratos.
Definition: process.h:49
void PrintData(std::ostream &rOStream) const override
Print object's data.
Definition: process.h:210
ProcessInfo holds the current value of different solution parameters.
Definition: process_info.h:59
A ten node tetrahedra geometry with quadratic shape functions.
Definition: tetrahedra_3d_10.h:75
double Volume() const override
This method calculate and return volume of this geometry.
Definition: tetrahedra_3d_10.h:411
A four node tetrahedra geometry with linear shape functions.
Definition: tetrahedra_3d_4.h:59
double Volume() const override
Definition: tetrahedra_3d_4.h:450
A three node 2D triangle geometry with linear shape functions.
Definition: triangle_2d_3.h:74
double Area() const override
Definition: triangle_2d_3.h:483
A six node 2D triangular geometry with quadratic shape functions.
Definition: triangle_2d_6.h:68
double Area() const override
This method calculates and returns area or surface area of this geometry depending to it's dimension.
Definition: triangle_2d_6.h:471
#define KRATOS_CATCH(MoreInfo)
Definition: define.h:110
#define KRATOS_TRY
Definition: define.h:109
static int EchoLevel
Definition: co_sim_EMPIRE_API.h:42
REF: G. R. Cowper, GAUSSIAN QUADRATURE FORMULAS FOR TRIANGLES.
Definition: mesh_condition.cpp:21
ModelPart::NodesContainerType NodesContainerType
Definition: find_conditions_neighbours_process.h:44
GlobalPointersVector< Node > NodeWeakPtrVectorType
Definition: build_model_part_boundary_process.hpp:59
std::istream & operator>>(std::istream &rIStream, LinearMasterSlaveConstraint &rThis)
input stream function
ModelPart::ElementsContainerType ElementsContainerType
Definition: clear_contact_conditions_mesher_process.hpp:43
std::ostream & operator<<(std::ostream &rOStream, const LinearMasterSlaveConstraint &rThis)
output stream function
Definition: linear_master_slave_constraint.h:432
GeometryType::PointsArrayType PointsArrayType
Definition: settle_model_structure_process.hpp:48
int dimension
Definition: isotropic_damage_automatic_differentiation.py:123
int d
Definition: ode_solve.py:397
integer i
Definition: TensorModule.f:17