From 7832d1dcf071538352f659daa3cb2ddeaa369857 Mon Sep 17 00:00:00 2001 From: Emily Bourne Date: Tue, 20 Feb 2024 14:52:17 +0000 Subject: [PATCH] Resolve "Remove perturb_mode and perturb_amplitude from SpeciesInfo" --- .../bump_on_tail/bumpontail_fem_uniform.cpp | 10 +- .../bump_on_tail/bumpontail_fft.cpp | 10 +- .../geometryXVx/landau/landau_fem_uniform.cpp | 10 +- simulations/geometryXVx/landau/landau_fft.cpp | 10 +- simulations/geometryXVx/sheath/sheath.cpp | 10 +- .../geometryXYVxVy/landau/landau4d_fft.cpp | 10 +- src/speciesinfo/species_info.hpp | 34 +-- .../advection_2d_rp/CMakeLists.txt | 2 +- .../advection_2d_rp/advection_all_tests.cpp | 22 +- .../advection_2d_rp/advection_functions.py | 222 ++++++---------- .../advection_selected_test.cpp | 62 +++-- ...ols.hpp => advection_simulation_utils.hpp} | 238 +++++++++--------- .../advection_2d_rp/animated_curves.py | 69 +++-- .../display_all_errors_for_gtest.py | 130 +++++----- .../advection_2d_rp/display_curves.py | 47 ++-- .../advection_2d_rp/display_feet_errors.py | 33 ++- .../advection_2d_rp/params.yaml.hpp | 8 +- .../advection_2d_rp/test_cases.hpp | 178 ++++--------- tests/geometryXVx/collisions_inter.cpp | 10 +- tests/geometryXVx/collisions_intra_gridvx.cpp | 10 +- .../collisions_intra_maxwellian.cpp | 10 +- .../femnonperiodicpoissonsolver.cpp | 10 +- .../geometryXVx/femperiodicpoissonsolver.cpp | 10 +- tests/geometryXVx/fftpoissonsolver.cpp | 10 +- tests/geometryXVx/fluid_moments.cpp | 10 +- tests/geometryXVx/kineticsource.cpp | 10 +- tests/geometryXVx/krooksource.cpp | 28 +-- tests/geometryXYVxVy/fft_poisson.cpp | 12 +- tests/species_info.cpp | 10 +- 29 files changed, 474 insertions(+), 761 deletions(-) rename tests/geometryRTheta/advection_2d_rp/{advection_maths_tools.hpp => advection_simulation_utils.hpp} (75%) diff --git a/simulations/geometryXVx/bump_on_tail/bumpontail_fem_uniform.cpp b/simulations/geometryXVx/bump_on_tail/bumpontail_fem_uniform.cpp index 5fa64d7ce..3bbdb49f7 100644 --- a/simulations/geometryXVx/bump_on_tail/bumpontail_fem_uniform.cpp +++ b/simulations/geometryXVx/bump_on_tail/bumpontail_fem_uniform.cpp @@ -143,11 +143,7 @@ int main(int argc, char** argv) } // Initialization of the distribution function - ddc::init_discrete_space( - std::move(charges), - std::move(masses), - std::move(init_perturb_amplitude), - std::move(init_perturb_mode)); + ddc::init_discrete_space(std::move(charges), std::move(masses)); device_t allfequilibrium_device(meshSpVx); BumpontailEquilibrium const init_fequilibrium( std::move(epsilon_bot), @@ -162,8 +158,8 @@ int main(int argc, char** argv) if (iter_start == 0) { SingleModePerturbInitialization const init(allfequilibrium_device, - ddc::host_discrete_space().perturb_modes(), - ddc::host_discrete_space().perturb_amplitudes()); + init_perturb_mode.span_cview(), + init_perturb_amplitude.span_cview()); init(allfdistribu_device); } else { RestartInitialization const restart(iter_start, time_start); diff --git a/simulations/geometryXVx/bump_on_tail/bumpontail_fft.cpp b/simulations/geometryXVx/bump_on_tail/bumpontail_fft.cpp index 0facc49fa..72a3b1533 100644 --- a/simulations/geometryXVx/bump_on_tail/bumpontail_fft.cpp +++ b/simulations/geometryXVx/bump_on_tail/bumpontail_fft.cpp @@ -138,11 +138,7 @@ int main(int argc, char** argv) } // Initialization of the distribution function - ddc::init_discrete_space( - std::move(charges), - std::move(masses), - std::move(init_perturb_amplitude), - std::move(init_perturb_mode)); + ddc::init_discrete_space(std::move(charges), std::move(masses)); device_t allfequilibrium_device(meshSpVx); BumpontailEquilibrium const init_fequilibrium( std::move(epsilon_bot), @@ -157,8 +153,8 @@ int main(int argc, char** argv) if (iter_start == 0) { SingleModePerturbInitialization const init(allfequilibrium_device, - ddc::host_discrete_space().perturb_modes(), - ddc::host_discrete_space().perturb_amplitudes()); + init_perturb_mode.span_cview(), + init_perturb_amplitude.span_cview()); init(allfdistribu_device); } else { RestartInitialization const restart(iter_start, time_start); diff --git a/simulations/geometryXVx/landau/landau_fem_uniform.cpp b/simulations/geometryXVx/landau/landau_fem_uniform.cpp index 33b55c4a7..7bb94a531 100644 --- a/simulations/geometryXVx/landau/landau_fem_uniform.cpp +++ b/simulations/geometryXVx/landau/landau_fem_uniform.cpp @@ -142,11 +142,7 @@ int main(int argc, char** argv) } // Initialization of the distribution function - ddc::init_discrete_space( - std::move(charges), - std::move(masses), - std::move(init_perturb_amplitude), - std::move(init_perturb_mode)); + ddc::init_discrete_space(std::move(charges), std::move(masses)); device_t allfequilibrium_device(meshSpVx); MaxwellianEquilibrium const init_fequilibrium( std::move(density_eq), @@ -161,8 +157,8 @@ int main(int argc, char** argv) if (iter_start == 0) { SingleModePerturbInitialization const init(allfequilibrium_device, - ddc::host_discrete_space().perturb_modes(), - ddc::host_discrete_space().perturb_amplitudes()); + init_perturb_mode.span_cview(), + init_perturb_amplitude.span_cview()); init(allfdistribu_device); } else { RestartInitialization const restart(iter_start, time_start); diff --git a/simulations/geometryXVx/landau/landau_fft.cpp b/simulations/geometryXVx/landau/landau_fft.cpp index d5eaf12fb..9b7a2b8f5 100644 --- a/simulations/geometryXVx/landau/landau_fft.cpp +++ b/simulations/geometryXVx/landau/landau_fft.cpp @@ -138,11 +138,7 @@ int main(int argc, char** argv) } // Initialization of the distribution function - ddc::init_discrete_space( - std::move(charges), - std::move(masses), - std::move(init_perturb_amplitude), - std::move(init_perturb_mode)); + ddc::init_discrete_space(std::move(charges), std::move(masses)); device_t allfequilibrium_device(meshSpVx); MaxwellianEquilibrium const init_fequilibrium( std::move(density_eq), @@ -157,8 +153,8 @@ int main(int argc, char** argv) if (iter_start == 0) { SingleModePerturbInitialization const init(allfequilibrium_device, - ddc::host_discrete_space().perturb_modes(), - ddc::host_discrete_space().perturb_amplitudes()); + init_perturb_mode.span_cview(), + init_perturb_amplitude.span_cview()); init(allfdistribu_device); } else { RestartInitialization const restart(iter_start, time_start); diff --git a/simulations/geometryXVx/sheath/sheath.cpp b/simulations/geometryXVx/sheath/sheath.cpp index d2575b344..2f1f0745d 100644 --- a/simulations/geometryXVx/sheath/sheath.cpp +++ b/simulations/geometryXVx/sheath/sheath.cpp @@ -157,11 +157,7 @@ int main(int argc, char** argv) } // Initialization of the distribution function - ddc::init_discrete_space( - std::move(charges), - std::move(masses), - std::move(init_perturb_amplitude), - std::move(init_perturb_mode)); + ddc::init_discrete_space(std::move(charges), std::move(masses)); device_t allfequilibrium_device(meshSpVx); MaxwellianEquilibrium const init_fequilibrium( std::move(density_eq), @@ -176,8 +172,8 @@ int main(int argc, char** argv) if (iter_start == 0) { SingleModePerturbInitialization const init(allfequilibrium_device, - ddc::host_discrete_space().perturb_modes(), - ddc::host_discrete_space().perturb_amplitudes()); + init_perturb_mode.span_cview(), + init_perturb_amplitude.span_cview()); init(allfdistribu_device); } else { RestartInitialization const restart(iter_start, time_start); diff --git a/simulations/geometryXYVxVy/landau/landau4d_fft.cpp b/simulations/geometryXYVxVy/landau/landau4d_fft.cpp index bd9114efe..fdafd173a 100644 --- a/simulations/geometryXYVxVy/landau/landau4d_fft.cpp +++ b/simulations/geometryXYVxVy/landau/landau4d_fft.cpp @@ -179,11 +179,7 @@ int main(int argc, char** argv) } // Initialization of the distribution function - ddc::init_discrete_space( - std::move(charges), - std::move(masses), - std::move(init_perturb_amplitude), - std::move(init_perturb_mode)); + ddc::init_discrete_space(std::move(charges), std::move(masses)); DFieldSpVxVy allfequilibrium(meshSpVxVy); MaxwellianEquilibrium const init_fequilibrium( std::move(density_eq), @@ -193,8 +189,8 @@ int main(int argc, char** argv) DFieldSpXYVxVy allfdistribu(meshSpXYVxVy); SingleModePerturbInitialization const init(allfequilibrium, - ddc::host_discrete_space().perturb_modes(), - ddc::host_discrete_space().perturb_amplitudes()); + init_perturb_mode.span_cview(), + init_perturb_amplitude.span_cview()); init(allfdistribu); // --> Algorithm info diff --git a/src/speciesinfo/species_info.hpp b/src/speciesinfo/species_info.hpp index 2bdab6c25..1e8fa5008 100644 --- a/src/speciesinfo/species_info.hpp +++ b/src/speciesinfo/species_info.hpp @@ -35,14 +35,6 @@ class SpeciesInformation // mass of the particles of all kinetic species ddc::Chunk> m_mass; - // Initial perturbation amplitude of all kinetic species - ddc::Chunk> - m_perturb_amplitude; - - // Initial perturbation mode of all kinetic species - ddc::Chunk> - m_perturb_mode; - // workaround to access charges on the device ddc::ChunkView m_charge_view; @@ -65,36 +57,24 @@ class SpeciesInformation explicit Impl(Impl const& impl) : m_charge(impl.m_charge.domain()) , m_mass(impl.m_mass.domain()) - , m_perturb_amplitude(impl.m_perturb_amplitude.domain()) - , m_perturb_mode(impl.m_perturb_mode.domain()) , m_ielec(impl.m_ielec) { m_charge_view = m_charge.span_cview(); m_mass_view = m_mass.span_cview(); ddc::deepcopy(m_charge, impl.m_charge); ddc::deepcopy(m_mass, impl.m_mass); - ddc::deepcopy(m_perturb_amplitude, impl.m_perturb_amplitude); - ddc::deepcopy(m_perturb_mode, impl.m_perturb_mode); } /** * @brief Main constructor taking all attributes * @param[in] charge array storing both kinetic and adiabatic charges * @param[in] mass array storing both kinetic and adiabatic masses - * @param[in] perturb_amplitude array storing kinetic pertubation amplitudes - * @param[in] perturb_mode array storing kinetic pertubation modes */ Impl(ddc::Chunk> charge, ddc::Chunk> - mass, - ddc::Chunk> - perturb_amplitude, - ddc::Chunk> - perturb_mode) + mass) : m_charge(std::move(charge)) , m_mass(std::move(mass)) - , m_perturb_amplitude(std::move(perturb_amplitude)) - , m_perturb_mode(std::move(perturb_mode)) { m_charge_view = m_charge.span_cview(); m_mass_view = m_mass.span_cview(); @@ -146,18 +126,6 @@ class SpeciesInformation { return m_mass.span_view(); } - - /// @return kinetic perturbation amplitudes array - auto perturb_amplitudes() const - { - return m_perturb_amplitude.span_view(); - } - - /// @return kinetic perturbation modes array - auto perturb_modes() const - { - return m_perturb_mode.span_view(); - } }; }; diff --git a/tests/geometryRTheta/advection_2d_rp/CMakeLists.txt b/tests/geometryRTheta/advection_2d_rp/CMakeLists.txt index 3d2b22c49..1ae59f68d 100644 --- a/tests/geometryRTheta/advection_2d_rp/CMakeLists.txt +++ b/tests/geometryRTheta/advection_2d_rp/CMakeLists.txt @@ -19,7 +19,7 @@ set(TIME_METHOD "CRANK_NICOLSON_METHOD") -foreach(MAPPING_TYPE "CIRCULAR_MAPPING" "CZARNY_MAPPING_PHYSICAL" "CZARNY_MAPPING_PSEUDO_CARTESIAN" "DISCRETE_MAPPING") +foreach(MAPPING_TYPE "CIRCULAR_MAPPING_PHYSICAL" "CZARNY_MAPPING_PHYSICAL" "CZARNY_MAPPING_PSEUDO_CARTESIAN" "DISCRETE_MAPPING_PSEUDO_CARTESIAN") foreach(SIMULATION "TRANSLATION_SIMULATION" "ROTATION_SIMULATION" "DECENTRED_ROTATION_SIMULATION") set(test_name "advection_${MAPPING_TYPE}__${TIME_METHOD}__${SIMULATION}") add_executable("${test_name}" diff --git a/tests/geometryRTheta/advection_2d_rp/advection_all_tests.cpp b/tests/geometryRTheta/advection_2d_rp/advection_all_tests.cpp index 5e175a668..dc9656c42 100644 --- a/tests/geometryRTheta/advection_2d_rp/advection_all_tests.cpp +++ b/tests/geometryRTheta/advection_2d_rp/advection_all_tests.cpp @@ -42,7 +42,7 @@ #include #include "advection_domain.hpp" -#include "advection_maths_tools.hpp" +#include "advection_simulation_utils.hpp" #include "bsl_advection_rp.hpp" #include "geometry.hpp" #include "paraconfpp.hpp" @@ -175,7 +175,6 @@ struct GeneralParameters double final_time; bool if_save_curves; bool if_save_feet; - int counter_function; }; template @@ -189,10 +188,15 @@ void run_simulations_with_methods( Numerics methods(sim.advection_domain, num_params); auto& num = std::get(methods.numerics); - std::ostringstream ss; - ss << sim.mapping_name << " MAPPING - " << sim.domain_name << " DOMAIN - " << num.method_name - << " - "; - std::string simulation_name = ss.str(); + std::ostringstream name_stream; + name_stream << sim.mapping_name << " MAPPING - " << sim.domain_name << " DOMAIN - " + << num.method_name << " - "; + std::string simulation_name = name_stream.str(); + + std::ostringstream output_stream; + output_stream << to_lower(sim.mapping_name) << "_" << to_lower(sim.domain_name) << "-" + << to_lower(num.method_name) << "-"; + std::string output_stem = output_stream.str(); simulate_the_3_simulations( sim.mapping, @@ -207,7 +211,7 @@ void run_simulations_with_methods( num.time_step, params.if_save_curves, params.if_save_feet, - params.counter_function, + output_stem, simulation_name); if constexpr (i_feet < methods.size_tuple - 1) { @@ -371,7 +375,6 @@ int main(int argc, char** argv) // SIMULATION: ========================================================================== - int counter_function(0); GeneralParameters params = {grid, interpolator, @@ -379,8 +382,7 @@ int main(int argc, char** argv) spline_evaluator_extrapol, final_time, if_save_curves, - if_save_feet, - counter_function}; + if_save_feet}; run_simulations_with_methods(simulations, num_params, params); end_full_simulation = std::chrono::system_clock::now(); diff --git a/tests/geometryRTheta/advection_2d_rp/advection_functions.py b/tests/geometryRTheta/advection_2d_rp/advection_functions.py index 502220056..09137305e 100644 --- a/tests/geometryRTheta/advection_2d_rp/advection_functions.py +++ b/tests/geometryRTheta/advection_2d_rp/advection_functions.py @@ -2,13 +2,16 @@ Define all the functions needed in the python files of the advection_2d_rp folder. """ +import argparse +import os import subprocess -import argparse +from collections import namedtuple import numpy as np +import yaml - +SimulationResults = namedtuple('SimulationResults', ('name', 'l_inf_error', 'l_2_error')) def set_input(rmin_def, rmax_def, Nr_def, Nth_def, dt_def, T_def, curves_def=False, feet_def=False): """ @@ -71,70 +74,27 @@ def set_input(rmin_def, rmax_def, Nr_def, Nth_def, dt_def, T_def, curves_def=Fal help=f'Boolean to select if the feet are saved. By default, feet = {"True"*feet_def + "False"*(not feet_def)}.') parser.add_argument('--plot', action='store_true', help='Plot the results.') - - print("") + parser.add_argument('--verbose', action='store_true', help='Output information about the execution.') args = parser.parse_args() - rmin = args.rmin - rmax = args.rmax - Nr = args.Nr - Nth = args.Nth - dt = args.dt - T = args.T - curves = args.curves - feet = args.feet - if_plot = args.plot + yaml_parameters = { + 'r_min': args.rmin, + 'r_max': args.rmax, + 'r_size': args.Nr, + 'p_size': args.Nth, + 'time_step': args.dt, + 'final_time': args.T, + 'save_curves': args.curves, + 'save_feet': args.feet + } executable = args.executable[0] - return executable, rmin, rmax, Nr, Nth, dt, T, curves, feet, if_plot + return executable, yaml_parameters, args.plot, args.verbose - -def params_file(rmin, rmax, Nr, Nth, dt, T, curves=False, feet=False): - """ - Fill in the params.yaml parameters file with the correct inputs. - - Parameters - ---------- - rmin : float - Minimum value of the r values. - - rmax : float - Maximum value of the r values. - - Nr : int - Number of break points in r dimension - - Nth : int - Number of break points in theta dimension - - dt : float - Time step. - - T : float - Final time. - - curves : bool - Boolean to select if the values of the advected function are saved. - - feet : bool - Boolean to select if the characteristic feet are saved. - """ - with open("params.yaml", "w", encoding="utf-8") as f: - print("Mesh:", file=f) - print(f" r_min: {rmin}", file=f) - print(f" r_max: {rmax}", file=f) - print(f" r_size: {Nr}", file=f) - print(f" p_size: {Nth}", file=f) - print(f" time_step: {dt}", file=f) - print(f" final_time: {T}", file=f) - print(" save_curves: "+"true"*curves + "false"*(not curves), file=f) - print(" save_feet: "+"true"*feet + "false"*(not feet), file=f) - - -def execute(executable, rmin, rmax, Nr, Nth, dt, T, curves=False, feet=False, print_out=True): +def execute(executable, yaml_parameters, print_out=True): """ Launch the executable given as input. @@ -143,29 +103,8 @@ def execute(executable, rmin, rmax, Nr, Nth, dt, T, curves=False, feet=False, pr executable : string Path the executable of the test we want to launch. - rmin : float - Minimum value of the r values. - - rmax : float - Maximum value of the r values. - - Nr : int - Number of break points in r dimension - - Nth : int - Number of break points in theta dimension - - dt : float - Time step. - - T : float - Final time. - - curves : bool - Boolean to select if the values of the advected function are saved. - - feet : bool - Boolean to select if the characteristic feet are saved. + yaml_parameters : dict + A dictionary describing the simulation parameters. print_out : bool Boolean to select if the output are printed in the console. @@ -174,89 +113,90 @@ def execute(executable, rmin, rmax, Nr, Nth, dt, T, curves=False, feet=False, pr ------- The output of the executable. """ - params_file(rmin, rmax, Nr, Nth, dt, T, curves, feet) + params_file = executable+"_params.yaml" + with open(params_file, "w", encoding="utf-8") as f: + print(yaml.dump({'Mesh':yaml_parameters}), file=f) - with subprocess.Popen([executable, "params.yaml"], stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True) as p: + with subprocess.Popen([executable, params_file], stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True) as p: out, err = p.communicate() + if err: + print(err) assert p.returncode == 0 if print_out: print(out) - if err: - print(err) - if print_out: print("") return out - - -def get_fct_names(var_out): +def get_simulation_config(executable_file): """ - Get the reduced names of all the test cases from the output. - The names are reduced to the name of the simulation (no mapping, - no advection domain, no method). + Get the keys which identify the simulation from the executable name. Parameters ---------- - var_out : string - The output of the executable. + executable_file : str + The location of the executable. Returns ------- - A list of string containing the names of the test cases. + mapping : str + The key which identifies the mapping (and domain). + method : str + The key which identifies the numerical method. + domain : str + The key which identifies the domain (physical/pseudo cartesian). + simulation : str + The key which identifies the simulation. + description : str + The description of the simulation. """ - out_lines = var_out.split('\n') - out_words = [line.split(' - ') for line in out_lines[1:] if "MAPPING" in line and "DOMAIN" in line] - fct_names = [line[3][:-3].lower() for line in out_words] - return fct_names - -def get_full_fct_names(var_out): + executable_name = os.path.basename(executable_file) + mapping, method, simulation = executable_name.replace('advection_', '').split('__') + mapping, domain = mapping.lower().split('_mapping_') + method = method.replace('_METHOD', '').lower() + simulation = simulation.replace('_SIMULATION', '').capitalize() + description = f'{simulation.capitalize()} with {method} on {mapping} and {domain}' + return mapping, method, domain, simulation, description + +def extract_simulation_results(var_out): """ - Get the full names of all the test cases from the output. + Get the results of a set of simulations. Parameters ---------- - var_out : string - The output of the executable. + var_out : list[str] + A list containing the output of each simulation that was run. Returns ------- - A list of string containing the names of the test cases. + dict[tuple[str, str, str], SimulationResults] + A dictionary whose keys are a 3-tuple describing the numerical method, the mapping, and the + simulation that was run, and whose values are SimulationResults tuples containing the values + for the different errors and a descriptive name for the simulation. """ - out_lines = var_out.split('\n') - out_words = [[l.strip(' :') for l in line.split(' - ')] for line in out_lines[1:] if "MAPPING" in line and "DOMAIN" in line] - fct_names = [line[3].capitalize() + " with " + line[2].lower() + " on " - + line[0].lower() + " and " + line[1].lower() for line in out_words] - return fct_names + out_lines = [o.split('\n') for o in var_out] -def get_fct_name_key(full_name): - """ - Get the keys which identify the test case from its full name. + # Extract lines which describe the simulation + # E.g: CIRCULAR MAPPING - PHYSICAL DOMAIN - CRANK NICOLSON - DECENTRED ROTATION : + simulation_description = [[l.strip(' :').lower() for l in line.split(' - ')] for line in out_lines[0] + if "MAPPING" in line and "DOMAIN" in line] - Parameters - ---------- - full_name : str - The full name of the case as outputted by get_full_fct_names. + # Build a readable description of the simulation + simulation_names = [f'{simu.capitalize()} with {method} on {mapping} and {domain}' + for mapping, domain, method, simu in simulation_description] - Returns - ------- - problem_type : str - The key describing the problem type ['Translation'|'Rotation'|'Decentered rotation']. - time_integration_method : str - The time integration method used to solve the problem ['euler', 'crank nicolson', 'rk3', 'rk4']. - mapping : str - The mapping which was examined in the test ['circular', 'czarny_physical', 'czarny_pseudo_cart', 'discrete']. - """ - problem_type, s = full_name.split(' with ') - time_integration_method, s = s.split(' on ') - mapping, domain = s.split(' and ') - mapping, _ = mapping.split(' mapping') - if mapping == 'czarny': - domain, _ = domain.split(' domain') - domain = domain.replace(' ','_').lower() - mapping = f'{mapping}_{domain}' - return problem_type, time_integration_method, mapping + simulation_keys = [(method, mapping.replace(" mapping","")+" "+domain.replace(" domain",""), simu.capitalize()) + for mapping, domain, method, simu in simulation_description] + + l_inf_errors = [[float(line.split()[-1]) for line in o if "Max absolute error" in line] for o in out_lines] + l_2_errors = [[float(line.split()[-1]) for line in o if "Relative L2 norm error" in line] for o in out_lines] + + simulation_results = {key: SimulationResults(name, linf_err, l2_err) + for key, name, linf_err, l2_err + in zip(simulation_keys, simulation_names, zip(*l_inf_errors), zip(*l_2_errors))} + + return simulation_results def treatment(namefile): @@ -273,13 +213,13 @@ def treatment(namefile): Lists of the function values; coordinates in r; coordinates in theta; coordinates in x; coordinates in y. """ - File = np.loadtxt(namefile) + File = np.loadtxt(namefile, float) #Ir, Ip, IVr, IVp = [], [], [], [] - CoordR = File[:, 4] - CoordP = File[:, 5] - CoordX = File[:, 6] - CoordY = File[:, 7] - list_F = File[:, 8] + CoordR = File[:, 2] + CoordP = File[:, 3] + CoordX = File[:, 4] + CoordY = File[:, 5] + list_F = File[:, 6] return list_F, CoordR, CoordP, CoordX, CoordY diff --git a/tests/geometryRTheta/advection_2d_rp/advection_selected_test.cpp b/tests/geometryRTheta/advection_2d_rp/advection_selected_test.cpp index 1f10ae637..b6702ad76 100644 --- a/tests/geometryRTheta/advection_2d_rp/advection_selected_test.cpp +++ b/tests/geometryRTheta/advection_2d_rp/advection_selected_test.cpp @@ -45,7 +45,7 @@ #include #include -#include "advection_maths_tools.hpp" +#include "advection_simulation_utils.hpp" #include "itimestepper.hpp" #include "spline_foot_finder.hpp" @@ -54,7 +54,7 @@ namespace fs = std::filesystem; namespace { -#if defined(CIRCULAR_MAPPING) +#if defined(CIRCULAR_MAPPING_PHYSICAL) using RDimX_adv = typename AdvectionPhysicalDomain< CircularToCartesian>::RDimX_adv; using RDimY_adv = typename AdvectionPhysicalDomain< @@ -71,7 +71,7 @@ using RDimX_adv = typename AdvectionPseudoCartesianDomain< using RDimY_adv = typename AdvectionPseudoCartesianDomain< CzarnyToCartesian>::RDimY_adv; -#elif defined(DISCRETE_MAPPING) +#elif defined(DISCRETE_MAPPING_PSEUDO_CARTESIAN) using RDimX_adv = typename AdvectionPseudoCartesianDomain< DiscreteToCartesian>::RDimX_adv; using RDimY_adv = typename AdvectionPseudoCartesianDomain< @@ -109,14 +109,14 @@ int main(int argc, char** argv) int const Nt = PCpp_int(conf_voicexx, ".Mesh.p_size"); double const dt = PCpp_double(conf_voicexx, ".Mesh.time_step"); double const final_time = PCpp_double(conf_voicexx, ".Mesh.final_time"); - bool const if_save_curves = PCpp_bool(conf_voicexx, ".Mesh.save_curves"); - bool const if_save_feet = PCpp_bool(conf_voicexx, ".Mesh.save_feet"); + bool const save_curves = PCpp_bool(conf_voicexx, ".Mesh.save_curves"); + bool const save_feet = PCpp_bool(conf_voicexx, ".Mesh.save_feet"); PC_tree_destroy(&conf_voicexx); - if (if_save_curves or if_save_feet) { + if (save_curves or save_feet) { fs::create_directory("output"); } - if (if_save_curves) { + if (save_curves) { fs::create_directory("output/curves"); } @@ -195,24 +195,28 @@ int main(int argc, char** argv) g_null_boundary_2d); - - double const czarny_e = 0.3; - double const czarny_epsilon = 1.4; + std::string key; // SELECTION OF THE MAPPING AND THE ADVECTION DOMAIN. -#if defined(CIRCULAR_MAPPING) +#if defined(CIRCULAR_MAPPING_PHYSICAL) CircularToCartesian analytical_mapping; CircularToCartesian mapping; AdvectionPhysicalDomain advection_domain(analytical_mapping); std::string const mapping_name = "CIRCULAR"; std::string const domain_name = "PHYSICAL"; + key += "circular_physical"; +#else -#elif defined(CZARNY_MAPPING_PHYSICAL) + double const czarny_e = 0.3; + double const czarny_epsilon = 1.4; + +#if defined(CZARNY_MAPPING_PHYSICAL) CzarnyToCartesian analytical_mapping(czarny_e, czarny_epsilon); CzarnyToCartesian mapping(czarny_e, czarny_epsilon); AdvectionPhysicalDomain advection_domain(analytical_mapping); std::string const mapping_name = "CZARNY"; std::string const domain_name = "PHYSICAL"; + key += "czarny_physical"; #elif defined(CZARNY_MAPPING_PSEUDO_CARTESIAN) CzarnyToCartesian analytical_mapping(czarny_e, czarny_epsilon); @@ -220,8 +224,9 @@ int main(int argc, char** argv) AdvectionPseudoCartesianDomain advection_domain(mapping); std::string const mapping_name = "CZARNY"; std::string const domain_name = "PSEUDO CARTESIAN"; + key += "czarny_pseudo_cartesian"; -#elif defined(DISCRETE_MAPPING) +#elif defined(DISCRETE_MAPPING_PSEUDO_CARTESIAN) CzarnyToCartesian analytical_mapping(czarny_e, czarny_epsilon); DiscreteToCartesian mapping = DiscreteToCartesian:: @@ -229,47 +234,62 @@ int main(int argc, char** argv) AdvectionPseudoCartesianDomain advection_domain(mapping); std::string const mapping_name = "DISCRETE"; std::string const domain_name = "PSEUDO CARTESIAN"; + key += "discrete_pseudo_cartesian"; +#endif #endif - + key += "-"; // SELECTION OF THE TIME INTEGRATION METHOD. #if defined(EULER_METHOD) Euler, VectorDFieldRP> time_stepper(grid); std::string const method_name = "EULER"; + key += "euler"; #elif defined(CRANK_NICOLSON_METHOD) double const epsilon_CN = 1e-8; CrankNicolson, VectorDFieldRP> time_stepper(grid, 20, epsilon_CN); std::string const method_name = "CRANK NICOLSON"; + key += "crank_nicolson"; #elif defined(RK3_METHOD) RK3, VectorDFieldRP> time_stepper(grid); std::string const method_name = "RK3"; + key += "rk3"; #elif defined(RK4_METHOD) RK4, VectorDFieldRP> time_stepper(grid); std::string const method_name = "RK4"; + key += "rk4"; #endif + key += "-"; // SELECTION OF THE SIMULATION. #if defined(TRANSLATION_SIMULATION) TranslationSimulation simulation(mapping, rmin, rmax); - std::string const simu_type = " TRANSLATION : "; + std::string const simu_type = "TRANSLATION"; + key += "Translation"; #elif defined(ROTATION_SIMULATION) RotationSimulation simulation(mapping, rmin, rmax); - std::string const simu_type = " ROTATION : "; + std::string const simu_type = "ROTATION"; + key += "Rotation"; #elif defined(DECENTRED_ROTATION_SIMULATION) DecentredRotationSimulation simulation(mapping); - std::string const simu_type = " DECENTRED ROTATION : "; + std::string const simu_type = "DECENTRED ROTATION"; + key += "Decentred_rotation"; #endif + std::string output_folder = key + "_output"; + if (save_curves or save_feet) { + fs::create_directory(output_folder); + } + std::cout << mapping_name << " MAPPING - " << domain_name << " DOMAIN - " << method_name - << " - " << simu_type << std::endl; + << " - " << simu_type << " : " << std::endl; simulate( mapping, analytical_mapping, @@ -282,7 +302,7 @@ int main(int argc, char** argv) spline_evaluator_extrapol, final_time, dt, - if_save_curves, - if_save_feet, - -1); + save_curves, + save_feet, + output_folder); } diff --git a/tests/geometryRTheta/advection_2d_rp/advection_maths_tools.hpp b/tests/geometryRTheta/advection_2d_rp/advection_simulation_utils.hpp similarity index 75% rename from tests/geometryRTheta/advection_2d_rp/advection_maths_tools.hpp rename to tests/geometryRTheta/advection_2d_rp/advection_simulation_utils.hpp index 809c273d5..aa81fbcdc 100644 --- a/tests/geometryRTheta/advection_2d_rp/advection_maths_tools.hpp +++ b/tests/geometryRTheta/advection_2d_rp/advection_simulation_utils.hpp @@ -48,6 +48,47 @@ namespace fs = std::filesystem; +std::string to_lower(std::string s) +{ + std::transform(s.begin(), s.end(), s.begin(), [](unsigned char c) { + if (c == ' ') { + return '_'; + } else { + return static_cast(std::tolower(c)); + } + }); + return s; +} + +/** + * Print the grid position to a file. + * + * @param[inout] out_file + * The stream to which the output is printed. + * @param[in] coord_rp + * The coordinate to be printed. + * @param[in] mapping + * The mapping function from the logical domain to the physical domain. + * @param[in] p_dom + * The domain to which the poloidal coordinate should be restricted. + */ +template +void print_coordinate( + std::ofstream& out_file, + CoordRP coord_rp, + Mapping const& mapping, + IDomainP p_dom) +{ + double const r = ddc::get(coord_rp); + double const th = ddcHelper::restrict_to_domain(ddc::select(coord_rp), p_dom); + + CoordXY coord_xy(mapping(coord_rp)); + double const x = ddc::get(coord_xy); + double const y = ddc::get(coord_xy); + + out_file << std::setw(25) << r << std::setw(25) << th << std::setw(25) << x << std::setw(25) + << y; +} /** * @brief Save the characteristic feet in the logical domain @@ -70,36 +111,21 @@ void save_feet( SpanRP const& feet_coords_rp, std::string const& name) { - FILE* file_feet_ptr = fopen(name.c_str(), "w"); + std::ofstream file_feet(name, std::ofstream::out); + file_feet << std::fixed << std::setprecision(16); ddc::for_each(rp_dom, [&](IndexRP const irp) { - double const r = coordinate(ddc::select(irp)); - double const th = coordinate(ddc::select(irp)); - - CoordXY coord_xy(mapping(CoordRP(r, th))); - double const x = ddc::get(coord_xy); - double const y = ddc::get(coord_xy); - - double const feet_r = ddc::get(feet_coords_rp(irp)); - double const feet_th = ddcHelper:: - restrict_to_domain(ddc::select(feet_coords_rp(irp)), IDomainP(rp_dom)); - - CoordXY feet_xy(mapping(CoordRP(feet_r, feet_th))); - double const feet_x = ddc::get(feet_xy); - double const feet_y = ddc::get(feet_xy); - - - fprintf(file_feet_ptr, "%10.0f", double(ddc::select(irp).uid())); - fprintf(file_feet_ptr, " %10.0f", double(ddc::select(irp).uid())); - fprintf(file_feet_ptr, " %10.16f", r); - fprintf(file_feet_ptr, " %10.16f", th); - fprintf(file_feet_ptr, " %10.16f", x); - fprintf(file_feet_ptr, " %10.16f", y); - fprintf(file_feet_ptr, " %10.16f", feet_r); - fprintf(file_feet_ptr, " %10.16f", feet_th); - fprintf(file_feet_ptr, " %10.16f", feet_x); - fprintf(file_feet_ptr, " %10.16f\n", feet_y); + IDomainP p_dom = ddc::select(rp_dom); + + IndexR const ir(ddc::select(irp)); + IndexP const ip(ddc::select(irp)); + + file_feet << std::setw(15) << ddc::select(irp).uid() << std::setw(15) + << ddc::select(irp).uid(); + print_coordinate(file_feet, ddc::coordinate(irp), mapping, p_dom); + print_coordinate(file_feet, feet_coords_rp(irp), mapping, p_dom); + file_feet << std::endl; }); - fclose(file_feet_ptr); + file_feet.close(); }; @@ -117,32 +143,22 @@ void save_feet( template void saving_computed(Mapping const& mapping, DSpanRP function, std::string const& name) { - auto const grid = ddc::get_domain(function); + IDomainRP const grid = function.domain(); + std::ofstream out_file(name, std::ofstream::out); + out_file << std::fixed << std::setprecision(16); - - FILE* file_ptr = fopen(name.c_str(), "w"); for_each(grid, [&](IndexRP const irp) { - double const r = ddc::coordinate(ddc::select(irp)); - double const th = ddc::coordinate(ddc::select(irp)); - - CoordXY coord_xy(mapping(CoordRP(r, th))); - double const x = ddc::get(coord_xy); - double const y = ddc::get(coord_xy); + IDomainP p_dom = ddc::select(grid); IndexR const ir(ddc::select(irp)); IndexP const ip(ddc::select(irp)); - fprintf(file_ptr, "%10.0f", double(ir.uid())); - fprintf(file_ptr, " %10.0f", double(ip.uid())); - fprintf(file_ptr, " %10.0f", 0.); - fprintf(file_ptr, " %10.0f", 0.); - fprintf(file_ptr, " %10.16f", r); - fprintf(file_ptr, " %10.16f", th); - fprintf(file_ptr, " %10.16f", x); - fprintf(file_ptr, " %10.16f", y); - fprintf(file_ptr, " %10.16f \n", function(irp)); + out_file << std::setw(15) << ir.uid() << std::setw(15) << ip.uid(); + print_coordinate(out_file, ddc::coordinate(irp), mapping, p_dom); + out_file << std::setw(25) << function(irp); + out_file << std::endl; }); - fclose(file_ptr); + out_file.close(); } /** @@ -169,20 +185,14 @@ FieldRP compute_exact_feet_rp( AdvectionField const& advection_field, double const time) { - assert(typeid(mapping) != typeid(DiscreteToCartesian)); + static_assert(!std::is_same_v>); FieldRP feet_coords_rp(rp_dom); CoordXY const coord_xy_center = CoordXY(mapping(CoordRP(0, 0))); ddc::for_each(rp_dom, [&](IndexRP const irp) { CoordRP const coord_rp = ddc::coordinate(irp); - CoordXY coord_xy = mapping(coord_rp); - double const x = ddc::get(coord_xy); - double const y = ddc::get(coord_xy); - - double const feet_x = advection_field.exact_feet_x(x, y, time); - double const feet_y = advection_field.exact_feet_y(x, y, time); - coord_xy = CoordXY(feet_x, feet_y); + CoordXY const coord_xy = advection_field.exact_feet(mapping(coord_rp), time); CoordXY const coord_diff = coord_xy - coord_xy_center; if (norm_inf(coord_diff) < 1e-15) { @@ -226,9 +236,7 @@ double compute_difference_L2_norm( { DFieldRP exact_function(grid); ddc::for_each(grid, [&](IndexRP const irp) { - double const feet_r = ddc::get(feet_coord(irp)); - double const feet_th = ddc::get(feet_coord(irp)); - exact_function(irp) = function_to_be_advected(feet_r, feet_th); + exact_function(irp) = function_to_be_advected(feet_coord(irp)); }); DFieldRP quadrature_coeffs @@ -298,10 +306,10 @@ void display_time( * The final time of the simulation. * @param[in] dt * The time step. - * @param[in] if_save_curves + * @param[in] save_curves * A boolean to select if the values of the function are saved in a text file * for each time step. True: save in output folder; False: do not save. - * @param[in] if_save_feet + * @param[in] save_feet * A boolean to select if the values of the characteristic for the last time step * are saved in a text file. True: save in output folder; False: do not save. * @param[in] counter_function @@ -341,17 +349,10 @@ void simulate( SplineRPEvaluator& advection_evaluator, double const final_time, double const dt, - bool const& if_save_curves, - bool const& if_save_feet, - int const& counter_function) + bool if_save_curves, + bool if_save_feet, + std::string const& output_folder) { - if (if_save_curves or if_save_feet) { - fs::create_directory("output"); - } - if (if_save_curves) { - fs::create_directory("output/curves_" + std::to_string(counter_function)); - } - SplineFootFinder const foot_finder( time_stepper, advection_domain, @@ -360,8 +361,8 @@ void simulate( advection_evaluator); BslAdvectionRP advection_operator(function_interpolator, foot_finder); - auto function_to_be_advected_test = *(simulation.get_test_function()); - auto advection_field_test = *(simulation.get_advection_field()); + auto function_to_be_advected_test = simulation.get_test_function(); + auto advection_field_test = simulation.get_advection_field(); @@ -387,12 +388,11 @@ void simulate( // Initialization of the advected function: for_each(grid, [&](IndexRP const irp) { - double const r = coordinate(ddc::select(irp)); - double th = coordinate(ddc::select(irp)); - if (r <= 1e-15) { - th = 0; + CoordRP coord = coordinate(irp); + if (ddc::get(coord) <= 1e-15) { + ddc::get(coord) = 0; } - allfdistribu_test(irp) = function_to_be_advected_test(r, th); + allfdistribu_test(irp) = function_to_be_advected_test(coord); }); @@ -401,14 +401,11 @@ void simulate( for_each(grid, [&](IndexRP const irp) { // Moving the coordinates in the physical domain: CoordXY const coord_xy = mapping(ddc::coordinate(irp)); - double const x = ddc::get(coord_xy); - double const y = ddc::get(coord_xy); + CoordXY const advection_field = advection_field_test(coord_xy, 0.); // Define the advection field on the physical domain: - ddcHelper::get(advection_field_test_vec)(irp) - = advection_field_test.x_value(x, y, 0.); - ddcHelper::get(advection_field_test_vec)(irp) - = advection_field_test.y_value(x, y, 0.); + ddcHelper::get(advection_field_test_vec)(irp) = ddc::get(advection_field); + ddcHelper::get(advection_field_test_vec)(irp) = ddc::get(advection_field); }); @@ -420,8 +417,7 @@ void simulate( // Save the advected function for each iteration: if (if_save_curves) { - std::string const name = "output/curves_" + std::to_string(counter_function) + "/after_" - + std::to_string(i + 1) + ".txt"; + std::string const name = output_folder + "/after_" + std::to_string(i + 1) + ".txt"; saving_computed(mapping, allfdistribu_advected_test.span_view(), name); } } @@ -440,13 +436,9 @@ void simulate( // Compute the maximal absolute error on the space at the end of the simulation: double max_err = 0.; for_each(grid, [&](IndexRP const irp) { - double const feet_r = ddc::get(feet_coords_rp_end_time(irp)); - double const feet_th = ddcHelper::restrict_to_domain( - ddc::select(feet_coords_rp_end_time(irp)), - ddc::get_domain(feet_coords_rp_end_time)); - - double const err = fabs( - allfdistribu_advected_test(irp) - function_to_be_advected_test(feet_r, feet_th)); + double const err + = fabs(allfdistribu_advected_test(irp) + - function_to_be_advected_test(feet_coords_rp_end_time(irp))); max_err = max_err > err ? max_err : err; }); @@ -478,30 +470,25 @@ void simulate( // Save the computed characteristic feet: if (if_save_feet) { FieldRP feet(grid); + for_each(grid, [&](const IndexRP irp) { feet(irp) = ddc::coordinate(irp); }); foot_finder(feet.span_view(), advection_field_test_vec, dt); - std::string const name - = "output/feet_computed_" + std::to_string(counter_function) + ".txt"; + std::string const name = output_folder + "/feet_computed.txt"; save_feet(mapping, grid, feet.span_view(), name); } // Save the values of the exact function at the initial and final states: if (if_save_curves) { - std::string const name_0 = "output/curves_" + std::to_string(counter_function) + "/after_" - + std::to_string(0) + ".txt"; - std::string const name_1 = "output/curves_" + std::to_string(counter_function) + "/after_" - + std::to_string(iteration_number) + "_exact.txt"; + std::string const name_0 = output_folder + "/after_" + std::to_string(0) + ".txt"; + std::string const name_1 + = output_folder + "/after_" + std::to_string(iteration_number) + "_exact.txt"; DFieldRP initial_function(grid); DFieldRP end_function(grid); for_each(grid, [&](const IndexRP irp) { - double const r = coordinate(ddc::select(irp)); - double const th = coordinate(ddc::select(irp)); - initial_function(irp) = function_to_be_advected_test(r, th); + initial_function(irp) = function_to_be_advected_test(ddc::coordinate(irp)); // Exact final state - double const feet_r = ddc::get(feet_coords_rp_end_time(irp)); - double const feet_th = ddc::get(feet_coords_rp_end_time(irp)); - end_function(irp) = function_to_be_advected_test(feet_r, feet_th); + end_function(irp) = function_to_be_advected_test(feet_coords_rp_end_time(irp)); }); saving_computed(mapping, initial_function.span_view(), name_0); saving_computed(mapping, end_function.span_view(), name_1); @@ -511,7 +498,7 @@ void simulate( // Save the exact characteristic feet for a displacement on dt: if (if_save_feet) { - std::string const name = "output/feet_exact_" + std::to_string(counter_function) + ".txt"; + std::string const name = output_folder + "/feet_exact.txt"; save_feet(mapping, grid, feet_coords_rp_dt.span_view(), name); } @@ -550,10 +537,10 @@ void simulate( * The final time of the simulation. * @param[in] dt * The time step. - * @param[in] if_save_curves + * @param[in] save_curves * A boolean to select if the values of the function are saved in a text file * for each time step. True: save in output folder; False: do not save. - * @param[in] if_save_feet + * @param[in] save_feet * A boolean to select if the values of the characteristic for the last time step * are saved in a text file. True: save in output folder; False: do not save. * @param[in] counter_function @@ -578,9 +565,9 @@ void simulate_the_3_simulations( SplineRPEvaluator& advection_evaluator, double const final_time, double const dt, - bool const& if_save_curves, - bool const& if_save_feet, - int& counter_function, + bool const& save_curves, + bool const& save_feet, + std::string const& output_stem, std::string const& title) { auto const r_domain = ddc::select(grid); @@ -595,7 +582,10 @@ void simulate_the_3_simulations( std::string const title_simu_2 = " ROTATION : "; std::string const title_simu_3 = " DECENTRED ROTATION : "; - + std::string output_folder = output_stem + "Translation_output"; + if (save_curves or save_feet) { + fs::create_directory(output_folder); + } std::cout << title + title_simu_1 << std::endl; simulate( mapping, @@ -609,10 +599,14 @@ void simulate_the_3_simulations( advection_evaluator, final_time, dt, - if_save_curves, - if_save_feet, - counter_function++); + save_curves, + save_feet, + output_folder); + output_folder = output_stem + "Rotation_output"; + if (save_curves or save_feet) { + fs::create_directory(output_folder); + } std::cout << title + title_simu_2 << std::endl; simulate( mapping, @@ -626,10 +620,14 @@ void simulate_the_3_simulations( advection_evaluator, final_time, dt, - if_save_curves, - if_save_feet, - counter_function++); + save_curves, + save_feet, + output_folder); + output_folder = output_stem + "Decentred_rotation_output"; + if (save_curves or save_feet) { + fs::create_directory(output_folder); + } std::cout << title + title_simu_3 << std::endl; simulate( mapping, @@ -643,7 +641,7 @@ void simulate_the_3_simulations( advection_evaluator, final_time, dt, - if_save_curves, - if_save_feet, - counter_function++); + save_curves, + save_feet, + output_folder); } diff --git a/tests/geometryRTheta/advection_2d_rp/animated_curves.py b/tests/geometryRTheta/advection_2d_rp/animated_curves.py index 6aef748c5..86186cdb8 100644 --- a/tests/geometryRTheta/advection_2d_rp/animated_curves.py +++ b/tests/geometryRTheta/advection_2d_rp/animated_curves.py @@ -59,12 +59,12 @@ from matplotlib.animation import FuncAnimation -from advection_functions import set_input, execute, params_file, treatment, get_full_fct_names +from advection_functions import set_input, execute, treatment, get_simulation_config # --------------------------------------------------------------------------- -def animate (iter_nb, file_name, test_name, function_number): +def animate (iter_nb, file_name, test_name, output_folder): """ Save an animated version of the selected advection simulations. @@ -79,10 +79,6 @@ def animate (iter_nb, file_name, test_name, function_number): test_name : string The title of the test simulation. - - function_number : int - The number refering to the selected test case. - (See explanations string.) """ iter_nb_lim = 100 if iter_nb < iter_nb_lim: @@ -93,7 +89,7 @@ def animate (iter_nb, file_name, test_name, function_number): zarray = [] for idx in iter_numbers: - namefile = f"output/curves_{function_number}/after_{idx}.txt" + namefile = os.path.join(output_folder, f"after_{idx}.txt") list_F, _, _, CoordX, CoordY = treatment(namefile) zarray += [[CoordX, CoordY, list_F]] @@ -187,15 +183,12 @@ def set_axis (figure, idx, elev, azim, roll): # Get the inputs ----------------------------------------------- -executable, rmin, rmax, Nr, Nt, dt, T, curves, feet, _ = set_input(0, 1, 60, 120, 0.01, 0.8, True, False) +executable, yaml_parameters, _, verbose = set_input(0, 1, 60, 120, 0.01, 0.8, True, False) executable_name = os.path.basename(executable) -if os.path.isdir("output"): - answer1 = input("Do you want to launch the executable? [y/n]: ") - ask_execute = (answer1=="y") -else : - ask_execute = True +answer1 = input("Do you want to launch the executable? [y/n]: ") +ask_execute = (answer1=="y") if executable_name == "advection_ALL": @@ -207,16 +200,7 @@ def set_axis (figure, idx, elev, azim, roll): if ask_execute : # Execute the test file given as input in the command ---------- - out = execute(executable, rmin, rmax, Nr, Nt, dt, T, True, feet) - fct_names = get_full_fct_names(out) - - # Put "False" the savings of files for the next launch --------- - params_file(rmin, rmax, Nr, Nt, dt, T) - -else : - out = execute(executable, rmin, rmax, 4, 4, T, T, False, feet, False) - fct_names = get_full_fct_names(out) - + out = execute(executable, yaml_parameters, verbose) # Display the curves -------------------------------------------- @@ -231,26 +215,31 @@ def set_axis (figure, idx, elev, azim, roll): else : [a, b] = el.split("-") selected_test += list(range(int(a), int(b) + 1)) + possible_output_folder_names = [d for d in os.listdir() if d.endswith('_output') and d.count('-')==2] + output_folder_names = [possible_output_folder_names[s] for s in selected_test] + keys = [folder.replace('_output','').split('-') for folder in output_folder_names] + fct_names = [f'{simulation.capitalize()} with {method.replace("_"," ")} on {mapping.replace("_", " ")}' + for mapping, method, simulation in keys] else : - name = executable_name.lower().split('__') - fct_names = [name[2].lower().replace("_", " ") ] - fct_names[0] += " with " + name[1].lower().replace("_", " ") - fct_names[0] += " on " + ' '.join(name[0].split("_")[1:]).lower() - fct_names[0] = fct_names[0][0].upper() + fct_names[0][1:] + mapping, method, domain, simulation, name = get_simulation_config(executable) + output_folder_names = [f'{mapping.replace(" ","_")}_{domain}-{method.replace(" ","_")}-{simulation}_output'] + fct_names = [name] selected_test = [-1] - -if executable_name == "advection_ALL": - DT = ([dt/10] * 3 + [dt] * 9)*4 -else: - DT = [dt] - +rmin = yaml_parameters['r_min'] +rmax = yaml_parameters['r_max'] +Nr = yaml_parameters['r_size'] +Nt = yaml_parameters['p_size'] +dt0 = yaml_parameters['time_step'] +T = yaml_parameters['final_time'] details1 = f"_{Nr}x{Nt}_[{rmin}_{rmax}]" -for s in selected_test: - dt = DT[s] +for i, (name, folder) in enumerate(zip(fct_names, output_folder_names)): + dt = dt0 + if 'euler' in folder: + dt *= 0.1 iter_nb = int(T/dt) details2 = f"\n $NrxNt$ = {Nr}x{Nt}; [$rmin$,$rmax$] = [{rmin},{rmax}]; dt = {dt}" - animate(iter_nb, fct_names[s].replace(" ", "_")+details1, fct_names[s]+details2, s) + animate(iter_nb, name.replace(" ", "_")+details1, name+details2, folder) if executable_name == "advection_ALL": print(f"The animation of the {selected_test} test case have been saved in ./animations/ folder.") @@ -261,7 +250,9 @@ def set_axis (figure, idx, elev, azim, roll): if ask_remove: - shutil.rmtree("output") - print("The ./output/ folder has been removed.") + delete_folders = possible_output_folder_names if executable_name == "advection_ALL" else output_folder_names + for folder in delete_folders: + shutil.rmtree(folder) + print(f"The {folder} folder has been removed.") diff --git a/tests/geometryRTheta/advection_2d_rp/display_all_errors_for_gtest.py b/tests/geometryRTheta/advection_2d_rp/display_all_errors_for_gtest.py index 8962c9fca..79c0c2376 100644 --- a/tests/geometryRTheta/advection_2d_rp/display_all_errors_for_gtest.py +++ b/tests/geometryRTheta/advection_2d_rp/display_all_errors_for_gtest.py @@ -57,88 +57,85 @@ import numpy as np import matplotlib.pyplot as plt -from advection_functions import set_input, execute, take_errors_from_out, get_full_fct_names, get_fct_names, get_fct_name_key +from advection_functions import set_input, execute, extract_simulation_results # Get the inputs ----------------------------------------------- -executable, rmin, rmax, Nr0, Nt0, dt0, T, curves, feet, if_plot = set_input(0, 1, 32, 64, 0.1, 0.4) +executable, yaml_parameters, plot_results, verbose = set_input(0, 1, 32, 64, 0.1, 0.4) -if if_plot: +if plot_results: list_pow = [0, 1, 2, 3] else : list_pow = [0, 2] -NNr = [Nr0 * 2**i for i in list_pow] -NNt = [Nt0 * 2**i for i in list_pow] -DT = [dt0 / 2**i for i in list_pow] -Order = [2**(-i) for i in list_pow] +yaml_configs = [yaml_parameters.copy() for _ in list_pow] +Nr0 = yaml_parameters['r_size'] +Nt0 = yaml_parameters['p_size'] +dt0 = yaml_parameters['time_step'] +for i, p in enumerate(list_pow): + yaml_configs[i].update({'r_size': Nr0 * 2**p, + 'p_size': Nt0 * 2**p, + 'time_step': dt0 / 2**p}) +Order = [2**-i for i in list_pow] -# Get the names of the test cases ------------------------------- -out = execute(executable, rmin, rmax, 4, 4, T, T, False, False, False) -fct_names = get_full_fct_names(out) -short_fct_names = get_fct_names(out) -nb_fct = len(fct_names) - # Expected convergence orders -------------------------- order_expected = {'euler': { - 'circular': {'Translation':3, 'Rotation':1, 'Decentred rotation':1}, - 'czarny_physical': {'Translation':3, 'Rotation':1, 'Decentred rotation':1}, - 'czarny_pseudo_cartesian': {'Translation':1, 'Rotation':1, 'Decentred rotation':1}, - 'discrete': {'Translation':1, 'Rotation':1, 'Decentred rotation':1} + 'circular physical': {'Translation':3, 'Rotation':1, 'Decentred rotation':1}, + 'czarny physical': {'Translation':3, 'Rotation':1, 'Decentred rotation':1}, + 'czarny pseudo cartesian': {'Translation':1, 'Rotation':1, 'Decentred rotation':1}, + 'discrete pseudo cartesian': {'Translation':1, 'Rotation':1, 'Decentred rotation':1} }, 'crank nicolson': { - 'circular': {'Translation':3, 'Rotation':2, 'Decentred rotation':2}, - 'czarny_physical': {'Translation':3, 'Rotation':2, 'Decentred rotation':2}, - 'czarny_pseudo_cartesian': {'Translation':3, 'Rotation':2, 'Decentred rotation':2}, - 'discrete': {'Translation':3, 'Rotation':2, 'Decentred rotation':2} + 'circular physical': {'Translation':3, 'Rotation':2, 'Decentred rotation':2}, + 'czarny physical': {'Translation':3, 'Rotation':2, 'Decentred rotation':2}, + 'czarny pseudo cartesian': {'Translation':3, 'Rotation':2, 'Decentred rotation':2}, + 'discrete pseudo cartesian': {'Translation':3, 'Rotation':2, 'Decentred rotation':2} }, 'rk3': { - 'circular': {'Translation':3, 'Rotation':3, 'Decentred rotation':3}, - 'czarny_physical': {'Translation':3, 'Rotation':3, 'Decentred rotation':3}, - 'czarny_pseudo_cartesian': {'Translation':3, 'Rotation':3, 'Decentred rotation':3}, - 'discrete': {'Translation':3, 'Rotation':3, 'Decentred rotation':3} + 'circular physical': {'Translation':3, 'Rotation':3, 'Decentred rotation':3}, + 'czarny physical': {'Translation':3, 'Rotation':3, 'Decentred rotation':3}, + 'czarny pseudo cartesian': {'Translation':3, 'Rotation':3, 'Decentred rotation':3}, + 'discrete pseudo cartesian': {'Translation':3, 'Rotation':3, 'Decentred rotation':3} }, 'rk4': { - 'circular': {'Translation':3, 'Rotation':3, 'Decentred rotation':3}, - 'czarny_physical': {'Translation':3, 'Rotation':3, 'Decentred rotation':3}, - 'czarny_pseudo_cartesian': {'Translation':3, 'Rotation':3, 'Decentred rotation':3}, - 'discrete': {'Translation':3, 'Rotation':3, 'Decentred rotation':3} + 'circular physical': {'Translation':3, 'Rotation':3, 'Decentred rotation':3}, + 'czarny physical': {'Translation':3, 'Rotation':3, 'Decentred rotation':3}, + 'czarny pseudo cartesian': {'Translation':3, 'Rotation':3, 'Decentred rotation':3}, + 'discrete pseudo cartesian': {'Translation':3, 'Rotation':3, 'Decentred rotation':3} } } +# Run the simulations ------------------------------------------- +execution_output = [execute(executable, params, verbose) for params in yaml_configs] - -# Get the errors ------------------------------------------------ -total_Errors = [take_errors_from_out(execute(executable, rmin, rmax, NNr[i], NNt[i], DT[i], T, False, False, False)) for i in range(len(Order))] -Errors_by_fct = [[err[j] for err in total_Errors] for j in range(nb_fct)] - +# Get the results of the simulation +simulation_results = extract_simulation_results(execution_output) +nb_fct = len(simulation_results) # Check the convergence order ----------------------------------- -for index in range(nb_fct): - Coeffs = np.polyfit(np.log(Order),np.log(Errors_by_fct[index]),1) +for (method, mapping, problem_type), result in simulation_results.items(): + Coeffs = np.polyfit(np.log(Order), np.log(result.l_inf_error),1) slope = Coeffs[0] - problem_type, time_interation_method, mapping = get_fct_name_key(fct_names[index]) - - theoretical_order = order_expected[time_interation_method][mapping][problem_type] - print(f">{fct_names[index]} : \n order = {round(slope,3)} ({theoretical_order} expected).") + theoretical_order = order_expected[method][mapping][problem_type] + print(f">{result.name} :") + print(f" order = {round(slope,3)} ({theoretical_order} expected).") # Order expected: if (slope < theoretical_order - 0.25): - print(fct_names[index] + f" has not the right convergence order: got {slope}, expected {theoretical_order - 0.25}.") + print(f">{result.name} :") + print(f" Wrong convergence order: got {slope}, expected {theoretical_order - 0.25}.") assert (slope > theoretical_order - 0.25) - - # Plot the errors ----------------------------------------------- -if if_plot: +if plot_results: fig = plt.figure(figsize = (16,9)) fig.suptitle(f"Errors of advection operator (starting with dt = {dt0}$^*$ and NrxNt = {Nr0}x{Nt0})\n ($^*$dt = {dt0/10} for Euler method)", fontsize=16) - def set_subplot(index, i0, title): + def set_subplot(index, method, mapping): """ Plot the errors and their slope for the three test simulations: translated Gaussianne; @@ -148,25 +145,23 @@ def set_subplot(index, i0, title): ---------- index: int Index of the subplot. - i0: int - Index corresponding to the translation test case. - title : string - The title of the method and the mapping used. + method : str + The method used. + mapping : str + The mapping used. """ ax = fig.add_subplot(4, 4, index) plt.tight_layout(pad=0.4, w_pad=0.2, h_pad=-0.2) - # Translation - slope = np.polyfit(np.log(Order),np.log(Errors_by_fct[i0]),1) - ax.loglog(Order, Errors_by_fct[i0], "+--", label=f"{short_fct_names[i0]} (slope = {round(slope[0],2)})", linewidth = 0.7) - - # Rotation - slope = np.polyfit(np.log(Order),np.log(Errors_by_fct[i0+1]),1) - ax.loglog(Order, Errors_by_fct[i0+1], "+--", label=f"{short_fct_names[i0+1]} (slope = {round(slope[0],2)})", linewidth = 0.7) - # Decentred rotation - slope = np.polyfit(np.log(Order),np.log(Errors_by_fct[i0+2]),1) - ax.loglog(Order, Errors_by_fct[i0+2], "+--", label=f"{short_fct_names[i0+2]} (slope = {round(slope[0],2)})", linewidth = 0.7) + for simu in ('Translation', 'Rotation', 'Decentred rotation'): + try: + _, linf_errors, _ = simulation_results[(method, mapping, simu)] + except KeyError: + print(f"Simulation {method}, {mapping}, {simu} was not run") + continue + slope = np.polyfit(np.log(Order),np.log(linf_errors),1) + ax.loglog(Order, linf_errors, "+--", label=f"{simu} (slope = {round(slope[0],2)})", linewidth = 0.7) ax.legend() ax.grid() @@ -175,18 +170,13 @@ def set_subplot(index, i0, title): ax.set_ylabel("Errors (log)") ax.set_adjustable("box") - ax.set_title(title, fontsize=12) - - - names_method = ["Euler", "Crank Nicolson", "RK3", "RK4"] - names_mapping = ["Circular mapping and physical domain", - "Czarny mapping and physical domain", - "Czarny mapping and pseudo Cartesian domain", - "Discrete mapping and pseudo Cartesian domain"] + ax.set_title(f'{method.capitalize()} on {mapping}', fontsize=12) - for i in range(nb_fct//3): - index = i + 1 - set_subplot(index, 3*i, names_mapping[i//4] + " \n " + names_method[i%4]) + index = 1 + for method, method_types in order_expected.items(): + for mapping in method_types: + set_subplot(index, method, mapping) + index += 1 plt.show() diff --git a/tests/geometryRTheta/advection_2d_rp/display_curves.py b/tests/geometryRTheta/advection_2d_rp/display_curves.py index 75f42de46..95bfb2c2a 100644 --- a/tests/geometryRTheta/advection_2d_rp/display_curves.py +++ b/tests/geometryRTheta/advection_2d_rp/display_curves.py @@ -55,7 +55,7 @@ import matplotlib.pyplot as plt -from advection_functions import set_input, execute, params_file, treatment +from advection_functions import set_input, execute, treatment, get_simulation_config # Definition of functions --------------------------------------- def set_axis(ax, x_label, y_label, z_label, ax_label): @@ -124,7 +124,7 @@ def set_surface(fig, nb_x, nb_y, n_idx, X, Y, Z, elev, azim, roll): return ax -def display(iter_nb, dt, title, subtitle): +def display(iter_nb, dt, title, subtitle, output_folder): """ Plot the advected function for different time steps. @@ -145,7 +145,7 @@ def display(iter_nb, dt, title, subtitle): Idx_list = [0]+[min(i*(iter_nb//9) + 1,iter_nb) for i in range(9)] + [iter_nb] for n_idx in range(9 + 2): idx = Idx_list[n_idx] - namefile = f"output/curves/after_{idx}.txt" + namefile = os.path.join(output_folder, f"after_{idx}.txt") list_F, _, _, CoordX, CoordY = treatment(namefile) X = np.array(CoordX) @@ -155,17 +155,17 @@ def display(iter_nb, dt, title, subtitle): ax = set_surface(fig, 3, 5, n_idx, X, Y, Z, 90, -90, 0) if idx == 0 : - plt.title(f"Initial condition\n (maximum = {max(Z)}) ") + plt.title(f"Initial condition\n (maximum = {max(Z):.3}) ") elif idx (coord_xy); double const y = ddc::get(coord_xy); @@ -163,12 +161,13 @@ class FunctionToBeAdvected_gaussian : public FunctionToBeAdvected , m_rmax(rmax) {}; ~FunctionToBeAdvected_gaussian() {}; - double operator()(double r, double th) final + double operator()(CoordRP coord_rp) final { // Gaussian centered in (x0, y0): - CoordXY const coord_xy(m_mapping(CoordRP(r, th))); + CoordXY const coord_xy(m_mapping(coord_rp)); double const x = ddc::get(coord_xy); double const y = ddc::get(coord_xy); + double const r = ddc::get(coord_rp); if ((m_rmin <= r) and (r <= m_rmax)) { return m_constant * std::exp( @@ -196,68 +195,28 @@ class AdvectionField virtual ~AdvectionField() = default; /** - * @brief Get the first component in the physical domain of the - * advection field. + * @brief Get the advection field in the physical domain. * - * @param[in] x - * First component of the coordinate in the physical domain. - * @param[in] y - * Second component of the coordinate in the physical domain. + * @param[in] coord + * The coordinate in the physical domain. * @param[in] t * Time component. * - * @return The value of the first component in the physical domain of the - * advection field. + * @return The advection field in the physical domain. */ - virtual double x_value(double const x, double const y, double const t = 0.) const = 0; + virtual CoordXY operator()(CoordXY const coord, double const t = 0.) const = 0; /** - * @brief Get the second component in the physical domain of the - * advection field. + * @brief Get the characteristic feet in the physical domain. * - * @param[in] x - * First component of the coordinate in the physical domain. - * @param[in] y - * Second component of the coordinate in the physical domain. + * @param[in] coord + * The original coordinate in the physical domain. * @param[in] t * Time component. * - * @return The value of the second component in the physical domain of the - * advection field. + * @return The characteristic feet in the physical domain. */ - virtual double y_value(double const x, double const y, double const t = 0.) const = 0; - - /** - * @brief Get the first component in the physical domain of the - * characteristic feet. - * - * @param[in] r - * First component of the coordinate in the logical domain. - * @param[in] th - * Second component of the coordinate in the logical domain. - * @param[in] t - * Time component. - * - * @return The value of the first component in the physical domain of the - * characteristic feet. - */ - virtual double exact_feet_x(double r, double th, double t) const = 0; - - /** - * @brief Get the second component in the physical domain of the - * characteristic feet. - * - * @param[in] r - * First component of the coordinate in the logical domain. - * @param[in] th - * Second component of the coordinate in the logical domain. - * @param[in] t - * Time component. - * - * @return The value of the second component in the physical domain of the - * characteristic feet. - */ - virtual double exact_feet_y(double r, double th, double t) const = 0; + virtual CoordXY exact_feet(CoordXY coord, double t) const = 0; }; @@ -297,24 +256,22 @@ class AdvectionField_decentred_rotation : public AdvectionField , m_y_bar(0.) {}; ~AdvectionField_decentred_rotation() {}; - double x_value(double const x, double const y, double const t) const final - { - return m_omega * (m_yc - y); - }; - - double y_value(double const x, double const y, double const t) const final - { - return m_omega * (x - m_xc); - }; - - double exact_feet_x(double const x, double const y, double const t) const final + CoordXY operator()(CoordXY const coord, double const t) const final { - return m_xc + (x - m_xc) * std::cos(m_omega * -t) - (y - m_yc) * std::sin(m_omega * -t); + double const x = m_omega * (m_yc - ddc::get(coord)); + double const y = m_omega * (ddc::get(coord) - m_xc); + return CoordXY(x, y); }; - double exact_feet_y(double const x, double const y, double const t) const final + CoordXY exact_feet(CoordXY coord, double const t) const final { - return m_yc + (x - m_xc) * std::sin(m_omega * -t) + (y - m_yc) * std::cos(m_omega * -t); + double const x = ddc::get(coord); + double const y = ddc::get(coord); + double const foot_x + = m_xc + (x - m_xc) * std::cos(m_omega * -t) - (y - m_yc) * std::sin(m_omega * -t); + double const foot_y + = m_yc + (x - m_xc) * std::sin(m_omega * -t) + (y - m_yc) * std::cos(m_omega * -t); + return CoordXY(foot_x, foot_y); }; }; @@ -338,8 +295,7 @@ class AdvectionField_decentred_rotation : public AdvectionField class AdvectionField_translation : public AdvectionField { private: - double const m_vx; - double const m_vy; + CoordXY const m_velocity; public: /** @@ -350,27 +306,18 @@ class AdvectionField_translation : public AdvectionField * @param[in] vy * The constant second component of the advection field in the physical domain. */ - AdvectionField_translation(CoordVx vx, CoordVy vy) : m_vx(vx), m_vy(vy) {}; + AdvectionField_translation(CoordVx vx, CoordVy vy) + : m_velocity(ddc::get(vx), ddc::get(vy)) {}; ~AdvectionField_translation() {}; - double x_value(double const x, double const y, double const t) const final - { - return m_vx; - }; - - double y_value(double const x, double const y, double const t) const final - { - return m_vy; - }; - - double exact_feet_x(double const x, double const y, double const t) const final + CoordXY operator()(CoordXY const coord, double const t) const final { - return x - t * m_vx; + return m_velocity; }; - double exact_feet_y(double const x, double const y, double const t) const final + CoordXY exact_feet(CoordXY coord, double const t) const final { - return y - t * m_vy; + return coord - t * m_velocity; }; }; @@ -414,36 +361,21 @@ class AdvectionField_rotation : public AdvectionField AdvectionField_rotation(CoordVr vr, CoordVp vp) : m_vr(vr), m_vp(vp), m_mapping() {}; ~AdvectionField_rotation() {}; - double x_value(double const x, double const y, double const t) const final - { - CoordRP const coord_rp(m_mapping(CoordXY(x, y))); - double const vx - = m_vr * m_mapping.jacobian_11(coord_rp) + m_vp * m_mapping.jacobian_12(coord_rp); - return vx; - }; - - double y_value(double const x, double const y, double const t) const final - { - CoordRP const coord_rp(m_mapping(CoordXY(x, y))); - double const vy - = m_vr * m_mapping.jacobian_21(coord_rp) + m_vp * m_mapping.jacobian_22(coord_rp); - return vy; - }; - - double exact_feet_x(double const x, double const y, double const t) const final + CoordXY operator()(CoordXY const coord, double const t) const final { - CoordRP const coord_rp(m_mapping(CoordXY(x, y))); - double const r = ddc::get(coord_rp) - t * m_vr; - double const theta = ddc::get(coord_rp) - t * m_vp; - return ddc::get(CoordXY(m_mapping(CoordRP(r, theta)))); + CoordRP const coord_rp(m_mapping(coord)); + std::array, 2> jacobian; + m_mapping.jacobian_matrix(coord_rp, jacobian); + double const vx = m_vr * jacobian[0][0] + m_vp * jacobian[0][1]; + double const vy = m_vr * jacobian[1][0] + m_vp * jacobian[1][1]; + return CoordXY(vx, vy); }; - double exact_feet_y(double const x, double const y, double const t) const final + CoordXY exact_feet(CoordXY coord_xy, double const t) const final { - CoordRP const coord_rp(m_mapping(CoordXY(x, y))); - double const r = ddc::get(coord_rp) - t * m_vr; - double const theta = ddc::get(coord_rp) - t * m_vp; - return ddc::get(CoordXY(m_mapping(CoordRP(r, theta)))); + CoordRP const coord_rp(m_mapping(coord_xy)); + CoordRP const velocity(m_vr, m_vp); + return m_mapping(coord_rp - t * velocity); }; }; @@ -493,21 +425,21 @@ class AdvectionSimulation /** * @brief Get the advection field of the simulation. * - * @return A pointer to the advection field created in the AdvectionSimulation child class. + * @return A constant reference to the advection field created in the AdvectionSimulation child class. */ - std::unique_ptr get_advection_field() + AdvectionField const& get_advection_field() const { - return std::make_unique(m_advection_field); + return m_advection_field; }; /** * @brief Get the test function of the simulation. * - * @return A pointer to the test function created in the AdvectionSimulation child class. + * @return A constant reference to the test function created in the AdvectionSimulation child class. */ - std::unique_ptr get_test_function() + FunctionToBeAdvected const& get_test_function() const { - return std::make_unique(m_function); + return m_function; }; }; diff --git a/tests/geometryXVx/collisions_inter.cpp b/tests/geometryXVx/collisions_inter.cpp index 920234a40..5ae2edce5 100644 --- a/tests/geometryXVx/collisions_inter.cpp +++ b/tests/geometryXVx/collisions_inter.cpp @@ -62,17 +62,9 @@ TEST(CollisionsInter, CollisionsInter) double const mass_ion(400.), mass_elec(1.); masses(my_ielec) = mass_elec; masses(my_iion) = mass_ion; - FieldSp init_perturb_mode(dom_sp); - ddc::fill(init_perturb_mode, 0); - DFieldSp init_perturb_amplitude(dom_sp); - ddc::fill(init_perturb_amplitude, 0); // Initialization of the distribution function as a maxwellian - ddc::init_discrete_space( - std::move(charges), - std::move(masses), - std::move(init_perturb_amplitude), - std::move(init_perturb_mode)); + ddc::init_discrete_space(std::move(charges), std::move(masses)); device_t allfdistribu_device(mesh); std::vector deltat_list = {0.1, 0.01}; diff --git a/tests/geometryXVx/collisions_intra_gridvx.cpp b/tests/geometryXVx/collisions_intra_gridvx.cpp index b1bbb4850..cfa569c54 100644 --- a/tests/geometryXVx/collisions_intra_gridvx.cpp +++ b/tests/geometryXVx/collisions_intra_gridvx.cpp @@ -63,15 +63,7 @@ TEST(CollisionsIntraGridvx, CollisionsIntraGridvx) double const mass_elec(1); masses(my_ielec) = mass_elec; masses(my_iion) = mass_ion; - FieldSp init_perturb_mode(dom_sp); - ddc::fill(init_perturb_mode, 0); - DFieldSp init_perturb_amplitude(dom_sp); - ddc::fill(init_perturb_amplitude, 0); - ddc::init_discrete_space( - std::move(charges), - std::move(masses), - std::move(init_perturb_amplitude), - std::move(init_perturb_mode)); + ddc::init_discrete_space(std::move(charges), std::move(masses)); // collision operator double const nustar0(1.); diff --git a/tests/geometryXVx/collisions_intra_maxwellian.cpp b/tests/geometryXVx/collisions_intra_maxwellian.cpp index 211c409f2..18be608d7 100644 --- a/tests/geometryXVx/collisions_intra_maxwellian.cpp +++ b/tests/geometryXVx/collisions_intra_maxwellian.cpp @@ -67,17 +67,9 @@ TEST(CollisionsIntraMaxwellian, CollisionsIntraMaxwellian) double const mass_ion(400), mass_elec(1); masses(my_ielec) = mass_elec; masses(my_iion) = mass_ion; - FieldSp init_perturb_mode(dom_sp); - ddc::fill(init_perturb_mode, 0); - DFieldSp init_perturb_amplitude(dom_sp); - ddc::fill(init_perturb_amplitude, 0); // Initialization of the distribution function as a maxwellian - ddc::init_discrete_space( - std::move(charges), - std::move(masses), - std::move(init_perturb_amplitude), - std::move(init_perturb_mode)); + ddc::init_discrete_space(std::move(charges), std::move(masses)); device_t allfdistribu_device(mesh); // Initialization of the distribution function as a maxwellian with diff --git a/tests/geometryXVx/femnonperiodicpoissonsolver.cpp b/tests/geometryXVx/femnonperiodicpoissonsolver.cpp index 829318feb..5742a19c7 100644 --- a/tests/geometryXVx/femnonperiodicpoissonsolver.cpp +++ b/tests/geometryXVx/femnonperiodicpoissonsolver.cpp @@ -65,17 +65,9 @@ TEST(FemNonPeriodicPoissonSolver, Ordering) charges(my_iion) = 1; DFieldSp masses(dom_sp); ddc::fill(masses, 1); - FieldSp init_perturb_mode(dom_sp); - ddc::fill(init_perturb_mode, 0); - DFieldSp init_perturb_amplitude(dom_sp); - ddc::fill(init_perturb_amplitude, 0); // Initialization of the distribution function - ddc::init_discrete_space( - std::move(charges), - std::move(masses), - std::move(init_perturb_amplitude), - std::move(init_perturb_mode)); + ddc::init_discrete_space(std::move(charges), std::move(masses)); DFieldVx const quadrature_coeffs = neumann_spline_quadrature_coefficients(gridvx, builder_vx); Quadrature const integrate_v(quadrature_coeffs); diff --git a/tests/geometryXVx/femperiodicpoissonsolver.cpp b/tests/geometryXVx/femperiodicpoissonsolver.cpp index fcc594201..d744722c0 100644 --- a/tests/geometryXVx/femperiodicpoissonsolver.cpp +++ b/tests/geometryXVx/femperiodicpoissonsolver.cpp @@ -61,17 +61,9 @@ TEST(FemPeriodicPoissonSolver, CosineSource) charges(my_iion) = 1; DFieldSp masses(dom_sp); ddc::fill(masses, 1); - FieldSp init_perturb_mode(dom_sp); - ddc::fill(init_perturb_mode, 0); - DFieldSp init_perturb_amplitude(dom_sp); - ddc::fill(init_perturb_amplitude, 0); // Initialization of the distribution function - ddc::init_discrete_space( - std::move(charges), - std::move(masses), - std::move(init_perturb_amplitude), - std::move(init_perturb_mode)); + ddc::init_discrete_space(std::move(charges), std::move(masses)); DFieldVx const quadrature_coeffs = neumann_spline_quadrature_coefficients(gridvx, builder_vx); Quadrature const integrate_v(quadrature_coeffs); diff --git a/tests/geometryXVx/fftpoissonsolver.cpp b/tests/geometryXVx/fftpoissonsolver.cpp index 1ef3712cc..e9bd539c9 100644 --- a/tests/geometryXVx/fftpoissonsolver.cpp +++ b/tests/geometryXVx/fftpoissonsolver.cpp @@ -57,17 +57,9 @@ TEST(FftPoissonSolver, CosineSource) charges(my_iion) = 1; DFieldSp masses(dom_sp); ddc::fill(masses, 1); - FieldSp init_perturb_mode(dom_sp); - ddc::fill(init_perturb_mode, 0); - DFieldSp init_perturb_amplitude(dom_sp); - ddc::fill(init_perturb_amplitude, 0); // Initialization of the distribution function - ddc::init_discrete_space( - std::move(charges), - std::move(masses), - std::move(init_perturb_amplitude), - std::move(init_perturb_mode)); + ddc::init_discrete_space(std::move(charges), std::move(masses)); DFieldVx const quadrature_coeffs = neumann_spline_quadrature_coefficients(gridvx, builder_vx); Quadrature const integrate_v(quadrature_coeffs); diff --git a/tests/geometryXVx/fluid_moments.cpp b/tests/geometryXVx/fluid_moments.cpp index 88289be5f..228a46683 100644 --- a/tests/geometryXVx/fluid_moments.cpp +++ b/tests/geometryXVx/fluid_moments.cpp @@ -56,17 +56,9 @@ TEST(Physics, FluidMoments) charges(my_iion) = 1; DFieldSp masses(dom_sp); ddc::fill(masses, 1); - FieldSp init_perturb_mode(dom_sp); - ddc::fill(init_perturb_mode, 0); - DFieldSp init_perturb_amplitude(dom_sp); - ddc::fill(init_perturb_amplitude, 0); // Initialization of the distribution function as a maxwellian - ddc::init_discrete_space( - std::move(charges), - std::move(masses), - std::move(init_perturb_amplitude), - std::move(init_perturb_mode)); + ddc::init_discrete_space(std::move(charges), std::move(masses)); DFieldSpXVx allfdistribu(mesh); // Initialization of the distribution function as a maxwellian with diff --git a/tests/geometryXVx/kineticsource.cpp b/tests/geometryXVx/kineticsource.cpp index 43478f729..1ee500be8 100644 --- a/tests/geometryXVx/kineticsource.cpp +++ b/tests/geometryXVx/kineticsource.cpp @@ -60,17 +60,9 @@ TEST(KineticSource, Moments) charges(my_iion) = 1; DFieldSp masses(dom_sp); ddc::fill(masses, 1); - FieldSp init_perturb_mode(dom_sp); - ddc::fill(init_perturb_mode, 0); - DFieldSp init_perturb_amplitude(dom_sp); - ddc::fill(init_perturb_amplitude, 0); // Initialization of the distribution function - ddc::init_discrete_space( - std::move(charges), - std::move(masses), - std::move(init_perturb_amplitude), - std::move(init_perturb_mode)); + ddc::init_discrete_space(std::move(charges), std::move(masses)); device_t allfdistribu_device(mesh); // Initialization of the distribution function diff --git a/tests/geometryXVx/krooksource.cpp b/tests/geometryXVx/krooksource.cpp index 56ea95e69..f87e0fdcd 100644 --- a/tests/geometryXVx/krooksource.cpp +++ b/tests/geometryXVx/krooksource.cpp @@ -63,24 +63,14 @@ TEST(KrookSource, Adaptive) FieldSp charges(dom_sp); DFieldSp masses(dom_sp); - FieldSp init_perturb_mode(dom_sp); - DFieldSp init_perturb_amplitude(dom_sp); IndexSp my_iion(dom_sp.front()); IndexSp my_ielec(dom_sp.back()); charges(my_iion) = 1; charges(my_ielec) = -1; - ddc::for_each(dom_sp, [&](IndexSp const isp) { - masses(isp) = 1.0; - init_perturb_mode(isp) = 0; - init_perturb_amplitude(isp) = 0.0; - }); + ddc::for_each(dom_sp, [&](IndexSp const isp) { masses(isp) = 1.0; }); // Initialization of the distribution function - ddc::init_discrete_space( - std::move(charges), - std::move(masses), - std::move(init_perturb_amplitude), - std::move(init_perturb_mode)); + ddc::init_discrete_space(std::move(charges), std::move(masses)); double const extent = 0.5; double const stiffness = 0.01; @@ -208,22 +198,12 @@ TEST(KrookSource, Constant) FieldSp charges(dom_sp); DFieldSp masses(dom_sp); - FieldSp init_perturb_mode(dom_sp); - DFieldSp init_perturb_amplitude(dom_sp); charges(dom_sp.front()) = 1; charges(dom_sp.back()) = -1; - ddc::for_each(dom_sp, [&](IndexSp const isp) { - masses(isp) = 1.0; - init_perturb_mode(isp) = 0; - init_perturb_amplitude(isp) = 0.0; - }); + ddc::for_each(dom_sp, [&](IndexSp const isp) { masses(isp) = 1.0; }); // Initialization of the distribution function - ddc::init_discrete_space( - std::move(charges), - std::move(masses), - std::move(init_perturb_amplitude), - std::move(init_perturb_mode)); + ddc::init_discrete_space(std::move(charges), std::move(masses)); double const extent = 0.25; double const stiffness = 0.01; diff --git a/tests/geometryXYVxVy/fft_poisson.cpp b/tests/geometryXYVxVy/fft_poisson.cpp index f02e5ac1b..94acdaa97 100644 --- a/tests/geometryXYVxVy/fft_poisson.cpp +++ b/tests/geometryXYVxVy/fft_poisson.cpp @@ -73,16 +73,8 @@ TEST(FftPoissonSolver, CosineSource) charges(my_iion) = 1; DFieldSp masses(dom_sp); ddc::fill(masses, 1); - FieldSp init_perturb_mode(dom_sp); - ddc::fill(init_perturb_mode, 0); - DFieldSp init_perturb_amplitude(dom_sp); - ddc::fill(init_perturb_amplitude, 0); - - ddc::init_discrete_space( - std::move(charges), - std::move(masses), - std::move(init_perturb_amplitude), - std::move(init_perturb_mode)); + + ddc::init_discrete_space(std::move(charges), std::move(masses)); ChargeDensityCalculator rhs(builder_vx_vy, evaluator_vx_vy); FftPoissonSolver poisson(rhs); diff --git a/tests/species_info.cpp b/tests/species_info.cpp index 34314632e..836e55605 100644 --- a/tests/species_info.cpp +++ b/tests/species_info.cpp @@ -26,19 +26,11 @@ TEST(SpeciesInfo, Ielec) FieldSp charges(dom_sp); FieldSp masses(dom_sp); - FieldSp init_perturb_mode(dom_sp); - FieldSp init_perturb_amplitude(dom_sp); charges(my_ielec) = -1; charges(my_iion) = 1; ddc::fill(masses, 1.); - ddc::fill(init_perturb_amplitude, 0); - ddc::fill(init_perturb_mode, 0); // Initialization of the distribution function - ddc::init_discrete_space( - std::move(charges), - std::move(masses), - std::move(init_perturb_amplitude), - std::move(init_perturb_mode)); + ddc::init_discrete_space(std::move(charges), std::move(masses)); EXPECT_EQ(my_ielec, ielec()); }