1%% ========================================================================
2% Main Model Build Script for COMSOL Multiphysics via MATLAB LiveLink
3% ------------------------------------------------------------------------
4% This script constructs a COMSOL model for low-temperature plasma using
5% chemistry and general input data defined in JSON files. It sets up the
6% full modeling environment, including physics interfaces, parameters,
7% geometry, meshing, solvers, and postprocessing configurations.
8%
9% Institution: Leibniz Institute for Plasma Science and Technology (INP)
10% Date: 10/10/2025
11% =========================================================================
12
13
14%% ====================================
15% === Initialization and input Load ===
16% =====================================
17
18clear inp flags model GeomName ModPath; % Clear previous data
19
20inp.cfg_RKM_file = 'plasma/Ar_Becker_2009.json'; % Define path for reaction kinetic input file
21inp.cfg_General_file = 'applications/Generic2D/General_input_data.json'; % Define path for general model
22 % settings input file
23
24addpath('toolbox'); % Add a path to make the "Toolbox" folder accessible
25
26inp.cfg_RKM_obj = ReadJSON(inp.cfg_RKM_file); % Load chemistry model from JSON input data
27inp.cfg_General_obj = ReadJSON(inp.cfg_General_file); % Load general model settings from JSON input data
28
29inp = InpRKM(inp); % Initialize reaction kinetic model
30flags = struct();
31[inp, flags, ModellingGeo] = InpGeneral(inp, flags); % Initialize general model parameters and geometry
32
33%% ==================================
34% === COMSOL model initialization ===
35% ===================================
36
37% Import COMSOL class in order to use the ModelUtil commands
38import com.comsol.model.*
39import com.comsol.model.util.*
40
41flags.debug = 3; % Set debug level
42
43ModPath = [pwd, '/applications/Generic', ModellingGeo]; % Define model path
44pathParts = strsplit(ModPath, '/');
45BaseName = pathParts{end}; % Define base name
46
47msg(1, sprintf('Creating model %s in %s', BaseName, ModPath), flags); % Display model creation message
48
49% Create COMSOL model and set basic identifiers
50model = ModelUtil.create('Model');
51model.modelPath(ModPath);
52model.name([BaseName '.mph']);
53model.label(BaseName);
54model.modelNode.create('mod1');
55
56% Add project comments and write to file
57ModComment = 'Low-temperature plasma modelling';
58msg(1, ModComment, flags);
59dlmwrite([ModPath '/Comments.txt'], ModComment, 'delimiter', '');
60model.comments(ModComment);
61
62%% =====================
63% === Display input ===
64% ======================
65
66if flags.debug > 0
67 inp % Display the input structure
68end
69
70%% ================================
71% === Core Model Setup Pipeline ===
72% =================================
73
74SetParameters(inp, flags, model); % Set user-defined parameters
75
76addpath(ModPath); % Ensure application path is active
77
78SetGeometry(inp, flags, model); % Define geometry
79
80addpath('toolbox'); % Ensure Toolbox path is active
81
82SetConstants(flags, model); % Set necessary constants
83SetVariables(inp, flags, model); % Define variables
84SetTransportCoefficients(inp, flags, model); % Define transport coefficients
85SetRateCoefficients(inp, flags, model); % Define rate coefficients
86SetEnergyRateCoefficients(inp, flags, model); % Define energy rate coefficients
87SetRates(inp, flags, model); % Define reaction rates
88SetEnergyRates(inp, flags, model); % Define electron energy-related rates
89
90SetFluxes(inp, flags, model); % Set flux terms
91SetSources(inp, flags, model); % Set source terms
92
93AddSurfaceChargeAccumulation(inp, flags, model); % Add equation for surface charge accumulation
94AddPoissonEquation(inp, flags, model); % Add Poisson's equation
95AddFluidEquations(inp, flags, model); % Add fluid equations
96
97SetElectrical(inp, flags, model); % Configure electrical settings
98SetProbesAndGraphs(inp, flags, model); % Configure probes and plots
99
100addpath(ModPath); % Ensure application path is active
101
102SetMesh(inp, flags, model); % Generate computational mesh
103SetProject(inp, flags, model); % Finalize solver, study, and output settings
104
105%% =========================
106% === Save Model to File ===
107% ==========================
108
109mphsave(model, [ModPath, '/', BaseName '.mph']);
110msg(1, sprintf('Model saved to %s.mph', BaseName), flags);
111
112out = model; % Export final model object