Instantiating a new FlowEngine after removing does not work

Asked by Zhicheng Gao on 2021-06-07

Hi,

I'm also trying to remove some particles from the simulation while using FlowEngine engine to simulate a fluid flow. According to Questions #452277 and #670889, I used the simple method of instantiating a brand new FlowEngine after removing particles, however, segmentation faults still occurred.

For complex methods, reset functions need to be executed in C + + code. Can you give the relevant C + + source code link? Thanks a lot!

My code is shown as follow:
## ______________ First section, similar to triax-tutorial/script-session1.py _________________
from __future__ import print_function

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)

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')

triax=TriaxialStressController(
 maxMultiplier=1.+2e4/young, # spheres growing factor (fast growth)
 finalMaxMultiplier=1.+2e3/young, # spheres growing factor (slow growth)
 thickness = 0,
 stressMask = 7,
 max_vel = 0.005,
 internalCompaction=True, # If true the confining pressure is generated by growing particles
)

newton=NewtonIntegrator(damping=0.2)

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"),#introduced as a dead engine for the moment, see 2nd section
 GlobalStiffnessTimeStepper(active=1,timeStepUpdateInterval=100,timestepSafetyCoefficient=0.8),
 triax,
 newton
]

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

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

setContactFriction(radians(finalFricDegree))

## ______________ Oedometer section _________________

#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

O.run(1,1)
csdList=flow.getConstrictionsFull()
print(len(O.bodies),len(csdList),'finished')
flow.dead=1
print(O.bodies[10].shape.radius)
for i in range(10,100):
    O.bodies.erase(i)
print(len(O.bodies))
del O.engines[3]
O.engines=O.engines[0:3]+[FlowEngine(dead=0,label="flow"),]+O.engines[4:]
O.run(1000,True)

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.run(1,1)
#flow.updateTriangulation=True #force remeshing to reflect new BC immediately
csdList1=flow.getConstrictionsFull()
print(len(csdList1))

Question information

Language:
English Edit question
Status:
Solved
For:
Yade Edit question
Assignee:
No assignee Edit question
Solved by:
Robert Caulk
Solved:
Last query:
Last reply:

This question was reopened

Revision history for this message
Robert Caulk (rcaulk) said :
#1

Hello,

> According to Questions #452277 and #670889

I'm not sure what these questions are, can you please link to them?

Two things to try:

1) Don't delete the old FlowEngine, it should beenough to simply set flow.dead = 1
2) Don't reuse labels in python, here both of your flowengines have the same label 'flow.' It seems unnecessarily risky. Why not just label the new one 'flow2?'

Cheers,

Robert

Revision history for this message
Zhicheng Gao (zhichenggao) said :
#2
Revision history for this message
Zhicheng Gao (zhichenggao) said :
#3

Can anyone help? Thank you very much!

Revision history for this message
Robert Caulk (rcaulk) said :
#4

Hello,

Please see my suggestions.

Cheers,

Robert

Revision history for this message
Zhicheng Gao (zhichenggao) said :
#5

Dear Robert,

I'm doing erosion experiments, so I need to delete particles many times, maybe 10000 times, maybe more. According to your method, I need to add 10000 FlowEngines. Will this cause the problem of insufficient memory

Revision history for this message
Robert Caulk (rcaulk) said :
#6

New information has entered the fold ! ;)

Probably yes. So you will need to implement a reset in FlowEngine source like Bruno suggests in [1].

[1]https://answers.launchpad.net/yade/+question/452277

Revision history for this message
Best Robert Caulk (rcaulk) said :
#7

Although looking at source [1] this may not be an issue anymore. What you should try is to set flow.updateTriangulation=True each time you remove a body. i.e. you should be able to delete particles without reinstancing a new FlowEngine. As far as I can tell the setPositionsBuffer is already updated every step and accounts for deleted bodies, and then it is used for triangulation when a triangulate flag is set.

[1]https://gitlab.com/yade-dev/trunk/-/blob/master/pkg/pfv/FlowEngine.ipp.in
[2]https://gitlab.com/yade-dev/trunk/-/blob/master/pkg/pfv/FlowEngine.ipp.in#L497

Revision history for this message
Zhicheng Gao (zhichenggao) said :
#8

Thank you. I'll try your advice. It helps me a lot. Thank you very much

Revision history for this message
Zhicheng Gao (zhichenggao) said :
#9

