Python Script Tutorial: Main Solution

From KratosWiki
Revision as of 19:25, 9 May 2012 by Jcotela (Talk | contribs)
Jump to: navigation, search

Dynamic solution

In more dynamic problems, we will want to iterate over time. We do this from the main Python file, looping over time steps. An example of this can be seen in this Kratos example.

The part we are interested in is at the end of the file, after we have read the model part and initialized a solver.

Dt = 0.02
nsteps = 101

gid_io.InitializeResults(mesh_name,(model_part).GetMesh())

for step in range(0,nsteps):
  time = Dt*step
  model_part.CloneTimeStep(time)
 
  if(step > 3):
    solver.Solve()
    gid_io.WriteNodalResults(DISPLACEMENT,model_part.Nodes,time,0)
    gid_io.PrintOnGaussPoints(PK2_STRESS_TENSOR,model_part,time)
gid_io.FinalizeResults()

Ignoring the output-specific parts of the code, which have already been explained in a previous tutorial, this code block is defining a time step and a number of steps, and looping over the time steps

Dt = 0.02
nsteps = 101

...

for step in range(0,nsteps):

At every time step, it updates the current time and creates a new solution step, advancing the nodal solution step data to a new iteration

  time = Dt*step
  model_part.CloneTimeStep(time)

It then skips some time steps, in order to have a full set of nodal solution step data once it starts iterating

  if(step > 3):

And, once we have enough previous time steps to use the time iteration scheme, it calls the solver

    solver.Solve()

Once the solver is finished, it prints the results and advances to the next step.

Previous Tutorial : Python Script Tutorial: Using Kratos Solvers

Personal tools
Categories