Raw File
clean_outputs.m
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% This file is part of NS2DDV.                                                      %
%                                                                                   %
% Copyright(C) 2011-2018    C. Calgaro  (caterina.calgaro@math.univ-lille1.fr)      %
%                           E. Creusé   (emmanuel.creuse@math.univ-lille1.fr)       %
%                           T. Goudon   (thierry.goudon@inria.fr)                   %
%                           A. Mouton   (alexandre.mouton@math.univ-lille1.fr)      %
%                                                                                   %
% NS2DDV is free software: you can redistribute it and/or modify it under the terms %
% of the GNU General Public License as published by the Free Software Foundation,   %
% either version 3 of the License, or (at your option) any later version.           %
%                                                                                   %
% NS2DDV is distributed in the hope that it will be useful, but WITHOUT ANY         %
% WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A   %
% PARTICULAR PURPOSE. See the GNU General Public License for more details.          %
%                                                                                   %
% You should have received a copy of the GNU General Public License along with      %
% NS2DDV. If not, see <http://www.gnu.org/licenses/>.                               %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function[] = clean_outputs(namefile)

	% INPUT
	% namefile		Name of the setup file for which there are some conflicts

	clearvars -except namefile
	warning('off', 'MATLAB:nargchk:deprecated')
	warning('off', 'MATLAB:contour:ConstantData')
    close all

	% Load the architecture of the code
	load_paths();

	% Load the input file that contains the parameters
	run(namefile);

	cvfiles = {strcat(PARAMETERS.OUTPUT.DIRECTORY_NAME, '/error_p_in_hmax.eps'), ...
				strcat(PARAMETERS.OUTPUT.DIRECTORY_NAME, '/error_u_in_hmax.eps'), ...
				strcat(PARAMETERS.OUTPUT.DIRECTORY_NAME, '/error_rho_in_hmax.eps'), ...
				strcat(PARAMETERS.OUTPUT.DIRECTORY_NAME, '/error_p_in_dtFE.eps'), ...
				strcat(PARAMETERS.OUTPUT.DIRECTORY_NAME, '/error_u_in_dtFE.eps'), ...
				strcat(PARAMETERS.OUTPUT.DIRECTORY_NAME, '/error_rho_in_dtFE.eps'), ...
				strcat(PARAMETERS.OUTPUT.DIRECTORY_NAME, '/error_p_in_Re.eps'), ...
				strcat(PARAMETERS.OUTPUT.DIRECTORY_NAME, '/error_u_in_Re.eps'), ...
				strcat(PARAMETERS.OUTPUT.DIRECTORY_NAME, '/error_rho_in_Re.eps'), ...
				strcat(PARAMETERS.OUTPUT.DIRECTORY_NAME, '/log_over_time')};

	switch PARAMETERS.CV_STUDY
		case {'NONE'}
			PARAMETERS_SET{1} = PARAMETERS;

		case {'IN_SPACE', 'IN_SPACETIME'}
			switch PARAMETERS.MESH.GENERATION
				case {'NS2DDV'}
					switch PARAMETERS.DOMAIN.GEOMETRY
						case {'RECTANGLE'}
							if (numel(PARAMETERS.MESH.NBSEG_X) == numel(PARAMETERS.MESH.NBSEG_Y))
								for kr=1:numel(PARAMETERS.MESH.NBSEG_X)
									PARAMETERS_SET{kr} = PARAMETERS;
									PARAMETERS_SET{kr}.MESH.NBSEG_X = PARAMETERS.MESH.NBSEG_X{kr};
									PARAMETERS_SET{kr}.MESH.NBSEG_Y = PARAMETERS.MESH.NBSEG_Y{kr};
									PARAMETERS_SET{kr}.MESH.NBSEG_X_LIST = PARAMETERS.MESH.NBSEG_X;
									PARAMETERS_SET{kr}.MESH.NBSEG_Y_LIST = PARAMETERS.MESH.NBSEG_Y;
								end
							else
								error('PARAMETERS.MESH.NBSEG_X and PARAMETERS.MESH.NBSEG_Y must have the same number of elements');
							end

						case {'CIRCLE'}
							for kr=1:numel(PARAMETERS.MESH.NBSEG_C)
								PARAMETERS_SET{kr} = PARAMETERS;
								PARAMETERS_SET{kr}.MESH.NBSEG_C = PARAMETERS.MESH.NBSEG_C{kr};
								PARAMETERS_SET{kr}.MESH.NBSEG_C_LIST = PARAMETERS.MESH.NBSEG_C;
							end

						otherwise
							error('Only RECTANGLE and CIRCLE domain geometry are allowed with NS2DDV mesh generation method');
					end

				case {'PDET'}
					for kr=1:numel(PARAMETERS.MESH.H0)
						PARAMETERS_SET{kr} = PARAMETERS;
						PARAMETERS_SET{kr}.MESH.H0 = PARAMETERS.MESH.H0{kr};
						PARAMETERS_SET{kr}.MESH.H0_LIST = PARAMETERS.MESH.H0;
					end

				otherwise
					error('Only NS2DDV and PDET mesh generation methods are allowed in a convergence/analysis study');
			end

		case {'IN_TIME'}
			for kr=1:numel(PARAMETERS.FE.C_STEP_TIME)
				PARAMETERS_SET{kr} = PARAMETERS;
				PARAMETERS_SET{kr}.FE.C_STEP_TIME = PARAMETERS.FE.C_STEP_TIME{kr};
				PARAMETERS_SET{kr}.FE.C_STEP_TIME_LIST = PARAMETERS.FE.C_STEP_TIME;
			end

		case {'IN_REYNOLDS'}
			for kr=1:numel(PARAMETERS.PHYSICAL.RE)
				PARAMETERS_SET{kr} = PARAMETERS;
				PARAMETERS_SET{kr}.PHYSICAL.RE = PARAMETERS.PHYSICAL.RE{kr};
				PARAMETERS_SET{kr}.PHYSICAL.RE_LIST = PARAMETERS.PHYSICAL.RE;
				PARAMETERS_SET{kr}.FE.ROT_CORRECTION = PARAMETERS.FE.ROT_CORRECTION{kr};
				PARAMETERS_SET{kr}.FE.ROT_CORRECTION_LIST = PARAMETERS.FE.ROT_CORRECTION;
			end

		otherwise
			error('Wrong value for CV_STUDY');
	end

	for kr=1:numel(PARAMETERS_SET)
		if ~strcmp(PARAMETERS.CV_STUDY, 'NONE')
			% Provide an output directory per run
			PARAMETERS_SET{kr}.OUTPUT.DIRECTORY_NAME = strcat(PARAMETERS.OUTPUT.DIRECTORY_NAME, '/', ...
						PARAMETERS.MODEL, '_', PARAMETERS.TESTCASE, '_', sprintf('%d', kr));
		end

		thedir = PARAMETERS_SET{kr}.OUTPUT.DIRECTORY_NAME;
		prefix = PARAMETERS_SET{kr}.OUTPUT.FILE_NAME;

		% Data files
		i = 0;
		thefile = strcat(thedir, '/', prefix, '_', num2str(i), '.h5');
		while (exist(thefile) == 2)
			delete(thefile);
			i = i+1;
			thefile = strcat(thedir, '/', prefix, '_', num2str(i), '.h5');
		end
		i = 0;
		thefile = strcat(thedir, '/', prefix, '_', num2str(i), '.xdmf');
		while (exist(thefile) == 2)
			delete(thefile);
			i = i+1;
			thefile = strcat(thedir, '/', prefix, '_', num2str(i), '.xdmf');
		end
		i = 0;
		thefile = strcat(thedir, '/', prefix, '_', num2str(i), '.mat');
		while (exist(thefile) == 2)
			delete(thefile);
			i = i+1;
			thefile = strcat(thedir, '/', prefix, '_', num2str(i), '.mat');
		end

		% Mesh files
		i = 0;
		thefile = strcat(thedir, '/', prefix, '_MESH_', num2str(i), '.h5');
		while (exist(thefile) == 2)
			delete(thefile);
			i = i+1;
			thefile = strcat(thedir, '/', prefix, '_MESH_', num2str(i), '.h5');
		end
		i = 0;
		thefile = strcat(thedir, '/', prefix, '_MESH_', num2str(i), '.mat');
		while (exist(thefile) == 2)
			delete(thefile);
			i = i+1;
			thefile = strcat(thedir, '/', prefix, '_MESH_', num2str(i), '.mat');
		end

		% Log file
		thefile = strcat(thedir, '/', prefix, '_log');
		if (exist(thefile) == 2)
			delete(thefile);
		end

		% Parameters binary file
		thefile = strcat(thedir, '/', prefix, '_parameters.mat');
		if (exist(thefile) == 2)
			delete(thefile);
		end

		% Backup files
		thedir = PARAMETERS_SET{kr}.BACKUP.DIRECTORY_NAME;
		i = 0;
		thefile = strcat(thedir, '/backup_', prefix, '_', num2str(i), '.mat');
		while (exist(thefile) == 2)
			delete(thefile);
			i = i+1;
			thefile = strcat(thedir, '/backup_', prefix, '_', num2str(i), '.mat');
		end

		if ~strcmp(PARAMETERS.CV_STUDY, 'NONE')
			thedir = PARAMETERS_SET{kr}.OUTPUT.DIRECTORY_NAME;
			if (exist(thedir) == 7)
				rmdir(thedir);
			end
			for i=1:numel(cvfiles)
				if (exist(cvfiles{i}) == 2)
					delete(cvfiles{i});
				end
			end
		end
	end
end
		
back to top