If i want to optimize parameters of nonlinear spring to minimize error between simulated and desired force but the RSME error increase what should I do?

55 views (last 30 days)
nVars = 22; % Number of optimization variables
% Lower and upper bounds for the optimization variables
lb = [18.0, 31.5, 36.0, 40.5, 45.0, 49.5, 54.0, 58.5, 63.0, 67.5, 72.0, 10.8, 10.8, 10.8, 10.8, 10.8, 10.8, 10.8, 10.8, 10.8, 10.8, 10.8];
ub = [40, 55, 60, 65, 70, 75, 80, 85, 90, 95, 100, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32];
initialCondition = [20, 35, 40, 45,50, 55, 60, 65, 70, 75, 80, 12,12,12,12,12,12,12,12,12,12,12];
options = optimoptions('ga', ...
'Display', 'iter', ...
'MaxGenerations', 20, ... % Maximum number of generations
'PopulationSize', 3, ... % Population size
'MutationFcn', {@mutationadaptfeasible, 0.05}, ... % Adaptive mutation
'CrossoverFraction', 0.8, ... % Crossover fraction
'PlotFcn', {@gaplotbestf, @gaplotstopping}, ... % Plot functions
'OutputFcn', @gaOutputFcn, ... % Custom output function
'InitialPopulation', initialCondition); % Provide the initial condition as one individual
  10 Comments
