← Back to team overview

yade-users team mailing list archive

Re: [Question #403663]: Modeling 2 materilas by CPM model

 

Question #403663 on Yade changed:
https://answers.launchpad.net/yade/+question/403663

    Status: Open => Answered

Jan Stránský proposed the following answer:
Hi Seti,

random.random() returns uniform distribution random number in the range
(0,1), so random.random()<0.2 means that 0.2=20/100=20% of spheres will
have mat1, the rest 80% mat2. You can use of course any other value than
0.2.

The indentation error comes from your script, probably from copy-paste
process. I will rewrite the code with only spaces (I used tabs originally)
co copy-paste again should work. Please try it and let us know.

##############
from yade import pack
import random

mat1 = CpmMat() # ...
mat2 = CpmMat() # ...

sp = pack.randomDensePack(pack.inAlignedBox((0,0,0),(1,1,1)),
radius=.05,spheresInCell=500,returnSpherePack=True)
sp.toSimulation()

for b in O.bodies:
  if random.random() < 0.2:
    b.mat = mat1
    b.shape.color = (1,0,0)
  else:
    b.mat = mat2
  b.shape.color = (0,1,1)
##############

cheers
Jan


2016-10-31 13:23 GMT+01:00 Seti <question403663@xxxxxxxxxxxxxxxxxxxxx>:

> Question #403663 on Yade changed:
> https://answers.launchpad.net/yade/+question/403663
>
>     Status: Answered => Open
>
> Seti is still having a problem:
> Hi Jan,
>
> Thanks so much for your reply,  would you please let me know what is
> meaning of " if random.random() < 0.2:" commend in your example?
>
> I have tried  to do a quick test based on your recommendation, below
> error will be pop up related to  "if random.random() < 0.2:" line
>
> "IndentationError: expected an indented block"
>
>
> Cheers,
> Seti
>
> --
> You received this question notification because your team yade-users is
> an answer contact for Yade.
>
> _______________________________________________
> Mailing list: https://launchpad.net/~yade-users
> Post to     : yade-users@xxxxxxxxxxxxxxxxxxx
> Unsubscribe : https://launchpad.net/~yade-users
> More help   : https://help.launchpad.net/ListHelp
>

-- 
You received this question notification because your team yade-users is
an answer contact for Yade.