This shows you the differences between two versions of the page.
Next revision | Previous revision | ||
optimization [2018/09/18 10:21] mark.naves created |
optimization [2022/01/12 13:41] (current) jan.dejong |
||
---|---|---|---|
Line 1: | Line 1: | ||
===== Example: Shape optimization of cross-hinge ===== | ===== Example: Shape optimization of cross-hinge ===== | ||
- | This example provides a shape optimization of a single cross flexure by using matlab' | + | This example provides a shape optimization of a single cross flexure by using matlab' |
+ | |||
+ | The cost function of the optimization is defined by the inverse of the first eigenfrequency. Additionally, | ||
+ | |||
+ | < | ||
+ | function [cost, out] = run_sim(P, Silent)% EXAMPLE SCRIPT FOR RUNNING SPACAR LIGHT | ||
+ | if nargin == 1 | ||
+ | Silent = true; %run in silent mode when called by optimizer | ||
+ | end | ||
+ | |||
+ | % DESIGN PARAMETERS | ||
+ | H = P(1); | ||
+ | B = P(2); | ||
+ | w = P(3); | ||
+ | t = P(4); | ||
+ | |||
+ | % Optimization parameters | ||
+ | stressmax = 300e6; %Max stress [MPa] | ||
+ | Mmax = 2.5; %Max actuation moment [Nm] | ||
+ | Stroke = 0.5; %Max stroke [Rad] | ||
+ | |||
+ | |||
+ | %% NODE POSITIONS | ||
+ | % x y z | ||
+ | nodes = [ 0 0 0; %node 1 | ||
+ | 0 H 0; %node 2 | ||
+ | B H 0; %node 3 | ||
+ | B 0 0]; %node 4 | ||
+ | |||
+ | |||
+ | %% ELEMENT CONNECTIVITY | ||
+ | % | ||
+ | elements = [ 1 | ||
+ | 2 | ||
+ | 2 4]; %element 3 | ||
+ | |||
+ | %% NODE PROPERTIES | ||
+ | %node 1 | ||
+ | nprops(1).fix | ||
+ | |||
+ | %node 3 | ||
+ | nprops(3).rot_z | ||
+ | nprops(3).mass | ||
+ | nprops(3).mominertia | ||
+ | |||
+ | %node 4 | ||
+ | nprops(4).fix | ||
+ | |||
+ | |||
+ | %% ELEMENT PROPERTIES | ||
+ | %Property set 1 | ||
+ | eprops(1).elems | ||
+ | eprops(1).emod | ||
+ | eprops(1).smod | ||
+ | eprops(1).dens | ||
+ | eprops(1).cshape | ||
+ | eprops(1).dim | ||
+ | eprops(1).orien | ||
+ | eprops(1).nbeams | ||
+ | eprops(1).flex | ||
+ | eprops(1).color | ||
+ | eprops(1).opacity | ||
+ | eprops(1).cw | ||
+ | |||
+ | %Property set 2 | ||
+ | eprops(2).elems | ||
+ | eprops(2).dens | ||
+ | eprops(2).cshape | ||
+ | eprops(2).dim | ||
+ | eprops(2).orien | ||
+ | eprops(2).nbeams | ||
+ | eprops(2).color | ||
+ | |||
+ | |||
+ | %% OPTIONAL ARGUMENTS | ||
+ | opt.filename | ||
+ | opt.calccompl | ||
+ | opt.silent | ||
+ | |||
+ | %% CALL SPACAR_LIGHT AND COMPUTE COST FUNCTION | ||
+ | try | ||
+ | out = spacarlight(nodes, | ||
+ | cost = 1/ | ||
+ | stress = max(out.stressmax); | ||
+ | Mact = max(out.node(3).Mreac(3,: | ||
+ | |||
+ | %add penalty if limits are exceeded | ||
+ | if stress > stressmax | ||
+ | cost = cost * (1 + (stress-stressmax)/ | ||
+ | end | ||
+ | if Mact > Mmax | ||
+ | cost = cost * (1 + (Mact-Mmax)/ | ||
+ | end | ||
+ | catch %if sumulation fails, cost is inf | ||
+ | cost = inf; | ||
+ | end | ||
+ | </ | ||
+ | |||
+ | An example to conduct the optimization is provided below, taking into account additional boundary conditions on the design parameters of the cross-hinge. See matlab' | ||
+ | |||
+ | <code matlab optimization.m> | ||
+ | %filename | ||
+ | simulation = @run_sim; | ||
+ | |||
+ | %starting point | ||
+ | x0 = [0.1; 0.1; 50e-3; 0.2e-3]; | ||
+ | |||
+ | %constraints | ||
+ | b1 = [0.05; 0.05; 25e-3; 0.1e-3]; | ||
+ | b2 = [0.2; 0.2; 75e-3; 1e-3 ]; % Upper bound (x < b2) | ||
+ | |||
+ | A = [-eye(4); eye(4)]; | ||
+ | b = [-b1;b2]; | ||
+ | |||
+ | %optimization | ||
+ | x_opt = fmincon(simulation, | ||
+ | |||
+ | %show results | ||
+ | [cost, out] = run_sim(x_opt, | ||
+ | </ | ||
+ | //Note: prescribing input rotation is only supported for SPACAR light version 1.27 or higher.// |