commit f9b6f7071138180f6b1141ea53a8646e31aab709
parent 4785a3d5f5faa607bf552d5c3f8990568b65509b
Author: Vincent Forest <vincent.forest@meso-star.com>
Date: Thu, 20 Oct 2022 15:31:31 +0200
Begin the implementation of the htrdr-planeto command
Diffstat:
10 files changed, 466 insertions(+), 6 deletions(-)
diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt
@@ -29,6 +29,7 @@ set(VERSION ${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH})
option(HTRDR_BUILD_ATMOSPHERE "Build the htrdr-atmosphere program" ON)
option(HTRDR_BUILD_COMBUSTION "Build the htrdr-combustion program" ON)
+option(HTRDR_BUILD_PLANETO "Build the htrdr-planeto program" ON)
set(HTRDR_BUILD_COMMANDS "")
if(HTRDR_BUILD_ATMOSPHERE)
@@ -37,6 +38,9 @@ endif()
if(HTRDR_BUILD_COMBUSTION)
set(HTRDR_BUILD_COMMANDS "${HTRDR_BUILD_COMMANDS};HTRDR_BUILD_COMBUSTION")
endif()
+if(HTRDR_BUILD_COMBUSTION)
+ set(HTRDR_BUILD_COMMANDS "${HTRDR_BUILD_COMMANDS};HTRDR_BUILD_PLANETO")
+endif()
################################################################################
# Add sub projects
@@ -49,6 +53,9 @@ endif()
if(HTRDR_BUILD_COMBUSTION)
add_subdirectory(combustion)
endif()
+if(HTRDR_BUILD_PLANETO)
+ add_subdirectory(planeto)
+endif()
add_subdirectory(commands)
add_subdirectory(doc)
diff --git a/cmake/combustion/CMakeLists.txt b/cmake/combustion/CMakeLists.txt
@@ -81,7 +81,7 @@ set(HTRDR_COMBUSTION_FILES_INC
rcmake_prepend_path(HTRDR_COMBUSTION_FILES_SRC ${HTRDR_SOURCE_DIR}/combustion)
rcmake_prepend_path(HTRDR_COMBUSTION_FILES_INC ${HTRDR_SOURCE_DIR}/combustion)
-# Atmosphere library
+# Combustion library
add_library(htrdr-combustion SHARED
${HTRDR_COMBUSTION_FILES_SRC}
${HTRDR_COMBUSTION_FILES_INC})
diff --git a/cmake/commands/CMakeLists.txt b/cmake/commands/CMakeLists.txt
@@ -28,6 +28,9 @@ endif()
if(HTRDR_BUILD_COMBUSTION)
list(APPEND _link_libraries htrdr-combustion)
endif()
+if(HTRDR_BUILD_PLANETO)
+ list(APPEND _lin_libraries htrdr-planeto)
+endif()
################################################################################
# Check dependencies
@@ -62,10 +65,19 @@ if(HTRDR_BUILD_COMBUSTION)
target_link_libraries(htrdr_combustion_cmd htrdr-combustion)
endif()
+add_executable(htrdr_planeto_cmd
+ ${HTRDR_SOURCE_DIR}/commands/htrdr_planeto_cmd.c)
+set_target_properties(htrdr_planeto_cmd PROPERTIES
+ COMPILE_DEFINITIONS "${HTRDR_BUILD_COMMANDS}"
+ OUTPUT_NAME htrdr-planeto)
+if(HTRDR_BUILD_PLANETO)
+ target_link_libraries(htrdr_planeto_cmd htrdr-planeto)
+endif()
+
################################################################################
# Define output & install directories
################################################################################
-install(TARGETS htrdr_cmd htrdr_atmosphere_cmd htrdr_combustion_cmd
+install(TARGETS htrdr_cmd htrdr_atmosphere_cmd htrdr_combustion_cmd htrdr_planeto_cmd
ARCHIVE DESTINATION bin
LIBRARY DESTINATION lib
RUNTIME DESTINATION bin)
diff --git a/cmake/planeto/CMakeLists.txt b/cmake/planeto/CMakeLists.txt
@@ -0,0 +1,84 @@
+# Copyright (C) 2018, 2019, 2020, 2021 |Meso|Star> (contact@meso-star.com)
+# Copyright (C) 2018, 2019, 2021 CNRS
+# Copyright (C) 2018, 2019 Université Paul Sabatier
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+cmake_minimum_required(VERSION 3.1)
+project(htrdr-planet)
+
+################################################################################
+# Check dependencies
+################################################################################
+find_package(RCMake 0.4 REQUIRED)
+find_package(RNATM 0.0 REQUIRED)
+find_package(RNGRD 0.0 REQUIRED)
+find_package(RSys 0.11 REQUIRED)
+find_package(Star3D 0.8 REQUIRED)
+find_package(StarCamera 0.0 REQUIRED)
+find_package(StarSF 0.6 REQUIRED)
+find_package(StarSP 0.12 REQUIRED)
+find_package(StarVX 0.1 REQUIRED)
+
+set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${RCMAKE_SOURCE_DIR})
+include(rcmake)
+include(rcmake_runtime)
+
+include_directories(
+ ${RNATM_INCLUDE_DIR}
+ ${RNGRD}
+ ${RSys_INCLUDE_DIR}
+ ${Star3D_INCLUDE_DIR}
+ ${StarCamera_INCLUDE_DIR}
+ ${StarSF_INCLUDE_DIR}
+ ${StarSP_INCLUDE_DIR}
+ ${StarVX_INCLUDE_DIR}
+ ${HTRDR_BUILD_DIR}
+ ${HTRDR_SOURCE_DIR})
+
+################################################################################
+# Configure and define targets
+################################################################################
+set(HTRDR_PLANETO_FILES_SRC
+ htrdr_planeto_args.c
+ htrdr_planeto_main.c)
+
+set(HTRDR_PLANETO_FILES_INC
+ htrdr_planeto.h
+ htrdr_planeto_args.h)
+
+# Prepend each file in the `HTRDR_FILES_<SRC|INC>' list by `HTRDR_SOURCE_DIR'
+rcmake_prepend_path(HTRDR_PLANETO_FILES_SRC ${HTRDR_SOURCE_DIR}/planeto)
+rcmake_prepend_path(HTRDR_PLANETO_FILES_INC ${HTRDR_SOURCE_DIR}/planeto)
+
+# Planeto library
+add_library(htrdr-planeto SHARED
+ ${HTRDR_PLANETO_FILES_SRC}
+ ${HTRDR_PLANETO_FILES_INC})
+target_link_libraries(htrdr-planeto
+ htrdr-core RNATM RNGRD RSys Star3D StarCamera StarSF StarSP)
+
+set_target_properties(htrdr-planeto PROPERTIES
+ DEFINE_SYMBOL HTRDR_SHARED_BUILD
+ VERSION ${VERSION}
+ SOVERSION ${VERSION_MAJOR})
+
+################################################################################
+# Define output & install directories
+################################################################################
+install(TARGETS htrdr-planeto
+ ARCHIVE DESTINATION bin
+ LIBRARY DESTINATION lib
+ RUNTIME DESTINATION bin)
+
diff --git a/src/commands/htrdr_planeto_cmd.c b/src/commands/htrdr_planeto_cmd.c
@@ -0,0 +1,35 @@
+/* Copyright (C) 2018, 2019, 2020, 2021 |Meso|Star> (contact@meso-star.com)
+ * Copyright (C) 2018, 2019, 2021 CNRS
+ * Copyright (C) 2018, 2019 Université Paul Sabatier
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+#ifdef HTRDR_BUILD_PLANETO
+ #include "planeto/htrdr_planeto.h"
+#else
+ #include <stdio.h>
+#endif
+
+int
+main(int argc, char** argv)
+{
+#ifdef HTRDR_BUILD_PLANETO
+ return htrdr_planeto_main(argc, argv);
+#else
+ (void)argc, (void)argv;
+ fprintf(stderr,
+ "The htrdr-planeto command is not available in this htrdr build.\n");
+ return 1;
+#endif
+}
diff --git a/src/core/htrdr.h b/src/core/htrdr.h
@@ -67,9 +67,9 @@ htrdr_fprint_copyright(const char* cmd, FILE* stream)
{
(void)cmd;
fprintf(stream,
-"Copyright (C) 2018, 2019, 2020, 2021 |Meso|Star> <contact@meso-star.com>.\n"
-"Copyright (C) 2018, 2019, 2021 CNRS.\n"
-"Copyright (C) 2018, 2019 Université Paul Sabatier.\n");
+"Copyright (C) 2018, 2019, 2020, 2021 |Meso|Star> <contact@meso-star.com>\n"
+"Copyright (C) 2018, 2019, 2021 CNRS\n"
+"Copyright (C) 2018, 2019 Université Paul Sabatier\n");
}
static INLINE void
@@ -79,7 +79,7 @@ htrdr_fprint_license(const char* cmd, FILE* stream)
fprintf(stream,
"%s is free software released under the GNU GPL license,\n"
"version 3 or later. You are free to change or redistribute it\n"
-"under certain conditions <http://gnu.org/licenses/gpl.html>.\n",
+"under certain conditions <http://gnu.org/licenses/gpl.html>\n",
cmd);
}
diff --git a/src/planeto/htrdr_planeto.h b/src/planeto/htrdr_planeto.h
@@ -0,0 +1,55 @@
+/* Copyright (C) 2018, 2019, 2020, 2021 |Meso|Star> (contact@meso-star.com)
+ * Copyright (C) 2018, 2019, 2021 CNRS
+ * Copyright (C) 2018, 2019, Université Paul Sabatier
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+#ifndef HTRDR_PLANETO_H
+#define HTRDR_PLANETO_H
+
+#include "core/htrdr.h"
+#include <rsys/rsys.h>
+
+struct htrdr;
+struct htrdr_planeto;
+struct htrdr_planeto_args;
+
+BEGIN_DECLS
+
+HTRDR_API res_T
+htrdr_planeto_create
+ (struct htrdr* htrdr,
+ const struct htrdr_planeto_args* args,
+ struct htrdr_planeto** cmd);
+
+HTRDR_API void
+htrdr_planeto_ref_get
+ (struct htrdr_planeto* cmd);
+
+HTRDR_API void
+htrdr_planeto_ref_put
+ (struct htrdr_planeto* cmd);
+
+HTRDR_API res_T
+htrdr_planeto_run
+ (struct htrdr_planeto* cmd);
+
+HTRDR_API int
+htrdr_planeto_main
+ (int argc,
+ char** argv);
+
+END_DECLS
+
+#endif /* HTRDR_PLANETO_H */
diff --git a/src/planeto/htrdr_planeto_args.c b/src/planeto/htrdr_planeto_args.c
@@ -0,0 +1,123 @@
+/* Copyright (C) 2018, 2019, 2020, 2021 |Meso|Star> (contact@meso-star.com)
+ * Copyright (C) 2018, 2019, 2021 CNRS
+ * Copyright (C) 2018, 2019, Université Paul Sabatier
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+#define _POSIX_C_SOURCE 200112L /* strtok_r support */
+
+#include "planeto/htrdr_planeto_args.h"
+
+#include <getopt.h>
+#include <string.h>
+
+/*******************************************************************************
+ * Helper functions
+ ******************************************************************************/
+static void
+print_help(const char* cmd)
+{
+ ASSERT(cmd);
+ printf(
+"Usage: %s [-dfhv] [-s spectral_domain] [-t threads]\n"
+" [-T optical_thickness] [-V octree_definition]\n"
+" [-O octrees_storage] [-o output]\n"
+" [-a aerosol]... -g gas -G ground\n", cmd);
+ printf(
+"Simulate radiative transfer in heterogeneous 3D planetary atmosphere.\n"
+"See htrdr-planeto(1) man page for details\n\n");
+ printf(
+" -a aerosol define an aerosol\n");
+ printf(
+" -d write the atmospheric acceleration structures\n");
+ printf(
+" -f force overwrite the output file\n");
+ printf(
+" -G ground define the ground of the planet\n");
+ printf(
+" -g gas define the gas mixture\n");
+ printf(
+" -h display this help and exit\n");
+ printf(
+" -O octrees_storage\n"
+" file where atmospheric acceleration structures are\n"
+" stored/loaded\n");
+ printf(
+" -o output file where the result is written. If not defined,\n"
+" the result is written to standard output\n");
+ printf(
+" -s spectral_domain\n"
+" define the spectral domain of integration\n");
+ printf(
+" -T optical_thickness\n"
+" optical thickness criteria for octree building.\n"
+" Default is %g\n",
+ HTRDR_PLANETO_ARGS_DEFAULT.optical_thickness);
+ printf(
+" -t threads hint on the number of threads to use.\n"
+" Default assumes as mayn threads as CPU cores\n");
+ printf(
+" -V octree_definition\n"
+" advice on the definition of the atmospheric\n"
+" acceleration structures. Default is %u\n",
+ HTRDR_PLANETO_ARGS_DEFAULT.octree_definition_hint);
+ printf(
+" -v make the command verbose\n");
+ printf("\n");
+ htrdr_fprint_license(cmd, stdout);
+}
+
+/*******************************************************************************
+ * Local functions
+ ******************************************************************************/
+res_T
+htrdr_planeto_args_init(struct htrdr_planeto_args* args, int argc, char** argv)
+{
+ int opt;
+ res_T res = RES_OK;
+ ASSERT(args && argc && argv);
+
+ *args = HTRDR_PLANETO_ARGS_DEFAULT;
+
+ while((opt = getopt(argc, argv, "a:dfG:g:hO:o:s:T:t:V:v")) != -1) {
+ switch(opt) {
+ case 'h':
+ print_help(argv[0]);
+ htrdr_planeto_args_release(args);
+ args->quit = 1;
+ goto exit;
+ default: res = RES_BAD_ARG; goto error;
+ }
+ if(res != RES_OK) {
+ if(optarg) {
+ fprintf(stderr, "%s: invalid option argument '%s' -- '%c'\n",
+ argv[0], optarg, opt);
+ }
+ goto error;
+ }
+ }
+
+exit:
+ return res;
+error:
+ htrdr_planeto_args_release(args);
+ goto exit;
+}
+
+void
+htrdr_planeto_args_release(struct htrdr_planeto_args* args)
+{
+ ASSERT(args);
+ *args = HTRDR_PLANETO_ARGS_DEFAULT;
+}
diff --git a/src/planeto/htrdr_planeto_args.h b/src/planeto/htrdr_planeto_args.h
@@ -0,0 +1,95 @@
+/* Copyright (C) 2018, 2019, 2020, 2021 |Meso|Star> (contact@meso-star.com)
+ * Copyright (C) 2018, 2019, 2021 CNRS
+ * Copyright (C) 2018, 2019, Université Paul Sabatier
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+#ifndef HTRDR_PLANETO_ARGS_H
+#define HTRDR_PLANETO_ARGS_H
+
+#include "core/htrdr_args.h"
+
+#include <rad-net/rnatm.h>
+#include <rsys/rsys.h>
+
+#include <limits.h> /* UINT_MAX */
+
+struct htrdr_planeto_ground_args {
+ char* smsh_filename; /* The Star-Mesh geometry */
+ char* props_filename; /* Per triangle physical properties */
+ char* mtllst_filename; /* List of used materials */
+};
+#define HTRDR_PLANETO_GROUND_ARGS_NULL__ {NULL,NULL,NULL}
+static const struct htrdr_planeto_ground_args HTRDR_PLANETO_GROUND_ARGS_NULL =
+ HTRDR_PLANETO_GROUND_ARGS_NULL__;
+
+struct htrdr_planeto_args {
+ /* System data */
+ struct rnatm_gas_args gas;
+ struct rnatm_aerosol_args* aerosols;
+ size_t naerosols;
+ struct htrdr_planeto_ground_args ground;
+
+ /* Read/Write file where octrees are stored. May be NULL => octres are built
+ * at runtime and kept in memory */
+ char* octrees_storage;
+
+ unsigned octree_definition_hint; /* Hint on octree definition */
+ double optical_thickness; /* Threshold used during octree building */
+
+ char* output; /* File where the result is written */
+
+ /* Integration spectral domain */
+ struct htrdr_args_spectral spectral_domain;
+
+ /* Miscellaneous arguments */
+ unsigned nthreads; /* Hint on the nimber of threads to use */
+ int force_output_overwrite; /* Replace output if it exists */
+ int verbose; /* Verbose level */
+ int quit; /* Stop the command */
+};
+#define HTRDR_PLANETO_ARGS_DEFAULT__ { \
+ RNATM_GAS_ARGS_NULL__, /* Gas */ \
+ NULL, /* List of aerosols */ \
+ 0, /* Number of aerosols */ \
+ HTRDR_PLANETO_GROUND_ARGS_NULL__, /* Ground */ \
+ \
+ NULL, /* File where to dump octrees */ \
+ \
+ 512, /* Hint on octree definition */ \
+ 10, /* Optical thickness criteria */ \
+ \
+ NULL, /* Ouput file */ \
+ \
+ HTRDR_ARGS_SPECTRAL_DEFAULT__, /* Spectral domain */ \
+ \
+ UINT_MAX, /* Number of threads */ \
+ 0, /* Force output overwrite */ \
+ 0, /* Verbosity level */ \
+ 0 /* Stop the command */ \
+}
+static const struct htrdr_planeto_args HTRDR_PLANETO_ARGS_DEFAULT =
+ HTRDR_PLANETO_ARGS_DEFAULT__;
+
+extern LOCAL_SYM res_T
+htrdr_planeto_args_init
+ (struct htrdr_planeto_args* args,
+ int argc,
+ char** argv);
+
+extern LOCAL_SYM void
+htrdr_planeto_args_release
+ (struct htrdr_planeto_args* args);
+
+#endif /* HTRDR_PLANETO_ARGS_H */
diff --git a/src/planeto/htrdr_planeto_main.c b/src/planeto/htrdr_planeto_main.c
@@ -0,0 +1,49 @@
+/* Copyright (C) 2018, 2019, 2020, 2021 |Meso|Star> (contact@meso-star.com)
+ * Copyright (C) 2018, 2019, 2021 CNRS
+ * Copyright (C) 2018, 2019, Université Paul Sabatier
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+#include "planeto/htrdr_planeto.h"
+#include "planeto/htrdr_planeto_args.h"
+
+int
+htrdr_planeto_main(int argc, char** argv)
+{
+ char cmd_name[] = "htrdr-planeto";
+ struct htrdr_planeto_args cmd_args = HTRDR_PLANETO_ARGS_DEFAULT;
+ int is_mpi_init = 0;
+ res_T res = RES_OK;
+ int err = 0;
+
+ /* Overwrite command name */
+ argv[0] = cmd_name;
+
+ res = htrdr_mpi_init(argc, argv);
+ if(res != RES_OK) goto error;
+ is_mpi_init = 1;
+
+ res = htrdr_planeto_args_init(&cmd_args, argc, argv);
+ if(res != RES_OK) goto error;
+ if(cmd_args.quit) goto exit;
+
+exit:
+ htrdr_planeto_args_release(&cmd_args);
+ if(is_mpi_init) htrdr_mpi_finalize();
+ return err;
+error:
+ err = -1;
+ goto exit;
+}
+