Quantcast
Channel: Latest Discussions - COMSOL Forums
Viewing all articles
Browse latest Browse all 5773

COMSOL with matlab cannot use "model.sol('sol1').run; "

$
0
0

DERA All, I use COMSOL with matlab to run my model with a for-loop (change some parameters every time) . About three month ago, I can use "model.sol('sol1').run; " to run my model. However, today, it is useless, and, the problem described by Matlab is bellow:

错误使用 test_para (line 25)
Java exception occurred:
Exception:
    com.comsol.util.exceptions.FlException: No current feature assigned
Messages:
    No current feature assigned
Stack trace:
    at com.comsol.model.dbmodel.SolverSequenceDb.current(SourceFile:196)
    at com.comsol.model.method.SolverSequenceMethod.doRun(SourceFile:2711)
    at com.comsol.model.dbmodel.SolverSequenceDb.run(SourceFile:186)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at com.comsol.bridge.command.b.a(SourceFile:145)
    at com.comsol.bridge.command.b.run(SourceFile:90)
    at com.comsol.bridge.command.i.execute(SourceFile:45)
    at com.comsol.bridge.command.j.d(SourceFile:711)
    at com.comsol.bridge.command.j.a(SourceFile:699)
    at com.comsol.bridge.command.j$3.a(SourceFile:600)
    at com.comsol.bridge.command.j$3.call(SourceFile:1)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
    at java.lang.Thread.run(Thread.java:748)

And here is my code:

import com.comsol.model.*
import com.comsol.model.util.*
fp = fopen('run_log.txt','a+');
for x1 = 0.8 : 0.05 : 0.9
    for x2 = 1 : 0.5 : 2     
        for x3 = 0.1 : 0.5 : 2.1
            disp(strcat('f = ',num2str(x1)));
            fprintf(fp, '%s\n',strcat('f = ',num2str(x1)));
            disp(strcat('ra = ',num2str(x2)));
            fprintf(fp, '%s\n',strcat('ra = ',num2str(x2)));
            disp(strcat('ha = ',num2str(x3)));
            fprintf(fp, '%s\n',strcat('ha = ',num2str(x3)));
            disp(datetime)
            fprintf(fp, '%s\n',datetime);            
            model = mphload("curve_threePointMem.mph");
            model.param.set('f',num2str(x1));
            model.param.set('ra',num2str(x2));
            model.param.set('ha',num2str(x3));         
            model.sol('sol1').run;
            coefficient = mphglobal(model,'Alpha');
            total = 0;
            for i = 1 : 59
                total = total + (coefficient(i) + coefficient(i + 1));
            end
            z = -(0.5 * total) / 59;
            disp(strcat('Average Absorption Coefficient= ',num2str(-z)));
            fprintf(fp, '%s\n',strcat('Average Absorption Coefficient= ',num2str(-z)));
            disp("-----------------------------");
            fprintf(fp, '%s\n',"-----------------------------");
        end
    end
end
fclose(fp);

my version is COMSOL Multiphysics 5.4.0.388


Viewing all articles
Browse latest Browse all 5773

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>