Update parameters from a file or a database in JAVA code, through COMSOL java API

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"); } }


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.