diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 2e8242e27d8d8d75520fead5f939d5c103031c1e..a03f9900c387ee1b9b3c184e41b6bb460616d94c 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -200,6 +200,11 @@ sanity_stage: - chmod +x test_inclusion_outputs - valgrind --leak-check=full --log-file=valgrind_inclusion.log ./test_inclusion_outputs - grep "0 errors from 0 contexts" valgrind_inclusion.log + - rm -rf c_OINCLU + - chmod +x test_sphere_outputs + - valgrind --leak-check=full --log-file=valgrind_sphere.log ./test_sphere_outputs + - grep "0 errors from 0 contexts" valgrind_sphere.log + - rm -rf c_OSPH running_stage: stage: run @@ -308,4 +313,9 @@ testing_stage: - export FFILE=../../test_data/inclusion/OINCLU - python3 ../../src/scripts/pycompare.py --no-progress --ffile $FFILE --cfile c_OINCLU - rm -rf c_OINCLU + - chmod u+x test_sphere_outputs + - ./test_sphere_outputs + - export FFILE=../../test_data/sphere/OSPH + - python3 ../../src/scripts/pycompare.py --no-progress --ffile $FFILE --cfile c_OSPH + - rm -rf c_OSPH \ No newline at end of file diff --git a/build/Makefile b/build/Makefile index cba30075e68395cbbb87ea589cb98b5d691a00da..5ae144d03206c40cfbf01114f487808653b49d8d 100644 --- a/build/Makefile +++ b/build/Makefile @@ -29,8 +29,8 @@ NP_SPHERE_BINS=sphere/np_sphere NP_TRAPPING_SRCS=../src/trapping/np_trapping.cpp ../src/trapping/cfrfme.cpp ../src/trapping/clffft.cpp NP_TRAPPING_OBJS=../src/trapping/np_trapping.o ../src/trapping/cfrfme.o ../src/trapping/clffft.o NP_TRAPPING_BINS=trapping/np_trapping -NP_TESTING_OBJS=../src/testing/test_cluster_outputs.o ../src/testing/test_inclusion_outputs.o ../src/testing/test_ParticleDescriptor.o ../src/testing/test_TEDF.o ../src/testing/test_TTMS.o -NP_TESTING_BINS=testing/test_cluster_outputs testing/test_inclusion_outputs testing/test_ParticleDescriptor testing/test_TEDF testing/test_TTMS +NP_TESTING_OBJS=../src/testing/test_cluster_outputs.o ../src/testing/test_inclusion_outputs.o ../src/testing/test_sphere_outputs.o ../src/testing/test_ParticleDescriptor.o ../src/testing/test_TEDF.o ../src/testing/test_TTMS.o +NP_TESTING_BINS=testing/test_cluster_outputs testing/test_inclusion_outputs testing/test_sphere_outputs testing/test_ParticleDescriptor testing/test_TEDF testing/test_TTMS all: $(NPTM_LIB) $(FORTRAN_BINS) $(NP_CLUSTER_BINS) $(NP_INCLUSION_BINS) $(NP_SPHERE_BINS) $(NP_TRAPPING_BINS) $(NP_TESTING_BINS) @@ -89,6 +89,9 @@ testing/test_cluster_outputs: $(NPTM_LIB) ../src/testing/test_cluster_outputs.o testing/test_inclusion_outputs: $(NPTM_LIB) ../src/testing/test_inclusion_outputs.o $(CXX) $(CXXFLAGS) ../src/testing/test_inclusion_outputs.o -o $@ $(CXXLDFLAGS) +testing/test_sphere_outputs: $(NPTM_LIB) ../src/testing/test_sphere_outputs.o + $(CXX) $(CXXFLAGS) ../src/testing/test_sphere_outputs.o -o $@ $(CXXLDFLAGS) + testing/test_TEDF: $(NPTM_LIB) ../src/testing/test_TEDF.o $(CXX) $(CXXFLAGS) ../src/testing/test_TEDF.o -o $@ $(CXXLDFLAGS) diff --git a/src/libnptm/outputs.cpp b/src/libnptm/outputs.cpp index 71cf7b781222e17c42da9f7129da9e4a511949f5..9cab3e0989517ee21a0c0e8d7294ac88d798f6f4 100644 --- a/src/libnptm/outputs.cpp +++ b/src/libnptm/outputs.cpp @@ -4921,7 +4921,7 @@ SphereOutputInfo::SphereOutputInfo(const std::string &hdf5_name) { _num_phis = (phsstp == 0.0) ? 1 : 1 + int((phslst - phs) / phsstp); ndirs = _num_theta * _num_thetas * _num_phi * _num_phis; status = hdf_file->read("EXRI", "FLOAT64_(1)", &exri); - status = hdf_file->read("NUM_CONF", "FLOAT64_(1)", &configurations); + status = hdf_file->read("NUM_CONF", "INT32_(1)", &configurations); status = hdf_file->read("IDFC", "INT32_(1)", &idfc); status = hdf_file->read("XI1", "INT32_(1)", &_first_xi); status = hdf_file->read("NXI", "INT32_(1)", &xi_block_size); @@ -4938,49 +4938,49 @@ SphereOutputInfo::SphereOutputInfo(const std::string &hdf5_name) { vec_vk = new double[xi_block_size]; status = hdf_file->read("VEC_VK", str_type, vec_vk); vec_xi = new double[xi_block_size]; - status = hdf_file->read("VEC_VK", str_type, vec_xi); + status = hdf_file->read("VEC_XI", str_type, vec_xi); str_type = "FLOAT64_(" + to_string(configurations * xi_block_size) + ")"; - vec_sphere_sizes = new double[xi_block_size]; + vec_sphere_sizes = new double[configurations * xi_block_size]; status = hdf_file->read("VEC_SPH_SIZES", str_type, vec_sphere_sizes); str_type = "FLOAT64_(" + to_string(2 * configurations * xi_block_size) + ")"; - vec_sphere_ref_indices = new dcomplex[xi_block_size]; + vec_sphere_ref_indices = new dcomplex[configurations * xi_block_size]; status = hdf_file->read("VEC_SPH_REFRI", str_type, vec_sphere_ref_indices); str_type = "FLOAT64_(" + to_string(configurations * xi_block_size) + ")"; - vec_scs = new double[xi_block_size]; + vec_scs = new double[configurations * xi_block_size]; status = hdf_file->read("VEC_SCS", str_type, vec_scs); - vec_abs = new double[xi_block_size]; + vec_abs = new double[configurations * xi_block_size]; status = hdf_file->read("VEC_ABS", str_type, vec_abs); - vec_exs = new double[xi_block_size]; + vec_exs = new double[configurations * xi_block_size]; status = hdf_file->read("VEC_EXS", str_type, vec_exs); - vec_albeds = new double[xi_block_size]; + vec_albeds = new double[configurations * xi_block_size]; status = hdf_file->read("VEC_ALBEDS", str_type, vec_albeds); - vec_scsrt = new double[xi_block_size]; + vec_scsrt = new double[configurations * xi_block_size]; status = hdf_file->read("VEC_SCSRT", str_type, vec_scsrt); - vec_absrt = new double[xi_block_size]; + vec_absrt = new double[configurations * xi_block_size]; status = hdf_file->read("VEC_ABSRT", str_type, vec_absrt); - vec_exsrt = new double[xi_block_size]; + vec_exsrt = new double[configurations * xi_block_size]; status = hdf_file->read("VEC_EXSRT", str_type, vec_exsrt); str_type = "FLOAT64_(" + to_string(2 * configurations * xi_block_size) + ")"; - vec_fsas = new dcomplex[xi_block_size]; + vec_fsas = new dcomplex[configurations * xi_block_size]; status = hdf_file->read("VEC_FSAS", str_type, vec_fsas); str_type = "FLOAT64_(" + to_string(configurations * xi_block_size) + ")"; - vec_qschu = new double[xi_block_size]; + vec_qschu = new double[configurations * xi_block_size]; status = hdf_file->read("VEC_QSCHU", str_type, vec_qschu); - vec_pschu = new double[xi_block_size]; + vec_pschu = new double[configurations * xi_block_size]; status = hdf_file->read("VEC_PSCHU", str_type, vec_pschu); - vec_s0mag = new double[xi_block_size]; + vec_s0mag = new double[configurations * xi_block_size]; status = hdf_file->read("VEC_S0MAG", str_type, vec_s0mag); - vec_cosav = new double[xi_block_size]; + vec_cosav = new double[configurations * xi_block_size]; status = hdf_file->read("VEC_COSAV", str_type, vec_cosav); - vec_raprs = new double[xi_block_size]; + vec_raprs = new double[configurations * xi_block_size]; status = hdf_file->read("VEC_RAPRS", str_type, vec_raprs); - vec_tqek1 = new double[xi_block_size]; + vec_tqek1 = new double[configurations * xi_block_size]; status = hdf_file->read("VEC_TQEK1", str_type, vec_tqek1); - vec_tqek2 = new double[xi_block_size]; + vec_tqek2 = new double[configurations * xi_block_size]; status = hdf_file->read("VEC_TQEK2", str_type, vec_tqek2); - vec_tqsk1 = new double[xi_block_size]; + vec_tqsk1 = new double[configurations * xi_block_size]; status = hdf_file->read("VEC_TQSK1", str_type, vec_tqsk1); - vec_tqsk2 = new double[xi_block_size]; + vec_tqsk2 = new double[configurations * xi_block_size]; status = hdf_file->read("VEC_TQSK2", str_type, vec_tqsk2); if (nsph != 1) { str_type = "FLOAT64_(" + to_string(2 * xi_block_size) + ")"; @@ -5345,9 +5345,9 @@ int SphereOutputInfo::write_hdf5(const std::string &file_name) { rec_name_list->append("IDFC"); rec_type_list->append("INT32_(1)"); rec_ptr_list->append(&idfc); - rec_name_list->set(0, "NUM_CONF"); - rec_type_list->set(0, "INT32_(1)"); - rec_ptr_list->set(0, &configurations); + rec_name_list->append("NUM_CONF"); + rec_type_list->append("INT32_(1)"); + rec_ptr_list->append(&configurations); rec_name_list->append("XI1"); rec_type_list->append("INT32_(1)"); rec_ptr_list->append(&_first_xi); diff --git a/src/testing/test_sphere_outputs.cpp b/src/testing/test_sphere_outputs.cpp new file mode 100644 index 0000000000000000000000000000000000000000..5acb13c197768345dfcf846b0e538dcfe2fc7e53 --- /dev/null +++ b/src/testing/test_sphere_outputs.cpp @@ -0,0 +1,65 @@ +#include <string> + +#ifndef INCLUDE_TYPES_H_ +#include "../include/types.h" +#endif + +#ifndef INCLUDE_ERRORS_H_ +#include "../include/errors.h" +#endif + +#ifndef INCLUDE_CONFIGURATION_H_ +#include "../include/Configuration.h" +#endif + +#ifndef INCLUDE_COMMONS_H_ +#include "../include/Commons.h" +#endif + +#ifndef INCLUDE_OUTPUTS_H_ +#include "../include/outputs.h" +#endif + +using namespace std; + +int test_sphere_hdf5_output(); +int test_sphere_devel(); + +int main() { + int result = 0; + result += test_sphere_hdf5_output(); // 1 if failed + result += test_sphere_devel(); // 10 if failed + return result; +} + +int test_sphere_hdf5_output() { + int result = 0; + try { + const string hdf5_file = "../../test_data/sphere/c_OSPH.hd5"; + SphereOutputInfo *oi = new SphereOutputInfo(hdf5_file); + oi->write("c_OSPH", "LEGACY"); + delete oi; + } catch (const exception& ex) { + result = 1; + } + return result; +} + +int test_sphere_devel() { + int result = 0; + try { + const string geom_data_file = "../../test_data/sphere/DSPH"; + const string scat_data_file = "../../test_data/sphere/DEDFB"; + mixMPI *mpidata = new mixMPI(); + GeometryConfiguration *gconf = GeometryConfiguration::from_legacy(geom_data_file); + ScattererConfiguration *sconf = ScattererConfiguration::from_dedfb(scat_data_file); + SphereOutputInfo *oi = new SphereOutputInfo(sconf, gconf, mpidata); + delete gconf; + delete sconf; + delete oi; + delete mpidata; + } catch (const exception& ex) { + result = 10; + } + return result; +} diff --git a/test_data/sphere/c_OSPH.hd5 b/test_data/sphere/c_OSPH.hd5 new file mode 100644 index 0000000000000000000000000000000000000000..efa38e592809ede0e0bd4867a0d476fdb3849f7e Binary files /dev/null and b/test_data/sphere/c_OSPH.hd5 differ