### Example: Electrostatics Interface Setup Source: https://doc.comsol.com/6.4/doc/com.comsol.help.comsol/comsol_api_general.47.51.html Example demonstrating the creation of an Electrostatics interface and setting boundary conditions. ```APIDOC ## Java Example ```java model.component("comp1").physics().create("es","Electrostatics","geom1"); model.component("comp1").physics("es").create("gnd1", "Ground", 2); model.component("comp1").physics("es").feature("gnd1").selection().set(new int[]{3, 8}); model.component("comp1").physics("es").create("pot1", "ElectricPotential", 2); model.component("comp1").physics("es").feature("pot1").selection().set(new int[]{4}); model.component("comp1").physics("es").feature("pot1").set("V0", "1"); model.component("comp1").physics("es").feature("ccn1").set("epsilonr_mat", "userdef"); model.component("comp1").physics("es").feature("ccn1").set("epsilonr", "1"); ``` ``` ```APIDOC ## MATLAB Example ```matlab model.component('comp1').physics.create('es','Electrostatics','geom1'); model.component('comp1').physics('es').create('gnd1', 'Ground', 2); model.component('comp1').physics('es').feature('gnd1').selection().set([3, 8]); model.component('comp1').physics('es').create('pot1', 'ElectricPotential', 2); model.component('comp1').physics('es').feature('pot1').selection.set(4); model.component('comp1').physics('es').feature('pot1').set('V0', '1'); model.component('comp1').physics('es').feature('ccn1').set('epsilonr_mat', 'userdef'); model.component('comp1').physics('es').feature('ccn1').set('epsilonr', '1'); ``` ``` -------------------------------- ### Starting COMSOL Installer from Mounted DVD Source: https://doc.comsol.com/6.4/doc/com.comsol.help.comsol/comsol_installation.02.079.html Navigate to the mounted DVD directory and execute the setup script to launch the COMSOL installer. This command assumes the DVD image is mounted at /mnt. ```bash /mnt/setup ``` -------------------------------- ### Automated COMSOL Installation Command Source: https://doc.comsol.com/6.4/doc/com.comsol.help.comsol/comsol_installation.02.053.html Execute this command in the terminal to start the automated installation. Ensure the paths to the setup executable and the answer file are correct. The command structure varies slightly based on the CPU architecture. ```bash /Volumes/COMSOL64_full_macarm64/COMSOL\ 6.4\ Installer.app/Contents/Resources/setup -s /Users/username/Desktop/setupconfig.ini ``` ```bash /Volumes/COMSOL64_full_maci64/COMSOL\ 6.4\ Installer.app/Contents/Resources/setup -s /Users/username/Desktop/setupconfig.ini ``` -------------------------------- ### Start COMSOL Multiphysics with Classkit License Source: https://doc.comsol.com/6.4/doc/com.comsol.help.comsol/comsol_installation.02.071.html Use the -ckl command-line option to start COMSOL Multiphysics with a Classkit License. This example is for macOS. ```bash /Applications/COMSOL64/Multiphysics/bin/comsol -ckl ``` -------------------------------- ### Detailed Programming of a Study Setup Source: https://doc.comsol.com/6.4/doc/com.comsol.help.comsol/application_programming_guide.15.27.html This example shows a more detailed approach to programming a study setup, mirroring the output of 'Record Code' with 'Store complete solver history' enabled. It explicitly defines the Solution data structure and its operations. ```matlab model.study().create("std1"); model.study("std1").create("stat", "Stationary"); model.sol().create("sol1"); model.sol("sol1").study("std1"); model.sol("sol1").create("st1", "StudyStep"); model.sol("sol1").feature("st1").set("study", "std1"); model.sol("sol1").feature("st1").set("studystep", "stat"); model.sol("sol1").create("v1", "Variables"); model.sol("sol1").create("s1", "Stationary"); model.sol("sol1").feature("s1").create("i1", "Iterative"); model.sol("sol1").feature("s1").feature("i1").create("mg1", "Multigrid"); model.sol("sol1").attach("std1"); model.sol("sol1").runAll(); ``` -------------------------------- ### 1D Stationary Heat Transfer Simulation Setup Source: https://doc.comsol.com/6.4/doc/com.comsol.help.comsol/application_programming_guide.15.30.html This comprehensive example demonstrates setting up and running a 1D stationary heat transfer simulation, including geometry, physics, and material definitions. ```java // Set up and run a 1D stationary heat transfer simulation clearModel(model); model.component().create("comp1", true); model.component("comp1").geom().create("geom1", 1); model.component("comp1").mesh().create("mesh1"); model.component("comp1").geom("geom1").create("i1", "Interval"); model.component("comp1").geom("geom1").feature("i1").setIndex("coord", 0.1, 1); model.component("comp1").geom("geom1").run(); model.component("comp1").physics().create("ht", "HeatTransfer", "geom1"); model.component("comp1").material().create("mat1", "Common"); model.component("comp1").material("mat1").label("Steel AISI 4340"); ``` -------------------------------- ### Example Code Source: https://doc.comsol.com/6.4/doc/com.comsol.help.comsol/application_programming_guide.15.40.html Examples demonstrating how to use MainWindow methods and properties. ```APIDOC // Do not show the filename in the application user interface window bar. app.mainWindow().set("showfilename", false); // Set dark application theme. app.mainWindow().set("theme", "$dark"); // Set light image export theme. app.mainWindow().set("imagetheme", "$light"); ``` -------------------------------- ### For Loop Example Source: https://doc.comsol.com/6.4/doc/com.comsol.help.comsol/application_builder_introduction.08.071.html Illustrates how to iterate a specified number of times using a for loop. The loop counter starts from 1. ```Java int N=10; for (int i = 1; i <= N; i++) { // Do something } ``` -------------------------------- ### Example Usage Source: https://doc.comsol.com/6.4/doc/com.comsol.help.comsol/application_programming_guide.15.43.html Examples demonstrating how to use Item methods and properties. ```APIDOC ## Example Code ```java // Set the title of a menu bar item app.mainWindow().menuBar("menu1").set("title", "new title"); // Set the text of a toggle item app.mainWindow().menuBar("menu1").item("toggle_item1").set("text", "test"); ``` ``` -------------------------------- ### Example Code Source: https://doc.comsol.com/6.4/doc/com.comsol.help.comsol/application_programming_guide.15.41.html Illustrative examples of how to use the Form class methods and properties. ```APIDOC ## Example Code ```java app.form("form1").set("icon", "compute.png"); app.form("form1").formObject("button1").set("enabled", false); DataSource ds = app.form("form1").declaration("var"); ``` For examples of how to use the declaration method, see The Main Application Methods. ``` -------------------------------- ### Declaration Access Examples Source: https://doc.comsol.com/6.4/doc/com.comsol.help.comsol/application_programming_guide.15.44.html Examples demonstrating how to access and manipulate declarations using the Java API. ```APIDOC ## Example Code ### Get and Set Scalar Double ```java // Get a scalar double declaration DataSource ds = app.declaration("var"); // The 'var' declaration is a scalar double so we use the getDouble method // to read its value. double cur = ds.getDouble(); // Modifying the local field 'cur' does not affect the value stored in the // data source ds cur = cur + 1; // Set the value of the data source ds.set(cur); ``` ### Accessing Declaration Groups ```java // Retrieve a DeclarationGroup object containing entries of the // "string1" String declarations node DeclarationGroup group = app.declaration().group("string1"); // Retrieve a DeclarationGroup object containing entries of the // "string1" String declarations node under the given form group = app.form("form1").declaration().group("string1"); // Get the value of the "svar" declaration among the entries String value = group.get("svar").getString(); ``` ### Getting Declaration Names ```java // Get the names of all individual declaration variables String[] names = app.declaration().names(); // Get the names of all global primitive declaration nodes names = app.declaration().group().names(); // Get the names of the local primitive declaration nodes of a given form names = app.form("form1").declaration().group().names(); ``` ``` -------------------------------- ### Set up a study sequence for waveguide analysis Source: https://doc.comsol.com/6.4/doc/com.comsol.help.comsol/comsol_api_general.47.60.html This example demonstrates setting up a study sequence involving structural mechanics, boundary mode analysis for a port, and frequency domain wave propagation with manual multigrid levels. It requires creating components, geometries, meshes, and physics interfaces. ```java Model model = ModelUtil.create("Model"); model.component().create("comp1"); model.component("comp1").geom().create("geom1", 3); model.component("comp1").geom("geom1").create("blk1", "Block"); model.component("comp1").geom().run(); model.component("comp1").mesh().create("mesh1", "geom1"); model.component("comp1").mesh().create("mesh2", "geom1"); model.component("comp1").mesh().create("mesh3", "geom1"); model.physics().create("rfw1", "ElectromagneticWaves", "geom1"); model.study().create("seq1"); Study s1 = model.study("seq1"); s1.create("struct","Stationary"); s1.feature("struct").mesh("geom1","mesh1"); s1.create("port","BoundaryModeAnalysis"); s1.feature("port").set("PortName","port1"); s1.feature("port").mesh("geom1","mesh2"); s1.create("wave","Frequency"); s1.feature("wave").mesh("geom1","mesh2"); s1.feature("wave").mglevel().create("mgl1"); s1.feature("wave").mglevel().create("mgl2"); s1.feature("wave").mglevel("mgl2").mesh("geom1","mesh3"); model.physics("rfw1").create("mgl1","Discretization"); model.physics("rfw1").feature("mgl1").set("order","1"); ``` -------------------------------- ### Get Start Time for Explicit Event Source: https://doc.comsol.com/6.4/doc/com.comsol.help.comsol/comsol_api_general.47.59.html Retrieves the current start time setting for an explicit event. ```java model.solverEvent().start(); ``` -------------------------------- ### Get Event Start Time Source: https://doc.comsol.com/6.4/doc/com.comsol.help.comsol/api/com/comsol/model/Event.html Retrieves the start time expression for triggering an explicit event. This specifies when the event should begin. ```java java.lang.String start() ``` -------------------------------- ### Set up a study sequence for waveguide analysis (MATLAB) Source: https://doc.comsol.com/6.4/doc/com.comsol.help.comsol/comsol_api_general.47.60.html This example demonstrates setting up a study sequence involving structural mechanics, boundary mode analysis for a port, and frequency domain wave propagation with manual multigrid levels. It requires creating components, geometries, meshes, and physics interfaces. ```matlab model = ModelUtil.create('Model'); model.component.create('comp1'); model.component('comp1').geom.create('geom1', 3); model.component('comp1').geom('geom1').create('blk1', 'Block'); model.component('comp1').geom.run; model.component('comp1').mesh.create('mesh1', 'geom1'); model.component('comp1').mesh.create('mesh2', 'geom1'); model.component('comp1').mesh.create('mesh3', 'geom1'); model.physics.create('rfw1', 'ElectromagneticWaves', 'geom1'); model.study.create('seq1'); s1 = model.study('seq1'); s1.create('struct','Stationary'); s1.feature('struct').mesh('geom1','mesh1'); s1.create('port','BoundaryModeAnalysis'); s1.feature('port').set('PortName','port1'); s1.feature('port').mesh('geom1','mesh2'); s1.create('wave','Frequency'); s1.feature('wave').mesh('geom1','mesh2'); s1.feature('wave').mglevel.create('mgl1'); s1.feature('wave').mglevel.create('mgl2'); s1.feature('wave').mglevel('mgl2').mesh('geom1','mesh3'); model.physics('rfw1').create('mgl1','Discretization'); model.physics('rfw1').feature('mgl1').set('order','1'); ``` -------------------------------- ### Example Code Source: https://doc.comsol.com/6.4/doc/com.comsol.help.comsol/application_programming_guide.15.54.html Example demonstrating how to configure email server settings, send an email, and attach a report. ```APIDOC /** * Sends an email with the simulation report attached. */ EmailMessage mail = new EmailMessage(); // Custom email server settings used if (isOverrideEmail) { mail.setServer(emailServerHost, emailServerPort); mail.setUser(emailUser, util1.password); mail.setSecurity(emailSecurity); mail.setFrom(emailFromAddress); } mail.setTo(emailTo); mail.setSubject(translate("Tubular_reactor_simulation", true)); mail.setBodyText(translate("The_computation_has_finished._please_find_the_report_attached")); mail.attachFromModel(model.result().report("rpt1")); mail.send(); ``` -------------------------------- ### Get Available Data Types Source: https://doc.comsol.com/6.4/doc/com.comsol.help.comsol/api/com/comsol/model/ResultFeature.html Gets the available data types within a plot rendering. For example, '_Color_' is a possible return value. ```java java.lang.String[] getDataTypes​(int renderIndex) ``` -------------------------------- ### String Length Calculation Source: https://doc.comsol.com/6.4/doc/com.comsol.help.comsol/application_programming_guide.15.03.html Example of how to get the length of a string using the .length() method. ```java int len=str.length(); ``` -------------------------------- ### Get Model Parameter Example Source: https://doc.comsol.com/6.4/doc/com.comsol.help.comsol/application_builder_manual_method_editor.13.21.html Use this code to retrieve the value of a model parameter. ```java model.param().get("w") ``` -------------------------------- ### License File Configuration with Options File Path Source: https://doc.comsol.com/6.4/doc/com.comsol.help.comsol/comsol_installation.02.092.html Example of a VENDOR line in the license.dat file, specifying the port and the path to the options file for license management. ```text VENDOR LMCOMSOL port=1719 options=/usr/local/comsol64/multiphysics/license/LMCOMSOL.opt ``` -------------------------------- ### getVertex (position, number) Source: https://doc.comsol.com/6.4/doc/com.comsol.help.comsol/api/com/comsol/model/MeshSequence.html Gets a block of coordinates for mesh vertices starting from a specified position. ```APIDOC ## getVertex (position, number) ### Description Gets block of coordinates of the mesh vertices. ### Method ```java double[][] getVertex(int position, int number) ``` ### Parameters #### Path Parameters - **position** (int) - Required - Start index. - **number** (int) - Required - Length of block. ### Returns Matrix where each column corresponds to a mesh vertex. ``` -------------------------------- ### Get Feature Double Property Example Source: https://doc.comsol.com/6.4/doc/com.comsol.help.comsol/application_builder_manual_method_editor.13.21.html Use this code to retrieve a double-precision floating-point property of a feature. ```java model.component("comp1").geom("geom1").feature("r1").getDouble("rot") ``` -------------------------------- ### Select Domains for Partitioning Source: https://doc.comsol.com/6.4/doc/com.comsol.help.comsol/comsol_api_geom.48.121.html This example shows how to specify the domains that will be partitioned. The 'domain' property expects a selection object. ```matlab model.component().geom().feature().selection("domain"); ``` -------------------------------- ### Get Names of Declarations Source: https://doc.comsol.com/6.4/doc/com.comsol.help.comsol/application_programming_guide.15.44.html Provides examples for retrieving the names of all declaration variables, both globally and within a specific form. ```java // Get the names of all individual declaration variables String[] names = app.declaration().names(); // Get the names of all global primitive declaration nodes String[] names = app.declaration().group().names(); // Get the names of the local primitive declaration nodes of a given form String[] names = app.form("form1").declaration().group().names(); ``` -------------------------------- ### Run Solver Example Source: https://doc.comsol.com/6.4/doc/com.comsol.help.comsol/application_builder_manual_method_editor.13.21.html Use this code to execute a solver sequence. ```java model.sol("sol1").run(); ``` -------------------------------- ### Example: Setting Domain 1 and 2 in 3D Geometry Source: https://doc.comsol.com/6.4/doc/com.comsol.help.comsol/comsol_api_mesh.49.016.html An example demonstrating how to select specific domains (entities) in a 3D geometry using the set method. ```java model.component().mesh().feature().selection().geom(3).set(new int[]{1,2}); ``` -------------------------------- ### Extracting Substring within Range Source: https://doc.comsol.com/6.4/doc/com.comsol.help.comsol/application_programming_guide.15.03.html Example of extracting a substring within a specified range of start and end indices. ```java String substring(int beginIndex, int endIndex); ``` -------------------------------- ### Configure Automatic Startup for COMSOL License Manager Source: https://doc.comsol.com/6.4/doc/com.comsol.help.comsol/comsol_installation.02.063.html Copy the template plist file to the LaunchDaemons directory and set appropriate permissions. Ensure paths within the plist are correct and a non-root user is specified. ```bash sudo cp /Applications/COMSOL64/Multiphysics/license/macarm64/com.comsol.lmcomsol.plist /Library/LaunchDaemons/ or sudo cp /Applications/COMSOL64/Multiphysics/license/maci64/com.comsol.lmcomsol.plist /Library/LaunchDaemons/ ``` ```bash sudo chmod 600 /Library/LaunchDaemons/com.comsol.lmcomsol.plist ``` ```bash sudo launchctl load -w /Library/LaunchDaemons/com.comsol.lmcomsol.plist ``` -------------------------------- ### getElem (type, position, number) Source: https://doc.comsol.com/6.4/doc/com.comsol.help.comsol/api/com/comsol/model/MeshSequence.html Gets blocks of elements from the mesh based on type, starting position, and number of elements. ```APIDOC ## getElem (type, position, number) ### Description Gets blocks of elements from the mesh. ### Method ```java int[][] getElem(java.lang.String type, int position, int number) ``` ### Parameters #### Path Parameters - **type** (string) - Required - Mesh type. - **position** (int) - Required - Start index. - **number** (int) - Required - Length of block. ### Returns Matrix where each column contains the mesh vertex indices of an element's corners. ``` -------------------------------- ### Start COMSOL Server with MATLAB Source: https://doc.comsol.com/6.4/doc/com.comsol.help.comsol/comsol_installation.02.108.html Launches a COMSOL Multiphysics server and MATLAB Desktop without the COMSOL GUI. Use this for server-only operations. ```bash comsol mphserver matlab ``` -------------------------------- ### forUpdateBranch() Source: https://doc.comsol.com/6.4/doc/com.comsol.help.comsol/api/index-all.html Get a generator for input parameters used when updating the settings of a branch in a repository (including, for example, renaming the branch). ```APIDOC ## forUpdateBranch() ### Description Get a generator for input parameters used when updating the settings of a branch in a repository (including, for example, renaming the branch). ### Method (Not specified, assumed to be a method call) ### Endpoint (Not applicable for SDK methods) ### Parameters (No parameters specified) ### Request Example (Not applicable for SDK methods) ### Response (Not specified, assumed to return a parameter generator object) ``` -------------------------------- ### UpdateSnapshotParamGenerator Source: https://doc.comsol.com/6.4/doc/com.comsol.help.comsol/api/com/comsol/api/database/param/DatabaseApiParamGenerators.html Get a generator for input parameters used when updating the settings of a snapshot in a repository (including, for example, renaming the snapshot). ```APIDOC UpdateSnapshotParamGenerator forUpdateSnapshot() ``` -------------------------------- ### Creating and Configuring Unit Systems Source: https://doc.comsol.com/6.4/doc/com.comsol.help.comsol/comsol_api_general.47.62.html Demonstrates how to create a new unit system, define base units, add derived units with their definitions, and specify additional units with offsets. ```APIDOC ## Unit System Operations ### Description Provides methods for creating and managing unit systems within the COMSOL model. ### Methods - `model.unitSystem().create(String tagName)`: Creates a new unit system with the specified tag. - `us.baseUnit().create(String tag, String symbol, String quantity)`: Creates a base unit for a given physical quantity. - `us.derivedUnit().create(String tag, int[] powers)`: Creates a derived unit with specified powers for base dimensions. - `us.derivedUnit(String tag).definition(String[] units, int[] powers)`: Sets the definition of a derived unit in terms of other units and their powers. - `us.additionalUnit().create(String tag, int[] dim)`: Creates an additional unit. - `us.additionalUnit(String tag).offset(double offset)`: Sets the offset for an additional unit. - `us.additionalUnit(String tag).scale(double scale)`: Sets the scale for an additional unit. - `us.additionalUnit(String tag).symbol(String symbol)`: Sets the symbol for an additional unit. - `us.derivedUnit(String tag).symbol(String symbol)`: Sets the symbol for a derived unit. ### Example (Java) ```java Model model = ModelUtil.create("Model"); UnitSystem us = model.unitSystem().create("cgs2"); model.baseSystem("cgs2"); us.baseUnit().create("centimeter","cm","length"); us.derivedUnit().create("meter_per_second",new int[]{1,0,-1,0,0,0,0,0}); Unit du = us.derivedUnit("meter_per_second"); du.definition(new String[]{"meter","second"},new int[]{1,-1,0,0,0,0,0,0}); Unit au = us.additionalUnit().create("celsius",new int[]{0,0,0,0,1,0,0,0}); au.offset(273.15); ``` ### Example (MATLAB) ```matlab model = ModelUtil.create('Model'); us = model.unitSystem.create('cgs2'); model.baseSystem('cgs2'); us.baseUnit.create('centimeter','cm','length'); us.derivedUnit.create('meter_per_second',[1,0,-1,0,0,0,0,0]); du = us.derivedUnit('meter_per_second'); du.definition({'meter','second'},[1,-1,0,0,0,0,0,0]); au = us.additionalUnit.create('celsius',[0,0,0,0,1,0,0,0]); au.offset(273.15); ``` ``` -------------------------------- ### Create Shortcut for COMSOL with Simulink Source: https://doc.comsol.com/6.4/doc/com.comsol.help.comsol/comsol_installation.02.041.html Launch COMSOL with Simulink by adding 'simulink' to the 'comsolmphserver.exe' path in the shortcut's Target field. Adjust the executable path if necessary. ```batch "C:\Program Files\COMSOL\COMSOL64\Multiphysics\bin\win64\comsolmphserver.exe" simulink ``` -------------------------------- ### UpdateBranchParamGenerator Source: https://doc.comsol.com/6.4/doc/com.comsol.help.comsol/api/com/comsol/api/database/param/DatabaseApiParamGenerators.html Get a generator for input parameters used when updating the settings of a branch in a repository (including, for example, renaming the branch). ```APIDOC UpdateBranchParamGenerator forUpdateBranch() ``` -------------------------------- ### Grid File Example for Importing Data Source: https://doc.comsol.com/6.4/doc/com.comsol.help.comsol/comsol_ref_definitions.21.067.html This example demonstrates the structure of a grid file used for importing data. It includes grid points and corresponding data values for a 2D function. ```text %Grid 0 1 2 3 4 0 1 2 3 %Data 0 1 4 9 16 1 2 5 10 17 2 3 6 11 18 3 4 7 12 19 ``` -------------------------------- ### C++ External Function Interface Example Source: https://doc.comsol.com/6.4/doc/com.comsol.help.comsol/comsol_api_general.47.34.html Example C++ code for defining an external function 'extsinc' that computes the sinc function. It includes initialization, error handling, and function evaluation logic. Ensure correct compiler setup for your platform. ```cpp #include #include #include #ifdef _MSC_VER #define EXPORT __declspec(dllexport) #else #define EXPORT #endif static const char *error = NULL; EXPORT int init(const char *str) { return 1; } EXPORT const char * getLastError() { return error; } EXPORT int eval(const char *func, int nArgs, const double **inReal, const double **inImag, int blockSize, double *outReal, double *outImag) { if (strcmp("extsinc", func) == 0) { if (nArgs != 1) { error = "One argument expected"; return 0; } for (int i = 0; i < blockSize; i++) { double x = inReal[0][i]; outReal[i] = (x == 0) ? 1 : sin(x) / x; } return 1; } else { error = "Unknown function"; return 0; } } ``` -------------------------------- ### Get Vector Block Source: https://doc.comsol.com/6.4/doc/com.comsol.help.comsol/comsol_api_solver.51.30.html Retrieves a block of real values from a vector. Specify the vector name and the start and stop indices for the block. ```java solver.feature(fname).getVectorBlock(vname,start,stop) ``` -------------------------------- ### setupDomainDecompositionSolver Source: https://doc.comsol.com/6.4/doc/com.comsol.help.comsol/api/com/comsol/model/SolverSequence.html Sets up a domain decomposition solver based on the current solver configuration. ```APIDOC ## setupDomainDecompositionSolver ### Description Setup a domain decomposition solver based on the current solver. ### Method ```java void setupDomainDecompositionSolver​(java.lang.String solverOperationID) ``` ### Parameters * `solverOperationID` (String) - Required - Type of domain decomposition solver. ``` -------------------------------- ### Start COMSOL with Classkit License Source: https://doc.comsol.com/6.4/doc/com.comsol.help.comsol/comsol_installation.02.105.html Use the -ckl option when launching COMSOL Multiphysics from the command line to enable Classkit licensing. ```bash comsol -ckl ``` -------------------------------- ### UpdateCommitParamGenerator Source: https://doc.comsol.com/6.4/doc/com.comsol.help.comsol/api/com/comsol/api/database/param/DatabaseApiParamGenerators.html Get a generator for input parameters used when updating the settings of a commit (including, for example, modifying the comment associated with the commit). ```APIDOC UpdateCommitParamGenerator forUpdateCommit() ``` -------------------------------- ### Update Snapshot Source: https://doc.comsol.com/6.4/doc/com.comsol.help.comsol/api/com/comsol/api/database/param/DatabaseApiParamGenerators.html Get a generator for input parameters used when updating the settings of a snapshot in a repository (including, for example, renaming the snapshot). ```java UpdateSnapshotParamGenerator forUpdateSnapshot() ``` -------------------------------- ### Update Branch Source: https://doc.comsol.com/6.4/doc/com.comsol.help.comsol/api/com/comsol/api/database/param/DatabaseApiParamGenerators.html Get a generator for input parameters used when updating the settings of a branch in a repository (including, for example, renaming the branch). ```java UpdateBranchParamGenerator forUpdateBranch() ``` -------------------------------- ### Create Component, Geometry, and Analytic Function Source: https://doc.comsol.com/6.4/doc/com.comsol.help.comsol/comsol_api_general.47.23.html Example demonstrating how to create a new component, assign a geometry to it, and create an analytic function. ```APIDOC ## Create Component, Geometry, and Analytic Function ### Description This example shows the basic steps to initialize a COMSOL model by creating a component, defining a 3D geometry within that component, and adding an analytic function. ### Example (Java) ```java model.component().create("comp1"); model.component("comp1").geom().create("geom1", 3); model.component("comp1").func().create("an1", "Analytic"); ``` ### Example (MATLAB) ```matlab model.component.create('comp1'); model.component('comp1').geom.create('geom1', 3); model.component('comp1').func.create('an1', 'Analytic'); ``` ``` -------------------------------- ### Get Vector Block (Imaginary) Source: https://doc.comsol.com/6.4/doc/com.comsol.help.comsol/comsol_api_solver.51.30.html Retrieves a block of imaginary values from a vector. Specify the vector name and the start and stop indices for the block. ```java solver.feature(fname).getVectorImagBlock(vname,start,stop) ``` -------------------------------- ### Using Multiple Argument Files Source: https://doc.comsol.com/6.4/doc/com.comsol.help.comsol/application_builder_manual_tools.11.24.html Example command line using '-appargvarlist' and '-appargfilelist' to specify variables and their corresponding data files. ```bash comsol -run myapp.mph -appargvarlist temperature,voltage -appargfilelist , ``` -------------------------------- ### Install xterm on OpenSUSE Source: https://doc.comsol.com/6.4/doc/com.comsol.help.comsol/comsol_installation.02.109.html Use this command to install the 'xterm' package, which is required for running 'comsol mphserver simulink', on OpenSUSE. ```bash sudo zypper install xterm ``` -------------------------------- ### Get Geometry Attribute Label Source: https://doc.comsol.com/6.4/doc/com.comsol.help.comsol/comsol_api_geom.48.020.html Retrieves the localized display label for a geometry attribute. Examples include 'Construction geometry' or 'PCB component'. ```matlab model.geom().attribute().label(); ``` -------------------------------- ### UpdateRepositoryParamGenerator Source: https://doc.comsol.com/6.4/doc/com.comsol.help.comsol/api/com/comsol/api/database/param/DatabaseApiParamGenerators.html Get a generator for input parameters used when updating the settings of a repository in a Model Manager database (including, for example, renaming the repository). ```APIDOC UpdateRepositoryParamGenerator forUpdateRepository() ``` -------------------------------- ### Create and Configure a Stationary Solver (Java) Source: https://doc.comsol.com/6.4/doc/com.comsol.help.comsol/comsol_api_general.47.58.html Creates a new solution, configures a stationary solver step, and sets study and study step information. This is used for setting up basic solver configurations. ```java model.sol().create("s","step1","vars1"); model.sol("s").feature("step1").set("study","st1"); model.sol("s").feature("step1").set("studystep","stat1"); model.sol("s").create("solver1","Stationary"); ``` -------------------------------- ### Display Application Help Text Source: https://doc.comsol.com/6.4/doc/com.comsol.help.comsol/application_builder_manual_tools.11.24.html Use this command to display the help text for an application's input arguments when launching from the command line. ```bash comsol -help myapp.mph ``` -------------------------------- ### Update Commit Source: https://doc.comsol.com/6.4/doc/com.comsol.help.comsol/api/com/comsol/api/database/param/DatabaseApiParamGenerators.html Get a generator for input parameters used when updating the settings of a commit (including, for example, modifying the comment associated with the commit). ```java UpdateCommitParamGenerator forUpdateCommit() ``` -------------------------------- ### Create Repository (Default Settings) Source: https://doc.comsol.com/6.4/doc/com.comsol.help.comsol/api/com/comsol/api/database/Database.html Creates a new repository with default settings, including an automatically created default branch. ```java Repository createRepository(java.lang.String name, java.lang.String commitComment) ``` -------------------------------- ### SourceFileParamGenerator Source: https://doc.comsol.com/6.4/doc/com.comsol.help.comsol/api/com/comsol/api/database/param/DatabaseApiParamGenerators.html Get a generator for input parameters used when updating an existing file item (including, for example, updating its title, description, or assigned tags). ```APIDOC ## forSourceFile ### Description Get a generator for input parameters used when updating an existing file item (including, for example, updating its title, description, or assigned tags). ### Method N/A ### Endpoint N/A ### Parameters N/A ### Request Example N/A ### Response #### Success Response (N/A) - **generator** (SourceFileParamGenerator) - A generator for input parameters used when updating an existing file item. ### Response Example N/A ``` -------------------------------- ### SaveFileItemParamGenerator Source: https://doc.comsol.com/6.4/doc/com.comsol.help.comsol/api/com/comsol/api/database/param/DatabaseApiParamGenerators.html Get a generator for input parameters used when updating an existing model item (including, for example, updating its title, description, or assigned tags). ```APIDOC ## forSaveFile ### Description Get a generator for input parameters used when updating an existing model item (including, for example, updating its title, description, or assigned tags). ### Method N/A ### Endpoint N/A ### Parameters N/A ### Request Example N/A ### Response #### Success Response (N/A) - **generator** (SaveFileItemParamGenerator) - A generator for input parameters used when updating an existing model item. ### Response Example N/A ``` -------------------------------- ### Quickly Generate and Run a Study Source: https://doc.comsol.com/6.4/doc/com.comsol.help.comsol/application_programming_guide.15.27.html This method provides a shortcut for generating the solver sequence automatically. Use `createAutoSequences("all")` followed by `run()` to quickly set up and execute a study. ```matlab model.study("std1").createAutoSequences("all"); model.study("std1").run(); ``` -------------------------------- ### SaveModelItemParamGenerator Source: https://doc.comsol.com/6.4/doc/com.comsol.help.comsol/api/com/comsol/api/database/param/DatabaseApiParamGenerators.html Get a generator for input parameters used when updating an existing tag item (including, for example, updating its title or assigned parent tags). ```APIDOC ## forSaveModel ### Description Get a generator for input parameters used when updating an existing tag item (including, for example, updating its title or assigned parent tags). ### Method N/A ### Endpoint N/A ### Parameters N/A ### Request Example N/A ### Response #### Success Response (N/A) - **generator** (SaveModelItemParamGenerator) - A generator for input parameters used when updating an existing tag item. ### Response Example N/A ``` -------------------------------- ### Setting up a 3D Heat Transfer Simulation in COMSOL API Source: https://doc.comsol.com/6.4/doc/com.comsol.help.comsol/application_programming_guide.15.74.html This snippet demonstrates the setup of a 3D stationary heat transfer simulation, including geometry creation, material assignment, physics configuration, and study setup. ```java clearModel(model); model.component().create("comp1", true); model.component("comp1").geom().create("geom1", 3); model.component("comp1").geom("geom1").geomRep("comsol"); model.component("comp1").mesh().create("mesh1"); model.component("comp1").geom("geom1").create("cyl1", "Cylinder"); model.component("comp1").geom("geom1").feature("cyl1").set("h", 0.1); model.component("comp1").geom("geom1").feature("cyl1").set("r", 0.005); model.component("comp1").geom("geom1").run(); model.component("comp1").geom("geom1").create("arr1", "Array"); model.component("comp1").geom("geom1").feature("arr1").selection("input").set("cyl1"); model.component("comp1").geom("geom1").feature("arr1").set("fullsize", new int[]{3, 3, 1}); model.component("comp1").geom("geom1").feature("arr1").set("displ", new double[]{0.02, 0.02, 0}); model.component("comp1").geom("geom1").run(); model.component("comp1").physics().create("ht", "HeatTransfer", "geom1"); model.component("comp1").material().create("mat1", "Common"); model.component("comp1").material("mat1").label("Steel AISI 4340"); model.component("comp1").material("mat1").propertyGroup("def").set("density", "7850[kg/m^3]"); model.component("comp1").material("mat1").propertyGroup("def").set("heatcapacity", "475[J/(kg*K)]"); model.component("comp1").material("mat1").propertyGroup("def") .set("thermalconductivity", new String[]{"44.5[W/(m*K)]", "0", "0", "0", "44.5[W/(m*K)]", "0", "0", "0", "44.5[W/(m*K)]"}); model.func().create("rn1", "Random"); model.func("rn1").set("type", "uniform"); model.func("rn1").set("nargs", 3); model.func("rn1").set("mean", 0.5); model.component("comp1").physics("ht").create("temp1", "TemperatureBoundary", 2); model.component("comp1").physics("ht").feature("temp1").set("T0", "300[K]"); int[] bnds = new int[]{3, 7, 11, 21, 25, 29, 39, 43, 47}; model.component("comp1").physics("ht").feature("temp1").selection().set(bnds); model.component("comp1").physics("ht").create("hs1", "HeatSource", 3); int[] doms = new int[]{1, 2, 3, 4, 5, 6, 7, 8, 9}; model.component("comp1").physics("ht").feature("hs1").selection().set(doms); model.component("comp1").physics("ht").feature("hs1").set("Q0", "1e6*(1+rn1(x,y,z))"); model.study().create("std1"); model.study("std1").create("stat", "Stationary"); model.study("std1").feature("stat").setSolveFor("/physics/ht", true); model.study("std1").createAutoSequences("all"); model.sol("sol1").runAll(); model.result().create("pg1", "PlotGroup3D"); model.result("pg1").label("Temperature (ht)"); model.result("pg1").feature().create("vol1", "Volume"); model.result("pg1").feature("vol1").set("colortable", "HeatCameraLight"); model.result("pg1").run(); ``` -------------------------------- ### UpdateTagItemParamGenerator Source: https://doc.comsol.com/6.4/doc/com.comsol.help.comsol/api/com/comsol/api/database/param/DatabaseApiParamGenerators.html Get a generator for input parameters used when updating an existing tag item (including, for example, updating its title or assigned parent tags). ```APIDOC UpdateTagItemParamGenerator forUpdateTag() ``` -------------------------------- ### Create and Reference Meshing Sequences (Java) Source: https://doc.comsol.com/6.4/doc/com.comsol.help.comsol/comsol_api_mesh.49.094.html Demonstrates creating two meshing sequences, one with scaling, and then referencing the first sequence from the second in Java. Use this to create coarser versions of existing meshes. ```java Model model = ModelUtil.create("Model"); model.component().create("comp1"); GeomSequence g = model.component("comp1").geom().create("geom1", 2); MeshSequence m1 = model.component("comp1").mesh().create("mesh1", "geom1"); g.create("sq1", "Square"); g.create("sq2", "Square"); g.feature("sq2").set("size", "0.5"); g.run(); m1.create("map1", "Map"); m1.feature("map1").selection().geom("geom1", 2).set(new int[]{1}); m1.create("ftri1", "FreeTri"); m1.feature("ftri1").selection().geom("geom1", 2).set(new int[]{2}); m1.run(); MeshSequence m2 = model.mesh().create("mesh2", "geom1"); m2.create("sca1", "Scale"); m2.feature("sca1").set("scale", "2"); m2.create("rf1", "Reference"); m2.feature("rf1").set("sequence", "mesh1"); m2.run(); ``` -------------------------------- ### UpdateModelItemParamGenerator Source: https://doc.comsol.com/6.4/doc/com.comsol.help.comsol/api/com/comsol/api/database/param/DatabaseApiParamGenerators.html Get a generator for input parameters used when updating an existing model item (including, for example, updating its title, description, or assigned tags). ```APIDOC UpdateModelItemParamGenerator forUpdateModel() ``` -------------------------------- ### Example: Idealized Bouncing Ball Simulation Source: https://doc.comsol.com/6.4/doc/com.comsol.help.comsol/comsol_api_general.47.59.html This example demonstrates setting up a transient study with non-discrete and discrete states, an implicit event, and reinitialization for simulating a bouncing ball. ```java Model model = ModelUtil.create("Model"); model.study().create("std1"); model.study("std1").create("time1", "Transient"); model.study("std1").feature("time1").set("tlist", "0 10"); model.study("std1").feature("time1").set("rtol", 1e-6); // Nondiscrete states model.ode().create("ode1"); model.ode("ode1").ode("y", "-2*y-ytt"); model.init().create("ode1"); model.init("ode1").selection().global(); model.init("ode1").set("y", "1"); // Discrete states model.ode().create("ode2").type("quadrature"); model.ode("ode2").ode("z1", "y"); // Implicit event model.solverEvent().create("impl1", "Implicit"); model.solverEvent("impl1").condition("!(z1>=0)"); model.solverEvent("impl1").reinit().create("reinit"); ``` -------------------------------- ### UpdateFileItemParamGenerator Source: https://doc.comsol.com/6.4/doc/com.comsol.help.comsol/api/com/comsol/api/database/param/DatabaseApiParamGenerators.html Get a generator for input parameters used when updating an existing file item (including, for example, updating its title, description, or assigned tags). ```APIDOC UpdateFileItemParamGenerator forUpdateFile() ``` -------------------------------- ### Update Repository Source: https://doc.comsol.com/6.4/doc/com.comsol.help.comsol/api/com/comsol/api/database/param/DatabaseApiParamGenerators.html Get a generator for input parameters used when updating the settings of a repository in a Model Manager database (including, for example, renaming the repository). ```java UpdateRepositoryParamGenerator forUpdateRepository() ``` -------------------------------- ### SearchItemVersions Example Source: https://doc.comsol.com/6.4/doc/com.comsol.help.comsol/api/com/comsol/api/database/param/package-summary.html An example demonstrating how to use parameter generators to search for item versions with specific criteria, including filtering by save type and data size, and sorting the results. ```APIDOC ## SearchItemVersions with Parameter Generators ### Description Searches for all draft versions having built, computed, and plotted data larger than 1 MB, returning the result as a stream sorted by the computed data size in decreasing order. ### Method `database.searchItemVersions(...)` ### Parameters Uses parameter generators to construct the search criteria. ### Request Example ```java Database database = DatabaseApiUtil.api().databaseByAlias("My Database"); SearchItemVersionResultStream resultStream = database .searchItemVersions(DatabaseApiUtil.param() .forSearchItemVersions() .withSearchFilters("@itemSaveType:draft", "@computedData:[1MB TO *]") .withSortByComputedData() .withSortDescending()); ``` ### Response - **resultStream** (SearchItemVersionResultStream) - A stream of search results. ``` -------------------------------- ### Manually Starting the License Manager Source: https://doc.comsol.com/6.4/doc/com.comsol.help.comsol/comsol_installation.02.032.html Use this command in a Windows command window to start the license manager manually. It specifies the license file and the debug log file. ```bash lmgrd -c ..\license.dat -l ..\comsol64.log ``` -------------------------------- ### Get Sparse Matrix Column Block Source: https://doc.comsol.com/6.4/doc/com.comsol.help.comsol/comsol_api_solver.51.30.html Retrieves a block of column indices for a sparse matrix. Specify the matrix name and the start and stop indices for the block. ```java solver.feature(fname).getSparseMatrixColBlock(mname,start,stop) ``` -------------------------------- ### Creating and Configuring Weak Form Equations Source: https://doc.comsol.com/6.4/doc/com.comsol.help.comsol/comsol_api_general.47.65.html Demonstrates the creation of weak form equations, assignment of integration rules, and setting of weak expressions. It also shows how to assign these equations to a named selection. ```APIDOC ## Creating and Configuring Weak Form Equations ### Description This operation allows for the creation of weak form equations, the assignment of integration rules, and the definition of weak expressions. It also covers assigning these equations to a specified named selection. ### Syntax ``` model.weak().create(); model.weak().weak(); model.weak().weak(,); model.weak().intRule(); model.weak().intRule(,); model.weak().condition(); model.weak().selection().named(); ``` ### Parameters - `` (string): A unique identifier for the weak form equations. - `` (string or string array): A list of weak expressions. - `` (integer): The position in the list of equations or integration rules. - `` (string): A single weak expression. - `` (list): A list of integration rules. Must have the same length as the list of equations or be of length 1. - `` (string): A single integration rule. - `` (string): A conditional expression for assembly. - `` (string): The tag of the named selection to assign the weak equations to. ### Example (Java) ```java model.weak().create("w1").selection().named("dom1"); model.weak("w1").intRule("gp1"); model.weak("w1").weak(new String[]{"u*test(u)","v*test(v)"}); ``` ### Example (MATLAB) ```matlab model.weak.create('w1').selection.named('dom1'); model.weak('w1').intRule('gp1'); model.weak('w1').weak({'u*test(u)','v*test(v)'}); ``` ``` -------------------------------- ### Get Sparse Matrix Row Block Source: https://doc.comsol.com/6.4/doc/com.comsol.help.comsol/comsol_api_solver.51.30.html Retrieves a block of row indices for a sparse matrix. Specify the matrix name and the start and stop indices for the block. ```java solver.feature(fname).getSparseMatrixRowBlock(mname,start,stop) ``` -------------------------------- ### Specifying Custom Command-Line Arguments Source: https://doc.comsol.com/6.4/doc/com.comsol.help.comsol/application_builder_manual_tools.11.24.html Example of a command line specifying custom application arguments 'width' and 'height' along with a built-in argument for the renderer. ```bash comsol -run myapp.mph -3drend ogl -appargnames width,height -appargvalues 12.3,7.4 ``` -------------------------------- ### SaveFileItemParamGenerator forSaveFile Source: https://doc.comsol.com/6.4/doc/com.comsol.help.comsol/api/com/comsol/api/database/param/DatabaseApiParamGenerators.html Get a generator for input parameters used when updating an existing model item (including, for example, updating its title, description, or assigned tags). ```java SaveFileItemParamGenerator forSaveFile() ``` -------------------------------- ### SaveModelItemParamGenerator forSaveModel Source: https://doc.comsol.com/6.4/doc/com.comsol.help.comsol/api/com/comsol/api/database/param/DatabaseApiParamGenerators.html Get a generator for input parameters used when updating an existing tag item (including, for example, updating its title or assigned parent tags). ```java SaveModelItemParamGenerator forSaveModel() ``` -------------------------------- ### Get Sparse Matrix Value Block (Imaginary) Source: https://doc.comsol.com/6.4/doc/com.comsol.help.comsol/comsol_api_solver.51.30.html Retrieves a block of imaginary values from a sparse matrix. Specify the matrix name and the start and stop indices for the block. ```java solver.feature(fname).getSparseMatrixValImagBlock(mname,start,stop) ``` -------------------------------- ### Create and Run a Basic Stationary Study Source: https://doc.comsol.com/6.4/doc/com.comsol.help.comsol/application_programming_guide.15.27.html This snippet demonstrates the simplest way to create a study, add a Stationary study step, and run it. The `run()` method automatically generates and executes the solver sequence. ```matlab model.study().create("std1"); // Study with tag std1 model.study("std1").create("stat", "Stationary"); model.study("std1").run(); ``` -------------------------------- ### Get Sparse Matrix Value Block (Real) Source: https://doc.comsol.com/6.4/doc/com.comsol.help.comsol/comsol_api_solver.51.30.html Retrieves a block of real values from a sparse matrix. Specify the matrix name and the start and stop indices for the block. ```java solver.feature(fname).getSparseMatrixValBlock(mname,start,stop) ``` -------------------------------- ### Start COMSOL Multiphysics Server for Simulink Source: https://doc.comsol.com/6.4/doc/com.comsol.help.comsol/comsol_installation.02.109.html Run this command in your terminal to launch a COMSOL Multiphysics server and connect it to MATLAB Desktop for Simulink integration. The COMSOL GUI will not open. ```bash comsol mphserver simulink ``` -------------------------------- ### Update Tag Item Source: https://doc.comsol.com/6.4/doc/com.comsol.help.comsol/api/com/comsol/api/database/param/DatabaseApiParamGenerators.html Get a generator for input parameters used when updating an existing tag item (including, for example, updating its title or assigned parent tags). ```java UpdateTagItemParamGenerator forUpdateTag() ``` -------------------------------- ### Start COMSOL Server with MATLAB using Graphics Source: https://doc.comsol.com/6.4/doc/com.comsol.help.comsol/comsol_installation.02.108.html Starts COMSOL Multiphysics with MATLAB and enables the graphics server to display plots in a COMSOL graphics window. Use the -graphics flag for visual output. ```bash comsol mphserver matlab -graphics ``` -------------------------------- ### Update Model Item Source: https://doc.comsol.com/6.4/doc/com.comsol.help.comsol/api/com/comsol/api/database/param/DatabaseApiParamGenerators.html Get a generator for input parameters used when updating an existing model item (including, for example, updating its title, description, or assigned tags). ```java UpdateModelItemParamGenerator forUpdateModel() ``` -------------------------------- ### Creating and Setting Element Properties Source: https://doc.comsol.com/6.4/doc/com.comsol.help.comsol/comsol_api_general.47.27.html Demonstrates how to create a new element of a specified type and set its properties. This includes setting fields like 'name', 'file', and 'method'. ```APIDOC ## model.elem() ### Description Provides methods for creating and manipulating elements within the COMSOL model. ### Methods - `create(, eltype)`: Creates a new element of type `eltype` with the given tag. - `set(, value)`: Sets the field tagged `` to `value` for the selected element. ### Examples #### Java ```java model.elem().create("fun1","elinterp"); model.elem("fun1").set("name",new String[]{"sol"}); model.elem("fun1").set("file","solution_data.txt"); model.elem("fun1").set("fileindex",new String[]{"1"}); model.elem("fun1").set("defvars",new String[]{"true"}); model.elem("fun1").set("method",new String[]{"linear"}); model.elem("fun1").set("extmethod",new String[]{"const"}); ``` #### MATLAB ```matlab model.elem.create('fun1','elinterp'); model.elem('fun1').set('name',{'sol'}); model.elem('fun1').set('file','solution_data.txt'); model.elem('fun1').set('fileindex',{'1'}); model.elem('fun1').set('defvars',{'true'}); model.elem('fun1').set('method',{'linear'}); model.elem('fun1').set('extmethod',{'const'}); ``` ```