15#include <ProblemTrio.h>
16#include <Probleme_U.h>
17#include <Probleme_base.h>
18#include <ICoCoExceptions.h>
20#include <Comm_Group_MPI.h>
23#include <ICoCoTrioField.h>
24#include <Schema_Temps_base.h>
25#include <Catch_SIGINIT.h>
26#include <Init_Params.h>
30#include <medcoupling++.h>
32#include <ICoCoMEDDoubleField.h>
33#include <MEDCouplingFieldDouble.hxx>
34#include <MEDCoupling_version.h>
36#include <Convert_ICoCoTrioField.h>
37#include <Perf_counters.h>
38#include <Field_base.h>
40#include <Equation_base.h>
45using ICoCo::TrioField;
49extern void TRUST_global_finalize();
54bool TRUST_MPI_COMM_SET =
false;
65 TRUST_global_finalize();
77extern "C" Problem* getProblem()
93extern void TRUST_set_library_mode(
bool);
98 TRUST_set_library_mode(
false);
102 pb(nullptr),
p(nullptr)
106 (*my_params).problem_name=
"pb";
108 (*my_params).is_mpi=0;
109 TRUST_set_library_mode(
true);
115 (*my_params).data_file=file;
122 (*my_params).is_mpi=1;
123 (*my_params).comm=*((MPI_Comm*)(mpicomm));
136 if (((*my_params).problem_name==
"default_vvvvv") || ((*my_params).data_file==
"default_vvvvv"))
137 throw WrongArgument(
"??",
"Constructor",
"data",
"data shoud point to the name of a Probleme_U");
142 if ((*my_params).is_mpi!=0 && !TRUST_MPI_COMM_SET)
144 if (MPI_Comm_rank((*my_params).comm,&rank_in_comm)!=MPI_SUCCESS)
145 throw WrongArgument((*my_params).problem_name,
"initialize",
"comm",
"This process should belong to comm");
146 if (rank_in_comm==MPI_UNDEFINED)
147 throw WrongArgument((*my_params).problem_name,
"initialize",
"comm",
"This process should belong to comm");
149 Comm_Group_MPI::set_trio_u_world((*my_params).comm);
152 TRUST_MPI_COMM_SET =
true;
154 Comm_Group_MPI::set_must_mpi_initialize(
false);
159 char** argv=
new char*[argc];
160 string code=
"TRUST wrapper";
162 argv[0]=
new char[code.length()+1];
163 strcpy(argv[0],code.c_str());
164 argv[1]=
new char[(*my_params).data_file.length()+1];
165 strcpy(argv[1],(*my_params).data_file.c_str());
171 res=main_TRUST(argc,argv,
p,(*my_params).is_mpi);
174 statistics().begin_count(STD_COUNTERS::total_execution_time);
180 Nom nom(
"ICoCoProblemName"),nom_pb;
181 if (nom.interprete().objet_existant(nom))
183 nom_pb=ref_cast(
Nom,get_obj(nom));
184 Cout<<finl<<
" ICoCoProblemName from data file "<<nom_pb<< finl;
189 Cout<<finl<<
" ICoCoProblemName not found in data file, we try "<<nom_pb<< finl;
192 (*my_params).problem_name=nom_pb;
195 throw WrongArgument((*my_params).problem_name,
"initialize",
"problem_name",
"No problem of that name found in data file");
207 statistics().print_TU_files(
"Computation start-up statistics");
232 statistics().end_count(STD_COUNTERS::total_execution_time);
260 return pb->presentTime();
275 return pb->computeTimeStep(stop);
290 return pb->initTimeStep(dt);
305 bool res=
pb->solveTimeStep();
320 pb->validateTimeStep();
325 bool stop_ = sch.
stop();
326 if (!stop_)
pb->postraiter(0);
342 return pb->isStationary();
348 Cerr <<
"ProblemTrio::setStationaryMode() not impl!" << finl;
355 Cerr <<
"ProblemTrio::getStationaryMode() not impl!" << finl;
409 return pb->iterateTimeStep(converged);
420 pb->getInputFieldsNames(noms);
421 for (
const auto& itr : noms)
422 v.push_back(itr.getChar());
432 pb->getInputFieldTemplate(nom,afield);
441 pb->setInputField(nom,afield);
447 pb->setInputDoubleValue(mot,val);
452 pb->setInputStringValue(name, val);
457 return pb->getOutputStringValue(name);
467 catch (WrongArgument& err)
470 if (std::find(fld.begin(), fld.end(), name) == fld.end())
473 Cerr <<
"WARNING: trying to call getOutputDoubleValue() of an input field...!!" << finl;
476 if (f.nb_values()!=1)
477 throw WrongArgument((*my_params).problem_name,
"getOutputDoubleValue",name,
"invalid field size (should be 1)!!");
486 pb->setInputIntValue(nom, val);
495 return (
int)
pb->getOutputIntValue(nom);
499 const std::vector<double>& x,
500 const std::vector<double>& y,
501 const std::vector<double>& z,
502 std::vector<double>& vals,
int compo)
504 pb->getOutputPointValues(
Nom(name), x, y, z, vals, compo);
509 return pb->getOutputPointValues(
Nom(name), x, y, z, compo);
517 pb->getOutputFieldsNames(my_names);
518 vector<string> output_names;
519 for (
const auto& itr : my_names)
520 output_names.push_back(itr.getChar());
528 if (std::find(fld.begin(), fld.end(), name) == fld.end())
531 if (std::find(fld.begin(), fld.end(), name) == fld.end())
532 throw WrongArgument((*my_params).problem_name,
"getFieldType",
"name",
"invalid field name!!");
535 return ICoCo::ValueType::Double;
540 const Nom name(name_);
541 pb->getOutputField(name,afield);
555 medfield= build_medfield(triofield);
558 throw NotImplemented(
"No ParaMEDMEM",
"getInputMEDDoubleField");
567 medfield=build_medfield(triofield);
569 throw NotImplemented(
"No ParaMEDMEM",
"getInputMEDDoubleFieldTemplate");
579#ifdef OLD_MEDCOUPLING
580 const ParaMEDMEM::DataArrayDouble *fieldArr=afield.getField()->getArray();
582 const MEDCoupling::DataArrayDouble *fieldArr=afield.getMCField()->getArray();
584 triofield._field=
const_cast<double*
> (fieldArr->getConstPointer());
591 const unsigned int nbcomp = (int)fieldArr->getNumberOfComponents();
592 std::vector<std::string> compo_names = fieldArr->getInfoOnComponents();
595 assert(nbcomp == (
unsigned)ch->nb_comp());
596 for (
unsigned int i = 0; i < nbcomp; i++)
598 Nom compo_name(compo_names[i]);
599 ch->fixer_nom_compo((
int)i, compo_name);
602 throw NotImplemented(
"No ParaMEDMEM",
"setInputMEDDoubleField");
612 medfield= build_medfield(triofield);
615 throw NotImplemented(
"No ParaMEDMEM",
"getInputMEDDoubleField");
622#ifdef OLD_MEDCOUPLING
625 return MEDCOUPLING_VERSION_MAJOR;
631#ifdef OLD_MEDCOUPLING
634 return sizeof(mcIdType) == 8;
644 using namespace MEDCoupling;
649 double * ptr =
nullptr;
650 size_t nbTup = 0, nbCompo = 0;
665 throw WrongArgument((*my_params).problem_name,
"getDirectAccessToUnknown",
"unk_name",
"invalid unknown name!!");
668 MCAuto<DataArrayDouble> da = DataArrayDouble::New();
669 da->useExternalArrayWithRWAccess(ptr, nbTup, nbCompo);
670 MCAuto<MEDCouplingFieldDouble> f = MEDCouplingFieldDouble::New(ON_CELLS,ONE_TIME);
672 MEDDoubleField ret(f);
676 throw WrongArgument((*my_params).problem_name,
"getDirectAccessToUnknown",
"",
"Problem type must derive from Probleme_base!!");
681Objet_U& get_obj(
const char* chr)
static void signal_callback_handler(int signum)
void set_nom_cas_pour_signal(const Nom &cas)
DoubleTab & futur(int i=1) override
Renvoie les valeurs du champs a l'instant t+i.
DoubleTab & valeurs() override
Renvoie le tableau des valeurs du champ au temps courant.
virtual const Champ_Inc_base & inconnue() const =0
const Nom & le_nom() const override
Renvoie le nom du champ.
void setMPIComm(void *) override
void updateOutputMEDDoubleField(const std::string &name, MEDDoubleField &afield) const override
void terminate() override
This method is called once at the end, after any other one.
void getOutputPointValues(const std::string &name, const std::vector< double > &x, const std::vector< double > &y, const std::vector< double > &z, std::vector< double > &vals, int compo=0)
bool iterateTimeStep(bool &converged) override
In the case solveTimeStep uses an iterative process, this method executes a single iteration.
double getOutputDoubleValue(const std::string &name) const override
bool getStationaryMode() const override
double computeTimeStep(bool &stop) const override
Compute the value the Problem would like for the next time step.
ValueType getFieldType(const std::string &name) const override
bool supports_multiple_runs_
int getMEDCouplingMajorVersion() const override
std::vector< std::string > getInputFieldsNames() const override
This method is used to find the names of input fields understood by the Problem.
void getInputMEDDoubleFieldTemplate(const std::string &name, MEDDoubleField &afield) const override
void validateTimeStep() override
Validates the calculated unknown by moving the present time at the end of the time step.
double presentTime() const override
Returns the present time.
void setInputDoubleValue(const std::string &name, const double &val) override
void getInputFieldTemplate(const std::string &name, TrioField &afield) const override
This method is used to get a template of a field expected for the given name.
bool initialize() override
This method is called once at the beginning, before any other one of the interface Problem.
std::string getOutputStringValue(const std::string &name) const override
void resetTime(double time) override
Reset the current time of the Problem to a given value.
bool isMEDCoupling64Bits() const override
void setInputField(const std::string &name, const TrioField &afield) override
This method is used to provide the Problem with an input field.
bool initialize_pb(Probleme_U &pb)
void getOutputField(const std::string &name, TrioField &afield) const override
void getOutputMEDDoubleField(const std::string &name, MEDDoubleField &afield) const override
std::vector< std::string > getOutputFieldsNames() const override
void setInputMEDDoubleField(const std::string &name, const MEDDoubleField &afield) override
bool initTimeStep(double dt) override
This method allocates and initializes the unknown and given fields for the future time step.
void setDataFile(const std::string &datafile) override
void updateOutputField(const std::string &name, TrioField &afield) const override
void setStationaryMode(bool stationary) override
void setInputStringValue(const std::string &name, const std::string &val) override
bool solveTimeStep() override
Calculates the unknown fields for the next time step.
MEDDoubleField getDirectAccessToUnknown(const std::string &unk_name, bool isFuture)
int getOutputIntValue(const std::string &name) const override
bool isStationary() const override
Tells if the Problem unknowns have changed during the last time step.
void abortTimeStep() override
Aborts the resolution of the current time step.
void setInputIntValue(const std::string &name, const int &val) override
void deactivate_multiple_runs()
static Objet_U & objet(const Nom &)
Voir Interprete_bloc::objet_global() BM: la classe Interprete n'est pas le meilleur endroit pour cett...
Une chaine de caractere (Nom) en majuscules.
class Nom Une chaine de caractere pour nommer les objets de TRUST
Un tableau de chaine de caracteres (VECT(Nom)).
classe Objet_U Cette classe est la classe de base des Objets de TRUST
const Interprete & interprete() const
static int DEACTIVATE_SIGINT_CATCH
virtual int postraiter(int force=1)
Demande au probleme de postraiter ses champs, sondes,.
virtual void initialize()
This method is called once at the beginning, before any other one of the interface Problem.
classe Probleme_base C'est un Probleme_U qui n'est pas un couplage.
const Schema_Temps_base & schema_temps() const
Renvoie le schema en temps associe au probleme.
virtual int nombre_d_equations() const =0
virtual const Equation_base & equation(int) const =0
static int exception_sur_exit
static void exit(int exit_code=-1)
Routine de sortie de TRUST dans une region Kokkos.
virtual int stop() const
Renvoie 1 si il y lieu de stopper le calcul pour differente raisons: - le temps final est atteint.
_SIZE_ dimension_tot(int) const override