Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DEM]Changing some names according to the comments by Riccardo #3832

Merged
merged 4 commits into from
Jan 16, 2019
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -446,9 +446,11 @@ def PrintResults(self):
self.PrintResultsForGid(self.time)
self.time_old_print = self.time

# TODO: deprecated
def UpdateTimeInModelParts(self):
self.solver.UpdateTimeInModelParts(self.time, self.solver.dt, self.step, self.IsTimeToPrintPostProcess())
self.solver._UpdateTimeInModelParts(self.time, self.solver.dt, self.step, self.IsTimeToPrintPostProcess())

# TODO: deprecated
def UpdateTimeInOneModelPart(self):
pass

Expand All @@ -468,9 +470,9 @@ def InitializeTimeStep(self): # deprecated
self.InitializeSolutionStep()

def InitializeSolutionStep(self):
self.BeforeSolveOperations(self.time)
self._BeforeSolveOperations(self.time)

def BeforeSolveOperations(self, time):
def _BeforeSolveOperations(self, time):
if self.post_normal_impact_velocity_option:
if self.IsCountStep():
self.FillAnalyticSubModelPartsWithNewParticles()
Expand All @@ -482,8 +484,6 @@ def FinalizeSolutionStep(self):
super(DEMAnalysisStage, self).FinalizeSolutionStep()
self.AfterSolveOperations()

self._GetSolver().MoveAllMeshes(self.time, self.solver.dt)

##### adding DEM elements by the inlet ######
if self.DEM_parameters["dem_inlet_option"].GetBool():
self.DEM_inlet.CreateElementsFromInletMesh(self.spheres_model_part, self.cluster_model_part, self.creator_destructor) # After solving, to make sure that neighbours are already set.
Expand Down Expand Up @@ -602,14 +602,13 @@ def InitializeTime(self):
self.time = 0.0
self.time_old_print = 0.0

# TODO: deprecated
def UpdateTimeParameters(self):
self.InitializeSolutionStep()
self.step, self.time = self._GetSolver().AdvanceInTime(self.step, self.time)
self.DEMFEMProcedures.UpdateTimeInModelParts(self.all_model_parts, self.time, self.solver.dt, self.step)

def FinalizeSingleTimeStep(self):
self._GetSolver().MoveAllMeshes(self.time, self.solver.dt)
#DEMFEMProcedures.MoveAllMeshesUsingATable(rigid_face_model_part, time, dt)
##### adding DEM elements by the inlet ######
if self.DEM_parameters["dem_inlet_option"].GetBool():
self.DEM_inlet.CreateElementsFromInletMesh(self.spheres_model_part, self.cluster_model_part, self.creator_destructor) # After solving, to make sure that neighbours are already set.
Expand Down
24 changes: 21 additions & 3 deletions applications/DEMApplication/python_scripts/main_script.py
Original file line number Diff line number Diff line change
Expand Up @@ -431,13 +431,13 @@ def RunMainTemporalLoop(self):

self.UpdateTimeInModelParts()

self.BeforeSolveOperations(self.time)
self._BeforeSolveOperations(self.time)

self.SolverSolve()

self.AfterSolveOperations()

self.solver.MoveAllMeshes(self.time, self.solver.dt)
self.solver._MoveAllMeshes(self.time, self.solver.dt)

##### adding DEM elements by the inlet ######
if self.DEM_parameters["dem_inlet_option"].GetBool():
Expand Down Expand Up @@ -501,7 +501,16 @@ def SetInitialNodalValues(self):
def InitializeTimeStep(self):
pass

#TODO: deprecated
def BeforeSolveOperations(self, time):
message = 'Warning!'
message += '\nFunction \'BeforeSolveOperations\' is deprecated.'
message += '\nPlease call \'_BeforeSolveOperations\' instead.'
message += '\nThe deprecated version will be removed after 02/28/2019.\n'
Logger.PrintWarning("main_script.py", message)
self._BeforeSolveOperations(self, time)

def _BeforeSolveOperations(self, time):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we could leave the old method calling the new one plus printing a big warning on screen (with expiration date), in case someone is still using it from private applications. After some time we completely remove the old version. This is what we are doing in the Kratos core for every api breaker. What do you think?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suppose we dont't need to ensure backward compatibility with other methods

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would follow the same process with all methods that get deprecated. As systematically as possible.

if self.post_normal_impact_velocity_option:
if self.IsCountStep():
self.FillAnalyticSubModelPartsWithNewParticles()
Expand Down Expand Up @@ -610,14 +619,23 @@ def InitializeTime(self):
self.time = 0.0
self.time_old_print = 0.0