Pavl M.
Pavl M. on 26 Dec 2024 at 20:43
Edited: Walter Roberson on 27 Dec 2024 at 19:18
Good question, because it contains interaction between the major TCE and Ansys physical simulations sw,
Your question and problem is solvable, recoverable, settleable,
What if?
Whether it were needed? What was rationaly of doing?
To utilize what achieved so far, cyclic economy paradigm to continue only good.
Please see, to prevent now future crimes and offences more than 1 crime and offence commited against my indeed in southern Ukraine and southern Israel by locals,
again they commited crime against my, for what are they?,not by genuiune UK, US,
I complainted, I have no power to fight crimes, and what, what?
And they very, very not helped me, which what means? Not to help you? No, but to help you correctly there.
Construct this spring, put it to vehicle to production or replace in existing vehicles, important component of suspensions.
It must needs to dispatch, redistribute the entirely abundant, galore set of existing cars with individual key already to owners, which is I am an owner, while they plundered with very hard context to me, and you to own, which means to individualize, which very lack, to me and to you now is what will in fact and for sure solve numerous quite very focused important problems!
Which measure of which impactful factor? Which parameters of that force?
Nonlinear spring is a constituent of moving objects and of vehicle's suspension end motor section components as well as wheel hubs and more limited to only good working moving vehicle.
Are lb and ub in Newtons?
What is the morphism (function, methode, routine) of the necessary successful force, desired impactful factor output and which inputs signatures?
Define well options = optimoptions(...)
Show more who are they,
To simplify the literal proceeding:
% Persistent variable to count the number of times the function is called
is to move to + corrected N executions,
function error = objectiveFunction(x, desiredForce)
% Call the external function to handle ANSYS-related processes
[simulatedForce] = runANSYSProcess(x);
% Calculate the error using Root Mean Square Error (RMSE)
error = sqrt(mean((simulatedForce - desiredForce).^2)); % Scalar value
% Display the calculated RMSE
disp(['Calculated RMSE: ' num2str(error)]);
end
function [simulatedForce] = runANSYSProcess(x)
persistent ansysCounter, N = 100;
if isempty(ansysCounter)
ansysCounter = 0; % Initialize if empty
end
ansysCounter = ansysCounter + 1;
disp(['ANSYS execution count: ' num2str(ansysCounter)]);
% Extract parameters
D1 = x(1); D2 = x(2); D3 = x(3); D4 = x(4); D5 = x(5);
D6 = x(6); D7 = x(7); D8 = x(8); D9 = x(9); K99 = x(10); S55 = x(11);
H1 = x(12); H2 = x(13); H3 = x(14); H4 = x(15); H5 = x(16);
H6 = x(17); H7 = x(18); H8 = x(19); H9 = x(20); M33 = x(21);
L40=x(22);
% Define the path to the base ANSYS journal file
journalFile ="E:\spring small\first spring.wbjn";
if exist(journalFile, 'file') ~= 2
error('Journal file not found: %s', journalFile);
end
% Read the journal content into a string
journalContent = fileread(journalFile);
% Replace placeholders in the journal file with parameter values
journalContent = strrep(journalContent, 'D1', num2str(D1));
journalContent = strrep(journalContent, 'D2', num2str(D2));
journalContent = strrep(journalContent, 'D3', num2str(D3));
journalContent = strrep(journalContent, 'D4', num2str(D4));
journalContent = strrep(journalContent, 'D5', num2str(D5));
journalContent = strrep(journalContent, 'D6', num2str(D6));
journalContent = strrep(journalContent, 'D7', num2str(D7));
journalContent = strrep(journalContent, 'D8', num2str(D8));
journalContent = strrep(journalContent, 'D9', num2str(D9));
journalContent = strrep(journalContent, 'K99', num2str(K99));
journalContent = strrep(journalContent, 'S55', num2str(S55));
journalContent = strrep(journalContent, 'H1', num2str(H1));
journalContent = strrep(journalContent, 'H2', num2str(H2));
journalContent = strrep(journalContent, 'H3', num2str(H3));
journalContent = strrep(journalContent, 'H4', num2str(H4));
journalContent = strrep(journalContent, 'H5', num2str(H5));
journalContent = strrep(journalContent, 'H6', num2str(H6));
journalContent = strrep(journalContent, 'H7', num2str(H7));
journalContent = strrep(journalContent, 'H8', num2str(H8));
journalContent = strrep(journalContent, 'H9', num2str(H9));
journalContent = strrep(journalContent, 'M33', num2str(M33));
journalContent = strrep(journalContent, 'L40', num2str(L40));
% Save the modified journal file
modifiedJournalFile = 'finaljournal.wbjn';
fid = fopen(modifiedJournalFile, 'w');
fprintf(fid, '%s', journalContent);
fclose(fid);
% Run ANSYS using the modified journal file
status = system('"C:\Program Files\ANSYS Inc\v242\Framework\bin\Win64\runwb2.exe" -B -R "finaljournal.wbjn"');
if status ~= 0
error('ANSYS execution failed. Status code: %d', status);
end
% Wait for ANSYS to finish by checking if the output file exists
csvFile ="E:\spring small\first spring.csv"; % Path to the ANSYS output CSV file
% Load the force and displacement data from the CSV file generated by ANSYS
simulatedForce = readmatrix(csvFile, 'Range', 'X8:BP8');
desiredDeformation = [0, 0.138618791, 1.112429452, 2.125563798, 2.631098144, 3.681689186, 4.561854006, 5.565175553, 6.149462336, 7.273283416, 8.435716039, 9.884547347, 11.49354219, 12.97408264, 14.53258072, 15.84198591, 16.65918057, 18.08665982, 19.51171874, 21.09632662, 22.61775871, 23.67194743, 24.64443479, 26.42549672, 28.20528978, 29.98478422, 30.05559058, 31.19829601, 33.46354526, 35.14423574, 36.52254663, 38.71352157, 40.09593355, 41.64279889, 42.94848661, 44.01113287, 45.48512416, 46.88029165, 48.03262267, 49.35292104, 50.59404444, 52.25318701, 53.58588137, 54.42138391, 55.67749708, 55.92924535];
% Plot optimized force-deformation curve every N ANSYS executions
if mod(ansysCounter, N) == 0
figure(1); % Open or create figure window 1
hold on; % Retain the current plot to overlay new data
plot(desiredDeformation, simulatedForce, '-o', ...
'DisplayName', ['ANSYS Run ' num2str(ansysCounter)], 'LineWidth', 1);
end
end
Where do you plot desired force?
Why force were inverted in sign(-)?
Is desiredDeformation data from real road conditions?
In the nonlinear function in tabular form,
You can change with what in bold, Particle Swarm Optimization methode or regroup (make optimization by desiredDeformation+ after finding the rest part of parameters that provided most close to optimal target utility or using better than RMSE metric like AAD or better not to disturb our working (I completed a few which level of likelihood benign practices, can make more for which will help/aid me correctly), the parameters(+) to find optimal set of parameters values for your automotive element.
Sam Chak
Sam Chak on 27 Dec 2024 at 7:37

You didn't share the governing equations with us, so many of us don’t have a clear picture of your engineering problem. It’s likely that the equations are unfamiliar to you as well, since you’re just an Applications Engineer who is very good at using ANSYS.

I’m trying to help you describe the problem so that Optimization Experts can assist you. Let’s start with the idea that you’re probably just using ANSYS software to graphically design the mass-spring model (no math involved) and relying on its physics rendering and finite element capabilities to generate the simulated Force vs. Deformation results.

You want to find the best values for the 22 coupled nonlinear springs in ANSYS so that the desired Force vs. Deformation profile is generated. You’ve been using the `ga()` optimizer in MATLAB while running ANSYS at the same time. However, the results show a significant gap between 30 and 50 mm of deformation, which is unacceptable.

Now, here’s the engineering question: Does adding more springs, increasing the total to 26 (on par with the dimensions in Bosonic String Theory), reduce the "gap"? If so, it might explain that the 22 springs are insufficient to produce the desired force level at certain ranges of deformation.

Sign in to comment.

Answers (0)

Categories

Find more on Problem-Based Optimization Setup in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!