Dear Robert,
I reinstalled Yade from the source code,the version is yade-2021-06-08.git-4852d56, and the version of Ubuntu is 18.04.I tried to delete the particles. There is no problem for the FlowEngine, but the PeriodicFlowEngine will give the following warning.
CHOLMOD warning: matrix not positive definite. file: ../Supernodal/t_cholmod_super_numeric.c line: 911
something went wrong in Cholesky factorization, use LDLt as fallback this time1
Does it matter to the simulation? Here is my code:
##______________ First section, generate sample_________

from __future__ import print_function
from yade import pack, qt, plot
from math import *

nRead=readParamsFromTable(
        ## model parameters
        num_spheres=1000,
        targetPorosity= .4,
        confiningPressure=-100000,
        ## material parameters
        compFricDegree=15,#contact friction during the confining phase
        finalFricDegree=30,#contact friction during the deviatoric loading
        young=2e8,
        poisson=.2,
        density=2600,
        alphaKr=7.5,
        alphaKtw=0,
 competaRoll=.22,
        finaletaRoll=.22,
        etaTwist=0,
        normalCohesion=0,
        shearCohesion=0,
        ## fluid parameters
        fluidDensity=1000,
        dynamicViscosity=.001,
        ## control parameters
        damp=0,
        stabilityThreshold=.001,
        ## output specifications
        filename='suffusion',
        unknowOk=True
)

from yade.params.table import *

O.periodic=True
O.cell.hSize=Matrix3(1,0,0, 0,1,0, 0,0,1)
# create materials for spheres
#shear strength is the sum of friction and adhesion, so the momentRotationLaw=True
O.materials.append(CohFrictMat(alphaKr=alphaKr,alphaKtw=alphaKtw,density=density,etaRoll=competaRoll,etaTwist=etaTwist,frictionAngle=radians(compFricDegree),momentRotationLaw=True,normalCohesion=normalCohesion,poisson=poisson,shearCohesion=shearCohesion,young=young,label='spheres'))

# generate particles packing
sp=pack.SpherePack()
sp.makeCloud((0,0,0),(1,1,1),-1,0.3333,num_spheres,False, 0.95,seed=1)
sp.toSimulation(material='spheres')

O.engines=[
        ForceResetter(),
        InsertionSortCollider([Bo1_Sphere_Aabb()]),
        InteractionLoop(
            [Ig2_Sphere_Sphere_ScGeom6D()],
            [Ip2_CohFrictMat_CohFrictMat_CohFrictPhys(label='contact',setCohesionNow=False,setCohesionOnNewContacts=False)],
            [Law2_ScGeom6D_CohFrictPhys_CohesionMoment(useIncrementalForm=True,always_use_moment_law=True)],
 ),
        PeriodicFlowEngine(dead=1,label="flow"),#introduced as a dead engine for the moment, see 2nd section
        GlobalStiffnessTimeStepper(active=1,timeStepUpdateInterval=100,timestepSafetyCoefficient=0.8),
        PeriTriaxController(label='triax',
            # specify target values and whether they are strains or stresses
            goal=(confiningPressure,confiningPressure,confiningPressure), stressMask=7,
            # type of servo-control, the strain rate isn't determined, it shloud check the unbalanced force
            dynCell=True,maxStrainRate=(10,10,10),
            # wait until the unbalanced force goes below this value
            maxUnbalanced=stabilityThreshold,relStressTol=1e-3,
            doneHook='compactionFinished()'
            ),
        NewtonIntegrator(damping=0)
]

import sys
def compactionFinished():
 # after sample preparation, save the state
        O.save('compactedState'+filename+'.yade.gz')
        print('Compacted state saved', 'porosity', porosity())
        # next time, called python command
        triax.doneHook=''
        O.pause()
O.run()
O.wait()

#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.run(1,1)
csdList=flow.getConstrictionsFull()
print(len(O.bodies),len(csdList),'finished')
flow.dead=1
print(O.bodies[10].shape.radius)

for i in range(10,50):
    O.bodies.erase(i)
print(len(O.bodies))
O.run(1000,True)

flow.dead=0
flow.updateTriangulation=True

O.run(1,1)
csdList1=flow.getConstrictionsFull()
print(len(csdList1))

Revision history for this message
Zhicheng Gao (zhichenggao) said :
#10

Thanks Robert Caulk, that solved my question.