Skip to content

Commit 8361947

Browse files
committed
improved resume main.cpp
1 parent 27e3413 commit 8361947

1 file changed

Lines changed: 90 additions & 66 deletions

File tree

unit_tests/resume_sim/main.cpp

Lines changed: 90 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -86,57 +86,80 @@ using namespace PhysiCell;
8686
//-----------------------------------------
8787
int main( int argc, char* argv[] )
8888
{
89-
// load and parse settings file(s)
89+
// load and parse settings file(s)
9090

91-
bool XML_status = false;
92-
char copy_command [1024];
91+
bool XML_status = false;
92+
char copy_command [1024];
93+
bool resume_from_checkpoint = false;
9394
std::string resume_from_dir;
9495
std::string resume_from_file;
9596
int next_full_index, next_svg_index;
9697

97-
// std::cout << "argc = " << argc << "argv=" << argv << std::endl;
98-
if( argc < 5 )
99-
{
100-
std::cout << "\n Too few arguments. Usage: <.xml config file> <resume_folder> <resume_file> <next_full_index> <next_svg_index>" << std::endl;
101-
std::cout << " e.g. config/PhysiCell_settings.xml output output00000042.xml" << std::endl;
102-
exit(-1);
98+
std::cout << "argc = " << argc << ", argv[0]=" << argv[0] << std::endl;
99+
if( argc == 6 )
100+
{
101+
resume_from_checkpoint = true;
103102

104-
XML_status = load_PhysiCell_config_file( argv[1] );
105-
if( !XML_status )
106-
{ exit(-1); }
103+
XML_status = load_PhysiCell_config_file( argv[1] );
104+
if( !XML_status )
105+
{ exit(-1); }
107106

108-
sprintf( copy_command , "cp %s %s" , argv[1] , PhysiCell_settings.folder.c_str() );
109-
// copy config file to output directry
110-
system( copy_command );
107+
sprintf( copy_command , "cp %s %s" , argv[1] , PhysiCell_settings.folder.c_str() );
108+
// copy config file to output directry
109+
system( copy_command );
111110

112111
resume_from_dir = argv[2];
113112
resume_from_file = argv[3];
114113

115114
next_full_index = std::stoi(argv[4]);
116115
next_svg_index = std::stoi(argv[5]);
117-
}
118-
119-
// OpenMP setup
120-
omp_set_num_threads(PhysiCell_settings.omp_num_threads);
121-
122-
// time setup
123-
std::string time_units = "min";
116+
}
117+
else if( argc == 2 )
118+
{
119+
XML_status = load_PhysiCell_config_file( argv[1] );
120+
sprintf( copy_command , "cp %s %s" , argv[1] , PhysiCell_settings.folder.c_str() );
121+
}
122+
else if ( argc < 2 )
123+
{
124+
XML_status = load_PhysiCell_config_file( "./config/PhysiCell_settings.xml" );
125+
sprintf( copy_command , "cp ./config/PhysiCell_settings.xml %s" , PhysiCell_settings.folder.c_str() );
126+
}
127+
else
128+
{
129+
std::string err_msg = "\nIncorrect arguments. Usage options: \n"
130+
"- no args: will try to use ./config/PhysiCell_settings.xml\n"
131+
"- 1 arg: will try to use it as the config file\n"
132+
"- 5 args to resume a simulation:\n"
133+
" <.xml config file> <resume_folder> <resume_file> <next_full_index> <next_svg_index>\n";
124134

125-
/* Microenvironment setup */
126-
setup_microenvironment(); // modify this in the custom code
135+
std::cout << err_msg << std::endl;
136+
std::cout << " e.g. config/PhysiCell_settings.xml output output00000042.xml 43 43\n" << std::endl;
137+
exit(-1);
138+
}
127139

128-
/* PhysiCell setup */
129-
// set mechanics voxel size, and match the data structure to BioFVM
130-
double mechanics_voxel_size = 30;
131-
Cell_Container* cell_container = create_cell_container_for_microenvironment( microenvironment, mechanics_voxel_size );
132-
133-
/* Users typically start modifying here. START USERMODS */
134-
135-
create_cell_types();
140+
if( !XML_status )
141+
{ exit(-1); }
142+
143+
// OpenMP setup
144+
omp_set_num_threads(PhysiCell_settings.omp_num_threads);
145+
146+
// time setup
147+
std::string time_units = "min";
148+
149+
// Microenvironment setup
150+
setup_microenvironment(); // modify this in the custom code
151+
152+
// PhysiCell setup
153+
// set mechanics voxel size, and match the data structure to BioFVM
154+
double mechanics_voxel_size = 30;
155+
Cell_Container* cell_container = create_cell_container_for_microenvironment( microenvironment, mechanics_voxel_size );
156+
157+
// Users typically start modifying here. START USERMODS
158+
159+
create_cell_types();
136160

137161

138162
//---------
139-
bool resume_from_checkpoint = true;
140163
if ( !resume_from_checkpoint )
141164
{
142165
setup_tissue();
@@ -150,6 +173,7 @@ int main( int argc, char* argv[] )
150173

151174
// int resume_from_MultiCellDS(std::string folder_path, std::string xml_filename, bool create_cells = true, bool debug_print = false);
152175
int retval = resume_from_MultiCellDS(resume_from_dir, resume_from_file);
176+
// int retval = resume_from_MultiCellDS(resume_from_dir, resume_from_file, true, true);
153177

154178
// Another option: don't recreate state, but print out state of cells
155179
// int retval = resume_from_MultiCellDS(resume_from_dir, resume_from_file, false, true);
@@ -167,46 +191,46 @@ int main( int argc, char* argv[] )
167191
PhysiCell_globals.SVG_output_index = next_svg_index;
168192
}
169193

170-
/* Users typically stop modifying here. END USERMODS */
194+
// Users typically stop modifying here. END USERMODS
171195

172-
// set MultiCellDS save options
196+
// set MultiCellDS save options
173197

174-
set_save_biofvm_mesh_as_matlab( true );
175-
set_save_biofvm_data_as_matlab( true );
176-
set_save_biofvm_cell_data( true );
177-
set_save_biofvm_cell_data_as_custom_matlab( true );
178-
179-
// save a simulation snapshot
180-
181-
char filename[1024];
182-
sprintf( filename , "%s/initial" , PhysiCell_settings.folder.c_str() );
183-
save_PhysiCell_to_MultiCellDS_v2( filename , microenvironment , PhysiCell_globals.current_time );
184-
185-
// save a quick SVG cross section through z = 0, after setting its
186-
// length bar to 200 microns
198+
set_save_biofvm_mesh_as_matlab( true );
199+
set_save_biofvm_data_as_matlab( true );
200+
set_save_biofvm_cell_data( true );
201+
set_save_biofvm_cell_data_as_custom_matlab( true );
202+
203+
// save a simulation snapshot
187204

188-
PhysiCell_SVG_options.length_bar = 200;
205+
char filename[1024];
206+
sprintf( filename , "%s/initial" , PhysiCell_settings.folder.c_str() );
207+
save_PhysiCell_to_MultiCellDS_v2( filename , microenvironment , PhysiCell_globals.current_time );
208+
209+
// save a quick SVG cross section through z = 0, after setting its
210+
// length bar to 200 microns
211+
212+
PhysiCell_SVG_options.length_bar = 200;
189213

190214
// for simplicity, set a pathology coloring function
191-
192-
std::vector<std::string> (*cell_coloring_function)(Cell*) = my_coloring_function;
193-
std::string (*substrate_coloring_function)(double, double, double) = paint_by_density_percentage;
194215

195-
sprintf( filename , "%s/initial.svg" , PhysiCell_settings.folder.c_str() );
196-
SVG_plot( filename , microenvironment, 0.0 , PhysiCell_globals.current_time, cell_coloring_function );
197-
198-
sprintf( filename , "%s/legend.svg" , PhysiCell_settings.folder.c_str() );
199-
create_plot_legend( filename , cell_coloring_function );
200-
201-
display_citations();
202-
203-
// set the performance timers
216+
std::vector<std::string> (*cell_coloring_function)(Cell*) = my_coloring_function;
217+
std::string (*substrate_coloring_function)(double, double, double) = paint_by_density_percentage;
204218

205-
BioFVM::RUNTIME_TIC();
206-
BioFVM::TIC();
207-
208-
std::ofstream report_file;
209-
if( PhysiCell_settings.enable_legacy_saves == true )
219+
sprintf( filename , "%s/initial.svg" , PhysiCell_settings.folder.c_str() );
220+
SVG_plot( filename , microenvironment, 0.0 , PhysiCell_globals.current_time, cell_coloring_function );
221+
222+
sprintf( filename , "%s/legend.svg" , PhysiCell_settings.folder.c_str() );
223+
create_plot_legend( filename , cell_coloring_function );
224+
225+
display_citations();
226+
227+
// set the performance timers
228+
229+
BioFVM::RUNTIME_TIC();
230+
BioFVM::TIC();
231+
232+
std::ofstream report_file;
233+
if( PhysiCell_settings.enable_legacy_saves == true )
210234
{
211235
sprintf( filename , "%s/simulation_report.txt" , PhysiCell_settings.folder.c_str() );
212236

0 commit comments

Comments
 (0)