Unable to save/reload FlowEngine scene

Asked by Robert Caulk on 2019-09-06

Hey Yade community,

I am unable to save and reload a FlowEngine based scene. I reproduce the error here using the save-then-reload.py [1] as an example for modifying oedometer.py [2].

___The error is as follows:___

>>
GS : j=0 p_moy=-nan dp_moy=-nan
GS iterations : 0
totalForce = 0 0 0
>>

This error suggests that the scene is improperly loaded, considering these GS errors are associated with flow.useSolver=0 [3] (meanwhile the script defines flow.useSolver=3). Further, I've tried re-defining all the flow properties, such as flow.useSolver=3, again after O.load() and before O.run(), but the error does not change. My first thought is that FlowBoundingSphere/Linsolv is not serializable, and therefore we lose all information from the solver class during save/reload. Any ideas?

____The MWE is as follows:____

from __future__ import print_function
from builtins import range
from yade import pack

num_spheres=1000# number of spheres
young=1e6
compFricDegree = 3 # initial contact friction during the confining phase
finalFricDegree = 30 # contact friction during the deviatoric loading
mn,mx=Vector3(0,0,0),Vector3(1,1,1) # corners of the initial packing

O.materials.append(FrictMat(young=young,poisson=0.5,frictionAngle=radians(compFricDegree),density=2600,label='spheres'))
O.materials.append(FrictMat(young=young,poisson=0.5,frictionAngle=0,density=0,label='walls'))
walls=aabbWalls([mn,mx],thickness=0,material='walls')
wallIds=O.bodies.append(walls)

import os.path
savedState = os.path.exists('oedometer_state.yade.gz')

if not savedState:

 sp=pack.SpherePack()
 sp.makeCloud(mn,mx,-1,0.3333,num_spheres,False, 0.95,seed=1) #"seed" make the "random" generation always the same
 sp.toSimulation(material='spheres')

 O.engines=[
  ForceResetter(),
  InsertionSortCollider([Bo1_Sphere_Aabb(),Bo1_Box_Aabb()]),
  InteractionLoop(
   [Ig2_Sphere_Sphere_ScGeom(),Ig2_Box_Sphere_ScGeom()],
   [Ip2_FrictMat_FrictMat_FrictPhys()],
   [Law2_ScGeom_FrictPhys_CundallStrack()],label="iloop"
  ),
  FlowEngine(dead=1,label="flow"), GlobalStiffnessTimeStepper(active=1,timeStepUpdateInterval=100,timestepSafetyCoefficient=0.8),
  TriaxialStressController(maxMultiplier=1.+2e4/young, finalMaxMultiplier=1.+2e3/young, thickness = 0,stressMask = 7,max_vel = 0.005,internalCompaction=True,label='triax'),
  NewtonIntegrator(damping=0.2,label='newton')
 ]

 triax.goal1=triax.goal2=triax.goal3=-10000

if not savedState:
 while 1:
   O.run(1000, True)
   unb=unbalancedForce()
   if unb<0.001 and abs(-10000-triax.meanStress)/10000<0.001:
     break

 setContactFriction(radians(finalFricDegree))

 #B. Activate flow engine and set boundary conditions in order to get permeability
 flow.dead=0
 flow.defTolerance=0.3
 flow.meshUpdateInterval=200
 flow.useSolver=3
 flow.permeabilityFactor=1
 flow.viscosity=10
 flow.bndCondIsPressure=[0,0,1,1,0,0]
 flow.bndCondValue=[0,0,1,0,0,0]
 flow.boundaryUseMaxMin=[0,0,0,0,0,0]
 O.dt=0.1e-3
 O.dynDt=False

 O.run(1,1)
 Qin = flow.getBoundaryFlux(2)
 Qout = flow.getBoundaryFlux(3)
 permeability = abs(Qin)/1.e-4 #size is one, we compute K=V/∇H
 print("Qin=",Qin," Qout=",Qout," permeability=",permeability)

 #C. now the oedometer test, drained at the top, impermeable at the bottom plate
 flow.bndCondIsPressure=[0,0,0,1,0,0]
 flow.bndCondValue=[0,0,0,0,0,0]
 flow.updateTriangulation=True #force remeshing to reflect new BC immediately
 newton.damping=0

 triax.goal2=-11000
 O.run(1000,1)
 print('saving oedometer state with pore pressure at',flow.getPorePressure((0.5,0.1,0.5)))
 O.save('oedometer_state.yade.gz')
else:
 O.load('oedometer_state.yade.gz')
 print('loaded oedometer state with pore pressure at',flow.getPorePressure((0.5,0.1,0.5)))
 O.run(100,1)

from yade import plot

def history():
 plot.addData(t=O.time,p=flow.getPorePressure((0.5,0.1,0.5)),s22=-triax.stress(3)[1]-10000)

O.engines=O.engines+[PyRunner(iterPeriod=200,command='history()',label='recorder')]

from yade import plot
plot.plots={'t':('p')}
plot.plot()

