void Engine2D::Solve(Mesh2D &mesh)
{
	CheckStability(mesh);

	double alpha = (mesh.thermal_conductivity*time_step) / (mesh.spacial_step_size);
	double beta=alpha;
	vector<double> Temperature;
	// !Iterate over the states
	for (int i = 1; i <= number_of_states; i++)
	{
		// !Iterate through each row on the panel
		for (int j = 1; j < (mesh.spacial_length / mesh.spacial_step_size); j++)
		{
			// SET THE FIRST NODE FROM BC
			Temperature.push_back(5);
			current_configuration.push_back(std::make_tuple(mesh.all_node_locations.at(0), Temperature.at(0)));
			// !Iterate over the node
			for (int k = 1; k < mesh.number_of_nodes; k++)
			{
				Temperature.push_back(alpha*(GetPreviousTemperature(i, j, k, 'f') + GetPreviousTemperature(i, j, k, 'b')) +(beta*(GetPreviousTemperature(i, j,k, 'f') + GetPreviousTemperature(i, j, k, 'b'))) + ((1 - 2 * alpha - 2 * beta)*GetPreviousTemperature(i, j, k, 'n')));
				current_configuration.push_back(std::make_tuple(mesh.all_node_locations.at(k), Temperature.at(k)));
			}
			Temperature.push_back(5);
			current_configuration.push_back(std::make_tuple(mesh.all_node_locations.at(mesh.all_node_locations.size()-1), Temperature.at(mesh.number_of_nodes)));
			Instance.push_back(current_configuration);
			current_configuration.clear();
		}
		Results.push_back(Instance);
		Instance.clear();
	}
	CreateCSV(mesh);
}
示例#2
0
void CompTrainer::Train()
{
    /*First sampling for half a cycle(Time that sampling one set with size of STATIS_DATA_SIZE makes up of one cycle)
     *for each stream, and this operation is able to buffer the real stream.More important is that the trainer
     *calculate the sample which contains both the most recent data and outdated data every once half a cycle, the
     *sample what has mentioned above can reflect the trend and change more accurately.In one word, we always
     *hope that we can take less computation cost to obtain a better balanced effect.
     *By the way, if we ignore the computation cost(the computation in fact would cost not much time as the size of
     *the data set is not very large), we can consider the sampling procedure as a periodical behavior approximately.
     *The latter can maximum reduce the sampling error.
     */
    bool bStable;
    double max_regre_coeff;
    SampleEachStream(STATIS_DATA_SIZE/2);
    while (!m_bWantToStop)
    {
        bStable = true;
        max_regre_coeff = DBL_MIN;

        SampleEachStream(STATIS_DATA_SIZE/2);
        for (size_t i = 0; i < m_rMemPool.size(); i++)
        {
            CalcuStatis(i);
            if (!CheckStability(i))
            {
                bStable = false;
                double regre_coeff = CalculateRegreCoeff(i);
                if (regre_coeff > max_regre_coeff)
                    max_regre_coeff = regre_coeff;
            }
            usleep(1*1000); //sleep 1ms
        }
        if (!bStable)
            m_rMainVpp.TrainSleepInterval(max_regre_coeff);
    }
}