void Window_Profiles::Plot_Profiles()
{
	// Find the right x variable, together with the x axis lable
	QVector<double> axis_x;
	QString axis_x_title;
	FindXVariable(axis_x, axis_x_title);

	// XY Plot
	XYPlot* xyplot;
	xyplot = new XYPlot(this);
	xyplot->SetAbscissas(axis_x);
	xyplot->SetXTitle(axis_x_title);
	
	// Select additional y variables
	unsigned int n_selected_additional;
	{
		QList<QListWidgetItem*> selected_additional = ui.listWidget_Additional->selectedItems();
		n_selected_additional = selected_additional.size();
		for(unsigned int j=0;j<n_selected_additional;j++)
		{
			for(unsigned int k=0;k<data_->string_list_additional.size();k++)
			if (selected_additional[j]->text() == data_->string_list_additional[k])
			{
				xyplot->AddGraph(selected_additional[j]->text().toStdString(), data_->additional[k]);
				break;
			}
		}	
	}

	// Select y variables among the species
	{
		QList<QListWidgetItem*> selected_species = ui.listWidget_Species->selectedItems();
		unsigned int n_selected_species = selected_species.size();
		if (n_selected_species == 0 && n_selected_additional == 0)
		{
			QMessageBox msgBox;
			msgBox.setText(QString::fromStdString("At least one species must be selected in the Species Panel"));
			msgBox.exec();
			return;
		}

		for(unsigned int j=0;j<n_selected_species;j++)
		{
			for(unsigned int k=0;k<data_->string_list_massfractions_sorted.size();k++)
			if (selected_species[j]->text() == data_->string_list_massfractions_sorted[k])
			{
				QVector<double> tmp = data_->omega[data_->sorted_index[k]];
				const double mwj = data_->mw_species_[data_->sorted_index[k]];
			
				if (ui.radioButton_x->isChecked())
				{
					for(unsigned int i=0;i<data_->number_of_abscissas_;i++)
						tmp[i] = tmp[i] * data_->additional[data_->index_MW][i] / mwj;
				}
				else if (ui.radioButton_c->isChecked())
				{
					for(unsigned int i=0;i<data_->number_of_abscissas_;i++)
					{
						double cTot = data_->additional[data_->index_P][i]/PhysicalConstants::R_J_kmol/data_->additional[data_->index_T][i];
						tmp[i] = cTot * tmp[i] * data_->additional[data_->index_MW][i] / mwj;
					}
				}
				else if (ui.radioButton_p->isChecked())
				{
					for(unsigned int i=0;i<data_->number_of_abscissas_;i++)
						tmp[i] = tmp[i] * data_->additional[data_->index_MW][i] / mwj * (data_->additional[data_->index_P][i]/101325.);
				}

				xyplot->AddGraph(selected_species[j]->text().toStdString(), tmp);
				break;
			}
		}
	}

	// Plot
	xyplot->Plot();
}
void Window_Profiles::Plot_Selectivities()
{
	// Find the right x variable, together with the x axis lable
	QVector<double> axis_x;
	QString axis_x_title;
	FindXVariable(axis_x, axis_x_title);

	// XY Plot
	XYPlot* xyplot;
	xyplot = new XYPlot(this);
	xyplot->SetXTitle(axis_x_title);
	xyplot->SetYTitle("selectivity [-]");

	// Find the species for the conversion
	unsigned int index_species_conversion = data_->list_of_conversion_species_[ui.comboBox_Conversion->currentIndex()];

	// If the conversion is too small, the sensitivity coefficient is badly defined
	// Therefore the calculation is skipped in those points
	const double eta_threshold = 1.e-6;
	QVector<double> omega_conversion = data_->omega[index_species_conversion];
	QVector<double> eta_x;
	for(unsigned int i=0;i<data_->number_of_abscissas_;i++)
	{
		const double conversion = (omega_conversion[0] - omega_conversion[i])/omega_conversion[0];
		if (conversion > eta_threshold)	
				eta_x.push_back(axis_x[i]);
	}
	xyplot->SetAbscissas(eta_x);

	// Reconstruct the profiles
	{
		QList<QListWidgetItem*> selected_species_selectivity = ui.listWidget_Species_Selectivity->selectedItems();
		unsigned int n_selected_species = selected_species_selectivity.size();
		if (n_selected_species == 0)
		{
			QMessageBox msgBox;
			msgBox.setText(QString::fromStdString("At least one species must be selected in the Species (Selectivity) Panel"));
			msgBox.exec();
			return;
		}

		for(unsigned int j=0;j<n_selected_species;j++)
		{
			for(unsigned int k=0;k<data_->string_list_massfractions_sorted.size();k++)
			if (selected_species_selectivity[j]->text() == data_->string_list_massfractions_sorted[k])
			{
				unsigned int index_selectivity = data_->sorted_index[k];
				
				QVector<double> sigma;
				for(unsigned int i=0;i<data_->number_of_abscissas_;i++)
				{
					const double conversion = (omega_conversion[0] - omega_conversion[i])/omega_conversion[0];
					if (conversion > eta_threshold)
						sigma.push_back(data_->omega[index_selectivity][i]/omega_conversion[0]/conversion);
				}

				if (ui.radioButton_Selectivity_Mole->isChecked() == true)
				{
					const double mw_conversion = data_->mw_species_[index_species_conversion];
					const double mw_selectivity = data_->mw_species_[index_selectivity];
					for(unsigned int i=0;i<sigma.size();i++)
						sigma[i] *= mw_conversion/mw_selectivity;
				}

				if (ui.radioButton_Selectivity_Element->isChecked() == true)
				{
					const double n_conversion  = data_->thermodynamicsMapXML->atomic_composition()(index_species_conversion, ui.comboBox_Elements->currentIndex());
					const double n_selectivity = data_->thermodynamicsMapXML->atomic_composition()(index_selectivity, ui.comboBox_Elements->currentIndex());

					if (n_conversion > 0)
					{
						const double mw_conversion = data_->mw_species_[index_species_conversion];
						const double mw_selectivity = data_->mw_species_[index_selectivity];
						for(unsigned int i=0;i<sigma.size();i++)
							sigma[i] *= mw_conversion/mw_selectivity *n_selectivity/n_conversion;
					}
					else
					{
						QMessageBox msgBox;
						msgBox.setText(QString::fromStdString("The selected element is not present in the selected species (conversion side)"));
						msgBox.exec();
						return;
					}
				}

				xyplot->AddGraph(selected_species_selectivity[j]->text().toStdString(), sigma);
				break;
			}
		}

		// Plot
		xyplot->Plot();
	}
}