Skip to content

Commit

Permalink
Improve AdvectionRTheta tests
Browse files Browse the repository at this point in the history
Generalise the script `display_all_errors_for_gtest.py` so it can handle both the `advection_ALL` executable and the `advection_*_*_*` executables. Print the test name in the `advection_*_*_*` executables. Compile all `advection_*_*_*` executables which are useful for the tests (the same test cases as before but only with the crank-nicolson time integrator) and test each case individually
  • Loading branch information
EmilyBourne committed Dec 13, 2023
1 parent 6a8a6a8 commit df996c7
Show file tree
Hide file tree
Showing 4 changed files with 115 additions and 82 deletions.
99 changes: 33 additions & 66 deletions tests/geometryRTheta/advection_2d_rp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,71 +16,43 @@
# #
# #
#########################################################################################################

# EXAMPLE TEST N°1 --------------------------------------------------------------------------------------
set(MAPPING_TYPE "DISCRETE_MAPPING")
set(TIME_METHOD "CRANK_NICOLSON_METHOD")
set(SIMULATION "DECENTRED_ROTATION_SIMULATION")

set(test_name "advection_${MAPPING_TYPE}__${TIME_METHOD}__${SIMULATION}")
add_executable("${test_name}"
test_cases.hpp
advection_selected_test.cpp
)
target_compile_features("${test_name}" PUBLIC cxx_std_17)
target_link_libraries("${test_name}"
PUBLIC
DDC::DDC
DDC::PDI_Wrapper
paraconf::paraconf
PDI::pdi
Eigen3::Eigen

sll::splines

gslx::paraconfpp
gslx::interpolation_2D_rp
gslx::geometry_RTheta
gslx::advection_rp
gslx::quadrature
gslx::utils
gslx::timestepper
)
target_compile_definitions("${test_name}" PUBLIC -D${MAPPING_TYPE} -D${TIME_METHOD} -D${SIMULATION} -D${MESH})


# EXAMPLE TEST N°2 --------------------------------------------------------------------------------------
set(MAPPING_TYPE "CZARNY_MAPPING_PSEUDO_CARTESIAN")
set(TIME_METHOD "CRANK_NICOLSON_METHOD")
set(SIMULATION "TRANSLATION_SIMULATION")

set(test_name "advection_${MAPPING_TYPE}__${TIME_METHOD}__${SIMULATION}")
add_executable("${test_name}"
test_cases.hpp
advection_selected_test.cpp
)
target_compile_features("${test_name}" PUBLIC cxx_std_17)
target_link_libraries("${test_name}"
PUBLIC
DDC::DDC
DDC::PDI_Wrapper
paraconf::paraconf
PDI::pdi
Eigen3::Eigen

sll::splines

gslx::paraconfpp
gslx::interpolation_2D_rp
gslx::geometry_RTheta
gslx::advection_rp
gslx::quadrature
gslx::utils
gslx::timestepper
)
target_compile_definitions("${test_name}" PUBLIC -D${MAPPING_TYPE} -D${TIME_METHOD} -D${SIMULATION} -D${MESH})

foreach(MAPPING_TYPE "CIRCULAR_MAPPING" "CZARNY_MAPPING_PHYSICAL" "CZARNY_MAPPING_PSEUDO_CARTESIAN" "DISCRETE_MAPPING")
foreach(SIMULATION "TRANSLATION_SIMULATION" "ROTATION_SIMULATION" "DECENTRED_ROTATION_SIMULATION")
set(test_name "advection_${MAPPING_TYPE}__${TIME_METHOD}__${SIMULATION}")
add_executable("${test_name}"
test_cases.hpp
advection_selected_test.cpp
)
target_compile_features("${test_name}" PUBLIC cxx_std_17)
target_link_libraries("${test_name}"
PUBLIC
DDC::DDC
DDC::PDI_Wrapper
paraconf::paraconf
PDI::pdi
Eigen3::Eigen

sll::splines

gslx::paraconfpp
gslx::interpolation_2D_rp
gslx::geometry_RTheta
gslx::advection_rp
gslx::quadrature
gslx::utils
gslx::timestepper
)
target_compile_definitions("${test_name}" PUBLIC -D${MAPPING_TYPE} -D${TIME_METHOD} -D${SIMULATION} -D${MESH})
# CONVERGENCE ORDER TEST: ----------------------------------------
add_test(NAME TestAdvectionRPConvergence_${MAPPING_TYPE}__${TIME_METHOD}__${SIMULATION}
COMMAND "$<TARGET_FILE:Python3::Interpreter>" "${CMAKE_CURRENT_SOURCE_DIR}/display_all_errors_for_gtest.py"
"$<TARGET_FILE:advection_${MAPPING_TYPE}__${TIME_METHOD}__${SIMULATION}>")
set_property(TEST TestAdvectionRPConvergence_${MAPPING_TYPE}__${TIME_METHOD}__${SIMULATION} PROPERTY TIMEOUT 20)
endforeach()
endforeach()