[1]https://gitlab.com/yade-dev/trunk/blob/master/examples/simple-scene/save-then-reload.py
[2]https://gitlab.com/yade-dev/trunk/blob/master/examples/FluidCouplingPFV/oedometer.py
[3]https://gitlab.com/yade-dev/trunk/blob/master/lib/triangulation/FlowBoundingSphereLinSolv.ipp#L598

Question information

Language:
English Edit question
Status:
Solved
For:
Yade Edit question
Assignee:
No assignee Edit question
Solved by:
Robert Caulk
Solved:
2019-09-16
Last query:
2019-09-16
Last reply:
2019-09-06
Chareyre (bruno-chareyre-9) said : #1

Hi Robert, it seems you are somehow in a special case since the following
works:

:~$ yade
Welcome to Yade 1.20.0
...
Yade [1]: O.engines=O.engines+[FlowEngine(label="flow")]
Yade [2]: flow.useSolver=3
Yade [3]: O.save("test.yade")
Yade [4]:
Do you really want to exit ([y]/n)?
:~$ yade
Yade [1]: O.load("test.yade")
Yade [2]: flow.useSolver
 -> [2]: 3

Robert Caulk (rcaulk) said : #2

Hmmm, your example doesn't include a triangulation. Maybe it is a triangulation serialization problem since CGAL is involved? If we consider the least special case that includes a triangulation it still doesnt work:

from __future__ import print_function
from builtins import range
from yade import pack

num_spheres=1000# number of spheres
young=1e6
compFricDegree = 3 # initial contact friction during the confining phase
finalFricDegree = 30 # contact friction during the deviatoric loading
mn,mx=Vector3(0,0,0),Vector3(1,1,1) # corners of the initial packing

O.materials.append(FrictMat(young=young,poisson=0.5,frictionAngle=radians(compFricDegree),density=2600,label='spheres'))
O.materials.append(FrictMat(young=young,poisson=0.5,frictionAngle=0,density=0,label='walls'))
walls=aabbWalls([mn,mx],thickness=0,material='walls')
wallIds=O.bodies.append(walls)

import os.path
savedState = os.path.exists('oedometer_state.yade.gz')

if not savedState:

 sp=pack.SpherePack()
 sp.makeCloud(mn,mx,-1,0.3333,num_spheres,False, 0.95,seed=1) #"seed" make the "random" generation always the same
 sp.toSimulation(material='spheres')

 O.engines=[
  ForceResetter(),
  InsertionSortCollider([Bo1_Sphere_Aabb(),Bo1_Box_Aabb()]),
  InteractionLoop(
   [Ig2_Sphere_Sphere_ScGeom(),Ig2_Box_Sphere_ScGeom()],
   [Ip2_FrictMat_FrictMat_FrictPhys()],
   [Law2_ScGeom_FrictPhys_CundallStrack()],label="iloop"
  ),
  FlowEngine(dead=1,label="flow"), GlobalStiffnessTimeStepper(active=1,timeStepUpdateInterval=100,timestepSafetyCoefficient=0.8),
  NewtonIntegrator(damping=0.2,label='newton')
 ]

if not savedState:
 #B. Activate flow engine and set boundary conditions in order to get permeability
 flow.dead=0
 flow.defTolerance=-1
 flow.meshUpdateInterval=-1
 flow.useSolver=3
 flow.permeabilityFactor=1
 flow.viscosity=10
 flow.bndCondIsPressure=[0,0,1,1,0,0]
 flow.bndCondValue=[0,0,1,0,0,0]
 flow.boundaryUseMaxMin=[0,0,0,0,0,0]
 O.dt=0.1e-3
 O.dynDt=False
 newton.damping=0

 O.run(1000,1)
 print('saving oedometer state with pore pressure at',flow.getPorePressure((0.5,0.5,0.5)))
 O.save('oedometer_state.yade.gz')
else:
 O.load('oedometer_state.yade.gz')
 print('loaded oedometer state with pore pressure at',flow.getPorePressure((0.5,0.5,0.5)))
 O.run(100,1)

from yade import plot

def history():
 plot.addData(t=O.time,p=flow.getPorePressure((0.5,0.5,0.5)))

O.engines=O.engines+[PyRunner(iterPeriod=200,command='history()',label='recorder')]

from yade import plot

Robert Caulk (rcaulk) said : #3

Currently yade is unable to save and reload flowengine triangulations. Therefore it is i advised to use this method.

Robert Caulk (rcaulk) said : #4

Not advised *

For future reference: history-dependent problems (such as heat transfer) will not play well with save/load since, indeed, field data written in the triangulation will be lost.
Nevertheless history-independent problems (such as incompressible flow) will still work, since a new mesh will be created on reload, and it's just fine.

Robert Caulk (rcaulk) said : #6

>Nevertheless history-independent problems (such as incompressible flow) will still work, since a new mesh will be created on reload, and it's just fine.

The simple example I provide in #2 is incompressible flow and it does not readily work. No doubt, there are some mechanisms that still need to be developed and bug tested to make that work.