Salome HOME
updated copyright message
[modules/kernel.git] / src / DSC / DSC_User / Datastream / Calcium / CalciumCouplingPolicy.cxx
1 // Copyright (C) 2007-2023  CEA, EDF, OPEN CASCADE
2 //
3 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License, or (at your option) any later version.
10 //
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 // Lesser General Public License for more details.
15 //
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 //
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22
23 //  File   : CalciumCouplingPolicy.cxx
24 //  Author : Eric Fayolle (EDF)
25 //  Module : KERNEL
26 // Id          : $Id$
27 //
28 #include "CalciumCouplingPolicy.hxx"
29
30 CalciumCouplingPolicy::CalciumCouplingPolicy():_dependencyType(CalciumTypes::UNDEFINED_DEPENDENCY),
31                                                _storageLevel(CalciumTypes::UNLIMITED_STORAGE_LEVEL),
32                                                _dateCalSchem(CalciumTypes::TI_SCHEM),
33                                                _interpolationSchem(CalciumTypes::L1_SCHEM),
34                                                _extrapolationSchem(CalciumTypes::UNDEFINED_EXTRA_SCHEM),
35                                                _alpha(0.0),_deltaT(CalciumTypes::EPSILON),
36                                                _disconnectDirective(CalciumTypes::UNDEFINED_DIRECTIVE){}
37
38 void CalciumCouplingPolicy::setDependencyType (CalciumTypes::DependencyType dependencyType) {_dependencyType=dependencyType;}
39 CalciumTypes::DependencyType CalciumCouplingPolicy::getDependencyType () const              { return _dependencyType;}
40  
41 void   CalciumCouplingPolicy::setStorageLevel   (size_t         storageLevel)   {
42   MESSAGE( "CalciumCouplingPolicy::setStorageLevel: " << storageLevel );
43   if ( storageLevel < 1 && (storageLevel != (size_t)CalciumTypes::UNLIMITED_STORAGE_LEVEL)  )
44     throw CalciumException(CalciumTypes::CPRENA,LOC("StorageLevel < 1 is not allowed"));
45   _storageLevel = storageLevel;
46 }
47 size_t CalciumCouplingPolicy::getStorageLevel   () const                        {return _storageLevel;}
48 void   CalciumCouplingPolicy::setDateCalSchem   (CalciumTypes::DateCalSchem   dateCalSchem)   {
49   MESSAGE( "CalciumCouplingPolicy::setDateCalSchem: " << dateCalSchem );
50   if ( _dependencyType != CalciumTypes::TIME_DEPENDENCY )
51     throw CalciumException(CalciumTypes::CPITVR,LOC("Can't set a temporal scheme on a port that is not time dependent"));
52   _dateCalSchem = dateCalSchem;
53 }
54
55 CalciumTypes::DateCalSchem CalciumCouplingPolicy::getDateCalSchem () const   { return _dateCalSchem; }
56
57 void CalciumCouplingPolicy::setAlpha(double alpha) {
58   MESSAGE( "CalciumCouplingPolicy::setAlpha: " << alpha );
59   if ( _dependencyType != CalciumTypes::TIME_DEPENDENCY )
60     throw CalciumException(CalciumTypes::CPITVR,LOC("Can't set alpha on a port that is not time dependent"));
61   
62   if ( 0 <= alpha && alpha <= 1 ) _alpha = alpha; 
63   else 
64     throw CalciumException(CalciumTypes::CPRENA,LOC("alpha must be between [0,1]"));
65 }
66
67 double CalciumCouplingPolicy::getAlpha() const   { return _alpha; }
68
69 void CalciumCouplingPolicy::setDeltaT(double deltaT ) {
70   if ( _dependencyType != CalciumTypes::TIME_DEPENDENCY )
71     throw CalciumException(CalciumTypes::CPITVR,LOC("Can't set deltaT on a port that is not time dependent"));
72   if ( 0 <= deltaT && deltaT <= 1 ) _deltaT = deltaT; 
73   else 
74     throw(CalciumException(CalciumTypes::CPRENA,LOC("deltaT must be between [0,1]")));
75 }
76 double CalciumCouplingPolicy::getDeltaT() const  {return _deltaT;}
77
78 void CalciumCouplingPolicy::setInterpolationSchem (CalciumTypes::InterpolationSchem interpolationSchem) {
79   MESSAGE( "CalciumCouplingPolicy::setInterpolationSchem: " << interpolationSchem );
80   if ( _dependencyType != CalciumTypes::TIME_DEPENDENCY )
81     throw CalciumException(CalciumTypes::CPITVR,LOC("Can't set InterpolationSchem on a port that is not time dependent"));
82   _interpolationSchem=interpolationSchem;
83 }
84
85 void CalciumCouplingPolicy::setExtrapolationSchem (CalciumTypes::ExtrapolationSchem extrapolationSchem) {
86   if ( _dependencyType != CalciumTypes::TIME_DEPENDENCY )
87     throw CalciumException(CalciumTypes::CPITVR,LOC("Can't set ExtrapolationSchem on a port that is not time dependent"));
88 _extrapolationSchem=extrapolationSchem;
89 }
90
91 CalciumTypes::InterpolationSchem CalciumCouplingPolicy::getInterpolationSchem () const { return _interpolationSchem; }
92 CalciumTypes::ExtrapolationSchem CalciumCouplingPolicy::getExtrapolationSchem () const { return _extrapolationSchem; }
93
94
95 CalciumCouplingPolicy::TimeType 
96 CalciumCouplingPolicy::getEffectiveTime(CalciumCouplingPolicy::TimeType ti, 
97                                         CalciumCouplingPolicy::TimeType tf) {
98   if ( _dateCalSchem == CalciumTypes::TI_SCHEM )  return ti;
99   if ( _dateCalSchem == CalciumTypes::TF_SCHEM )  return tf;
100   
101   //CalciumTypes::ALPHA_SCHEM
102   return tf*_alpha + ti*(1-_alpha);
103 }
104
105 void CalciumCouplingPolicy::disconnect(bool provideLastGivenValue) {
106
107   if (provideLastGivenValue) {
108     if (SALOME::VerbosityActivated())
109       std::cout << "-------- CalciumCouplingPolicy::disconnect CP_CONT  ------------------" << std::endl;
110
111     _disconnectDirective = CalciumTypes::CONTINUE;
112   } else {
113     if (SALOME::VerbosityActivated())
114       std::cout << "-------- CalciumCouplingPolicy::disconnect CP_ARRET  ------------------" << std::endl;
115
116     _disconnectDirective = CalciumTypes::STOP;
117   }
118
119   //Wakeup get data if any
120   wakeupWaiting();  
121 }