Expand Down Expand Up @@ -118,10 +90,5 @@ target_compile_definitions(advection_ALL PUBLIC)

find_package(Python3 REQUIRED COMPONENTS Interpreter)

# CONVERGENCE ORDER TEST: ----------------------------------------
add_test(NAME TestAdvectionRPConvergence
COMMAND "$<TARGET_FILE:Python3::Interpreter>" "${CMAKE_CURRENT_SOURCE_DIR}/display_all_errors_for_gtest.py"
"$<TARGET_FILE:advection_ALL>")
set_property(TEST TestAdvectionRPConvergence PROPERTY TIMEOUT 10000)


31 changes: 29 additions & 2 deletions tests/geometryRTheta/advection_2d_rp/advection_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,11 +225,38 @@ def get_full_fct_names(var_out):
A list of string containing the names of the test cases.
"""
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][1].upper() + line[3][2:-3].lower() + " with " + line[2].lower() + " on "
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

def get_fct_name_key(full_name):
"""
Get the keys which identify the test case from its full name.
Parameters
----------
full_name : str
The full name of the case as outputted by get_full_fct_names.
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


def treatment(namefile):
Expand Down
17 changes: 17 additions & 0 deletions tests/geometryRTheta/advection_2d_rp/advection_selected_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -204,55 +204,72 @@ int main(int argc, char** argv)
CircularToCartesian<RDimX, RDimY, RDimR, RDimP> analytical_mapping;
CircularToCartesian<RDimX, RDimY, RDimR, RDimP> mapping;
AdvectionPhysicalDomain advection_domain(analytical_mapping);
std::string const mapping_name = "CIRCULAR";
std::string const domain_name = "PHYSICAL";

#elif defined(CZARNY_MAPPING_PHYSICAL)
CzarnyToCartesian<RDimX, RDimY, RDimR, RDimP> analytical_mapping(czarny_e, czarny_epsilon);
CzarnyToCartesian<RDimX, RDimY, RDimR, RDimP> mapping(czarny_e, czarny_epsilon);
AdvectionPhysicalDomain advection_domain(analytical_mapping);
std::string const mapping_name = "CZARNY";
std::string const domain_name = "PHYSICAL";

#elif defined(CZARNY_MAPPING_PSEUDO_CARTESIAN)
CzarnyToCartesian<RDimX, RDimY, RDimR, RDimP> analytical_mapping(czarny_e, czarny_epsilon);
CzarnyToCartesian<RDimX, RDimY, RDimR, RDimP> mapping(czarny_e, czarny_epsilon);
AdvectionPseudoCartesianDomain advection_domain(mapping);
std::string const mapping_name = "CZARNY";
std::string const domain_name = "PSEUDO CARTESIAN";

#elif defined(DISCRETE_MAPPING)
CzarnyToCartesian<RDimX, RDimY, RDimR, RDimP> analytical_mapping(czarny_e, czarny_epsilon);
DiscreteToCartesian<RDimX, RDimY, SplineRPBuilder> mapping
= DiscreteToCartesian<RDimX, RDimY, SplineRPBuilder>::
analytical_to_discrete(analytical_mapping, builder, spline_evaluator_extrapol);
AdvectionPseudoCartesianDomain advection_domain(mapping);
std::string const mapping_name = "DISCRETE";
std::string const domain_name = "PSEUDO CARTESIAN";
#endif



