TrioCFD 1.9.9_beta
TrioCFD documentation
Loading...
Searching...
No Matches
Partitionneur_Sous_Domaine.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_Sous_Domaine.h>
16#include <Interprete.h>
17#include <EFichier.h>
18#include <Domaine.h>
19#include <Param.h>
20#include <EChaine.h>
21
22// XD partitionneur_sous_dom partitionneur_deriv sous_dom INHERITS_BRACE Given a global partition of a global domain,
23// XD_CONT 'sous-domaine' allows to produce a conform partition of a sub-domain generated from the bigger one using the
24// XD_CONT keyword create_domain_from_sub_domain. The sub-domain will be partitionned in a conform fashion with the
25// XD_CONT global domain.
26Implemente_instanciable(Partitionneur_Sous_Domaine,"Partitionneur_Sous_Dom",Partitionneur_base);
27
28
29
31{
32 Cerr << "Partitionneur_Sous_Domaine::printOn invalid\n" << finl;
33 exit();
34 return os;
35}
36
37/*! @brief Reads the partitioner parameters from disk.
38 *
39 * Expected format:
40 * {
41 * fichier FILENAME
42 * fichier_ssz FILENAME
43 * }
44 * FILENAME is the name of an existing file in ArrOfInt ASCII format.
45 *
46 */
48{
49 // TODO (teo boutin) this might be cleaner/easier to understand if a flag/boolean option
50 // is used to choose between using a file or a subdomain from runtime instanciation in trust datafile
51 // rather than having 2 params and checking only one is used
52 param.ajouter("fichier",&filename_,Param::REQUIRED); // XD_ADD_P chaine
53 // XD_CONT fichier
54 param.ajouter("fichier_ssz",&filename_ssz_); // XD_ADD_P chaine
55 // XD_CONT fichier sous zone
56 param.ajouter("name_ssz",&name_ssz_); // XD_ADD_P chaine
57 // XD_CONT name of sub-domain (name of a Sous_Domaine object declared in the data file)
58}
59
61{
62 if (filename_ssz_ == "" && name_ssz_ == "")
63 Process::exit(que_suis_je() + " : at least one of filename_ssz or name_ssz are needed");
64 if (filename_ssz_ != "" && name_ssz_ != "")
65 Process::exit(que_suis_je() + " : only one of filename_ssz or name_ssz must be specified"); // not sure about that, but
66 Cerr << " filename : " << filename_ << finl;
67 Cerr << " filename_ssz : " << filename_ssz_ << finl;
68 Cerr << " name_ssz : " << name_ssz_ << finl;
69}
70
71/*! @brief Reads the content of "filename_" and stores the result in elem_part.
72 *
73 */
74void Partitionneur_Sous_Domaine::construire_partition(IntVect& elem_part, int& nb_parts_tot) const
75{
76 if (filename_ == "")
77 {
78 Cerr << "Error in Partitionneur_Sous_Domaine::construire_partition\n";
79 Cerr << " The file name has not been initialized" << finl;
80 exit();
81 }
82
83 Cerr << "Reading of splitting file : " << filename_ << finl;
84 EFichier file;
85 file.ouvrir(filename_);
86 if (!file.good())
87 {
88 Cerr << "Error in Partitionneur_Sous_Domaine::construire_partition\n";
89 Cerr << " Failed to open file " << filename_ << finl;
90 exit();
91 }
92 IntVect elem_part_glob;
93 file >> elem_part_glob;
94 file >> nb_parts_tot;
95 file.close();
96
97 ArrOfInt elem_ssz;
98 if (filename_ssz_ != "")
99 {
100 Cerr << "Reading of subdomaine file : " << filename_ssz_ << finl;
101 file.ouvrir(filename_ssz_);
102 if (!file.good())
103 {
104 Cerr << "Error in Partitionneur_Sous_Domaine::construire_partition\n";
105 Cerr << " Failed to open file " << filename_ssz_ << finl;
106 exit();
107 }
108 file >> elem_ssz;
109 file.close();
110 }
111 else
112 elem_ssz = ref_cast(Sous_Domaine, Interprete::objet(name_ssz_)).les_elems();
113
114 /* fill elem_part */
115 elem_part.resize(elem_ssz.size_array());
116 for (int i = 0; i < elem_ssz.size_array(); i++)
117 nb_parts_tot = std::max(nb_parts_tot, 1 + (elem_part[i] = elem_part_glob[elem_ssz[i]]));
118
119}
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.
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
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 the splitting of sub-domains (potentially overlapping) created by Create_domain_...
Nom name_ssz_
! Name of the sub-domain file
Nom filename_ssz_
! Name of the global splitting file
void validate_params() const override
Called in the readOn of Objet_U_With_Params, after reading the params.
void construire_partition(IntVect &elem_part, int &nb_parts_tot) const override
Reads the content of "filename_" and stores the result in elem_part.
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
_SIZE_ size_array() const
void resize(_SIZE_, RESIZE_OPTIONS opt=RESIZE_OPTIONS::COPY_INIT)
Definition TRUSTVect.tpp:91