Discussion Closed This discussion was created more than 6 months ago and has been closed. To start a new discussion with a link back to this one, click here.

Combine Two Parametric Solutions from Two Separate mph projects

Please login with a confirmed email address before reporting spam

Hello,

Is there a way to combine two frequency domain parametric sweep solutions from two separate mph projects? I completed 1/3 Octave ISO frequencies 200-6300Hz in a study, and then I re-ran this study on 8000 and 10kHz after the fact, because I was concerned they would not converge and didn't want that to break my Matlab Livelink loop. I technically ran 11 unique 200-6300Hz parametric solutions via Matlab Livelink for-loop and saved them all as individual mph projects. I just re-ran one of these at 8000 and 10kHz and was pleasantly surprised it converged. Now I have two mph projects with two solutions that together encompass the frequency range I am interested in. I appreciate any recommendations.

-Michael


1 Reply Last Post 2022年9月30日 GMT-4 03:30
Remi Magnard COMSOL Employee

Please login with a confirmed email address before reporting spam

Posted: 2 years ago 2022年9月30日 GMT-4 03:30

Dear Michael,

See below a script that illustrates how to combine the solutions of two models using the COMSOL API in MATLAB:

% Load source model
model1 = mphopen('open_pipe_solve1','Model1');
model2 = mphopen('open_pipe_solve2','Model2');
% Load destination model
model =  mphopen('open_pipe_solve1','ModelFull');
% Get Parameter list
PVals1 = model1.sol('sol1').getPVals;
PVals2 = model2.sol('sol1').getPVals;
% Construct thenew full list of parameters and set it to the source model
PVals = [PVals1;PVals2(2:end)];
model.sol('sol1').setPVals(PVals);
% Extract solution vectors in source models and set them in the destination 
n = length(PVals1);    
for i = 1:n;
    U = model1.sol('sol1').getU(i);
    model.sol('sol1').setU(i,U);
end   
for i=2:length(PVals2);
    U = model2.sol('sol1').getU(i);
    model.sol('sol1').setU(n+i-1,U);
end
% Create the solution
model.sol('sol1').createSolution;

Note that you could also have both solutions available within the same model, in this case use the Combine Solutions study step to generate a new solution, see the attached model combine_solution.mph (the model solution is reset to reduce its size, so you need to run Study 1, Study 2, and then Study 3).

Best regards,

Rémi

Dear Michael, See below a script that illustrates how to combine the solutions of two models using the COMSOL API in MATLAB: % Load source model model1 = mphopen('open_pipe_solve1','Model1'); model2 = mphopen('open_pipe_solve2','Model2'); % Load destination model model = mphopen('open_pipe_solve1','ModelFull'); % Get Parameter list PVals1 = model1.sol('sol1').getPVals; PVals2 = model2.sol('sol1').getPVals; % Construct thenew full list of parameters and set it to the source model PVals = [PVals1;PVals2(2:end)]; model.sol('sol1').setPVals(PVals); % Extract solution vectors in source models and set them in the destination n = length(PVals1); for i = 1:n; U = model1.sol('sol1').getU(i); model.sol('sol1').setU(i,U); end for i=2:length(PVals2); U = model2.sol('sol1').getU(i); model.sol('sol1').setU(n+i-1,U); end % Create the solution model.sol('sol1').createSolution; Note that you could also have both solutions available within the same model, in this case use the Combine Solutions study step to generate a new solution, see the attached model combine_solution.mph (the model solution is reset to reduce its size, so you need to run Study 1, Study 2, and then Study 3). Best regards, Rémi

Note that while COMSOL employees may participate in the discussion forum, COMSOL® software users who are on-subscription should submit their questions via the Support Center for a more comprehensive response from the Technical Support team.