Callback Functions

Module contains callback classes to save simulation data for rod-like objects

Description

The frequency at which you have your callback function save data will depend on what information you need from the simulation. Excessive call backs can cause performance penalties, however, it is rarely necessary to make call backs at a frequency that this becomes a problem. We have found that making a call back roughly every 100 iterations has a negligible performance penalty.

Currently, all data saved from call back functions is saved in memory. If you have many rods or are running for a long time, you may want to consider editing the call back function to write the saved data to disk so you do not run out of memory during the simulation.

CallBackBaseClass

This is the base class for callbacks for rod-like objects.

ExportCallBack

ExportCallback is an example callback class to demonstrate how to export rod-data into data file.

MyCallBack

MyCallBack class is derived from the base callback class.

Built-in Constraints

class elastica.callback_functions.CallBackBaseClass[source]

This is the base class for callbacks for rod-like objects.

Notes

Every new callback class must be derived from CallBackBaseClass.

__init__()[source]

CallBackBaseClass does not need any input parameters.

class elastica.callback_functions.ExportCallBack(step_skip, path, method, initial_file_count=0, save_every=100000000.0)[source]

ExportCallback is an example callback class to demonstrate how to export rod-data into data file.

If one wants to customize the saving data, we recommend to override make_callback method.

Attributes
AVAILABLE_METHOD

Supported method to save the file. We recommend binary save to maintain the tensor structure of data.

FILE_SIZE_CUTOFF

Maximum buffer size for each file. If the buffer size exceed, new file is created. Actual size of the file is expected to be marginally larger.

__init__(step_skip, path, method, initial_file_count=0, save_every=100000000.0)[source]
Parameters
step_skipint

Collect data at each step_skip steps.

pathstr

Path to save the file. If directories are prepended, they must exist. The filename depends on the method. The path is not expected to include extension.

methodstr

Method name. Only the name in AVAILABLE_METHOD is allowed.

initial_file_countint

Initial file count index that will be appended

save_everyint

Save the file every save_every steps. (default=1e8)

class elastica.callback_functions.MyCallBack(step_skip, callback_params)[source]

MyCallBack class is derived from the base callback class. This is just an example of a callback class, this class as an example/template to write new call back classes in your client file.

Attributes
sample_every: int

Collect data using make_callback method every sampling step.

callback_params: dict

Collected callback data is saved in this dictionary.

__init__(step_skip, callback_params)[source]
Parameters
step_skip: int

Collect data using make_callback method every step_skip step.

callback_params: dict

Collected data is saved in this dictionary.