
;(defrule MAIN::Check_We_All_Models_With_Evolution
;  (or (Divergence ?Stage) (Unknown ?Stage) )
;  (LocalValue (Sigle We) (Max ?We&:(> ?We 8.)) (Iter ?Iter) (Stage ?Stage))
;  (not (AlreadyWeAll ?Stage))
;  (Evolution (Step ?Step))
;=>
;  (bind ?Message1 
;     (str-cat "Localy, the computed Weisenberg number (We) is  " ?We ".  "
;              "It could be too large and induce convergence difficulties "
;              "for velocities or stresses variables.  "
;              "In this case, we suggest to reduce the evolution step size.  "
;              "If the step size becomes too small, "
;              "please contact the technial support for help."
;      )
;   )              
;  (assert (Message (Stage ?Stage) 
;                   (String ?Message1)
;                   (Level 3)
;                   (Kind LocalDiagnostic)))
;  (assert (AlreadyWeAll ?Stage))
;)
;(defrule MAIN::Check_We_All_Models_Without_Evolution
;  (or (Divergence ?Stage) (Unknown ?Stage) )
;  (LocalValue (Sigle We) (Max ?We&:(> ?We 0.1)) (Iter ?Iter) (Stage ?Stage))
;  (not (AlreadyWeAll ?Stage))
;  (not (Evolution (Step ?Step)))
;=>
;  (bind ?Message1 
;     (str-cat "Localy, the computed Weisenberg number (We) is  " ?We ".  "
;              "It could be too large and induces convergence difficulties "
;              "for velocities or stresses variables.  "
;              "In this case, we suggest to use an evolution scheme forwhich the"
;              " initial We should be of the order of magnitude of 0.1.  "
;      )
;   )              
;  (assert (Message (Stage ?Stage) 
;                   (String ?Message1)
;                   (Level 3)
;                   (Kind LocalDiagnostic)))
;  (assert (AlreadyWeAll ?Stage))
;)

;******************************************************************************
; Rule to suggest evolution for relaxation time of viscoelastic fluid         *
;                                                                             *
(defrule MAIN::Suggest_Evolution_For_Relaxation_Time_Of_Viscoelastic_Fluid
  (declare (salience (+ ?*SalienceNonLinear* 
                        ?*SalienceSuggestion*
                        ?*SuggestEvolution*
                      )
            )
   )
;                                                                             *
;******************************************************************************

; A evolution for relaxation time of viscoelastic fluid is suggested if :

;==============================================================================

; -1- There is a fact SuggestEvolution for relaxation time of viscoelastic fluid
  (SuggestEvolution (Name Viscoelastic_Relaxation_Time)
                    (MinValue ?MinValue)
                    (MaxValue ?MaxValue)
                    (ProblemName $?ProblemName)
   )

; -2- The Weissenberg number is too high
  ?INSAd_Num <- (object (is-a ADIMENSIONAL_NUMBER)
                    (Abreviation We)
                    (Name "Weissenberg")
                    (MaxValue ?Max)
                    (SdeValue ?Sde)
                    (MaxCriticalValue ?MaxCritical)
                    (MinCriticalValue ?MinCritical&:(> ?Max ?MinCritical))
                  )   

 => 

  (if (eq ?MinValue ?MaxValue) then
     (bind ?AuxString (str-cat "The value of the relaxation time is "
                              ?MinValue "."
                       )
      )
     (bind ?STRThis "this parameter")
   else
     (bind ?AuxString (str-cat "Values of the relaxation times are ranged from "
                              ?MinValue " to " ?MaxValue "."
                       )
      )
     (bind ?STRThis "those parameters")
   )

  (bind ?Message1 (str-cat "There is a non-linearity in problem " 
                           (implode$ $?ProblemName)
                           " introduced by the relaxation time of the "
                           "constitutive equation.  "
                           ?AuxString
                    )
   )

   (bind ?Message2 (str-cat "The expert system suggests to use an "
                            "evolution for " ?STRThis ".  "
                            "The evolution scheme must be the following : "
                    )
   )
  (bind ?Message3 (str-cat "   -   f(s) = s"))
  (bind ?Message4 (str-cat "   -   S-ini such as We < 0.1 " ))
  (bind ?Message5 (str-cat "   -   S-final = 1.0 "))
  (bind ?Message6 (str-cat "   -   Initial increment = S-ini"))
  (assert (Message (Stage  0) 
                   (String ?Message1 ?Message2 ?Message3
                           ?Message4 ?Message5 ?Message6
                    )
                   (Level 5)
                   (Kind Suggestion)
           )
   )
  (assert (Suggestion For Evolution))
 ) 


;******************************************************************************
; Rule to suggest evolution for the flow rate of viscoelastic fluid           *
;                                                                             *
(defrule MAIN::Suggest_Evolution_Flow_Rate_Of_Viscoelastic_Fluid
  (declare (salience (+ ?*SalienceNonLinear* 
                        ?*SalienceSuggestion*
                        ?*SuggestEvolution*
                      )
            )
   )
;                                                                             *
;******************************************************************************

; A evolution for Flow rate of viscoelastic fluid is suggested if :

;==============================================================================

; -1- There is a fact SuggestEvolution for relaxation time of viscoelastic fluid
  (SuggestEvolution (Name Viscoelastic_Relaxation_Time)
                    (MinValue ?MinValue)
                    (MaxValue ?MaxValue)
                    (ProblemName $?ProblemName)
   )

; -2- The Weissenberg number is too high
  ?INSAd_Num <- (object (is-a ADIMENSIONAL_NUMBER)
                    (Abreviation We)
                    (Name "Weissenberg")
                    (MaxValue ?Max)
                    (SdeValue ?Sde)
                    (MaxCriticalValue ?MaxCritical)
                    (MinCriticalValue ?MinCritical&:(> ?Max ?MinCritical))
                  )  
 
; -3- There is no fact for evolution for flow rate
  (not (EvolutionOnField (Name Flow_rate)))

 => 
  (if (eq ?MinValue ?MaxValue) then
     (bind ?AuxString (str-cat "The value of the relaxation time is "
                              (Better-Format ?MinValue 4) "."
                       )
      )
   else
     (bind ?AuxString (str-cat "Values of the relaxation times are ranged from "
                              (Better-Format ?MinValue 4) " to " 
                              (Better-Format ?MaxValue 4) "."
                       )
      )
   )
  (bind ?Message1 (str-cat "There is a non-linearity in problem " 
                           (implode$ $?ProblemName)
                           " introduced by the relaxation time of the "
                           "constitutive equation.  "
                           ?AuxString
                      )
      )

   (bind ?Message2 (str-cat "The expert system suggests to use an "
                            "evolution for the flow rate.  This evolution "
                            "must be applied for all flow rate : at the "
                            "inlet section and at the outlet section.  " 
                            "The evolution scheme must be the following : "
                    )
   )
  (bind ?Message3 (str-cat "   -   f(s) = s"))
  (bind ?Message4 (str-cat "   -   S-ini such as We < 0.1 " ))
  (bind ?Message5 (str-cat "   -   S-final = 1.0 "))
  (bind ?Message6 (str-cat "   -   Initial increment = S-ini"))
  (assert (Message (Stage  0) 
                   (String ?Message1 ?Message2 ?Message3
                           ?Message4 ?Message5 ?Message6
                    )
                   (Level 5)
                   (Kind Suggestion)
           )
   )
  (assert (Suggestion For Evolution))
 )


