Import packing text file into yade

Asked by Soheil Safari

Hello everyone;

Hope you are doing well.

I used yade.export.text('filename.txt', mask=-1) to extract the particle position and radii in #format x_y_z_r , now I want to import this text file to extract its pore data with ‘flow.savePoreNetwork()’.

I used yade.ymport.text for this purpose, but I faced with this error:

ValueError: could not convert string to float: '0.42264,0.478226,0.889397,0.115182'

(which are the values of first row)

Here is my code:

###

import os
import numpy as np
import pandas as pd
from yade import pack, ymport
from yade import utils, plot, timing
from yade import export

yade.ymport.text('final.txt', shift=Vector3(0, 0, 0), scale=1.0)

O.engines = [
  TwoPhaseFlowEngine(dead=0,label="flow"),
]

press=1000.

flow.dead=0
flow.meshUpdateInterval=-1
flow.useSolver=3
flow.permeabilityFactor=1
flow.viscosity=0.1

flow.bndCondIsWaterReservoir=[0,0,1,0,0,0]

flow.bndCondIsPressure=[0,0,1,0,0,0]
flow.bndCondValue=[0,0,press,0,0,0]
flow.boundaryUseMaxMin=[0,0,0,0,0,0]
flow.iniVoidVolumes=True

flow.surfaceTension = 0.0
flow.drainageFirst=False
flow.isDrainageActivated=False
flow.isImbibitionActivated=True
flow.isCellLabelActivated=True
flow.initialization()
cs=flow.getClusters()
c0=cs[1]

#flow.getCellVoidVolume(4)
#flow.getCellInSphereRadius(100)
flow.savePoreNetwork() #extract info about the pore

###

I am grateful for any hints or insights into this issue.

Best regards,
Soheil

Question information

Language:
English Edit question
Status:
Solved
For:
Yade Edit question
Assignee:
No assignee Edit question
Solved by:
Jan Stránský
Solved:
Last query:
Last reply:
Revision history for this message
Soheil Safari (soheilsafari) said :
#1

Also, I used O.bodies.append(ymport.text('final.txt',format='x_y_z_r'))
and I got this error:
TypeError: textExt() got multiple values for keyword argument 'format'

Revision history for this message
Jérôme Duriez (jduriez) said :
#2

Regarding #1, where did you see ymport.text should/ could be used with a format argument ?
Not at https://yade-dem.org/doc/yade.ymport.html#yade.ymport.text, I presume.

For the initial question, I could not reproduce your issue:

from yade import ymport,export
O.bodies.append(sphere((0,0,0),1))
export.text('final.txt', mask=-1)
ymport.text('final.txt', shift=Vector3(0, 0, 0), scale=1.0)

works for me with yadedaily 20220419-6447~fd04d86~focal1. You may try to precise your YADE version and shorten your script for additional support

Revision history for this message
Best Jan Stránský (honzik) said :
#3

Hello,

please provide a MWE [1]:
W = working, i.e. also with the saving part, such that we can test it ourselves
M = minimal, i.e. flow stuff is irrelevant to the expory / import error

Also provide Yade version ...

> I used yade.export.text('filename.txt', mask=-1)
> ValueError: could not convert string to float: '0.42264,0.478226,0.889397,0.115182'

... because in yade I am using, export.text saves file with tabs, not commas.
ymport.text expects the same format (tabs/spaces, not commas)
Have you modified the exported file in the meantime before ymport.text?

> I used O.bodies.append(ymport.text('final.txt',format='x_y_z_r')) and I got this error:
> TypeError: textExt() got multiple values for keyword argument 'format'

Either use
ymport.text(fileName) # [2]
or
ymport.textExt(filename,format=...) # [3]
not
ymport.text(fileName,format=...)
(ymport.text calls ymport.textExt internally and does not expect format parameter)

Cheers
Jan

[1] https://www.yade-dem.org/wiki/Howtoask
[2] https://yade-dem.org/doc/yade.ymport.html#yade.ymport.text
[3] https://yade-dem.org/doc/yade.ymport.html#yade.ymport.textExt

Revision history for this message
Soheil Safari (soheilsafari) said :
#4

Dear Jérôme,

Regarding #2 I tried to use [3] which was not correct.

Thank you for your reply.

[3] https://answers.launchpad.net/yade/+question/677475

Revision history for this message
Soheil Safari (soheilsafari) said :
#5

Dear Jan,

Thank you very much for your kind reply and valuable information.

It was very helpful. I am using Yade 2020.01a.

Also yade I am using, export.text saves files with tabs.

I tried to use the text file without any modification and it works.

I do not know if I can continue my issue here or not.

Because when I ran the code I faced with this error:

