TrioCFD 1.9.8
TrioCFD documentation
Loading...
Searching...
No Matches
Partitionneur_Union.cpp
1/****************************************************************************
2* Copyright (c) 2026, CEA
3* All rights reserved.
4*
5* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
6* 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
7* 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
8* 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
9*
10* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
11* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
12* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
13*
14*****************************************************************************/
15#include <Partitionneur_Union.h>
16#include <EFichier.h>
17#include <Domaine.h>
18#include <Param.h>
19#include <EChaine.h>
20#include <Sous_Domaine.h>
21#include <Interprete.h>
22
23Implemente_instanciable(Partitionneur_Union,"Partitionneur_Union",Partitionneur_base);
24// XD partitionneur_union partitionneur_deriv union BRACE Let several local domains be generated from a bigger one using
25// XD_CONT the keyword create_domain_from_sub_domain, and let their partitions be generated in the usual way. Provided
26// XD_CONT the list of partition files for each small domain, the keyword 'union' will partition the global domain in a
27// XD_CONT conform fashion with the smaller domains.
28
29// XD attr sous_domaines bloc_lecture sous_domaines REQ List of the partition files with the following syntaxe:
30// XD_CONT {sous_domaine1 decoupage1 ... sous_domaineim decoupageim } where sous_domaine1 ... sous_zomeim are small
31// XD_CONT domains names and decoupage1 ... decoupageim are partition files.
32
33
35{
36 Cerr << "Partitionneur_Union::printOn invalid\n" << finl;
38 return os;
39}
40
41
42/*! @brief Lecture des parametres du partitionneur sur disque.
43 *
44 * Format attendu:
45 * {
46 * sous_domaines N ssdom1 ... ssdomN
47 * fichiers_decoupage N file1 ... fileN
48 * }
49 *
50 */
52{
53
54 param.ajouter("sous_domaines", &fic_ssz, Param::REQUIRED);
55}
57{
58 Cerr << que_suis_je() << "::validate_params" << finl;
59
60 for (const auto& p: fic_ssz)
61 {
62 // p.first is name of subdomain and p.second is file name
63 // waiting for c++17 for syntax: for (const auto& [subdomain, filename]: fic_ssz)
64 if (Interprete::objet_existant(p.first) == 0)
65 {
66 Process::exit(p.first + "is not an existing TRUST object");
67 }
68 if (not sub_type(Sous_Domaine, Interprete::objet(p.first)))
69 {
70 Process::exit(p.first + " is not a Sous_Domaine object");
71 }
72 }
73
74}
75
76
77void Partitionneur_Union::associer_domaine(const Domaine& domaine)
78{
79 ref_domaine_ = domaine;
80}
81
82/*! @brief Lit le contenu du fichier "filename_" et stocke le resultat dans elem_part
83 *
84 */
85void Partitionneur_Union::construire_partition(IntVect& elem_part, int& nb_parts_tot) const
86{
87 elem_part.resize(ref_domaine_->nb_elem());
88 elem_part = -1;
89
90 for (const auto& p: fic_ssz)
91 {
92 Nom subdomain = Nom(p.first);
93 const std::string& filename = p.second;
94 //on recupere le sous-domaine par son nom et le decoupage en ouvrant le fichier...
95 const Objet_U& ref = Interprete::objet(subdomain); // need this or compiler complains of 'possibly' dangling ref
96 const Sous_Domaine& ssz = ref_cast(Sous_Domaine, ref);
97 EFichier file;
98 file.ouvrir(filename.c_str());
99 IntVect dec_ssz;
100 file >> dec_ssz;
101 file.close();
102 //... et on remplit un morceau de elem_part avec
103 if (dec_ssz.size_array() != ssz.nb_elem_tot())
104 {
105 Cerr << "Partitionneur_Union : incoherent element number for sub-domaine " <<subdomain << finl;
107 }
108 for (int i = 0; i < ssz.nb_elem_tot(); i++)
109 elem_part[ssz(i)] = dec_ssz(i);
110 }
111}
Fichier en lecture Cette classe est a la classe C++ ifstream ce que la classe Entree est a la.
Definition EFichier.h:29
virtual int ouvrir(const char *name, IOS_OPEN_MODE mode=ios::in)
static Objet_U & objet(const Nom &)
Voir Interprete_bloc::objet_global() BM: la classe Interprete n'est pas le meilleur endroit pour cett...
static int objet_existant(const Nom &)
Renvoie 1 si l'objet existe, 0 sinon voir Interprete_bloc::objet_global_existant().
class Nom Une chaine de caractere pour nommer les objets de TRUST
Definition Nom.h:31
virtual void set_param(Param &) const
Definition Objet_U.h:135
const Nom & que_suis_je() const
renvoie la chaine identifiant la classe.
Definition Objet_U.cpp:104
Objet_U()
Constructeur par defaut : attribue un numero d'identifiant unique a l'objet (object_id_),...
Definition Objet_U.cpp:55
virtual Sortie & printOn(Sortie &) const
Ecriture de l'objet sur un flot de sortie Methode a surcharger.
Definition Objet_U.cpp:282
Helper class to factorize the readOn method of Objet_U classes.
Definition Param.h:112
void ajouter(const char *keyword, const int *value, Param::Nature nat=Param::OPTIONAL)
Register an integer parameter.
Definition Param.cpp:364
@ REQUIRED
Definition Param.h:115
Decoupeur permettant de decouper un domaine global de maniere conforme avec un ensemble de sous-domai...
std::map< std::string, std::string > fic_ssz
void construire_partition(IntVect &elem_part, int &nb_parts_tot) const override
Lit le contenu du fichier "filename_" et stocke le resultat dans elem_part.
void associer_domaine(const Domaine &dom) override
void validate_params() const override
Called in the readOn of Objet_U_With_Params, after reading the params.
static void exit(int exit_code=-1)
Routine de sortie de TRUST dans une region Kokkos.
Definition Process.cpp:455
Classe de base des flux de sortie.
Definition Sortie.h:52
int_t nb_elem_tot() const
_SIZE_ size_array() const
void resize(_SIZE_, RESIZE_OPTIONS opt=RESIZE_OPTIONS::COPY_INIT)
Definition TRUSTVect.tpp:91