#TODO: deprecated
def UpdateTimeParameters(self):
message = 'Warning!'
message += '\nFunction \'UpdateTimeParameters\' is deprecated.'
message += '\nPlease call \'_UpdateTimeParameters\' instead.'
message += '\nThe deprecated version will be removed after 02/28/2019.\n'
Logger.PrintWarning("main_script.py", message)
self._UpdateTimeParameters()

def _UpdateTimeParameters(self):
self.InitializeTimeStep()
self.time = self.time + self.solver.dt
self.step += 1
self.DEMFEMProcedures.UpdateTimeInModelParts(self.all_model_parts, self.time, self.solver.dt, self.step)

def FinalizeSingleTimeStep(self):
self.solver.MoveAllMeshes(self.time, self.solver.dt)
self.solver._MoveAllMeshes(self.time, self.solver.dt)
#DEMFEMProcedures.MoveAllMeshesUsingATable(rigid_face_model_part, time, dt)
##### adding DEM elements by the inlet ######
if self.DEM_parameters["dem_inlet_option"].GetBool():
Expand Down
22 changes: 11 additions & 11 deletions applications/DEMApplication/python_scripts/sphere_strategy.py
Original file line number Diff line number Diff line change
Expand Up @@ -323,11 +323,10 @@ def SolveSolutionStep(self):
def AdvanceInTime(self, step, time, is_time_to_print = False):
step += 1
time += self.dt
self.UpdateTimeInModelParts(time, step, is_time_to_print)
self._UpdateTimeInModelParts(time, step, is_time_to_print)
return step, time

def MoveAllMeshes(self, time, dt):

def _MoveAllMeshes(self, time, dt):
spheres_model_part = self.all_model_parts.Get("SpheresPart")
DEM_inlet_model_part = self.all_model_parts.Get("DEMInletPart")
rigid_face_model_part = self.all_model_parts.Get("RigidFacePart")
Expand All @@ -338,25 +337,26 @@ def MoveAllMeshes(self, time, dt):
self.mesh_motion.MoveAllMeshes(DEM_inlet_model_part, time, dt)
self.mesh_motion.MoveAllMeshes(cluster_model_part, time, dt)

def UpdateTimeInModelParts(self, time, step, is_time_to_print = False):
def _UpdateTimeInModelParts(self, time, step, is_time_to_print = False):
spheres_model_part = self.all_model_parts.Get("SpheresPart")
cluster_model_part = self.all_model_parts.Get("ClusterPart")
DEM_inlet_model_part = self.all_model_parts.Get("DEMInletPart")
rigid_face_model_part = self.all_model_parts.Get("RigidFacePart")

self.UpdateTimeInOneModelPart(spheres_model_part, time, step, is_time_to_print)
self.UpdateTimeInOneModelPart(cluster_model_part, time, step, is_time_to_print)
self.UpdateTimeInOneModelPart(DEM_inlet_model_part, time, step, is_time_to_print)
self.UpdateTimeInOneModelPart(rigid_face_model_part, time, step, is_time_to_print)
self._UpdateTimeInOneModelPart(spheres_model_part, time, step, is_time_to_print)
self._UpdateTimeInOneModelPart(cluster_model_part, time, step, is_time_to_print)
self._UpdateTimeInOneModelPart(DEM_inlet_model_part, time, step, is_time_to_print)
self._UpdateTimeInOneModelPart(rigid_face_model_part, time, step, is_time_to_print)

def UpdateTimeInOneModelPart(self, model_part, time, step, is_time_to_print = False):
def _UpdateTimeInOneModelPart(self, model_part, time, step, is_time_to_print = False):
model_part.ProcessInfo[TIME] = time
model_part.ProcessInfo[DELTA_TIME] = self.dt
model_part.ProcessInfo[TIME_STEPS] = step
model_part.ProcessInfo[IS_TIME_TO_PRINT] = is_time_to_print

def FinalizeSolutionStep(self):
pass
time = self.spheres_model_part.ProcessInfo[TIME]
self._MoveAllMeshes(time, self.dt)

def SetNormalRadiiOnAllParticles(self):
(self.cplusplus_strategy).SetNormalRadiiOnAllParticles(self.spheres_model_part)
Expand All @@ -371,7 +371,7 @@ def Compute_RigidFace_Movement(self):
(self.cplusplus_strategy).Compute_RigidFace_Movement()


def FixDOFsManually(self,time):
def FixDOFsManually(self, time):
#if time>1.0:
#for node in self.spheres_model_part.Nodes:
#node.Fix(VELOCITY_X)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,8 @@ def GetClusterFilename(self):
def GetProblemTypeFilename(self):
return 'benchmark' + str(benchmark_number)

