You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In this tutorial, we will demonstrate how to use polyfem to optimize the initial velocity of throwing a ball to match a given trajectory.
6
6
7
7
<pfloat="left">
8
8
<imgsrc="../sim.gif"width="60%" />
9
9
</p>
10
10
11
-
The data for this tutorial can be found [here](https://github.com/polyfem/polyfem-data/tree/main/multi-material).
12
-
13
11
## Prerequisites
14
12
15
-
The following items are necessary to complete this tutorial. To replicate the experiment, you can feel free to use either the given mesh files or your own mesh.
13
+
The following items are necessary to complete this tutorial. To reproduce the experiment, you can feel free to use either the given mesh files or your own mesh.
The files can also be found at [polyfem-data](https://github.com/polyfem/polyfem-data/blob/main/differentiable/optimizations/initial-condition-trajectory-opt/).
23
+
24
24
### Build PolyFEM
25
25
26
-
The instructions for building PolyFEM can be found [here](../../../cxx_index).
26
+
The instructions for building PolyFEM can be found [here](../../cxx_index).
27
27
28
28
Then you can use it by
29
29
@@ -33,7 +33,7 @@ polyfem --help
33
33
34
34
## Setting up the Optimization
35
35
36
-
We will setup the optimization using PolyFEM's JSON interface. For more details, please refer to the [JSON Input](../../../json) documentation.
36
+
We will setup the optimization using PolyFEM's JSON interface. For more details, please refer to the [JSON Input](../../json.md) documentation.
37
37
38
38
We will only go over the JSON script for the optimization configuration, please refer to other tutorials for the JSON script for the simulation configuration.
39
39
@@ -69,7 +69,7 @@ In more complex optimizations, where several types of parameters are optimized,
69
69
}
70
70
```
71
71
72
-
In `states`, we specify the path to the JSON files of simulations, they follow the same [rules](../../../json) for the simulation JSON scripts. PolyFEM will create a number of simulators, one for each JSON file, whose parameters can be optimized. During the optimization, certain parameters in these configurations are optimized, but the optimized values will not overwrite the values in these JSON files. Each simulator gets an ID starting from 0, following the order in this list. The ID of simulators may be used in `variable to simulation` and `functionals`.
72
+
In `states`, we specify the path to the JSON files of simulations, they follow the same [rules](../../json.md) for the simulation JSON scripts. PolyFEM will create a number of simulators, one for each JSON file, whose parameters can be optimized. During the optimization, certain parameters in these configurations are optimized, but the optimized values will not overwrite the values in these JSON files. Each simulator gets an ID starting from 0, following the order in this list. The ID of simulators may be used in `variable to simulation` and `functionals`.
73
73
74
74
Here we have two simulators: The first one is the simulator being optimized, while the second one is a fixed simulation that generates a reference trajectory. These JSON files are only for initializing the simulators, so one can use the same path for multiple simulators if possible.
75
75
@@ -104,7 +104,7 @@ The initial condition parameter has a dimension of `2 * dim * n_basis`, where `d
104
104
105
105
In this tutorial, we only optimize the initial velocity of the ball, so we need to build a mapping, which we call `composition` in the JSON script, from the variable of size 2 to the full initial condition parameter of size `2 * dim * n_basis`. The `composition` is a list of some pre-defined mappings, which will apply to the optimization variables in order, and the final output of the mappings will be assigned to the initial condition parameter.
106
106
107
-
There are two objects with different volume IDs, specified in `barycenter.json` and `barycenter-target.json`, and we only want to control the initial velocity of the ball, with volume ID 1. First, in `append-values` we append two zeros to the optimization variable, which represents the zero initial velocity of the floor. Second, in `per-body-to-per-node` we map the per-volume values to per-node, whose output has the dimension of `dim * n_basis`. Finally, in `append-const` we append more zeros to the start of the vector, to account for the zero initial displacement. Please refer to the [opt-input-spec.json](https://github.com/geometryprocessing/adjoint-polyfem/blob/shock/opt-input-spec.json) for the documentation of compositions.
107
+
There are two objects with different volume IDs, specified in `barycenter.json` and `barycenter-target.json`, and we only want to control the initial velocity of the ball, with volume ID 1. First, in `append-values` we append two zeros to the optimization variable, which represents the zero initial velocity of the floor. Second, in `per-body-to-per-node` we map the per-volume values to per-node, whose output has the dimension of `dim * n_basis`. Finally, in `append-const` we append more zeros to the start of the vector, to account for the zero initial displacement. Please refer to the [opt-input-spec.json](https://github.com/polyfem/polyfem/blob/main/json-specs/opt-input-spec.json) for the documentation of compositions.
108
108
109
109
### Functionals
110
110
@@ -127,7 +127,7 @@ There are two objects with different volume IDs, specified in `barycenter.json`
127
127
}
128
128
```
129
129
130
-
The `functionals` specify the objective being minimized in the optimization. Please refer to [objective-input-spec.json](https://github.com/geometryprocessing/adjoint-polyfem/blob/shock/objective-input-spec.json) for the documentation of `functionals`.
130
+
The `functionals` specify the objective being minimized in the optimization. Please refer to [objective-input-spec.json](https://github.com/polyfem/polyfem/blob/main/json-specs/objective-spec.json) for the documentation of `functionals`.
131
131
132
132
Here we perform trajectory optimization on the ball, so the objective is the $L^2$ difference between the two ball barycenters in the two simulations, integrated over time.
133
133
@@ -157,11 +157,13 @@ The `transient integral` computes the integral over time of the `static objectiv
157
157
158
158
```json
159
159
"output": {
160
-
"solve_log_level": 3
160
+
"log": {
161
+
"level": 1
162
+
}
161
163
}
162
164
```
163
165
164
-
The `output` contains options regarding the logging of the optimization, here `solve_log_level` specifies a log level of 3, corresponding to `warning`, for simulations so that we can focus more on the optimization logs.
166
+
The `output` contains options regarding the logging of the optimization, here `output/log/level` specifies a log level of 1, corresponding to `debugging`, to log the energy and gradient during the optimization. The log level for simulations are specified in each state json, normally the simulation log level is set to `info` or `warn` so that we can focus more on the optimization logs.
0 commit comments