Edgar J. Kaiser
Certified Consultant
Please login with a confirmed email address before reporting spam
Posted:
1 year ago
Aug 3, 2023, 1:24 p.m. EDT
Hi,
I am not exactly sure what you mean by parallel code. It is possible to set up external functions and external material models. For this you need to make a DLL in your preferred development system and COMSOL will call the DLL at each solver call, e.g. at each time step. You can run any code in such a DLL. This is for Windows, I think the Linux version has similar mechanisms.
The model builder allows model methods in JAVA, but I don't think they can be called during computation. I am sometimes using them to set parameters and for post processing.
Check the documentation.
Cheers,
Edgar
-------------------
Edgar J. Kaiser
emPhys Physical Technology
www.emphys.com
Hi,
I am not exactly sure what you mean by parallel code. It is possible to set up external functions and external material models. For this you need to make a DLL in your preferred development system and COMSOL will call the DLL at each solver call, e.g. at each time step. You can run any code in such a DLL. This is for Windows, I think the Linux version has similar mechanisms.
The model builder allows model methods in JAVA, but I don't think they can be called during computation. I am sometimes using them to set parameters and for post processing.
Check the documentation.
Cheers,
Edgar
Please login with a confirmed email address before reporting spam
Posted:
1 year ago
Aug 4, 2023, 2:54 a.m. EDT
Hi,
I am not exactly sure what you mean by parallel code. It is possible to set up external functions and external material models. For this you need to make a DLL in your preferred development system and COMSOL will call the DLL at each solver call, e.g. at each time step. You can run any code in such a DLL. This is for Windows, I think the Linux version has similar mechanisms.
The model builder allows model methods in JAVA, but I don't think they can be called during computation. I am sometimes using them to set parameters and for post processing.
Check the documentation.
Cheers,
Edgar
HI Edgar, thanks for answer.
There is way to use methods during computatin but basically I use JAVA methods for post processing.
The example I provided is legit JAVA code which works but not in Comsol.
Thanks for the idea with external DLL. It's great and useful tool but it does not fit what I want to try.
For example we have parametric sweep with 3 steps, where 1, 2, 3 are indeces of those steps. In postprocessing we need to perform Global Evaluation
for each step independently.
I will omit imports, class name and execute
method of the class method11
and show simple example:
int[] indeces = new int[]{1, 2, 3};
for (int i: indeces)
{
with(model.result().numerical("sol2"));
set("outersolnumindices", i);
endwith();
model.result().numerical("gev1").setIndex("expr", "2+" + toString(i), 0);
model.result().numerical("gev1").setResult();
}
double[][] table = model.result().table("tbl1").getReal();
Previous code is a sequence. Next example suppose to be legit equivalent of previous.
int[] indeces = new int[]{1, 2, 3};
List<Integer> mylist = Arrays.asList(indeces);
mylist.parallelStream().map(i-> {
with(model.result().numerical("sol2"));
set("outersolnumindices", i);
endwith();
model.result().numerical("gev1").setIndex("expr", "2+" + toString(i), 0);
model.result().numerical("gev1").setResult();
});
double[][] table = model.result().table("tbl1").getReal();
// 'i' cannot be resolved to a variable.
But this code should run for each index i
an independent subprogram in the same time.
I suspect that it's impossible to do in the way I want but at least to have an option to run parallel JAVA code would be nice.
Best Regards,
Kostiantyn Vasko
>Hi,
>
>I am not exactly sure what you mean by parallel code. It is possible to set up external functions and external material models. For this you need to make a DLL in your preferred development system and COMSOL will call the DLL at each solver call, e.g. at each time step. You can run any code in such a DLL. This is for Windows, I think the Linux version has similar mechanisms.
>The model builder allows model methods in JAVA, but I don't think they can be called during computation. I am sometimes using them to set parameters and for post processing.
>Check the documentation.
>
>Cheers,
>Edgar
HI Edgar, thanks for answer.
There is way to use methods during computatin but basically I use JAVA methods for post processing.
The example I provided is legit JAVA code which works but not in Comsol.
Thanks for the idea with external DLL. It's great and useful tool but it does not fit what I want to try.
For example we have parametric sweep with 3 steps, where 1, 2, 3 are indeces of those steps. In postprocessing we need to perform `Global Evaluation` for each step independently.
I will omit imports, class name and `execute` method of the class `method11` and show simple example:
int[] indeces = new int[]{1, 2, 3};
for (int i: indeces)
{
with(model.result().numerical("sol2"));
set("outersolnumindices", i);
endwith();
model.result().numerical("gev1").setIndex("expr", "2+" + toString(i), 0);
model.result().numerical("gev1").setResult();
}
double[][] table = model.result().table("tbl1").getReal();
Previous code is a sequence. Next example suppose to be legit equivalent of previous.
int[] indeces = new int[]{1, 2, 3};
List mylist = Arrays.asList(indeces);
mylist.parallelStream().map(i-> {
with(model.result().numerical("sol2"));
set("outersolnumindices", i);
endwith();
model.result().numerical("gev1").setIndex("expr", "2+" + toString(i), 0);
model.result().numerical("gev1").setResult();
});
double[][] table = model.result().table("tbl1").getReal();
// 'i' cannot be resolved to a variable.
But this code should run for each index `i` an independent subprogram in the same time.
I suspect that it's impossible to do in the way I want but at least to have an option to run parallel JAVA code would be nice.
Best Regards,
Kostiantyn Vasko
Edgar J. Kaiser
Certified Consultant
Please login with a confirmed email address before reporting spam
Posted:
1 year ago
Aug 4, 2023, 5:02 a.m. EDT
You can submit model parameters to an external material and receive states from it.
-------------------
Edgar J. Kaiser
emPhys Physical Technology
www.emphys.com
You can submit model parameters to an external material and receive states from it.
Please login with a confirmed email address before reporting spam
Posted:
12 months ago
Aug 18, 2023, 7:37 a.m. EDT
You can submit model parameters to an external material and receive states from it.
Do you have a simple example of what you describing?
>You can submit model parameters to an external material and receive states from it.
Do you have a simple example of what you describing?
Edgar J. Kaiser
Certified Consultant
Please login with a confirmed email address before reporting spam
Posted:
12 months ago
Aug 20, 2023, 5:15 p.m. EDT
There are examples in the documentation. Unfortunately all I have is protected by confidentiality agreements and it is not exactly simple as well.
-------------------
Edgar J. Kaiser
emPhys Physical Technology
www.emphys.com
There are examples in the documentation. Unfortunately all I have is protected by confidentiality agreements and it is not exactly simple as well.
Edgar J. Kaiser
Certified Consultant
Please login with a confirmed email address before reporting spam
Posted:
12 months ago
Aug 21, 2023, 11:01 a.m. EDT
I would also advise to contact COMSOL support. I got examples from them when I started to look into external materials, but I don't think I am allowed to share this with other users.
-------------------
Edgar J. Kaiser
emPhys Physical Technology
www.emphys.com
I would also advise to contact COMSOL support. I got examples from them when I started to look into external materials, but I don't think I am allowed to share this with other users.