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 Sep 30, 2022, 3:30 a.m. EDT
Remi Magnard COMSOL Employee

Please login with a confirmed email address before reporting spam

Posted: 2 months ago Sep 30, 2022, 3:30 a.m. EDT

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

Reply

Please read the discussion forum rules before posting.

Please log in to post a reply.

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.