3
$\begingroup$

I am testing different FE formulations on a series of simple benchmark tests. Not all elements converge to the final solution for all the examples, so it occurs that a following (or a similar) message appears

enter image description here

The analysis is aborted and all the subsequent commands, like plotting the results are not executed.

What I would like to achieve is to run all analyses that are nested inside one big chapter in my notebook and when a certain analysis is aborted (either due to divergence or because maximum number of iterations is reached), the evaluation inside Mathematica would continue. So all the following commands would still be executed and the rest of my examples would be calculated.

Anyone has any idea if this can be done? If it makes a difference, I am using a simple loop for the time stepping algorithm

Do[SMTNextStep["dLambda"->0.1];
While[SMTConvergence[10^-8,10], SMTNewtonIteration[];];
AppendTo[SomeDataVector,DataToAppendToThisVector];
,{i,1,10}]
$\endgroup$
1
  • 2
    $\begingroup$ Isn't this a duplicate of this question (with answers)? I think the most straightforward method is to use CheckAbort. $\endgroup$
    – Pinti
    Feb 28, 2018 at 7:53

2 Answers 2

2
$\begingroup$

how about this:

<< AceFEM`;
Elements = {"MySEPST1DFLET1DHooke", "MySEPST1DFHYT1DNeoHookeWA"};
ResultsPerElement = {};
Do[
  SMTInputData[];
  SMTAddDomain["Cook", 
   CurrentElement, {"E *" -> 21000, "\[Nu] *" -> 0.3}];
  L = 48; H = 44; \[CapitalDelta]H = 16;
  SMTAddMesh[
   Polygon[{{0, 0}, {L, H}, {L, H + \[CapitalDelta]H}, {0, H}}], 
   "Cook", "T1", {40, 20}];
  SMTAddEssentialBoundary[{"X" == 0 &, 1 -> 0, 2 -> 0}];
  SMTAddNaturalBoundary[Line[{{L, H}, {L, H + \[CapitalDelta]H}}], 
   2 -> Line[{800}]];
  SMTAnalysis[]; CurrentResults = {};
  Do[
   SMTNextStep[.1, 1.];
   While[SMTConvergence[], SMTNewtonIteration[]];
   AppendTo[
    CurrentResults, {SMTNodeData["X" == 48 && "Y" == 60 &, "at"][[1, 
      2]], SMTData["Multiplier"]}];
   , {Step, 10}];
      AppendTo[ResultsPerElement, CurrentResults];
    , {CurrentElement, Elements}];

ListLinePlot[ResultsPerElement, 
PlotMarkers -> {"\[FilledDiamond]", 18}, 
PlotLegends -> {"Linear Formulation", "Nonlinear Formulation"}, 
AxesLabel -> {"\!\(\*SubscriptBox[\(u\), \(y\)]\)-disp.", 
 "\[Lambda]-load"}]
$\endgroup$
4
  • $\begingroup$ I am sorry, but I think this code doesn't answer OP's question on how to continue with evaluation even though $Aborted was encountered. $\endgroup$
    – Pinti
    Mar 1, 2018 at 8:44
  • $\begingroup$ @Pinti may I ask, how can we use SMSEigenvalues command? the same to Eigenvalue? $\endgroup$
    – ABCDEMMM
    Aug 2, 2019 at 1:08
  • $\begingroup$ @ABCDEMMM I have no experience with SMSEigenvalues. I only know what is written in documentation. $\endgroup$
    – Pinti
    Aug 2, 2019 at 7:47
  • $\begingroup$ @Pinti thanks a lot, ihis issue has been solved $\endgroup$
    – ABCDEMMM
    Aug 2, 2019 at 8:51
2
$\begingroup$

The answer by Sascha gives an interesting idea on running the same test for different FE formulations, but as Pinti pointed out, it does not answer the problem that I was facing.

Also using the CheckAbort function will not do the trick, since I want the analysis to continue, starting the next example if this one is aborted. Using the proposed function is useful if I am running only one example and want to collect the results despite the analysis being Aborted, but the evaluation inside the notebook still stops after the results are collected.

Checking the link that Pinti provided, I found the answer by BHudobivnik, which I used in my code.

err = False;

nstep = 20; dLambda = 1/nstep;
Do[
 SMTNextStep["dLambda"-> dLambda];
 While[(If[Not[BooleanQ[#]],
      Print["Error in iterative procedure step ",i,":",#]; 
      err = True; False,
      #]) &@
   SMTConvergence[10^-8,16,"Analyze"], SMTNewtonIteration[];];
 If[err, Return[],
  AppendTo[SomeDataVector,DataToAppendToThisVector];
  ]
 , {i, 1, nstep}]

Using the code that he proposed, with the option "Analyze" inside the SMTConvergence function, enables me to run multiple examples inside one notebook while even if one is aborted, the results are collected and the notebook evaluation continues with the next example.

$\endgroup$

Your Answer

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

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