commit 78f1e5d6d914ca403349f268e221fd0dd5c9ac26
parent 7d8b46e70367b8b09174d1a3ea8f6c68893c2441
Author: Vincent Forest <vincent.forest@meso-star.com>
Date: Sat, 21 Jan 2017 14:57:04 +0100
Setup and launch the solver
First draft of the main solstice comportment, i.e. compute the radiative
solar flux in a complex facility for a set of geometries defined as
receivers.
Diffstat:
5 files changed, 151 insertions(+), 5 deletions(-)
diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt
@@ -88,6 +88,7 @@ set(SOLSTICE_FILES_SRC
solstice_material.c
solstice_node.c
solstice_object.c
+ solstice_solve.c
solstice_sun.c)
set(SOLSTICE_FILES_INC
solstice.h
@@ -111,7 +112,7 @@ endif()
add_library(sollib STATIC ${SOLSTICE_FILES_SRC} ${SOLSTICE_FILES_INC})
add_executable(solstice ${SOLSTICE_SOURCE_DIR}/main.c)
target_link_libraries(solstice ${MATH_LIB} ${GETOPT_LIB}
- LibYAML RSys sollib solparser SolAnim SolSolver srcvl Star3DUT)
+ LibYAML RSys sollib solparser SolAnim SolSolver srcvl Star3DUT StarSP)
set_target_properties(solstice PROPERTIES
VERSION ${VERSION}
SOVERSION ${VERSION_MAJOR})
diff --git a/src/solstice.c b/src/solstice.c
@@ -245,14 +245,16 @@ error:
static res_T
setup_receivers(struct solstice* solstice, struct srcvl* srcvl)
{
+ struct solstice_receiver receiver;
size_t i, n;
res_T res = RES_OK;
ASSERT(solstice && srcvl);
+ solstice_receiver_init(solstice->allocator, &receiver);
+
n = srcvl_count(srcvl);
FOR_EACH(i, 0, n) {
struct srcvl_receiver rcv;
- struct solstice_receiver receiver;
const struct solparser_entity* entity;
srcvl_get(srcvl, i, &rcv);
@@ -265,7 +267,7 @@ setup_receivers(struct solstice* solstice, struct srcvl* srcvl)
if(entity->type != SOLPARSER_ENTITY_GEOMETRY) {
fprintf(stderr,
- "The entity `%s' is not geometry. It cannot be a receiver.\n",
+ "The entity `%s' is not a geometry. It cannot be a receiver.\n",
rcv.name);
res = RES_BAD_ARG;
goto error;
@@ -273,6 +275,7 @@ setup_receivers(struct solstice* solstice, struct srcvl* srcvl)
receiver.node = NULL;
receiver.side = rcv.side;
+ str_set(&receiver.name, rcv.name);
res = htable_receiver_set(&solstice->receivers, &entity, &receiver);
if(res != RES_OK) {
@@ -284,6 +287,7 @@ setup_receivers(struct solstice* solstice, struct srcvl* srcvl)
}
exit:
+ solstice_receiver_release(&receiver);
return res;
error:
htable_receiver_clear(&solstice->receivers);
@@ -458,8 +462,18 @@ solstice_run(struct solstice* solstice)
nsun_dirs /= 3/*#dims*/;
if(!solstice->framebuffer) { /* Solstice integration */
- res = RES_BAD_OP; /* TODO */
- goto error;
+ FOR_EACH(i, 0, nsun_dirs) {
+ const double* sun_dir = sun_dirs + i*3/*#dims*/;
+ res = ssol_sun_set_direction(solstice->sun, sun_dir);
+ if(res != RES_OK) {
+ fprintf(stderr, "Could not update the sun direction.\n");
+ goto error;
+ }
+ res = solstice_update_entities(solstice, sun_dir);
+ if(res != RES_OK) goto error;
+ res = solstice_solve(solstice);
+ if(res != RES_OK) goto error;
+ }
} else if(!nsun_dirs) {
res = solstice_draw(solstice);
if(res != RES_OK) goto error;
diff --git a/src/solstice.h b/src/solstice.h
@@ -22,6 +22,7 @@
#include <rsys/dynamic_array_double.h>
#include <rsys/hash_table.h>
#include <rsys/mem_allocator.h>
+#include <rsys/str.h>
struct solparser;
struct solstice_args;
@@ -33,9 +34,49 @@ struct sanim_node;
struct solstice_receiver {
struct solstice_node* node;
+ struct str name; /* Absolute entity name */
enum srcvl_side side;
};
+static void
+solstice_receiver_init
+ (struct mem_allocator* allocator,
+ struct solstice_receiver* receiver)
+{
+ ASSERT(allocator && receiver);
+ receiver->node = NULL;
+ receiver->side = SRCVL_FRONT_AND_BACK;
+ str_init(allocator, &receiver->name);
+}
+
+static void
+solstice_receiver_release(struct solstice_receiver* receiver)
+{
+ ASSERT(receiver);
+ str_release(&receiver->name);
+}
+
+static res_T
+solstice_receiver_copy
+ (struct solstice_receiver* dst,
+ const struct solstice_receiver* src)
+{
+ ASSERT(dst && src);
+ dst->node = src->node;
+ dst->side = src->side;
+ return str_copy(&dst->name, &src->name);
+}
+
+static res_T
+solstice_receiver_copy_and_release
+ (struct solstice_receiver* dst, struct solstice_receiver* src)
+{
+ ASSERT(dst && src);
+ dst->node = src->node;
+ dst->side = src->side;
+ return str_copy_and_release(&dst->name, &src->name);
+}
+
#define DARRAY_NAME nodes
#define DARRAY_DATA struct solstice_node*
#include <rsys/dynamic_array.h>
@@ -59,6 +100,10 @@ struct solstice_receiver {
#define HTABLE_NAME receiver
#define HTABLE_KEY const struct solparser_entity*
#define HTABLE_DATA struct solstice_receiver
+#define HTABLE_DATA_FUNCTOR_INIT solstice_receiver_init
+#define HTABLE_DATA_FUNCTOR_RELEASE solstice_receiver_release
+#define HTABLE_DATA_FUNCTOR_COPY solstice_receiver_copy
+#define HTABLE_DATA_FUNCTOR_COPY_AND_RELEASE solstice_receiver_copy_and_release
#include <rsys/hash_table.h>
struct solstice {
diff --git a/src/solstice_c.h b/src/solstice_c.h
@@ -46,6 +46,10 @@ solstice_draw
(struct solstice* solstice);
extern LOCAL_SYM res_T
+solstice_solve
+ (struct solstice* solstice);
+
+extern LOCAL_SYM res_T
solstice_create_sun
(struct solstice* solstice);
diff --git a/src/solstice_solve.c b/src/solstice_solve.c
@@ -0,0 +1,82 @@
+/* Copyright (C) CNRS 2016-2017
+ *
+ * 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 "solstice.h"
+#include "solstice_c.h"
+#include <solstice/ssol.h>
+#include <star/ssp.h>
+
+/*******************************************************************************
+ * Helper function
+ ******************************************************************************/
+static void
+write_header(struct solstice* solstice)
+{
+ struct htable_receiver_iterator it, end;
+ ASSERT(solstice);
+
+ htable_receiver_begin(&solstice->receivers, &it);
+ htable_receiver_end(&solstice->receivers, &end);
+
+ while(!htable_receiver_iterator_eq(&it, &end)) {
+ struct solstice_receiver* receiver = htable_receiver_iterator_data_get(&it);
+ uint32_t id;
+ SSOL(instance_get_id(receiver->node->instance, &id));
+ fprintf(solstice->output, "%u %s\n", id, str_cget(&receiver->name));
+ htable_receiver_iterator_next(&it);
+ }
+}
+
+/*******************************************************************************
+ * Local functions
+ ******************************************************************************/
+res_T
+solstice_solve(struct solstice* solstice)
+{
+ struct ssol_estimator* estimator = NULL;
+ struct ssol_estimator_status status;
+ struct ssp_rng* rng = NULL;
+ res_T res = RES_OK;
+ ASSERT(solstice);
+
+ res = ssp_rng_create(solstice->allocator, &ssp_rng_threefry, &rng);
+ if(res != RES_OK) {
+ fprintf(stderr, "Could not create the Random Number Generator .\n");
+ goto error;
+ }
+
+ res = ssol_estimator_create(solstice->ssol, &estimator);
+ if(res != RES_OK) {
+ fprintf(stderr, "Error in creating the Solstice Estimator.\n");
+ goto error;
+ }
+
+ write_header(solstice);
+
+ res = ssol_solve(solstice->scene, rng, solstice->nrealisations,
+ solstice->output, estimator);
+ if(res != RES_OK) {
+ fprintf(stderr, "Error in integrating the solar flux.\n");
+ goto error;
+ }
+
+exit:
+ if(estimator) SSOL(estimator_ref_put(estimator));
+ if(rng) SSP(rng_ref_put(rng));
+ return res;
+error:
+ goto exit;
+}
+