Why are some particles white

Asked by Zhicheng Gao

I wrote a program to identify the force chain particles. In order to display each force chain, I deleted the non force chain particles and set the color for each force chain, but there is no white. However, as a result, many particles appear white.
This is my display program:

def force_chain_display(force_chain,neighbors):
 """ Remove particles other than force chains, so the force chain is displayed
 use the index in array force_chain to find the id of force chain particles in neighbors,
 then delete the irrelevant particles
 """

 ## Only force chain particles are displayed
 fc_particle_index_list = force_chain.flatten().tolist()
 fc_particle_index_list = list(set(fc_particle_index_list))
 fc_particle_index_list.remove(-1)
 fc_particle_id_list = []
 for index in fc_particle_index_list:
  fc_particle_id_list.append(neighbors[index,0])
 for b in O.bodies:
  if isinstance(b.shape,Sphere):
   if b.id not in fc_particle_id_list:
    O.bodies.erase(b.id)

 ## Make the particles of the same force chain the same color
 fcn = force_chain.shape[0]
 valueToBeRemoved = -1
 ## Create RGB color array
 RGB_array = np.array([[47,79,79],[105,105,105],[112,128,144],[0,0,128],[100,149,237],[72,61,139],[0,191,255],[0,100,0],[85,107,47],[255,255,0],[205,92,92],[139,69,19],[255,0,0],[255,20,147],[160,32,240],[255,165,0],
 [205,133,63],[244,164,96],[192,255,62]])
 for i in range(fcn):
  single_force_chain_index_list = list(force_chain[i,:])
  single_force_chain_index_list = [value for value in single_force_chain_index_list if value != valueToBeRemoved]
  ran = random.randint(0,18)
  print(ran)
  for particle_index in single_force_chain_index_list:
   pid = neighbors[particle_index,0]
   O.bodies[pid].shape.color = (RGB_array[ran,0],RGB_array[ran,1],RGB_array[ran,2])

Question information

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

Hello,

please provide a MWE [1] - a complete code which we can try. I.e. here with the call of force_chain_display function and some meaningful (although M=minimal data).

Cheers
Jan

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

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

I generated a sample and carried out the loading experiment, and then used some methods to identify the force chain particles to get array force_chain. Then I call the above function to delete the particles other than the force chain particles, and set different colors for each force chain, excluding white, but finally many particles are displayed in white.
Because the force chain has branches, but the branches are not considered, the same particles may belong to different force chains. In this way, the color of the particles will be assigned twice. Is this the reason why the particles are white?

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

Instant replay:
please provide a MWE [1] - a complete code which we can try.

> I generated a sample ... used some methods ...

please be (much) more specific.
Ideally provide a MWE [1]

> Is this the reason why the particles are white?

Maybe yes, maybe no, we can only guess without a MWE [1]

> and set different colors for each force chain, excluding white, but finally many particles are displayed in white.

Isn't it the case that you simply color the particles white yourself?
shape.color [2] is a **normalized** form, i.e. values in range 0-1.
Trying your code, I simply get most of particles white (just because most of the values are > 1)
###
import numpy as np
RGB_array = np.array([[47,79,79],[105,105,105],[112,128,144],[0,0,128],[100,149,237],[72,61,139],[0,191,255],[0,100,0],[85,107,47],[255,255,0],[205,92,92],[139,69,19],[255,0,0],[255,20,147],[160,32,240],[255,165,0],[205,133,63],[244,164,96],[192,255,62]])
for i in range(100):
    ran = random.randint(0,18)
    color = (RGB_array[ran,0],RGB_array[ran,1],RGB_array[ran,2])
    color = [float(v) for v in color]
    O.bodies.append(sphere((i,0,0),0.5,color=color))
###

Are you aware of randomColor standard Yade function [3]?

Cheers
Jan

[2] https://yade-dem.org/doc/yade.wrapper.html#yade.wrapper.Shape.color
[3] https://yade-dem.org/doc/yade.utils.html#yade.utils.randomColor

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

Dear Jan,
Thank you for your quick reply. According to the answers and the links you provided, I found my mistake, Yade uses normalized RGB.
Thank you again for your enthusiasm and patience in answering such a simple question.
Best wishes
Zhicheng