|
a |
|
b/Tools/ModelUtilities/Validation/EvaluateMaxExternalLoad.any |
|
|
1 |
|
|
|
2 |
#class_template EvaluateMaxLoad( |
|
|
3 |
__CLASS__=AnyOperationSequence, |
|
|
4 |
STUDY, |
|
|
5 |
SET_MIN_MAX_STRICT=0, |
|
|
6 |
){ |
|
|
7 |
|
|
|
8 |
#var AnyObjectPtr LoadPtr; |
|
|
9 |
|
|
|
10 |
|
|
|
11 |
STUDY = { |
|
|
12 |
AnyOutputFun MaxMusActFun_##__NAME__ = { |
|
|
13 |
Val = .MaxMuscleActivity; |
|
|
14 |
}; |
|
|
15 |
|
|
|
16 |
#if SET_MIN_MAX_STRICT == 1 |
|
|
17 |
InverseDynamics.Criterion.Type = MR_MinMaxStrict; |
|
|
18 |
#endif |
|
|
19 |
|
|
|
20 |
|
|
|
21 |
}; |
|
|
22 |
|
|
|
23 |
|
|
|
24 |
|
|
|
25 |
AnyFolder Calculations = { |
|
|
26 |
|
|
|
27 |
AnyVar EnsureMinMaxStrict = assert(eqfun(STUDY.InverseDynamics.Criterion.Type, MR_MinMaxStrict), "Study must use MR_MinMaxStrict criterion to caclucate the correct maximum loading"); |
|
|
28 |
|
|
|
29 |
#var AnyVar InitialLoad = DesignVar(1); |
|
|
30 |
|
|
|
31 |
#var AnyVar Load1 = InitialLoad; |
|
|
32 |
#var AnyVar Load2 = 2*InitialLoad; |
|
|
33 |
AnyVector MaxMuscleActivityTemp = take(arrcat(STUDY.MaxMusActFun_##__NAME__(), zeros(STUDY.nStep)), iarr(0,STUDY.nStep-1)); |
|
|
34 |
AnyVector MaxMuscleActivity1 = MaxMuscleActivityTemp; |
|
|
35 |
AnyVector MaxMuscleActivity2 = MaxMuscleActivityTemp; |
|
|
36 |
AnyVector MaxMuscleActivityDiff = (MaxMuscleActivity2 - MaxMuscleActivity1); |
|
|
37 |
AnyVector a = (MaxMuscleActivityDiff)/(Load2 -Load1) + 0.01*not(MaxMuscleActivityDiff); |
|
|
38 |
AnyVector MaxLoad = 1/a - div(MaxMuscleActivity1, a) + Load1; |
|
|
39 |
}; |
|
|
40 |
|
|
|
41 |
|
|
|
42 |
AnyFolder Operations = { |
|
|
43 |
AnyOperation& RunStudy = STUDY.InverseDynamics; |
|
|
44 |
AnyOperationMacro UpdateValues = {MacroStr = {"classoperation Main " + strquote("Update Values")}; }; |
|
|
45 |
AnyOperationSetValue SetLoad1 = { |
|
|
46 |
Source = {&..Calculations.Load1}; |
|
|
47 |
Target = {..LoadPtr}; |
|
|
48 |
}; |
|
|
49 |
AnyOperationSetValue SetLoad2 = { |
|
|
50 |
Source = {&..Calculations.Load2}; |
|
|
51 |
Target = {..LoadPtr}; |
|
|
52 |
}; |
|
|
53 |
AnyOperationSetValue StoreMaxActivity1 = { |
|
|
54 |
Source = {&..Calculations.MaxMuscleActivityTemp}; |
|
|
55 |
Target = {&..Calculations.MaxMuscleActivity1}; |
|
|
56 |
}; |
|
|
57 |
AnyOperationSetValue StoreMaxActivity2 = { |
|
|
58 |
Source = {&..Calculations.MaxMuscleActivityTemp}; |
|
|
59 |
Target = {&..Calculations.MaxMuscleActivity2}; |
|
|
60 |
}; |
|
|
61 |
AnyOperationSetValue CopyInitialLoadValue = { |
|
|
62 |
Source = {..LoadPtr}; |
|
|
63 |
Target = {&..Calculations.InitialLoad}; |
|
|
64 |
}; |
|
|
65 |
AnyOperationSetValue StoreFinalMaxLoad = { |
|
|
66 |
Source = {&..Calculations.MaxLoad}; |
|
|
67 |
Target = {&..MaxLoad}; |
|
|
68 |
}; |
|
|
69 |
|
|
|
70 |
AnyOperationSequence CheckLoadPointerEvaluationMoment = { |
|
|
71 |
AnyInt testTrigger = DesignVar(0); |
|
|
72 |
AnyVar testRandomValue = 3.142443356676544; |
|
|
73 |
AnyMessage LoadPointerError = { |
|
|
74 |
TriggerRuntime = andfun(.testTrigger, neqfun(Obj2Num(...LoadPtr), .testRandomValue) ); |
|
|
75 |
Type = MSG_ErrorFatal; |
|
|
76 |
Message = strformat("\n"+ |
|
|
77 |
"------------------------------------------------------------------------------------------------------\n"+ |
|
|
78 |
" EVALUATE MAX LOADING ERROR \n"+ |
|
|
79 |
" The loading variable: " + strquote(CompleteNameOf(...LoadPtr)) + " is not editable/designvar. \n"+ |
|
|
80 |
" It must be editable/designvar for this tool to work. \n"+ |
|
|
81 |
" \n"+ |
|
|
82 |
" Try to wrap variable in a `DesignVar()` function to force it to be editable. \n"+ |
|
|
83 |
"------------------------------------------------------------------------------------------------------\n"); |
|
|
84 |
}; |
|
|
85 |
AnyOperationSetValue SetTestValue = { |
|
|
86 |
AnyInt OnVal = 1; |
|
|
87 |
Source = {&OnVal, &.testRandomValue}; |
|
|
88 |
Target = {&.testTrigger, ...LoadPtr}; |
|
|
89 |
}; |
|
|
90 |
AnyOperation& evaltest = .UpdateValues; |
|
|
91 |
AnyOperationSetValue ResetTestValue = { |
|
|
92 |
AnyInt OffVal = 0; |
|
|
93 |
Source = {&OffVal, &...Calculations.InitialLoad}; |
|
|
94 |
Target = {&.testTrigger, ...LoadPtr}; |
|
|
95 |
}; |
|
|
96 |
}; |
|
|
97 |
|
|
|
98 |
AnyOperationMacro PrintMaxLoad = {MacroStr = {"classoperation " + CompleteNameOf(&..MaxLoad) +" "+ strquote("Dump")}; }; |
|
|
99 |
}; |
|
|
100 |
AnyOperationSequence PreAnalysis = { |
|
|
101 |
AnyOperationDummy NoOp = {}; |
|
|
102 |
}; |
|
|
103 |
|
|
|
104 |
AnyOperationSequence Evaluate = { |
|
|
105 |
AnyOperation& CopyInitialLoadValue = .Operations.CopyInitialLoadValue; |
|
|
106 |
AnyOperation& CheckLoadPointer = .Operations.CheckLoadPointerEvaluationMoment; |
|
|
107 |
AnyOperation& Update0 = .Operations.UpdateValues; |
|
|
108 |
AnyOperation& SetLoad1 = .Operations.SetLoad1; |
|
|
109 |
AnyOperation& Update1 = .Operations.UpdateValues; |
|
|
110 |
AnyOperation& RunWithLoad1 = .Operations.RunStudy; |
|
|
111 |
AnyOperation& Update2 = .Operations.UpdateValues; |
|
|
112 |
AnyOperation& StoreMaxActivity1 = .Operations.StoreMaxActivity1; |
|
|
113 |
AnyOperation& SetLoad2 = .Operations.SetLoad2; |
|
|
114 |
AnyOperation& Update3 = .Operations.UpdateValues; |
|
|
115 |
AnyOperation& RunWithLoad2 = .Operations.RunStudy; |
|
|
116 |
AnyOperation& Update4 = .Operations.UpdateValues; |
|
|
117 |
AnyOperation& StoreMaxActivity2 = .Operations.StoreMaxActivity2; |
|
|
118 |
AnyOperation& Update5 = .Operations.UpdateValues; |
|
|
119 |
AnyOperation& StoreFinalMaxLoad = .Operations.StoreFinalMaxLoad; |
|
|
120 |
AnyOperation& PrintFinalResult = .Operations.PrintMaxLoad; |
|
|
121 |
}; |
|
|
122 |
|
|
|
123 |
AnyVector MaxLoad = Calculations.MaxLoad; |
|
|
124 |
|
|
|
125 |
}; |
|
|
126 |
|
|
|
127 |
|
|
|
128 |
|