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.
Update parameters from a file or a database in JAVA code, through COMSOL java API
Posted 2025年4月17日 GMT+8 00:18 API, Simulation Apps Version 6.3 0 Replies
Please login with a confirmed email address before reporting spam
I have a Java file for a sample model and would like to develop a process that allows me to update the model parameters directly in the Java code. I want to load the input model parameters either from a file or by connecting to a database. While I see this functionality is available in the UI, I’m interested in achieving this through the Java API.
commands similar to the following be appropriate?
comsolcompile sample_test.java comsolbatch -inputfile sample_test.java -paramfile sample_file.txt | (db_string)
import com.comsol.model.*; import com.comsol.model.util.*;
/** Model exported on Apr 15 2025, 11:34 by COMSOL 6.3.0.335. */ public class runSeriesOfModels {
public static Model run() { Model model = ModelUtil.create("Model");
model.modelPath("C:\Users\fs9357\comsol\temp_files");
//model.label("runSeriesOfModels.mph");
model.param().set("L", "21", "Length"); model.param().set("W", "7", "Width"); model.param().set("rho0", "1140[kg/m^3]", "Density"); model.param().set("E0", "2.13[GPa]", "Young's modulus"); } }
Hello Vishal Singh Bondili
Your Discussion has gone 30 days without a reply. If you still need help with COMSOL and have an on-subscription license, please visit our Support Center for help.
If you do not hold an on-subscription license, you may find an answer in another Discussion or in the Knowledge Base.