4
$\begingroup$

Using the code shown, Reynolds number is calculated for given parameters. Is it possible to display a warning message to the user if a parameter is outside applicable range? e.g., if the fluid velocity is more than 5 m/s.

Manipulate["Reynolds number: " <> ToString@Style[Rey[v], 14],Text[Style["Reynolds number calculator", 16]], Delimiter, {{v, 1.5,"Velocity of Fluid(m/s): "}, ControlType -> InputField, FieldSize -> 7}, {{roh, 1, "Fluid Density (Kg/m^3): "},ControlType -> InputField,FieldSize -> 7},{{dia, 0.01, "Hydraulic Diameter (m) "},ControlType -> InputField,FieldSize -> 7}, {{muh, 0.00089, "Dynamic Viscosity (Kg/ms): "},ControlType -> InputField, FieldSize -> 7}, Delimiter,Item[Button["Calculate", Nothing, BaseStyle -> {15}]],LabelStyle -> {14}, ContentSize -> 310,Initialization :> {Rey[v_] := (roh*v*dia)/muh}, TrackedSymbols :> All]

Now if the user puts a velocity value of more than 5 m/s, a warning message should appear: "Velocity should be less than 5 m/s".

$\endgroup$
0

1 Answer 1

7
$\begingroup$

Here is a quick way to do it. Just add another small window that shows the status. In there you can add messages.

enter image description here

Manipulate[

 Grid[{{Row[{"Reynolds number: ", ToString@Style[Rey[v], 14]}]},
   {Row[{"Status: ", Text[If[v <= 5, Style["Ok", Blue], 
        Style["Warning, v too large!!", Red]]]}]}
   }, Frame -> True, Alignment -> Left],

 Text[Style["Reynolds number calculator", 16]],
 Delimiter,
 {{v, 1.5, "Velocity of Fluid(m/s): "}, ControlType ->InputField, FieldSize -> 7},
 {{roh, 1, "Fluid Density (Kg/m^3): "}, ControlType ->InputField, FieldSize -> 7},
 {{dia, 0.01, "Hydraulic Diameter (m) "}, ControlType -> InputField, FieldSize -> 7},
 {{muh, 0.00089, "Dynamic Viscosity (Kg/ms): "}, ControlType -> InputField, FieldSize -> 7},
 Delimiter,
 Item[Button["Calculate", Nothing, BaseStyle -> {15}]], 
 LabelStyle -> {14}, ContentSize -> 310,
 Initialization :> {Rey[v_] := (roh*v*dia)/muh},
 TrackedSymbols :> All
 ]

Feel free to improve the layout.

Update

Yes, I want to display a message inside manipulate... but only when the condition goes wrong.

In this case, how about

enter image description here

Manipulate[
 If[v <= 5,
  Row[{"Reynolds number: ", ToString@Style[Rey[v], 14]}]
  ,
  Row[{Text[Style["Warning, v too large!!", Red]]}]
  ],
 Text[Style["Reynolds number calculator", 16]], Delimiter, {{v, 1.5, 
   "Velocity of Fluid(m/s): "}, ControlType -> InputField, 
  FieldSize -> 7}, {{roh, 1, "Fluid Density (Kg/m^3): "}, 
  ControlType -> InputField, 
  FieldSize -> 7}, {{dia, 0.01, "Hydraulic Diameter (m) "}, 
  ControlType -> InputField, 
  FieldSize -> 7}, {{muh, 0.00089, "Dynamic Viscosity (Kg/ms): "}, 
  ControlType -> InputField, FieldSize -> 7}, Delimiter, 
 Item[Button["Calculate", Nothing, BaseStyle -> {15}]], 
 LabelStyle -> {14}, ContentSize -> 310, 
 Initialization :> {Rey[v_] := (roh*v*dia)/muh}, 
 TrackedSymbols :> All]
$\endgroup$
5
  • $\begingroup$ Can it only display warning msg when v is more than 5 m/s? I don't want to put a status window for this. $\endgroup$
    – ASHISH
    Commented Oct 8, 2021 at 4:48
  • 1
    $\begingroup$ @ASHISHSHUKLA, the title of your post suggest that you want a message inside manipulate? $\endgroup$
    – Syed
    Commented Oct 8, 2021 at 7:03
  • $\begingroup$ Yes, I want to display a message inside manipulate... but only when the condition goes wrong. $\endgroup$
    – ASHISH
    Commented Oct 8, 2021 at 17:07
  • $\begingroup$ @ASHISHSHUKLA updated. $\endgroup$
    – Nasser
    Commented Oct 8, 2021 at 17:20
  • $\begingroup$ @Nasser Thank you so much for your time and efforts... This is what I was looking through... $\endgroup$
    – ASHISH
    Commented Oct 11, 2021 at 5:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.