I got a problem adding a steppable which for every bubble will output bubble id, volume, surface and number of neighbors.

21 days ago by
Dear all,

I am trying to follow the instructions in the quick start guide on how to add a steppable which for every bubble id will output several parameters (page 19), but it does not work, here is what it is displayed:

Community: CompuCell3D

8 Answers

20 days ago by
To add a new steppable:

In your python steppables file (e.g., MyProjectsteppables.py) make the new steppable, something like;

class MyNewSteppable(SteppableBasePy):
    def __init__(self,_simulator,_frequency=1):
    def start(self):
        # stuff to do at the start of the simulation
    def step(self,mcs):       
        # stuff to do every time the steppable is called
    def finish(self):
        # Finish Function gets called after the last MCS

To register this new python class, you need to add it to the main python file e.g., MyProject.py. At the bottom of this python, file after;

#Add Python steppables here


from InsertNameOfYourSteppablesPythonFile import MyNewSteppable
myNewSteppable = MyNewSteppable(sim,_frequency=1)

You should remove any reference to your new steppable from the CC3D .xml project file.
20 days ago by
So if I understood well: In def start(self) I will code something to create and open a new file
But in def step(self,mcs) how do I access the data in mcs, is it like a PIFF file?

Is this really the only solution to output the data from the foam coarsening?
20 days ago by
What data do you want to output? If you want screen shots of the simulation you can tell Player to do that.
<Tools><Configuration><Output> check "Save images every Nth MCS"

Otherwise, if you want to do things like output the number of cells, volume/cell, average volume etc. then you'll need to do that in Python and output to a file.

In the start you can use;
# create a plain text file in the output directory
import os

In the step you use;
self.reportFileHandle.write("Some interesting stuff\n")

And in the finish you use;

If you can post what kind of data you would like to save I might be able to help more.
20 days ago by
I want to output for each cell: his cell ID, his surface, his volume and number of neighbors.
20 days ago by
def step(self,mcs):
    for cell in self.cellList:
        for neighbor, commonSurfaceArea in self.getCellNeighborDataList(cell):
            if neighbor: # don't count neighbors that are medium
        self.reportFileHandle.write(str(mcs)+"\t"+str(cell.id)+"\t"+str(cell.surface)+ \

You might want to add a header line to the file in the start method;

The output file should be in the project directory but if isn't there check C:\Users\YOURUSERNAME\CC3DWorkspace\

You probably don't want to log the data every mcs.
Thank you so much, it worked very well! Indeed, I wanted to ask to you how do you change the frequency as I don't want to log the data every mcs?
written 17 days ago by Arthur M  
17 days ago by
I also got a problem getting screenshots of the simulation, I found no screenshots after the simulation ended. Here is what I put in the parameters.

14 days ago by
There are a couple ways to change the frequency of a steppable, but I find it easiest (though perhaps not the fastest) to simply do it directly in the step. For example; change

def step(self,mcs):
    for cell in self.cellList:


def step(self,mcs):
    if mcs % 100 == 0:
        for cell in self.cellList:

"%" is the python modulo operator and the if statement above will cause the lines below to execute only when the mcs step is evenly divisible by 100. In other words, every 100 steps you'll get output.
14 days ago by
Concerning the output screen shots. You need to find the folder that CC3D is using for output. It should be named something like <jobname>_cc3d_06_04_2018_11_25_42 where the string of numbers is the time you started the CC3D job (June 4, 2018 at 11:25:42 in this case). Your screenshots will be in that folder.

CC3D sometimes gets confused and puts the output in your default CC3D output folder, which on a PC is C:\Users\YOURUSERNAME\CC3DWorkspace\. Check that folder to see if your job files are there. You can tell CC3D to put the output files under the same directory as your source code by checking the box next to "=Project".
Please login to add an answer/comment or follow this question.

Similar posts:
Search »