int main(int argc, char** argv) {
	time_t start_time, end_time;

	//cadef and rundef
	heatModel = calCADef3D(ROWS, COLS, LAYERS, CAL_MOORE_NEIGHBORHOOD_3D, CAL_SPACE_FLAT, CAL_NO_OPT);
	heat_simulation = calRunDef3D(heatModel, 1, STEPS, CAL_UPDATE_IMPLICIT);
	//add substates
	Q_temperature = calAddSubstate3Dr(heatModel);
	Q_heat_source = calAddSubstate3Db(heatModel);
	//add transition function's elementary processes
	calAddElementaryProcess3D(heatModel, heatModel_TransitionFunction);

	//simulation run setup
	calRunAddInitFunc3D(heat_simulation, heatModel_SimulationInit);
	calRunInitSimulation3D(heat_simulation);	//It is required in the case the simulation main loop is explicitated; similarly for calRunFinalizeSimulation3D
//	calRunAddStopConditionFunc3D(heat_simulation, heatModel_SimulationStopCondition);

	start_time = time(NULL);
	calRun3D(heat_simulation);
	end_time = time(NULL);
	printf("%lds", end_time - start_time);

	// Save the substate to file
	calSaveSubstate3Dr(heatModel, Q_temperature, "./heat.txt");

	calRunFinalize3D(heat_simulation);
	calFinalize3D(heatModel);
	return 0;
}
예제 #2
0
void life3DCADef()
{
	//cadef and rundef
	mod2 = calCADef3D (ROWS, COLS, LAYERS, CAL_MOORE_NEIGHBORHOOD_3D, CAL_SPACE_TOROIDAL, CAL_NO_OPT);
	mod2_simulation = calRunDef3D(mod2, 1, CAL_RUN_LOOP, CAL_UPDATE_IMPLICIT);

	//add transition function's elementary processes
	calAddElementaryProcess3D(mod2, mod2TransitionFunction);

	//add substates
	Q.life = calAddSubstate3Db(mod2);

	//simulation run setup
	calRunAddInitFunc3D(mod2_simulation, mod2SimulationInit); calRunInitSimulation3D(mod2_simulation);
	calRunAddStopConditionFunc3D(mod2_simulation, mod2SimulationStopCondition);
}
예제 #3
0
void calglUpdate3D(struct CALGLRun3D* calglRun){
	if (calglRun->active){
		if (calglRun->firstRun){
			calglRun->firstRun = CAL_FALSE;
			calglRun->start_time = time (NULL);
			if (calglRun->calRun->init)
				calRunInitSimulation3D (calglRun->calRun);
		}
		//simulation main loop
		calglRun->step=calglRun->calRun->step++;
		//exectutes the global transition function, the steering function and check for the stop condition.
		calglRun->terminated = calRunCAStep3D(calglRun->calRun);
		//graphic rendering
		//#ifdef WIN32
		//		system("cls");
		//#else
		//		system("clear");
		//#endif
		//		printf("*----------------  Cellular Automata  ----------------*\n");
		//		printf(" Rows: %d, Columns: %d\n", calglGetGlobalSettings()->rows, calglGetGlobalSettings()->columns);
		//		printf(" Current Step: %d/%d; Active cells: %d\n", calglRun->calRun->step, calglGetGlobalSettings()->step, calglRun->calRun->ca3D->A.size_current);
		
        printf ("Cellular Automata: Current Step: %d/%d;", calglRun->calRun->step, calglRun->calRun->final_step);
		if(calglRun->calRun->ca3D->A)		
			printf("Active cells: %d\r", calglRun->calRun->ca3D->A->size_current);
		else
			printf("\r");
//		printf("*-----------------------------------------------------*\n");
		//check for the stop condition
		if (!calglRun->terminated)
		{
			calglRun->active = CAL_FALSE;
			//breaking the simulation
			calglRun->end_time = time(NULL);
			printf("\nSimulation terminated\n");
			printf(" Elapsed time: %d\n", (int)(calglRun->end_time - calglRun->start_time));
			printf("*-----------------------------------------------------*\n");
			//saving configuration
			//calglSaveStateUpdater3D(calglRun);
		}
	}
}
예제 #4
0
파일: mod2CA.c 프로젝트: knotman90/opencal
int main(int argc, char** argv){
	calglSetApplicationNameGlobalSettings("3D life");
	calglSetRowsAndColumnsGlobalSettings(25, 25);
	calglSetStepGlobalSettings(4000);
	calglSetWindowDimensionGlobalSettings(400, 400);
	calglSetWindowPositionGlobalSettings(40, 40);

	struct CALDrawModel3D* drawModel;

	//cadef and rundef
	life3D = calCADef3D(calglGetGlobalSettings()->rows, calglGetGlobalSettings()->columns, LAYERS, CAL_MOORE_NEIGHBORHOOD_3D, CAL_SPACE_TOROIDAL, CAL_NO_OPT);
	life3Dsimulation = calRunDef3D(life3D, 1, CAL_RUN_LOOP, CAL_UPDATE_IMPLICIT);
	//add substates
	Q.life = calAddSubstate3Db(life3D);
	//add transition function's elementary processes
	calAddElementaryProcess3D(life3D, life3DTransitionFunction);
	
	//simulation run setup
	calRunAddInitFunc3D(life3Dsimulation, life3DSimulationInit);
	calRunInitSimulation3D(life3Dsimulation);	//It is required in the case the simulation main loop is explicitated; similarly for calRunFinalizeSimulation3D
	calRunAddStopConditionFunc3D(life3Dsimulation, life3DSimulationStopCondition);

	//drawModel definition
	drawModel = calglDefDrawModel3D(CALGL_DRAW_MODE_FLAT, "Life", life3D, life3Dsimulation);
	calglAddToDrawModel3Db(drawModel, NULL, &Q.life, CALGL_TYPE_INFO_VERTEX_DATA, CALGL_TYPE_INFO_USE_DEFAULT, CALGL_DATA_TYPE_DYNAMIC);
	calglColor3D(drawModel, 0.5f, 0.5f, 0.5f, 1.0f);
	calglAddToDrawModel3Db(drawModel, Q.life, &Q.life, CALGL_TYPE_INFO_COLOR_DATA, CALGL_TYPE_INFO_USE_CONST_VALUE, CALGL_DATA_TYPE_DYNAMIC);
	calglAddToDrawModel3Db(drawModel, Q.life, &Q.life, CALGL_TYPE_INFO_NORMAL_DATA, CALGL_TYPE_INFO_USE_DEFAULT, CALGL_DATA_TYPE_DYNAMIC); 
	calglStartProcessWindow3D(argc, argv);

	//finalizations
	calRunFinalize3D(life3Dsimulation);
	calFinalize3D(life3D);

	calglDestroyGlobalSettings();
	calglCleanDrawModelList3D();
	return 0;
}