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

54
views
0
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

0
20 days ago by

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

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

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
# NOTE THE CHANGE IN CASE OF FIRST LETTER IN THE 2 LINES BELOW
myNewSteppable = MyNewSteppable(sim,_frequency=1)
steppableRegistry.registerSteppable(myNewSteppable)

You should remove any reference to your new steppable from the CC3D .xml project file.
0
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?
0
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
 reportFileName="Simulation_report.txt"
 self.reportFileHandle,fullFileName=self.openFileInSimulationOutputDirectory(reportFileName,"w")

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

And in the finish you use;
self.reportFileHandle.close()

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

You might want to add a header line to the file in the start method;
         self.reportFileHandle.write("mcs\tid\tsurf\tvol\tnneigh\n")

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
0
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.

0
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:

to;

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.
0
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".