def BeforeSolveOperations(self, time):
super(Solution, self).BeforeSolveOperations(time)
def _BeforeSolveOperations(self, time):
super(Solution, self)._BeforeSolveOperations(time)
benchmark.ApplyNodalRotation(time, self.dt, self.spheres_model_part)

def BeforePrintingOperations(self, time):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,8 @@ def GetClusterFilename(self):
def GetProblemTypeFilename(self):
return 'benchmark' + str(benchmark_number)

def BeforeSolveOperations(self, time):
super(DEMBenchamarksAnalysisStage, self).BeforeSolveOperations(time)
def _BeforeSolveOperations(self, time):
super(DEMBenchamarksAnalysisStage, self)._BeforeSolveOperations(time)
benchmark.ApplyNodalRotation(time, self.solver.dt, self.spheres_model_part)

def BeforePrintingOperations(self, time):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,8 +158,8 @@ def RunSolutionLoop(self):
self.dem_solution.step += 1

self.dem_solution.DEMFEMProcedures.UpdateTimeInModelParts(self.dem_solution.all_model_parts, self.dem_solution.time, self.dem_solution.solver.dt, self.dem_solution.step)
self.dem_solution.BeforeSolveOperations(self.dem_solution.time)

self.dem_solution._BeforeSolveOperations(self.dem_solution.time)

DemFem.InterpolateStructuralSolutionForDEM().InterpolateStructuralSolution(self.structural_mp, self.Dt_structural, self.structural_solution.time, self.dem_solution.time)

Expand All @@ -168,7 +168,7 @@ def RunSolutionLoop(self):
self.dem_solution.AfterSolveOperations()

DemFem.ComputeDEMFaceLoadUtility().CalculateDEMFaceLoads(self.skin_mp, self.dem_solution.solver.dt, self.Dt_structural)

self.dem_solution.DEMFEMProcedures.MoveAllMeshes(self.dem_solution.all_model_parts, self.dem_solution.time, self.dem_solution.solver.dt)
#DEMFEMProcedures.MoveAllMeshesUsingATable(rigid_face_model_part, time, dt)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,9 @@ def RunCoupledSystem():
print('current t: ',dem_analysis.time)

## call dem functions
dem_analysis.UpdateTimeParameters()
dem_analysis._UpdateTimeParameters()

dem_analysis.BeforeSolveOperations(dem_analysis.time)
dem_analysis._BeforeSolveOperations(dem_analysis.time)
dem_analysis.SolverSolve()
dem_analysis.AfterSolveOperations()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,15 +168,15 @@ def SolveSolutionStep(self): # Function to perform the coupling FEM <-> DEM
self.DEM_Solution.solver.dt,
self.DEM_Solution.step,
self.DEM_Solution.IsTimeToPrintPostProcess())
self.DEM_Solution.BeforeSolveOperations(self.DEM_Solution.time)
self.DEM_Solution._BeforeSolveOperations(self.DEM_Solution.time)

#### SOLVE DEM #########################################
self.DEM_Solution.solver.Solve()
########################################################

self.DEM_Solution.AfterSolveOperations()
self.DEM_Solution.DEMFEMProcedures.MoveAllMeshes(self.DEM_Solution.all_model_parts, self.DEM_Solution.time, self.DEM_Solution.dt)

# to print DEM with the FEM coordinates
self.UpdateDEMVariables()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def Initialize(self):
KratosMultiphysics.Logger.PrintInfo("| $$ | $$$$$$$$| $$ \/ | $$| $$$$$$$$| $$$$$$$/| $$$$$$$$| $$ \/ | $$")
KratosMultiphysics.Logger.PrintInfo("|__/ |________/|__/ |__/|________/|_______/ |________/|__/ |__/ 3D Application")
KratosMultiphysics.Logger.PrintInfo("")

#============================================================================================================================
def InitializeSolutionStep(self):

Expand Down Expand Up @@ -110,7 +110,7 @@ def SolveSolutionStep(self):
self.DEM_Solution.step = self.FEM_Solution.step

self.DEM_Solution.DEMFEMProcedures.UpdateTimeInModelParts(self.DEM_Solution.all_model_parts, self.DEM_Solution.time,self.DEM_Solution.solver.dt,self.DEM_Solution.step, self.DEM_Solution.IsTimeToPrintPostProcess(self.DEM_Solution.time))
self.DEM_Solution.BeforeSolveOperations(self.DEM_Solution.time)
self.DEM_Solution._BeforeSolveOperations(self.DEM_Solution.time)

#### SOLVE DEM #########################################
self.DEM_Solution.solver.Solve()
Expand Down