|
| 1 | +::: {rst-class} break |
| 2 | +::: |
| 3 | + |
| 4 | +# Lesson 4: Understanding Simulations |
| 5 | + |
| 6 | +Now that you have a basic understanding of the AnyBody Modeling System and have |
| 7 | +had some hands-on experience, this lesson will give you a deeper understanding |
| 8 | +of what studies and operations are - the core components of all simulations in |
| 9 | +AnyBody. |
| 10 | + |
| 11 | +In the AnyBody Modeling System, all types of simulations, whether they are pure |
| 12 | +mechanical system analysis, musculoskeletal analysis or design analysis, are |
| 13 | +carried out by objects that are referred to as “studies”. Studies have |
| 14 | +operations that can be executed to perform the analysis. |
| 15 | + |
| 16 | +Meaning, studies and operations are the mechanisms used to specify tasks to |
| 17 | +be performed on the model. Think of a study as a collector that brings together |
| 18 | +a model definition, the operations that execute the model, and the results to be |
| 19 | +analyzed afterwards. Meaning, operations are the tasks performed on the model. |
| 20 | +They can be executed from the AnyBody interface, generating and storing output |
| 21 | +in the study based on the function of the specific operation. |
| 22 | + |
| 23 | +## Why Do We Need Studies? |
| 24 | + |
| 25 | +You might wonder why we need studies. After all, couldn’t you just load a model |
| 26 | +and have operations readily available in the AnyBody interface? The answer lies |
| 27 | +in the flexibility that studies offer. |
| 28 | + |
| 29 | +Studies are defined as special classes, allowing you to have multiple studies in |
| 30 | +the same model. As objects in the model, you can have as many studies as you |
| 31 | +need (or as many as your computer can handle), and they don’t necessarily have |
| 32 | +to operate on the same model definition, even if they share elements. |
| 33 | + |
| 34 | +For instance, you might want to perform different operations on the same model, |
| 35 | +or perform the same operation on nearly identical models, and then compare the |
| 36 | +results. With two studies, you can do this within a single AnyBody model. |
| 37 | + |
| 38 | +## The Hierarchy of Study Classes |
| 39 | + |
| 40 | +Studies are derived from a base class called `AnyStudy`, and the operations found |
| 41 | +within studies are also defined as classes, all derived from the base class |
| 42 | +`AnyOperation`. |
| 43 | + |
| 44 | +Here's a look at the hierarchy of study classes in AnyBody: |
| 45 | + |
| 46 | + |
| 47 | +- `AnyStudy` (Base class for all studies) |
| 48 | + |
| 49 | + - `AnyTimeStudy` (Base class for time variation studies) |
| 50 | + |
| 51 | + - `AnyKinStudy` |
| 52 | + |
| 53 | + - `AnyMechStudy` |
| 54 | + - `AnyBodyStudy` |
| 55 | + - `AnyBodyCalibrationStudy` |
| 56 | + |
| 57 | + - `AnyDesStudy` (design variable studies, see *a separate tutorial*) |
| 58 | + |
| 59 | + |
| 60 | +## Mechanical Studies |
| 61 | + |
| 62 | +Mechanical studies, derived from `AnyMechStudyBase`, are quite similar, but they |
| 63 | +contain different sets of available operations. The base class is empty, with |
| 64 | +`AnyKinStudy` extending it with functionality for kinematic analysis. |
| 65 | +`AnyMechStudy` further extends this with kinetic (dynamic) analysis of basic |
| 66 | +mechanical systems. |
| 67 | + |
| 68 | +`AnyBodyStudy` is the most frequently used study by AnyBody users, as it extends |
| 69 | +the kinematic analysis functions with operations for kinetic (dynamic) analysis |
| 70 | +of musculoskeletal systems, which is the core functionality of the AnyBody |
| 71 | +Modeling System. It also contains almost all of the operations found in other |
| 72 | +mechanical studies. `AnyBodyCalibrationStudy` provides additional functionality |
| 73 | +to adjust/calibrate the musculoskeletal models systematically. |
| 74 | + |
| 75 | +## Understanding the Structure of a Study |
| 76 | + |
| 77 | +A study in AnyBody is essentially a folder that contains specifications. These |
| 78 | +specifications are placed between a pair of braces and become part of the study. |
| 79 | +A study has predefined properties that you can set, must set, or cannot modify. |
| 80 | + |
| 81 | +When you create a new model using `File` -> `New from Template...`, the system |
| 82 | +automatically inserts an AnyBodyStudy in the main file. It looks like this: |
| 83 | + |
| 84 | +```AnyScriptDoc |
| 85 | +// The study: Operations to be performed on the model |
| 86 | +AnyBodyStudy MyStudy = { |
| 87 | + AnyFolder &Model = .MyModel; |
| 88 | + Gravity = {0.0, -9.81, 0.0}; |
| 89 | +}; |
| 90 | +``` |
| 91 | + |
| 92 | +This study contains all the necessary elements. The first word after |
| 93 | +`AnyBodyStudy` defines the name of the study, which in this case is "MyStudy". The |
| 94 | +last line `Gravity = {0.0, -9.81, 0.0};` assigns a value to the Gravity |
| 95 | +variable, which specifies the gravitational acceleration vector affecting the |
| 96 | +model. |
| 97 | + |
| 98 | +An `AnyBodyStudy` has many more predefined properties that you can modify. You |
| 99 | +can view these properties using the Model Tree View, which is attached to the |
| 100 | +left of the Main Frame. Double-clicking any object in the Model Tree will show |
| 101 | +you properties of the objects in the Object Description dialog box. |
| 102 | + |
| 103 | +Most of the properties deal with solution methods, tolerances, and other |
| 104 | +advanced user features. However, some properties are essential for all users: |
| 105 | + |
| 106 | +* `tStart`: The time at which the study begins. Usually, this is zero. |
| 107 | +* `tEnd`: The time at which the study ends. This often needs to be set by the user. |
| 108 | +* `nStep`: Specifies how many steps the system should use to go from tStart to tEnd. |
| 109 | + |
| 110 | +Let's take a closer look at the first line of the study: |
| 111 | + |
| 112 | +```AnyScriptDoc |
| 113 | +AnyFolder &Model = .MyModel; |
| 114 | +``` |
| 115 | + |
| 116 | +:::{note} |
| 117 | +:class: margin |
| 118 | +You can choose to point to some subfolders of `MyModel` instead of the entire |
| 119 | +model. This means the study would work on just a subset of the model. For |
| 120 | +example, you might want to compare two nearly identical models. In this case, |
| 121 | +you can put all common parts in one folder and the distinctive parts in separate |
| 122 | +folders. Then, you can create two studies that reference the common part and |
| 123 | +their respective distinctive parts. |
| 124 | +::: |
| 125 | + |
| 126 | +Here, "AnyFolder" is a type definition. Unlike the predefined properties |
| 127 | +discussed above, this line introduces a new property to the study. This is a |
| 128 | +key aspect of studies: you can add almost anything to a study, and the study |
| 129 | +doesn't need to know its type in advance. |
| 130 | + |
| 131 | +This line defines a variable called "Model" and assigns it to `.MyModel`. In |
| 132 | +this case, `MyModel` is the folder that contains the entire model. The prefix `.` |
| 133 | +before `MyModel` indicates that it's one level up from where it's referenced. |
| 134 | + |
| 135 | +By assigning `MyModel` to the Model variable, the entire model comes under the |
| 136 | +influence of the study. The `&` before "Model" means that Model doesn't get |
| 137 | +replicated inside the study. Instead, it's a pointer to `MyModel`. If you're |
| 138 | +familiar with C, C++, or Java programming, you'll recognize this as the concept |
| 139 | +of pointers. If not, think of a pointer as a reference to something defined |
| 140 | +elsewhere. When you access it, you're actually interacting with what it points |
| 141 | +to. |
| 142 | + |
| 143 | +## The Standard Operations in a Study |
| 144 | + |
| 145 | +When you create an `AnyBodyStudy`, it automatically includes three standard |
| 146 | +operations in the study tree. These operations represent different actions you |
| 147 | +can perform on the model elements that the study points to: |
| 148 | + |
| 149 | +* `InitialConditions`: This operation reads the values of all drivers |
| 150 | + included in the study, and sets the model to match these drivers at the |
| 151 | + start time (tStart). Meaning it puts the model in the position it has at |
| 152 | + `time=tStart`. The model is first initialized into the positions from |
| 153 | + load time, and the kinematics is then solved in a few steps. This is |
| 154 | + especially helpful for inspecting the specified initial positions if you're |
| 155 | + having issues with the initial configuration of the mechanism. The |
| 156 | + `InitialConditions` can only run successfully if all joints and drivers are |
| 157 | + fully defined. |
| 158 | + |
| 159 | + Note, that the the model's positions after running `InitialConditions` |
| 160 | + is different from the position after just loading the model, called |
| 161 | + the load-time position. |
| 162 | + |
| 163 | +* `Kinematics`: This operation performs a kinematic analysis, which is a |
| 164 | + simulation of the model's movement without calculating any forces. This means |
| 165 | + you can run a Kinematics operation as soon as you've uniquely defined the |
| 166 | + movement and the model is kinematically determinate. You don't need any |
| 167 | + muscles in the model for this operation. |
| 168 | + |
| 169 | + The data you can extract from the Kinematics study includes positions, |
| 170 | + velocities, and accelerations. |
| 171 | + |
| 172 | +* `InverseDynamics`: This operation simulates the forces involved in the given |
| 173 | + movement or posture, along with anything that can be derived from them. The |
| 174 | + InverseDynamics operation uses the Kinematics operation as a subroutine, so it |
| 175 | + requires a correctly defined movement or posture, as well as the necessary |
| 176 | + muscles or motors to drive the model. |
| 177 | + This is also known as kinetic or dynamic analysis. |
| 178 | + |
| 179 | +:::{admonition} Note on InverseDynamics |
| 180 | +:class: note |
| 181 | +You might think that calculating forces in a rigid body mechanical system is |
| 182 | +straightforward. After all, isn’t it just about setting up equilibrium equations |
| 183 | +and solving them? Well, it’s a bit more complex than that, especially when it |
| 184 | +comes to biomechanics. |
| 185 | + |
| 186 | +In biomechanics, we often deal with statically indeterminate systems. This means |
| 187 | +we don’t have enough equilibrium equations to resolve the forces in the system. |
| 188 | +Plus, we have to consider that muscles can only pull, not push. This adds |
| 189 | +another layer of complexity to the problem. |
| 190 | + |
| 191 | +The `AnyBodyStudy` class is designed to handle these complexities. It uses |
| 192 | +algorithms that are tailored for musculoskeletal systems. |
| 193 | + |
| 194 | +There’s also the `AnyMechStudy` class, which contains a simpler InverseDynamics |
| 195 | +operation. This operation doesn’t deal with the complexities of musculoskeletal |
| 196 | +systems. Instead, it solves the basic inverse dynamics problem for a simple |
| 197 | +mechanical system, finding the reaction forces that balance the system. |
| 198 | +::: |
| 199 | + |
| 200 | +When you execute each of these operations, they compile their output in the |
| 201 | +Output section under the study tree. This allows you to easily access and |
| 202 | +analyze the results of each operation. |
| 203 | + |
0 commit comments