-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathwrite_input_file.m
More file actions
58 lines (50 loc) · 1.61 KB
/
write_input_file.m
File metadata and controls
58 lines (50 loc) · 1.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
function write_input_file(newInputFile, nodesFile, bcfile, mat_param)
%
% This function simply reads the template.inp file and replaces the
% names of the necessary files by the random string-based file names
% generated by the MATLAB codes.
%
originalFile = 'template.inp';
% Read txt into cell A
fid = fopen(originalFile,'r');
i = 1;
tline = fgetl(fid);
A{i} = tline;
while ischar(tline)
i = i+1;
tline = fgetl(fid);
% Add the Nodes file
k = strfind(tline, 'Add Nodes File');
if (numel(k) > 0)
tline = strrep(tline, 'Add Nodes File', nodesFile);
end
% Add Material Parameters
k = strfind(tline, 'Add Material Substrate Properties');
if (numel(k) > 0)
tline = strrep(tline, 'Add Material Substrate Properties',['Hyperelastic, mooney-rivlin', newline,...
num2str(mat_param(1)), ',', num2str(mat_param(2)),',', num2str(mat_param(3))]);
end
k = strfind(tline, 'Add Material Kirigami Properties');
if (numel(k) > 0)
tline = strrep(tline, 'Add Material Kirigami Properties',['Hyperelastic, mooney-rivlin', newline,...
num2str(mat_param(4)), ',', num2str(mat_param(5)),',', num2str(mat_param(6))]);
end
% Add the Boundary Condition file
k = strfind(tline, 'Add Boundary Conditions File');
if (numel(k) > 0)
tline = strrep(tline, 'Add Boundary Conditions File', bcfile);
end
A{i} = tline;
end
fclose(fid);
% Write cell A into txt
fid = fopen(newInputFile, 'w');
for i = 1:numel(A)
if A{i+1} == -1
fprintf(fid,'%s', A{i});
break
else
fprintf(fid,'%s\n', A{i});
end
end
end