star-gs

Literate program for a geometric sensitivity calculation
git clone git://git.meso-star.fr/star-gs.git
Log | Files | Refs | README | LICENSE

commit 92cd8557e50039ed77de7565d1ffbc4cbef6aec1
parent 801f6391227317fa38f74aee82e1366f381c2b63
Author: Vincent Forest <vincent.forest@meso-star.com>
Date:   Wed, 13 Jul 2022 15:52:26 +0200

Débute l'écriture lettrée du calcul de sensibilité

Diffstat:
Mcmake/CMakeLists.txt | 5+++++
Acmake/noweb/CMakeLists.txt | 69+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/sgs_compute_sensitivity_translation.nw | 233+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 307 insertions(+), 0 deletions(-)

diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt @@ -25,6 +25,11 @@ set(SGS_SOURCE_DIR ${PROJECT_SOURCE_DIR}/../src) option(NO_TEST "Do not build tests" OFF) ################################################################################ +# Sub directories +################################################################################ +add_subdirectory(noweb) + +################################################################################ # Check dependencies ################################################################################ find_package(RCMake 0.4 REQUIRED) diff --git a/cmake/noweb/CMakeLists.txt b/cmake/noweb/CMakeLists.txt @@ -0,0 +1,69 @@ +# Copyright (C) 2021 +# CNRS/RAPSODEE, +# CNRS/LMAP, +# |Meso|Star> (contact@meso-star.com), +# UPS/Laplace. +# +# 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/>. + +set(SGS_NOWEB_DIR ${PROJECT_SOURCE_DIR}/../src/) + +set(NOTANGLE_OPTS ) +set(NOWEAVE_OPTS -index -delay -v) + +################################################################################ +# Look for noweb programs +################################################################################ +find_program(_notangle NAMES notangle) +find_program(_noweave NAMES noweave) +find_program(_cpif NAMES cpif) +if(NOT _notangle OR NOT _noweave OR NOT _cpif) + message(FATAL_ERROR "Noweb programs are missing") +endif() + +################################################################################ +# Setup targets +################################################################################ +set(SGS_NOWEB_SRC + sgs_compute_sensitivity_translation.nw) + +set(C_FILES) +set(TEX_FILES) +foreach(_noweb IN LISTS SGS_NOWEB_SRC) + get_filename_component(_name ${_noweb} NAME_WLE) + set(_src ${SGS_NOWEB_DIR}/${_noweb}) + set(_dst_c ${CMAKE_CURRENT_BINARY_DIR}/${_name}.c) + set(_dst_tex ${CMAKE_CURRENT_BINARY_DIR}/${_name}.tex) + + string(REGEX REPLACE "_" "\\\\_" _chunk "${_name}.c") + + add_custom_command( + OUTPUT ${_dst_c} + COMMAND ${_notangle} ${NOTANGLE_OPTS} -R${_chunk} ${_src} | ${_cpif} ${_dst_c} + DEPENDS ${_src} + COMMENT "Tangle ${_src}" + VERBATIM) + list(APPEND C_FILES ${_dst_c}) + + add_custom_command( + OUTPUT ${_dst_tex} + COMMAND ${_noweave} ${NOWEAVE_OPTS} ${_src} > ${_dst_tex} + DEPENDS ${_src} + COMMENT "Weave ${_dst_tex}" + VERBATIM) + list(APPEND TEX_FILES ${_dst_tex}) +endforeach() + +add_custom_target(tangle ALL DEPENDS ${C_FILES}) +add_custom_target(weave ALL DEPENDS ${TEX_FILES}) diff --git a/src/sgs_compute_sensitivity_translation.nw b/src/sgs_compute_sensitivity_translation.nw @@ -0,0 +1,233 @@ +% 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/>. + +\documentclass[]{article} +%\documentclass[twoside]{book} +%\usepackage[Lenny]{fncychap} +\usepackage[utf8]{inputenc} +\usepackage[french]{babel} +\usepackage[top=1in, bottom=1in, inner=3.5cm, outer=2cm]{geometry} +%\usepackage[margin=1in]{geometry} +\usepackage{url} +\usepackage{amsmath} +\usepackage{graphicx} +\usepackage{noweb} +\usepackage{graphicx} +\usepackage{emptypage} +\noweboptions{smallcode,longchunks} + +% Remove clearpage after nwfilename +\makeatletter +\def\nw@laterfilename#1{\endgroup \markboth{#1}{#1}} +\makeatother + +% Avoid a page break after a code chunk +\def\nwendcode{\endtrivlist \endgroup} +\let\nwdocspar=\par +%\def\nwendcode{\endtrivlist \endgroup \vfil\penalty10\vfilneg} +%\let\nwdocspar=\smallbreak + +\begin{document} +\pagestyle{noweb} + +\title{Sensibilité à la translation} +\maketitle + +\paragraph{} Le but du présent document est d'illustrer la mise en oeuvre +algorithmique d'un calcul de sensibilité sur un exemple simple. Le problème est +décrit par un parallélépipède dont les paroi sont toutes noires à l'exception +de la paroi supérieure qui est spéculaire (figure~\ref{fig:configuration}). La +déformation géométrique que nous considérons est une translation de cette +paroi. Nous étudions l'impact de cette translation sur le flux reçu par un +récepteur situé sur la paroi inférieure. + +\begin{figure} + \includegraphics[width=1\linewidth]{TODO} + \caption{TODO} + \label{fig:configuration} +\end{figure} + +\paragraph{} +On veut estimer par Monte-Carlo la sensibilité géométrique du flux reçu par le +récepteur à l'épaisseur du cube. On va donc écrire un fichier +[[sgs_compute_trans_sensib.c]] qui lance ce calcul et affiche le résultat. +Ce fichier contient entre autre la boucle d'intégration et la fonction de +réalisation de l'algorithme. + +% TODO mettre le schéma + +<<sgs\_compute\_sensitivity\_translation.c>>= + <<copyright>> + <<licence>> + + <<liste des inclusions>> + + <<constantes du système>> + + <<boucle d'intégration>> + <<fonction de réalisation>> +@ + +\paragraph{} +La [[boucle d'intégration]] n'est pas l'objet principal de ce texte et sera +traité plus tard pour s'intéresser en priorité à la [[fonction de réalisation]]. + +<<fonction de réalisation>>= +static res_T +realisation + (void* weight, + struct ssp_rng* rng, /* Random Number Generator */ + const unsigned ithread, /* Thread identifier */ + void* ctx) /* User data */ +{ + <<liste de variables locales>> + double w = 0; /* Monte-Carlo weight */ + res_T res = RES_OK; + + <<récupérer la description de la scène>> + <<échantilloner un chemin de sensibilité>> + <<evaluer le poids Monte-Carlo de sensiblité>> + +exit: + SMC_DOUBLE(weight) = w; + return res; +error: + <<traiter l'erreur>> + goto exit; +} +@ + +% TODO travailler le référencement des blocs de code dans le Latex + +\paragraph{} +Algo Monte-Carlo fortement lié à la scène. Pas d'orthogonalité +données/traitement~: +\begin{itemize} + \item on a à l'échelle de la réalisation une description complète de + la scène considérée (section~\ref{sec:get-scene-data})\,; + \item les poids MC sont calculés (section~\ref{sec:mc-weight}) étant + donné le chemin préalablement échantillonné + (section~\ref{sec:sample-path}). +\end{itemize} + +\section{Récupérer les données de la scène} +\label{sec:get-scene-data} + +\paragraph{} La scène utilisée dans cet exemple est une parallélépipède +quelconque aligné aux axes, c'est à dire l'utilisateur peut définir +librement et sa dimension et son positionnement dans le repère. On +récupère ses données spatiales (dimensions et position) via la boîte +englobante de la géométrie. Ses caractéristiques sont stockées dans les +variables locales [[box_low]], [[box_upp]], et [[box_sz]]. Notre +géométrie étant un parallélépipède, elle est confondue avec sa propre +boîte englobante. + +<<liste de variables locales>>= +double box_low[3]; /* Lower bound of the box */ +double box_upp[3]; /* Upper bound of the box */ +double box_sz[3]; /* Size of the box */ +@ +<<récupérer la description de la scène>>= +sgs_geometry_get_aabb(sgs->geom, box_low, box_upp); +d3_sub(box_sz, box_upp, box_low); +@ + +\paragraph{} +Le récepteur et l'émetteur sont tout deux fixés relativement aux +dimensions de la boîte. Ces positions et dimensions relatives sont +définies dans les constantes suivantes~: +\begin{itemize} + \item{[[RECV_MIN]] et [[RECV_MAX]]~: décrivent les bornes + inférieure et supérieure du récepteur\,;} + \item{[[EMIT_E_THRESHOLD]]~: décrit la hauteur de la source + radiative\,;} + \item{[[EMIT_E_SZ]]~: } +\end{itemize} + +<<constantes du système>>= +static const double RECV_MIN[3] = {0.125, 0.375, 0}; +static const double RECV_MAX[3] = {0.375, 0.625, 0}; +static const double EMIT_E_THRESHOLD = 2.0/3.0; +@ + +<<récupérer la description de la scène>>= + recv_min[X] = RECV_MIN[X]*box_sz[X] + box_low[X]; + recv_min[Y] = RECV_MIN[Y]*box_sz[Y] + box_low[Y]; + recv_max[X] = RECV_MAX[X]*box_sz[X] + box_low[X]; + recv_max[Y] = RECV_MAX[Y]*box_sz[Y] + box_low[Y]; + emit_e_threshold = EMIT_E_THRESHOLD*box_sz[Z] + box_low[Z]; + emit_e_sz[X] = EMIT_E_SZ[X]*box_sz[X] + box_low[X]; + emit_e_sz[Y] = EMIT_E_SZ[Y]*box_sz[Y] + box_low[Y]; + emit_e_sz[Z] = EMIT_E_SZ[Z]*box_sz[Z] + box_low[Z]; + emit_s_sz[X] = EMIT_S_SZ[X]*box_sz[X] + box_low[X]; + emit_s_sz[Y] = EMIT_S_SZ[Y]*box_sz[Y] + box_low[Y]; + emit_s_sz[Z] = EMIT_S_SZ[Z]*box_sz[Z] + box_low[Z]; +@ + +\paragraph{} +Espace de chemin~: expliquer le choix de l'espace de chemin + +\paragraph{} +Parler de l'espace matériel et de l'espace géométrique bien que dans cet +exemple il ne soit pas explicité. Souligner l'importance d'un repaire +\emph{orthogonal} pour l'espace matériel. + +<<échantilloner un rayon sur la surface spéculaire>>= + /* Sample the sensitivity emissive surface */ + sgs_geometry_sample(sgs->geom, rng, &frag); + surf_emit = frag.surface; + + /* Sample the cosine weighted sampling of the emissive direction */ + ssp_ran_hemisphere_cos(rng, frag.normal, dir_emit, NULL); + + pos_emit[0] = frag.position[0]; + pos_emit[1] = frag.position[1]; + pos_emit[2] = frag.position[2]; +@ + +<<liste des inclusions>>= +#include "sgs_c.h" +#include "sgs_geometry.h" +#include "sgs_log.h" + +#include <star/smc.h> +#include <star/ssp.h> + +#include <rsys/cstr.h> +@ + + +<<copyright>>= +/* Copyright (C) 2021 + * CNRS/RAPSODEE, + * CNRS/LMAP, + * |Meso|Star> (contact@meso-star.com), + * UPS/Laplace. */ + +<<licence>>= +/* 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/>. */ +@ + +\end{document} +\nwfilename{test}