5
$\begingroup$

I would like to have a GUI with a button that starts AceFEM analysis and then some results appear. I have taken one example from the documentation on boundary condition specification and I wrapped it into a function. It works and returns graphics of the deformed mesh

<< AceFEM`

buttonContent[load_?NumberQ] := Module[{H = 50, A = 100, B = 75},
  SMTInputData[];
  SMTAddDomain["A","OL:SED3H1DFHYH1NeoHooke", {"E *" -> 1000., "ν *" -> .49}];
  SMTAddMesh[
   Hexahedron[{{0, 0, 0}, {A, 0, 0}, {A, B, 0}, {0, B, 0}, {0, 0, H}, {A, 0, H}, {A, B, H}, {0, B, H}}], 
   "A", "H1", {20, 15, 10}
   ];
  SMTAddEssentialBoundary[
   Polygon[{{0, 0, 0}, {0, B, 0}, {0, B, H}, {0, 0, H}}],
   1 -> 0, 2 -> 0, 3 -> 0
   ];
  SMTAddNaturalBoundary[
   Polygon[{{0, B/2, H}, {A/2, B/2, H}, {A/2, B, H}, {0, B, H}}],
   3 -> Polygon[{load}]
   ];
  SMTAnalysis[];

  Do[
   SMTNextStep["Δλ" -> 0.1];
   While[SMTConvergence[10^-8, 12], SMTNewtonIteration[];];,
   {i, 1, 10}];
  SMTShowMesh["DeformedMesh"->True,"BoundaryConditions"->True,"Field"->"u"]
 ]

buttonContent[-100]

enter image description here

When I use this function as the Button action it seems that analysis is initialized, but there are no results. Why is this happening? Is not possible to use AceFEM functions in Dynamic expressions and other GUI elements?

Column[{
  InputField[Dynamic[load], Number, FieldSize -> 8],
  Row[{"Load= ", Dynamic[load]}],
  Row[{
    Button["Calculate", gr = buttonContent[load]],
    Button["Clear", gr = ""]
    }],
  Dynamic[gr]
  }, Frame -> True]

enter image description here

$\endgroup$
  • 1
    $\begingroup$ How long does it take to compute? If you don't supply the Method->"Queued" option to Button it aborts after ~6 seconds. $\endgroup$ – b3m2a1 May 25 '17 at 15:51
4
$\begingroup$

Solution to the problem is to use Button[...,Method->"Queued"]. Quoting the documentation for Button

"By default, button functions are evaluated on a preemptive link and time out after 5 seconds:"

"Use Method->"Queued" to evaluate button functions on the main link, which never times out:"

Your analysis function was evaluated on the preemptive link by default and since it seems to take more than 5 seconds to evaluate, the link timed out.

buttonContent[-100]; // AbsoluteTiming
(*{8.78588, Null}*)

I think that all AceFEM analyses should be evaluated through the main link, because typically they are time consuming or unpredictable time-wise (e.g. using adaptive time step). See this link for more information on synchronous and asynchronous evaluation. I have also wrapped your example in DynamicModule to encapsulate local variables and prevent unwanted interaction of multiple GUIs.

DynamicModule[{load = -100, gr = ""},
 Column[{
   InputField[Dynamic[load], Number, FieldSize -> 8],
   Row[{"Load= ", Dynamic[load]}],
   Row[{
     Button["Calculate",
      gr = buttonContent[load],
      Method -> "Queued"
      ],
     Button["Clear", gr = ""]
     }],
   Dynamic[gr]
   }, Frame -> True]
 ]

gui

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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