← 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,

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


1) you should use only one random.random() call within the if-else structure
2) then you should use different numbers (if it was <0.2, else if <0.1 does
not make sense)

something like:

###############
r = random.random()
if r < 0.2: ... # 0-20%, in total 20 %
else if r < 0.3: ... # 20%-30%, in total 10%
else if r < 0.6: ... # 30 % - 60%, in total 30%
....
###############

cheers
Jan


2016-11-13 11:12 GMT+01:00 Seti <question403663@xxxxxxxxxxxxxxxxxxxxx>:

> Question #403663 on Yade changed:
> https://answers.launchpad.net/yade/+question/403663
>
>     Status: Solved => Open
>
> Seti is still having a problem:
> Hi Jan,
>
> Just a quick question, I am wondering to combine more materials in CPM
> model ( say 5 items), would you please advise me how I can specify the
> percentage of each material?
> My idea is as per below:
>
> ##############
> from yade import pack
> import random
>
> mat1 = CpmMat() # ...
> mat2 = CpmMat() # ...
> mat3 = CpmMat() # ...
> mat4 = CpmMat() # ...
> mat5 = 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)
>  elif random.random() < 0.1:
>     b.mat = mat2
>     b.shape.color = (0,1,0)
>  elif random.random() < 0.3:
>     b.mat = mat3
>     b.shape.color = (0,0,1)
>  elif random.random() < 0.2:
>     b.mat = mat4
>     b.shape.color = (1,1,0)
>   else:
>     b.mat = mat5
>   b.shape.color = (0,1,1)
>
>
> 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.