TrioCFD 1.9.9_beta
TrioCFD documentation
Loading...
Searching...
No Matches
Op_Diff_PolyMAC_HFV_base.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
16#include <Op_Diff_PolyMAC_HFV_Face.h>
17#include <Champ_Face_PolyMAC_HFV.h>
18#include <Domaine_Cl_PolyMAC_family.h>
19#include <Champ_Don_Fonc_xyz.h>
20#include <Champ_Uniforme.h>
21#include <Pb_Multiphase.h>
22#include <Simpler_Base.h>
23#include <Milieu_base.h>
24#include <EChaine.h>
25#include <deque>
26
27Implemente_base(Op_Diff_PolyMAC_HFV_base, "Op_Diff_PolyMAC_HFV_base", Op_Diff_PolyMAC_CDO_Gen_base);
28
30
32
34{
36 //if the field is constant in time, no need to recompute nu_ and the interpolations
37 if (t <= t_last_nu_)
38 return;
39
40 if (!nu_constant_)
41 nu_a_jour_ = 0;
42
43 t_last_nu_ = t;
44}
45
47{
49 const Equation_base& eq = equation();
50 int N = eq.inconnue().valeurs().line_size(), D = dimension, N_nu = std::max(N * dimension_min_nu(), diffusivite().valeurs().line_size());
51
52 if (N_nu == N)
53 nu_.resize(0, N); //isotrope
54 else if (N_nu == N * D)
55 nu_.resize(0, N, D); //diagonal
56 else if (N_nu == N * D * D)
57 nu_.resize(0, N, D, D); //complet
58 else
59 Process::exit(Nom("Op_Diff_PolyMAC_HFV_base : diffusivity component count ") + Nom(N_nu) + "not among (" + Nom(N) + ", " + Nom(N * D) + ", " + Nom(N * D * D) + ")!");
60
61 le_dom_poly_->domaine().creer_tableau_elements(nu_);
62}
63
65{
66 const Domaine_PolyMAC_HFV& domaine = ref_cast(Domaine_PolyMAC_HFV, le_dom_poly_.valeur());
67 const DoubleTab& nu_src = diffusivite().valeurs();
68 int e, i, m, n, N = equation().inconnue().valeurs().line_size(), N_nu = nu_.line_size(), N_nu_src = nu_src.line_size(), mult = N_nu / N, c_nu = nu_src.dimension_tot(0) == 1, d, db, D = dimension;
69 assert(N_nu % N == 0);
70
71 /* nu_: if necessary, the source field must be extended */
72 if (N_nu == N_nu_src)
73 for (e = 0; e < domaine.nb_elem_tot(); e++)
74 for (n = 0; n < N_nu; n++)
75 nu_.addr()[N_nu * e + n] = nu_src(!c_nu * e, n); //facile
76 else if (N_nu == N * D && N_nu_src == N)
77 for (e = 0; e < domaine.nb_elem_tot(); e++)
78 for (n = 0; n < N; n++)
79 for (d = 0; d < D; d++) //diagonal
80 nu_(e, n, d) = nu_src(!c_nu * e, n);
81 else if (N_nu == N * D * D && (N_nu_src == N || N_nu_src == N * D))
82 for (e = 0; e < domaine.nb_elem_tot(); e++)
83 for (n = 0; n < N; n++) //complet
84 for (d = 0; d < D; d++)
85 for (db = 0; db < D; db++)
86 nu_(e, n, d, db) = (d == db) * nu_src(!c_nu * e, N_nu_src == N ? n : D * n + d);
87 else
88 abort();
89
90 /* weighting of nu by porosity and by alpha (if pb_Multiphase) */
91 const DoubleTab *alp = sub_type(Pb_Multiphase, equation().probleme()) ? &ref_cast(Pb_Multiphase, equation().probleme()).equation_masse().inconnue().passe() : nullptr;
92 for (e = 0; e < domaine.nb_elem_tot(); e++)
93 for (n = 0, i = 0; n < N; n++)
94 for (m = 0; m < mult; m++, i++)
95 nu_.addr()[N_nu * e + i] *= equation().milieu().porosite_elem()(e) * (alp ? std::max((*alp)(e, n), 1e-8) : 1);
96
97 /* modification by a derived class */
99
100 nu_a_jour_ = 1;
101}
102
103/* compute the auxiliary variables in semi-implicit mode */
105{
106 const std::string& nom_inco = (le_champ_inco ? le_champ_inco.valeur() : equation().inconnue()).le_nom().getString();
107 int i, j, n_ext = (int) op_ext.size(), first_run = mat_aux.nb_lignes() == 0; /* number of operators */
108 if (first_run)
109 for (mat_aux.dimensionner(n_ext, n_ext), i = 0; i < n_ext; i++)
110 for (j = 0; j < n_ext; j++)
111 mat_aux.get_bloc(i, j).typer("Matrice_Morse");
112 std::vector<const Op_Diff_PolyMAC_HFV_base*> opp_ext(n_ext);
113 for (i = 0; i < n_ext; i++)
114 opp_ext[i] = &ref_cast(Op_Diff_PolyMAC_HFV_base, *op_ext[i]);
115 std::vector<matrices_t> lines(n_ext); /* in the form of arguments for dimensionner/assembler_blocs */
116 for (i = 0; i < n_ext; i++)
117 for (j = 0; j < n_ext; j++)
118 lines[i][nom_inco + (j == i ? "" : "/" + op_ext[j]->equation().probleme().le_nom().getString())] = &ref_cast(Matrice_Morse, mat_aux.get_bloc(i, j).valeur());
119 if (first_run)
120 for (i = 0; i < n_ext; i++)
121 opp_ext[i]->dimensionner_blocs_ext(1, lines[i]); //sizing
122
123 /* unknown / right-hand side */
124 std::deque<ConstDoubleTab_parts> v_part;
125 for (i = 0; i < n_ext; i++)
126 v_part.emplace_back(op_ext[i]->has_champ_inco() ? op_ext[i]->mon_inconnue().valeurs() : op_ext[i]->equation().inconnue().valeurs());
127 MD_Vector_composite mdc; //composite MD_Vector: built from all second blocks
128 for (i = 0; i < n_ext; i++)
129 mdc.add_part(v_part[i][1].get_md_vector(), v_part[i][1].line_size());
130 MD_Vector mdv;
131 mdv.copy(mdc);
132 DoubleTrav inco, secmem;
134 DoubleTab_parts p_inc(inco), p_sec(secmem);
135 for (i = 0; i < n_ext; i++)
136 p_inc[i] = v_part[i][1];
137
138 /* assemblage */
139 if (!first_run)
140 for (i = 0; i < n_ext; i++)
141 for (j = 0; j < n_ext; j++)
142 ref_cast(Matrice_Morse, mat_aux.get_bloc(i, j).valeur()).get_set_coeff() = 0;
143 for (i = 0; i < n_ext; i++)
144 opp_ext[i]->ajouter_blocs_ext(1, lines[i], p_sec[i]);
145 /* incremented/unknown transition */
146 mat_aux.ajouter_multvect(inco, secmem);
147 /* resolution */
148 if (first_run)
149 {
150 if (equation().parametre_equation())
151 solv_aux = ref_cast(Parametre_implicite, equation().parametre_equation().valeur()).solveur(); //copy the solver from the equation
152 else
153 {
154 EChaine chl("petsc cholesky { }");
155 chl >> solv_aux;
156 }
157 solv_aux->fixer_limpr(-1);
158 }
159
160 solv_aux->reinit();
161 solv_aux.resoudre_systeme(mat_aux, secmem, inco);
162 /* update var_aux / t_last_aux in all operators */
163 for (i = 0; i < n_ext; i++)
164 opp_ext[i]->var_aux = p_inc[i], opp_ext[i]->t_last_aux_ = t, opp_ext[i]->use_aux_ = 1;
165}
DoubleTab & valeurs() override
Returns the array of field values at the current time.
virtual DoubleTab & valeurs()=0
An input stream whose source is a character string.
Definition EChaine.h:31
Class defining operators and methods for all reading operation in an input flow (file,...
Definition Entree.h:42
class Equation_base The role of an equation is the calculation of one or more fields....
virtual const Milieu_base & milieu() const =0
virtual const Champ_Inc_base & inconnue() const =0
Metadata for a distributed composite vector.
void add_part(const MD_Vector &part, int shape=0, Nom name="")
Append the "part" descriptor to the composite vector.
static void creer_tableau_distribue(const MD_Vector &, Array_base &, RESIZE_OPTIONS opt=RESIZE_OPTIONS::COPY_INIT)
Transforms v into a parallel array having the structure md.
: This class is an OWN_PTR but the pointed object is shared among multiple
Definition MD_Vector.h:48
void copy(const MD_Vector_base &)
Constructs an MD_Vector object by copying an existing object.
Definition MD_Vector.cpp:26
Matrice_Morse class - Represents a (sparse) matrix M, not necessarily square,.
DoubleVect & porosite_elem()
Definition Milieu_base.h:58
const Equation_base & equation() const
Returns the reference to the equation pointed to by MorEqn::mon_equation.
Definition MorEqn.h:62
class Nom: a character string for naming TRUST objects.
Definition Nom.h:31
static int dimension
Definition Objet_U.h:94
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 const Nom & le_nom() const
Returns the name of the Objet_U. Virtual method to override: returns "neant" in this implementation.
Definition Objet_U.cpp:317
virtual Sortie & printOn(Sortie &) const
Writes the object to an output stream. Virtual method to override.
Definition Objet_U.cpp:278
class Op_Diff_PolyMAC_CDO_Gen_base
virtual void modifier_mu(DoubleTab &) const
const Champ_base & diffusivite() const override
class Op_Diff_PolyMAC_HFV_base
virtual void ajouter_blocs_ext(int aux_only, matrices_t matrices, DoubleTab &secmem, const tabs_t &semi_impl={ }) const =0
void completer() override
Associates the operator with the domaine_dis, the domaine_Cl_dis, and the unknown of its equation.
void mettre_a_jour(double t) override
DOES NOTHING - to override in derived classes.
virtual void dimensionner_blocs_ext(int aux_only, matrices_t matrices, const tabs_t &semi_impl={ }) const =0
std::vector< const Operateur_Diff_base * > op_ext
virtual void mettre_a_jour(double temps)
DOES NOTHING - to override in derived classes.
virtual void completer()
Associates the operator with the domaine_dis, the domaine_Cl_dis, and the unknown of its equation.
class Parametre_implicite A Parametre_implicite object groups together the various
Multiphase thermohydraulics problem of type "3*N equations":
static void abort()
Abort routine for TRUST on a fatal error.
Definition Process.cpp:573
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_ dimension_tot(int) const override
Definition TRUSTTab.tpp:160
int line_size() const
Definition TRUSTVect.tpp:67