TrioCFD 1.9.9_beta
TrioCFD documentation
Loading...
Searching...
No Matches
SolveurSys_base.cpp
1/****************************************************************************
2* Copyright (c) 2025, 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
16#include <SolveurSys_base.h>
17#include <EcrFicCollecte.h>
18#include <Matrice_Base.h>
19#include <MD_Vector_tools.h>
20#include <SChaine.h>
21#include <Motcle.h>
22
23Implemente_base_sans_constructeur(SolveurSys_base,"SolveurSys_base",Objet_U);
24// XD solveur_sys_base class_generic solveur_sys_base INHERITS_BRACE Basic class to solve the linear system.
25
29
31{
32 return s << que_suis_je();
33}
34
36{
37 return is;
38}
39
41 const DoubleVect& b,
42 DoubleVect& x,
43 int niter_max)
44{
46 return resoudre_systeme(A,b,x);
47}
48
49
50void SolveurSys_base::save_matrice_secmem_conditionnel(const Matrice_Base& la_matrice, const DoubleVect& secmem, const DoubleVect& solution, int binaire2 )
51{
52 int binaire=binaire2;
53 if (save_matrice_==1)
54 {
55 // simulate writing a Matrice rather than a Matrice_Base
56 // to facilitate re-reading
57 {
58 EcrFicCollecte sortie;
59 sortie.set_bin(binaire);
60 sortie.ouvrir("Matrice.sa");
61 sortie<<la_matrice.que_suis_je()<<finl;
62 sortie<<la_matrice;
63 }
64 // save the RHS vector (Secmem) with virtual spaces !!!!!
65 {
66 EcrFicCollecte sortie;
67 sortie.set_bin(binaire);
68 sortie.ouvrir("Secmem.sa");
70 }
71 // save the solution with virtual spaces !!!!!
72 {
73 EcrFicCollecte sortie;
74 sortie.set_bin(binaire);
75 sortie.ouvrir("Solution.sa");
77 }
78 Cout <<"Saving of the matrix, secmem and solution ended."<<finl;
79 }
80}
81
82
83// Read solver parameters
84// Ex: solveur type { ... }
85// chaine_lue_ = "type { ... }"
87{
88 // Read the keyword string
89 Motcle accolade_ouverte("{");
90 Motcle accolade_fermee("}");
91 Motcle motlu;
92 Nom nomlu;
93 is >> motlu;
94 SChaine prov;
95 prov<<motlu;
96 is >> motlu;
97 if (motlu != accolade_ouverte)
98 {
99 Cerr << "Error while reading parameters of Petsc: " << finl;
100 Cerr << "We expected " << accolade_ouverte << " instead of " << motlu << finl;
102 }
103 prov<<" { ";
104 int nb_acco=1;
105 while (nb_acco!=0)
106 {
107 is >> nomlu;
108 if ((Motcle)nomlu=="READ_MATRIX") set_read_matrix(true);
109 prov<<nomlu<<" ";
110 if (nomlu==accolade_ouverte)
111 nb_acco++;
112 else if (nomlu==accolade_fermee)
113 nb_acco--;
114 }
115 chaine_lue_=prov.get_str();
116}
117
Writing to a file. This class implements the operators and virtual methods of the SFichier class as f...
int ouvrir(const char *name, IOS_OPEN_MODE mode=ios::out) override
Opens the file with the given mode and prot parameters. These parameters are the parameters of the st...
Class defining operators and methods for all reading operation in an input flow (file,...
Definition Entree.h:42
static void dump_vector_with_md(const DoubleVect &, Sortie &)
dumps vector v with its parallel descriptor to os.
Matrice_Base class - Base class of the matrix hierarchy.
A character string (Nom) in uppercase.
Definition Motcle.h:26
class Nom: a character string for naming TRUST objects.
Definition Nom.h:31
Base class for TRUST objects (Objet_U).
Definition Objet_U.h:68
friend class Entree
Definition Objet_U.h:71
const Nom & que_suis_je() const
Returns the string identifying the class.
Definition Objet_U.cpp:104
virtual Entree & readOn(Entree &)
Reads an Objet_U from an input stream. Virtual method to override.
Definition Objet_U.cpp:289
virtual Sortie & printOn(Sortie &) const
Writes the object to an output stream. Virtual method to override.
Definition Objet_U.cpp:278
static void exit(int exit_code=-1)
Exit routine for TRUST within a Kokkos region.
Definition Process.cpp:466
This class, derived from Sortie, accumulates what is sent to it into a character string.
Definition SChaine.h:26
const char * get_str() const
returns a copy of the string stored by the SChaine
Definition SChaine.cpp:72
void save_matrice_secmem_conditionnel(const Matrice_Base &la_matrice, const DoubleVect &secmem, const DoubleVect &solution, int binaire=1)
virtual int resoudre_systeme(const Matrice_Base &a, const DoubleVect &b, DoubleVect &x)=0
void set_read_matrix(bool flag)
void lecture(Entree &)
Base class for output streams.
Definition Sortie.h:52
void set_bin(bool bin) override
Changes the write mode of the file.
Definition Sortie.cpp:252