TrioCFD 1.9.9_beta
TrioCFD documentation
Loading...
Searching...
No Matches
Champ_Input_Proto.cpp
1/****************************************************************************
2* Copyright (c) 2023, 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 <Convert_ICoCoTrioField.h>
17#include <Champ_Input_Proto.h>
18#include <Schema_Temps_base.h>
19#include <ICoCoExceptions.h>
20#include <Probleme_base.h>
21#include <Interprete.h>
22#include <TRUSTTab.h>
23#include <Domaine.h>
24
25using ICoCo::WrongArgument;
26
27/*! @brief Reading an input field from an input stream Factorization of the readOn methods of the different Champ_input
28 *
29 * Format:
30 * { nb_comp number_of_field_components
31 * nom field_name
32 * probleme name_of_associated_problem_base
33 * [sous_domaine name_of_associated_sous_domaine] }
34 *
35 * @param (Entree& is) input stream
36 * @return the modified input stream
37 * @throws no opening brace at the start of the format
38 * Exception: one of the 3 keywords missing, or another unrecognized keyword
39 * @throws no closing brace at the end of the data set
40 */
42{
43 Nom nom_champ;
44 Nom nom_pb;
45 Nom nom_sous_domaine;
46 int nbc=-1;
47
48 // Read nom_champ and nom_pb
49 Motcle accolade_ouverte("{");
50 Motcle accolade_fermee("}");
51 Motcle motlu;
52 is >> motlu;
53 if (motlu != accolade_ouverte)
54 {
55 Cerr << "It was expected { to start to read the Champ_Input" << finl;
57 }
58 is >> motlu;
59 while(1)
60 {
61 if (motlu == "nb_comp")
62 {
63 is >> nbc;
64 set_nb_comp(nbc);
65 }
66 else if (motlu == "nom")
67 {
68 is >> nom_champ;
69 }
70 else if (motlu == "initial_value")
71 {
72 is >> initial_value_;
73 }
74 else if (motlu=="probleme")
75 {
76 is >> nom_pb;
77 }
78 else if (motlu=="sous_domaine" || motlu=="sous_zone")
79 {
80 is >> nom_sous_domaine;
81 }
82 else if (motlu == accolade_fermee)
83 break;
84 else
85 {
86 Cerr << "Error in Ch_front_input_uniforme::readOn" << finl;
87 Cerr << "We expected a } instead of " << motlu << finl;
89 }
90 is >> motlu;
91 }
92 if (nom_champ=="??" || nom_pb=="??" || nbc==-1)
93 {
94 Cerr << "Error in Ch_front_input_uniforme::readOn" << finl;
95 Cerr << "It must be define the name, problem and number of components" << motlu << finl;
97 }
98 // Name the field
99 set_name(nom_champ);
100
101 // Find the problem and register in its list
102 mon_pb=ref_cast(Probleme_base,Interprete::objet(nom_pb));
103
104 mon_sous_domaine.reset();
105 if (nom_sous_domaine!="??")
106 {
107 if (!sous_domaine_ok)
108 {
109 Cerr << "Error in Ch_front_input_uniforme::readOn" << finl;
110 Cerr << "The sous_domaines are not managed by this field" << finl;
112 }
113 mon_sous_domaine=mon_pb->domaine().ss_domaine(nom_sous_domaine);
114 }
115}
116
117void Champ_Input_Proto::setValueOnTab(const TrioField& afield, DoubleTab& tab)
118{
119 if (afield._type==0)
120 {
121 if ((afield._nb_elems!=tab.dimension(0))&&(afield._nb_elems!=tab.dimension_tot(0)))
122 {
123
124 throw WrongArgument(mon_pb->le_nom().getChar(),"setInputField",afield.getCharName(),"should have the same _nb_elems as returned by getInputFieldTemplate");
125 }
126 }
127 else
128 {
129 if (afield._nbnodes!=tab.dimension(0))
130 throw WrongArgument(mon_pb->le_nom().getChar(),"setInputField","afield","should have the same _nb_elems as returned by getInputFieldTemplate");
131 if (afield._nb_field_components!=tab.dimension(1))
132
133 throw WrongArgument(mon_pb->le_nom().getChar(),"setInputField","afield","should have the same _nb_field_components as returned by getInputFieldTemplate");
134 }
135 // order is c1 c2 c3 c1 c2 c3 c1 c2 c3
136 memcpy(tab.addr(),afield._field,tab.size()*sizeof(double));
138}
139
140void Champ_Input_Proto::setInitialValue(const ArrOfDouble& vo)
141{
143}
144
146{
147 Cerr<< "You need to override setDoubleValue() in derived class of Champ_Input_Proto"<< finl;
148 throw;
149}
virtual void set_name(const Nom &name)=0
virtual void set_nb_comp(int i)=0
void setValueOnTab(const TrioField &afield, DoubleTab &tab)
void read(Entree &is)
Reading an input field from an input stream Factorization of the readOn methods of the different Cham...
void setInitialValue(const ArrOfDouble &vo)
virtual void setDoubleValue(const double val)
ArrOfDouble initial_value_
Class defining operators and methods for all reading operation in an input flow (file,...
Definition Entree.h:42
static Objet_U & objet(const Nom &)
See Interprete_bloc::objet_global(). BM: the Interprete class is not the best place for this.
A character string (Nom) in uppercase.
Definition Motcle.h:26
class Nom: a character string for naming TRUST objects.
Definition Nom.h:31
class Probleme_base It is a Probleme_U that is not a coupling.
static void exit(int exit_code=-1)
Exit routine for TRUST within a Kokkos region.
Definition Process.cpp:466
_TYPE_ * addr()
_SIZE_ dimension_tot(int) const override
Definition TRUSTTab.tpp:160
_SIZE_ dimension(int d) const
Definition TRUSTTab.tpp:133
_SIZE_ size() const
Definition TRUSTVect.tpp:45
virtual void echange_espace_virtuel(IsExchangeBlocking exchange_type=IsExchangeBlocking::DefaultBlocking, const std::string kernel_name="noname")