TCP python prompt on localhost:9000, auth cookie `sauyce'
XMLRPC info provider on http://localhost:21000
Running script 1.py
Traceback (most recent call last):
  File "/usr/bin/yade", line 336, in runScript
    execfile(script,globals())
  File "/usr/lib/python3/dist-packages/past/builtins/misc.py", line 87, in execfile
    exec_(code, myglobals, mylocals)
  File "1.py", line 50, in <module>
    flow.initialization()
RuntimeError: CGAL ERROR: assertion violation!
Expr: dexp != 2047
File: /usr/include/CGAL/Mpzf.h
Line: 404
Explanation: Creating an Mpzf from infinity or NaN.

Here is my text file data:

#format x_y_z_r
0.108316 0.446354 0.405371 0.1
0.385925 0.584268 0.404164 0.1
0.266271 0.335278 0.779746 0.1
0.699993 0.718399 0.539943 0.1
0.7529 0.251866 0.260316 0.1
0.101752 0.643533 0.110886 0.1
0.264525 0.734255 0.782473 0.1
0.64595 0.895112 0.332408 0.1
0.24546 0.224601 0.578429 0.1
0.813695 0.529448 0.739774 0.1
0.453208 0.792714 0.68934 0.1
0.142558 0.824175 0.308345 0.1
0.816278 0.497335 0.212273 0.1
0.649266 0.288894 0.899394 0.1
0.76397 0.242682 0.488743 0.1
0.233775 0.102176 0.419037 0.1
0.433978 0.848117 0.162744 0.1
0.770714 0.712419 0.107076 0.1
0.412006 0.591829 0.201775 0.1
0.176013 0.844046 0.561313 0.1
0.370268 0.86723 0.898086 0.1
0.593966 0.593603 0.327687 0.1
0.611039 0.531407 0.533922 0.1
0.476597 0.252552 0.669018 0.1
0.692468 0.802018 0.750006 0.1
0.507422 0.174782 0.476912 0.1
0.508109 0.148976 0.178023 0.1
0.837158 0.180356 0.813804 0.1
0.169296 0.514047 0.855917 0.1
0.893444 0.876796 0.862966 0.1
0.332611 0.110006 0.80685 0.1
0.566253 0.468939 0.750964 0.1
0.899925 0.42476 0.899659 0.1
0.874242 0.700281 0.351331 0.1
0.176129 0.573342 0.659617 0.1
0.285587 0.328712 0.37919 0.1
0.184362 0.60361 0.29202 0.1
0.33723 0.326092 0.136975 0.1
0.184264 0.170793 0.126237 0.1
0.612765 0.487743 0.120558 0.1
0.892392 0.315699 0.108565 0.1
0.233077 0.855653 0.118868 0.1
0.892404 0.438759 0.546704 0.1
0.593431 0.636812 0.893386 0.1
0.863798 0.121867 0.149614 0.1
0.341464 0.833798 0.348334 0.1
0.543872 0.118359 0.835191 0.1
0.876932 0.899792 0.55643 0.1
0.89683 0.104328 0.57049 0.1
0.385368 0.483966 0.599477 0.1
0.899303 0.87534 0.115881 0.1
0.499021 0.323427 0.306233 0.1
0.635067 0.129761 0.647935 0.1
0.401005 0.472595 0.874597 0.1
0.140286 0.149974 0.899759 0.1

and I used this code:

import os
import numpy as np
import pandas as pd
from yade import pack, ymport
from yade import utils, plot, timing
from yade import export

young=1.e6
compFricDegree = 3 # initial contact friction during the confining phase
finalFricDegree = 30 # contact friction during the deviatoric loading
mn,mx=Vector3(0,0,0),Vector3(2,2,2) # corners of the initial packing
graindensity=2600
errors=0
toleranceWarning =1.e-11
toleranceCritical=1.e-6

O.materials.append(FrictMat(young=young,poisson=0.5,frictionAngle=radians(compFricDegree),density=graindensity,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)

ymport.text('final.txt', shift=Vector3(0, 0, 0), scale=1.0)

O.engines = [
  TwoPhaseFlowEngine(dead=0,label="flow"),
]

press=1000.

flow.dead=0
flow.meshUpdateInterval=-1
flow.useSolver=3
flow.permeabilityFactor=1
flow.viscosity=0.1

flow.bndCondIsWaterReservoir=[0,0,1,0,0,0]

flow.bndCondIsPressure=[0,0,1,0,0,0]
flow.bndCondValue=[0,0,press,0,0,0]
flow.boundaryUseMaxMin=[0,0,0,0,0,0]
flow.iniVoidVolumes=True

flow.surfaceTension = 0.0
flow.drainageFirst=False
flow.isDrainageActivated=False
flow.isImbibitionActivated=True
flow.isCellLabelActivated=True
flow.initialization()
cs=flow.getClusters()
c0=cs[1]

#flow.getCellVoidVolume(4)
#flow.getCellInSphereRadius(100)
flow.savePoreNetwork() #extract info about the pore

Many thanks in advance.

Revision history for this message
Jan Stránský (honzik) said :
#6

> I do not know if I can continue my issue here or not.

because it has no relation to the OP, it would be better to create a new question ([1], point 5)

Cheers
Jan

[1] https://www.yade-dem.org/wiki/Howtoask

Revision history for this message
Soheil Safari (soheilsafari) said :
#7

Dear Jan,

Thank you very much for your kind reply.

Your valuable recommendations solved my first question.

Sure, I will open a new question for that.

Cheers,
Soheil

Revision history for this message
Soheil Safari (soheilsafari) said :
#8

Thanks Jan Stránský, that solved my question.

Revision history for this message
Bret Ritchie (ritchie141) said :
#9

Same issue here and I can't find any methods.

https://www.etenet.biz/