TrioCFD 1.9.9_beta
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 Reads the content of the file "filename_" and stores the result in 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 //retrieve the sub-domain by name and the partitioning by opening the file...
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 //... and fill a portion of elem_part with it
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}
File for reading. This class is to the C++ ifstream class what the Entree class is to the.
Definition EFichier.h:29
virtual int ouvrir(const char *name, IOS_OPEN_MODE mode=ios::in)
static Objet_U & objet(const Nom &)
See Interprete_bloc::objet_global(). BM: the Interprete class is not the best place for this.
static int objet_existant(const Nom &)
Returns 1 if the object exists, 0 otherwise. See Interprete_bloc::objet_global_existant().
class Nom: a character string for naming TRUST objects.
Definition Nom.h:31
virtual void set_param(Param &) const
Definition Objet_U.h:130
const Nom & que_suis_je() const
Returns the string identifying the class.
Definition Objet_U.cpp:104
Objet_U()
Default constructor: assigns a unique identifier to the object (object_id_) and registers the object ...
Definition Objet_U.cpp:54
virtual Sortie & printOn(Sortie &) const
Writes the object to an output stream. Virtual method to override.
Definition Objet_U.cpp:278
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
Partitioner allowing a global domain to be split conformally with a set of already-partitioned sub-do...
std::map< std::string, std::string > fic_ssz
void construire_partition(IntVect &elem_part, int &nb_parts_tot) const override
Reads the content of the file "filename_" and stores the result in 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)
Exit routine for TRUST within a Kokkos region.
Definition Process.cpp:466
Base class for output streams.
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