// SELECTION OF THE TIME INTEGRATION METHOD.
#if defined(EULER_METHOD)
Euler<FieldRP<CoordRP>, VectorDFieldRP<RDimX_adv, RDimY_adv>> time_stepper(grid);
std::string const method_name = "EULER";

#elif defined(CRANK_NICOLSON_METHOD)
double const epsilon_CN = 1e-8;
CrankNicolson<FieldRP<CoordRP>, VectorDFieldRP<RDimX_adv, RDimY_adv>>
time_stepper(grid, 20, epsilon_CN);
std::string const method_name = "CRANK NICOLSON";

#elif defined(RK3_METHOD)
RK3<FieldRP<CoordRP>, VectorDFieldRP<RDimX_adv, RDimY_adv>> time_stepper(grid);
std::string const method_name = "RK3";

#elif defined(RK4_METHOD)
RK4<FieldRP<CoordRP>, VectorDFieldRP<RDimX_adv, RDimY_adv>> time_stepper(grid);
std::string const method_name = "RK4";
#endif


// SELECTION OF THE SIMULATION.
#if defined(TRANSLATION_SIMULATION)
TranslationSimulation simulation(mapping, rmin, rmax);
std::string const simu_type = " TRANSLATION : ";

#elif defined(ROTATION_SIMULATION)
RotationSimulation simulation(mapping, rmin, rmax);
std::string const simu_type = " ROTATION : ";

#elif defined(DECENTRED_ROTATION_SIMULATION)
DecentredRotationSimulation simulation(mapping);
std::string const simu_type = " DECENTRED ROTATION : ";
#endif

std::cout << mapping_name << " MAPPING - " << domain_name << " DOMAIN - " << method_name
<< " - " << simu_type << std::endl;
simulate(
mapping,
analytical_mapping,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
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
from advection_functions import set_input, execute, take_errors_from_out, get_full_fct_names, get_fct_names, get_fct_name_key



Expand All @@ -82,13 +82,32 @@
short_fct_names = get_fct_names(out)
nb_fct = len(fct_names)

# Table of expected convergence orders --------------------------
# Euler Crank Nicolson RK3 RK4
order_expected = [3, 1, 1] + [3, 2, 2] + [3, 3, 3] + [3, 3, 3] # Circular map on physical dom
order_expected += [3, 1, 1] + [3, 2, 2] + [3, 3, 3] + [3, 3, 3] # Czarny map on physical dom
order_expected += [1, 1, 1] + [3, 2, 2] + [3, 3, 3] + [3, 3, 3] # Czarny map on pseudo Cart dom
order_expected += [1, 1, 1] + [3, 2, 2] + [3, 3, 3] + [3, 3, 3] # Discrete map on pseudo Cart dom

# 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}
},
'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}
},
'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}
},
'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}
}
}



Expand All @@ -98,16 +117,19 @@


# Check the convergence order -----------------------------------
for index in range(48):
for index in range(nb_fct):
Coeffs = np.polyfit(np.log(Order),np.log(Errors_by_fct[index]),1)
slope = Coeffs[0]

print(">" + (fct_names[index][:2]).upper() +fct_names[index][2:] + f" : \n order = {round(slope,3)} ({order_expected[index]} expected).")
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).")

# Order expected:
if (slope < order_expected[index] - 0.25):
print(fct_names[index] + f" has not the right convergence order: get {slope}, expected {order_expected[index] - 0.25}.")
assert (slope > order_expected[index] - 0.25)
if (slope < theoretical_order - 0.25):
print(fct_names[index] + f" has not the right convergence order: got {slope}, expected {theoretical_order - 0.25}.")
assert (slope > theoretical_order - 0.25)



Expand Down Expand Up @@ -162,7 +184,7 @@ def set_subplot(index, i0, title):
"Czarny mapping and pseudo Cartesian domain",
"Discrete mapping and pseudo Cartesian domain"]

for i in range(48//3):
for i in range(nb_fct//3):
index = i + 1
set_subplot(index, 3*i, names_mapping[i//4] + " \n " + names_method[i%4])

Expand Down

0 comments on commit df996c7

Please sign in to comment.