├── Trans3d.m ├── .gitattributes ├── ImportInp.m ├── .gitignore ├── RotAAx3d.m ├── README.md ├── ABAQUS_to_FLAC3d.m ├── ExportZone.m ├── LoadPart.m ├── LoadSet.m ├── ExportLinerSEL_NodePrior.m ├── LoadInstance.m └── ExportCPSEL.m /Trans3d.m: -------------------------------------------------------------------------------- 1 | function [ P1 ] = Trans3d( P, v ) 2 | % Translate input point array P to P1 using given translation vector v 3 | P1 = zeros(size(P, 1), 3); 4 | for i = 1:size(P, 1) 5 | P1(i,:) = P(i,:) + v; 6 | end 7 | end 8 | 9 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | 4 | # Custom for Visual Studio 5 | *.cs diff=csharp 6 | 7 | # Standard to msysgit 8 | *.doc diff=astextplain 9 | *.DOC diff=astextplain 10 | *.docx diff=astextplain 11 | *.DOCX diff=astextplain 12 | *.dot diff=astextplain 13 | *.DOT diff=astextplain 14 | *.pdf diff=astextplain 15 | *.PDF diff=astextplain 16 | *.rtf diff=astextplain 17 | *.RTF diff=astextplain 18 | -------------------------------------------------------------------------------- /ImportInp.m: -------------------------------------------------------------------------------- 1 | function [ InputModel ] = ImportInp( InputFileName ) 2 | % Read .inp file named InputFileName 3 | % InputFileName is a string 4 | fid = fopen(InputFileName); 5 | InputModel = cell(1e6, 1); 6 | i = 0; 7 | tline = fgetl(fid); 8 | while ischar(tline) 9 | i = i + 1; 10 | InputModel{i} = tline; 11 | tline = fgetl(fid); 12 | end 13 | fclose(fid); 14 | InputModel = InputModel(1:i); 15 | end 16 | 17 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Windows image file caches 2 | Thumbs.db 3 | ehthumbs.db 4 | 5 | # Folder config file 6 | Desktop.ini 7 | 8 | # Recycle Bin used on file shares 9 | $RECYCLE.BIN/ 10 | 11 | # Windows Installer files 12 | *.cab 13 | *.msi 14 | *.msm 15 | *.msp 16 | 17 | # Windows shortcuts 18 | *.lnk 19 | 20 | # ========================= 21 | # Operating System Files 22 | # ========================= 23 | 24 | # OSX 25 | # ========================= 26 | 27 | .DS_Store 28 | .AppleDouble 29 | .LSOverride 30 | 31 | # Thumbnails 32 | ._* 33 | 34 | # Files that might appear in the root of a volume 35 | .DocumentRevisions-V100 36 | .fseventsd 37 | .Spotlight-V100 38 | .TemporaryItems 39 | .Trashes 40 | .VolumeIcon.icns 41 | 42 | # Directories potentially created on remote AFP share 43 | .AppleDB 44 | .AppleDesktop 45 | Network Trash Folder 46 | Temporary Items 47 | .apdisk 48 | -------------------------------------------------------------------------------- /RotAAx3d.m: -------------------------------------------------------------------------------- 1 | function [ P1 ] = RotAAx3d( P, Sp, Ep, Deg ) 2 | % Rotate point array P to P1 about axis defined by start point Sp and end 3 | % point Ep for degree Deg 4 | % All input and output variables are non-homogeneous 5 | PNum = size(P, 1); 6 | P1 = ones(PNum, 4); 7 | %----------------------Homogenization---------------------- 8 | P(:, 4) = ones(PNum, 1); 9 | %-------------Translation matrix: Translate axis from Sp to origin----- 10 | T = eye(4); 11 | T(4, 1:3) = -Sp; 12 | EpT = Ep - Sp; % Translated end point of the axis 13 | %-------------Translation matrix: Rotate axis to xoz plane------------ 14 | Rx = eye(4); 15 | Rx(2, 2) = EpT(3) / sqrt(EpT(2)^2 + EpT(3)^2); 16 | Rx(3, 3) = Rx(2, 2); 17 | Rx(2, 3) = EpT(2) / sqrt(EpT(2)^2 + EpT(3)^2); 18 | Rx(3, 2) = -Rx(2, 3); 19 | if isnan(det(Rx)) 20 | Rx = eye(4); % Singularity distinguishing for vanishing rot-angle 21 | end 22 | %-------------Translation matrix: Rotate axis to coincide with z-axis-- 23 | Ry = eye(4); 24 | Ry(1, 1) = sqrt(EpT(2)^2 + EpT(3)^2) / norm(EpT); 25 | Ry(3, 3) = Ry(1, 1); 26 | Ry(3, 1) = -EpT(1) / norm(EpT); 27 | Ry(1, 3) = -Ry(3, 1); 28 | if isnan(det(Ry)) 29 | Ry = eye(4); % Singularity distinguishing for vanishing rot-angle 30 | end 31 | %-------------Translation matrix: Rotate about z axis for degree Deg--- 32 | Rz = eye(4); 33 | psi = Deg * pi / 180; 34 | Rz(1, 1) = cos(psi); 35 | Rz(2, 2) = Rz(1, 1); 36 | Rz(1, 2) = sin(psi); 37 | Rz(2, 1) = -sin(psi); 38 | if isnan(det(Rz)) 39 | Rz = eye(4); % Singularity distinguishing for vanishing rot-angle 40 | end 41 | %-------------Final translation matrix--------------------------------- 42 | H = T * Rx * Ry * Rz * Ry^(-1) * Rx^(-1) * T^(-1); 43 | %-------------Translation Operation------------------------------------ 44 | for i = 1:PNum 45 | P1(i, :) = P(i, :) * H; 46 | end 47 | P1(:, 4) = []; 48 | end -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # ABAQUS_to_FLAC3d 2 | (Also find this instruction in file ABAQUS_to_FLAC3d.m) 3 | % Convert solid elements and structural elements from ABAQUS to FLAC3d. 4 | % Author: liuzhan001st, liuzhan001st@163.com, https://github.com/liuzhan001st 5 | % 6 | % This code was wrote in MATLABr2015a and tested with 7 | % ABAQUS6.14.1 and FLAC3d5.0. 8 | % 9 | % Input model is orgnized by conceptions of part, set and assembly in 10 | % ABAQUS. 11 | % Solid elements are coverted directly to FLAC3d .flac3d file and 12 | % structrual elements are transfer to FLAC3d command lines. 13 | % Input: 14 | % An .inp file written by ABAQUS. 15 | % Rules of modeling with ABAQUS: 16 | % (1) Only one solid(shell) part correspongding to FLAC zones(SEL Liner/Shells) 17 | % should be created,and only one solid(shell) instance should be created 18 | % at Assembly level; 19 | % (2) A wire part should contain an individual wire meshed with truss or 20 | % beam elements, element number will be interpreted as segment number in 21 | % the output file, and the support system is created by patterning the 22 | % wire parts; 23 | % (3) Shell elements within a same part are treated as linked 24 | % shells/liners in the output file; 25 | % (4) Shell elements and wire shaped elements should be assigned to 26 | % different sets as their meshes need not to associate (Linkings need not 27 | % to be established); 28 | % (5) No wire feature exist in the solid part; 29 | % (6) Elsets should be created in Assembly level (by simply creating 30 | % geometry set within Assembly leverl), and structural elements and solid 31 | % elements can not be assigned to a same Elset; 32 | % (7) Rockbolts and cables should not be assigned to a same Elset. 33 | % (8) Elements converting rules: 34 | % Outputs: 35 | % (1) a .flac3d file contains grid points, zones and zgroup for solid 36 | % elements; and 37 | % (2) a series of .dat files contain command lines to generate structural 38 | % nodes and elements in FLAC3d. 39 | 40 | -------------------------------------------------------------------------------- /ABAQUS_to_FLAC3d.m: -------------------------------------------------------------------------------- 1 | % Convert solid elements and structural elements from ABAQUS to FLAC3d. 2 | % Author: liuzhan001st, liuzhan001st@163.com, https://github.com/liuzhan001st 3 | % 4 | % This code was wrote in MATLABr2015a and tested with 5 | % ABAQUS6.14.1 and FLAC3d5.0. 6 | % 7 | % Input model is orgnized by conceptions of part, set and assembly in 8 | % ABAQUS. 9 | % Solid elements are coverted directly to FLAC3d .flac3d file and 10 | % structrual elements are transfer to FLAC3d command lines. 11 | % Input: 12 | % An .inp file written by ABAQUS. 13 | % Rules of modeling with ABAQUS: 14 | % (1) Only one solid(shell) part correspongding to FLAC zones(SEL Liner/Shells) 15 | % should be created,and only one solid(shell) instance should be created 16 | % at Assembly level; 17 | % (2) A wire part should contain an individual wire meshed with truss or 18 | % beam elements, element number will be interpreted as segment number in 19 | % the output file, and the support system is created by patterning the 20 | % wire parts; 21 | % (3) Shell elements within a same part are treated as linked 22 | % shells/liners in the output file; 23 | % (4) Shell elements and wire shaped elements should be assigned to 24 | % different sets as their meshes need not to associate (Linkings need not 25 | % to be established); 26 | % (5) No wire feature exist in the solid part; 27 | % (6) Elsets should be created in Assembly level (by simply creating 28 | % geometry set within Assembly leverl), and structural elements and solid 29 | % elements can not be assigned to a same Elset; 30 | % (7) Rockbolts and cables should not be assigned to a same Elset. 31 | % (8) Elements converting rules: 32 | % Outputs: 33 | % (1) a .flac3d file contains grid points, zones and zgroup for solid 34 | % elements; and 35 | % (2) a series of .dat files contain command lines to generate structural 36 | % nodes and elements in FLAC3d. 37 | %-------------------------------------------------------------------------- 38 | close all 39 | clear 40 | clc 41 | %===========================Load Model============================= 42 | LoadingStart = tic; 43 | InputFileName = 'ABA-FLAC3d-StdTest.inp'; 44 | InputModel = ImportInp(InputFileName); 45 | Part = LoadPart(InputModel); 46 | % Returned Instances contain global node coordinates and FLAC3d formated 47 | % node orderings within elements. 48 | Instance = LoadInstance(InputModel, Part); 49 | ElSet = LoadSet(InputModel); % Homonymous instances within a set are not merged, 50 | % that may lead to incomplete zgroup defenition!!! 51 | LoadingTime = toc(LoadingStart) 52 | %==========================Export Model============================ 53 | %-------------Export zones and zgroups-------------- 54 | ExportStart = tic; 55 | FileName = sprintf('%s%s', InputFileName, '.flac3d'); 56 | ExportZone(Instance, ElSet, FileName); 57 | [TNodeNum, TCidNum] = ExportCPSEL(Instance, ElSet); 58 | %ExportLinerSEL(Instance,ElSet,TNodeNum,TCidNum); 59 | ExportLinerSEL_NodePrior(Instance, ElSet, TNodeNum, TCidNum); 60 | ExportTime = toc(ExportStart) -------------------------------------------------------------------------------- /ExportZone.m: -------------------------------------------------------------------------------- 1 | function ExportZone( Instance, ElSet, FileName ) 2 | % Exports FLAC3d zones and zgroups into a *.flac3d file 3 | fid = fopen(FileName, 'w'); 4 | CID = 0; % Index of solid instance 5 | CElType = {'C3D8R' 'C3D6' 'C3D4'}; 6 | for i = 1:length(Instance) 7 | CFlag = 0; % CFlag==1 if the instance is created from a solid part 8 | for j = 1:length(CElType) 9 | if strcmp(Instance(i).element{1, 1}, CElType{j}) 10 | CFlag = 1; 11 | break 12 | end 13 | end 14 | if CFlag == 1 15 | CID = i; 16 | break 17 | end 18 | end 19 | %================Export grids points and zones=================== 20 | %----------------Export nodes------------------------------------ 21 | fprintf(fid, '*GRIDPOINTS\r\n'); 22 | for i = 1:length(Instance(CID).node) % Index is used as node id 23 | formatspec = 'G %d %10.5f %10.5f %10.5f\r\n'; 24 | fprintf(fid,formatspec, i, Instance(CID).node(i,1), ... 25 | Instance(CID).node(i,2), Instance(CID).node(i,3)); 26 | end 27 | fprintf(fid, '\r\n'); 28 | %----------------Export zones------------------------------------- 29 | fprintf(fid, '*ZONES\r\n'); 30 | for i = 1:length(Instance(CID).element(:, 1)) 31 | if strcmp(Instance(CID).element{i, 1}, 'C3D8R') 32 | formatspec = 'Z B8 %d %d %d %d %d %d %d %d %d\r\n'; 33 | for j = 1:size(Instance(CID).element{i, 2}, 1); 34 | fprintf(fid, formatspec, Instance(CID).element{i, 2}(j, :)); 35 | end 36 | end 37 | if strcmp(Instance(CID).element{i, 1}, 'C3D6') 38 | formatspec = 'Z W6 %d %d %d %d %d %d %d\r\n'; 39 | for j = 1:size(Instance(CID).element{i, 2}, 1); 40 | fprintf(fid,formatspec,Instance(CID).element{i, 2}(j, :)); 41 | end 42 | end 43 | if strcmp(Instance(CID).element{i, 1}, 'C3D4') 44 | formatspec = 'Z T4 %d %d %d %d %d\r\n'; 45 | for j = 1:size(Instance(CID).element{i, 2}, 1); 46 | fprintf(fid, formatspec, Instance(CID).element{i, 2}(j, :)); 47 | end 48 | end 49 | end 50 | fprintf(fid, '\r\n'); 51 | %----------------Export zgroups----------------------------------- 52 | fprintf(fid, '*GROUPS\r\n'); 53 | for i = 1:length(ElSet) 54 | CFlag = 0; 55 | for j = 1:length(Instance) % Find corresponding instance 56 | if strcmp(ElSet(i).element{1, 1}, Instance(j).name) 57 | break 58 | end 59 | end 60 | for k = 1:length(CElType) % Determine solid instance 61 | if strcmp(Instance(j).element{1, 1}, CElType{k}) 62 | CFlag = 1; 63 | break 64 | end 65 | end 66 | if CFlag == 1 67 | GrpNameLine = sprintf('%s%s', 'ZGROUP ', ElSet(i).name); 68 | fprintf(fid, '%s\r\n', GrpNameLine); 69 | LENum = 0; % Total number of elements in a sinlge line 70 | for ii = 1:length(ElSet(i).element{1, 2}) 71 | LENum = LENum + 1; 72 | fprintf(fid, '%d ', ElSet(i).element{1, 2}(ii)); 73 | if mod(LENum, 10) == 0 74 | fprintf(fid, '\r\n'); 75 | end 76 | end 77 | fprintf(fid, '\r\n\r\n'); 78 | end 79 | end 80 | fclose(fid); 81 | end -------------------------------------------------------------------------------- /LoadPart.m: -------------------------------------------------------------------------------- 1 | function [ Part ] = LoadPart( InputModel ) 2 | % Recognizes parts from InputModel 3 | % InputModel is a cell array returned by function ImportInp 4 | % Part is a global struct array: 5 | % Part=struct('name','','node',[],'element',{}) 6 | % where feild 'element' stores element types and node indexes 7 | % { 'C3D8R' [] 8 | % 'C3D4' [] 9 | % ... } 10 | % [elementID node1 node2 ... ] 11 | % elementIDs are stored as they may not continuous if there are 12 | % two or more element types within one part! 13 | Part = struct('name', '', 'node', [], 'element', {}); 14 | % 'element' is a cell array:{'type1',[];'type2',[];...} 15 | LineIndex = 1; % Global line index 16 | tline = InputModel{LineIndex}; 17 | PNum = 0; % Total number of parts 18 | % PNumFlag=0; % Flag of PNum increament 19 | %====================Scan parts==================== 20 | while strncmp('** ASSEMBLY', tline, length('** ASSEMBLY')) == 0 21 | PNumFlag = 0; 22 | %---------------Recognizes a part------------- 23 | if strncmp('*Part', tline, length('*Part')) == 1 24 | PNum = PNum + 1; 25 | % PNumFlag=1; 26 | Part(PNum).name = InputModel{LineIndex}(length('*Part, name=') + 1:... 27 | length(InputModel{LineIndex})); 28 | LineIndex = LineIndex + 2; % Goto starting line of node data block 29 | NNum = 0; % Total number of nodes 30 | tNode = str2num(InputModel{LineIndex}); 31 | %-----------Load nodes------------------- 32 | while ~isempty(tNode) 33 | NNum = NNum + 1; 34 | Part(PNum).node(NNum, :) = tNode(2: 4); 35 | LineIndex = LineIndex + 1; 36 | tNode = str2num(InputModel{LineIndex}); 37 | end 38 | %-----------Load elements---------------- 39 | tline = InputModel{LineIndex}; 40 | ETNum = 0; % Total number of element types 41 | while strncmp('*End Part', tline, length('*End Part')) == 0 42 | if strncmp('*Element', tline, length('*Element')) == 1 43 | ETNum = ETNum + 1; 44 | TSIndex = regexp(tline, 'type'); 45 | Part(PNum).element{ETNum, 1} = InputModel{LineIndex}... 46 | (TSIndex + 5:length(InputModel{LineIndex})); 47 | LineIndex = LineIndex + 1; 48 | tline = InputModel{LineIndex}; 49 | %----------Load element matrix---------- 50 | tElement = str2num(tline); 51 | ENum = 0; %Total number of elements of current type 52 | while ~isempty(tElement) 53 | ENum = ENum + 1; 54 | Part(PNum).element{ETNum, 2}(ENum, :) = ... 55 | tElement(1:length(tElement)); 56 | LineIndex = LineIndex + 1; 57 | tline = InputModel{LineIndex}; 58 | tElement = str2num(tline); 59 | end 60 | LineIndex = LineIndex - 1; 61 | end 62 | LineIndex = LineIndex + 1; 63 | tline = InputModel{LineIndex}; 64 | end 65 | end 66 | if PNumFlag == 1 67 | LineIndex = LineIndex - 1; 68 | end 69 | LineIndex = LineIndex + 1; 70 | tline = InputModel{LineIndex}; 71 | end 72 | end -------------------------------------------------------------------------------- /LoadSet.m: -------------------------------------------------------------------------------- 1 | function [ ElSet ] = LoadSet( InputModel ) 2 | % Recognizes ElSets from InputModel and Instances 3 | ElSet = struct('name', '', 'element', {}); 4 | % ElSet(i).Element={'instance1' []; 5 | % 'instance2' []; 6 | % ... } 7 | %---------------------Find start line of Elset in Assembly level------ 8 | LineIndex = 1; 9 | tline = InputModel{LineIndex}; 10 | while ~strcmp(tline, '** ASSEMBLY') 11 | LineIndex = LineIndex + 1; 12 | tline = InputModel{LineIndex}; 13 | end 14 | while ~strncmp(tline, '*Elset', length('*Elset')) && ... 15 | LineIndex 0 53 | CIDExp = TCidNum; 54 | for i = 1:LSetNum 55 | CIDExp = CIDExp + 1000; 56 | FileName = sprintf('%s%s', LSELSet(i).name, '.dat'); 57 | fid = fopen(FileName, 'w'); 58 | CIDNum = length(LSELSet(i).element{1, 2}); 59 | fprintf(fid, ';creating %d linersels\r\n', CIDNum); 60 | CIDExpStart = CIDExp + 1; 61 | for j = 1:CIDNum 62 | fprintf(fid, '\r\n;-------------------------\r\n'); 63 | CIDExp = CIDExp + 1; 64 | tEID = LSELSet(i).element{1, 2}(j); % Temp element id. 65 | tNID = Instance(LIID).element{1, 2}(tEID, 2:4); % Temp node id 66 | formatspec = 'SEL linersel cid %d id 1 nodes %d %d %d\r\n'; 67 | fprintf(fid, formatspec, ... 68 | CIDExp, NodeIDExp(tNID(1)), NodeIDExp(tNID(2)), ... 69 | NodeIDExp(tNID(3))); 70 | for ii = 1:3 71 | % Create link between SEL and grid 72 | formatspec = 'SEL node init xpos %10.5f range id %d %d\r\n'; 73 | fprintf(fid, formatspec, LinerNode(tNID(ii), 1), ... 74 | NodeIDExp(tNID(ii)), NodeIDExp(tNID(ii))); 75 | end 76 | end 77 | fprintf(fid, '\r\n;-------------------------\r\n'); 78 | fprintf(fid, 'SEL group %s range cid %d %d\r\n', ... 79 | LSELSet(i).name, CIDExpStart, CIDExpStart + CIDNum - 1); 80 | fclose(fid); 81 | end 82 | end 83 | end -------------------------------------------------------------------------------- /LoadInstance.m: -------------------------------------------------------------------------------- 1 | function [ Instance ] = LoadInstance( InputModel, Part ) 2 | % Recognizes instances from InputModel and Part 3 | % The global coordinates of nodes are transformed by translation and 4 | % rotation about a specified axis 5 | % Zone element node orderings are transformed into FLAC3d format 6 | Instance = struct('name', '', 'part', '', 'node', [], 'element', {}); 7 | %----------Transform zone element node orderings into FLAC3d format--------- 8 | for i = 1:length(Part) 9 | for j = 1:length(Part(i).element(:, 1)) 10 | ColNum = length(Part(i).element{j, 2}(1, :)); 11 | AEl = Part(i).element{j, 2}(:, 2:ColNum); % Elements in Abaqus 12 | FEl = AEl; % Elements in FLAC 13 | if strcmp(Part(i).element{j, 1}, 'C3D8R') 14 | FEl(:, 1) = AEl(:, 7); 15 | FEl(:, 2) = AEl(:, 6); 16 | FEl(:, 3) = AEl(:, 8); 17 | FEl(:, 4) = AEl(:, 3); 18 | FEl(:, 5) = AEl(:, 5); 19 | FEl(:, 6) = AEl(:, 4); 20 | FEl(:, 7) = AEl(:, 2); 21 | FEl(:, 8) = AEl(:, 1); 22 | end 23 | if strcmp(Part(i).element{j, 1}, 'C3D6') 24 | FEl(:, 1) = AEl(:, 3); 25 | FEl(:, 2) = AEl(:, 2); 26 | FEl(:, 3) = AEl(:, 6); 27 | FEl(:, 4) = AEl(:, 1); 28 | FEl(:, 5) = AEl(:, 5); 29 | FEl(:, 6) = AEl(:, 4); 30 | end 31 | if strcmp(Part(i).element{j, 1}, 'C3D4') 32 | FEl(:, 1) = AEl(:, 3); 33 | FEl(:, 2) = AEl(:, 4); 34 | FEl(:, 3) = AEl(:, 1); 35 | FEl(:, 4) = AEl(:, 2); 36 | end 37 | Part(i).element{j, 2}(:, 2:ColNum) = FEl; 38 | end 39 | end 40 | %-----------------Find start line of assembly------------------ 41 | LineIndex = 1; 42 | tline = InputModel{LineIndex}; 43 | while strncmp('** ASSEMBLY', tline, length('** ASSEMBLY')) == 0 44 | LineIndex = LineIndex + 1; 45 | tline = InputModel{LineIndex}; 46 | end 47 | %=================Scan instances================================ 48 | INum = 0; % Total number of instances 49 | while strncmp('*End Assembly', tline, length('*End Assembly')) == 0 50 | if strncmp('*Instance', tline, length('*Instance')) == 1 51 | INum = INum + 1; 52 | commaP = regexp(tline, ','); % Find commas, 'P' for 'Position' 53 | nameP = regexp(tline, 'name'); % Find 'name' 54 | partP = regexp(tline, 'part'); % Find 'part' 55 | Instance(INum).name = tline(nameP + 5:commaP(2) - 1); 56 | Instance(INum).part = tline(partP + 5:length(tline)); 57 | for i = 1:length(Part) 58 | if strcmp(Instance(INum).part,Part(i).name) 59 | LNode = Part(i).node; % Local node coordinates 60 | Instance(INum).element = Part(i).element; % CAUTION!!! 61 | break 62 | end 63 | end 64 | %-------------Geometrical translation of node coordinates------ 65 | Instance(INum).node = LNode; % If there is no translation. 66 | LineIndex = LineIndex + 1; 67 | tline = str2num(InputModel{LineIndex}); 68 | if isempty(tline) == 0 69 | TNode = Trans3d(LNode, tline); 70 | LineIndex = LineIndex + 1; 71 | tline = str2num(InputModel{LineIndex}); 72 | if isempty(tline) == 0 73 | Instance(INum).node = RotAAx3d(TNode, tline(1:3), tline(4:6)... 74 | , tline(7)); 75 | else 76 | Instance(INum).node = TNode; 77 | end 78 | end 79 | end 80 | LineIndex = LineIndex + 1; 81 | tline = InputModel{LineIndex}; 82 | end 83 | end -------------------------------------------------------------------------------- /ExportCPSEL.m: -------------------------------------------------------------------------------- 1 | function [TNodeNum, TCidNum] = ExportCPSEL( Instance, ElSet ) 2 | % Exports cable and pile (for rockbolt) sels, and total number of ids will 3 | % be written to head of the output file as a comment. 4 | % Output files' names follow structural sets. 5 | % Returns Total Node Numbers TNodeNum. 6 | WSELSet = struct('name', '', 'type', '', 'element', {}); % Wire shaped sel set. 7 | % *.element = {'InstName1' [element nodeid] [node] 8 | % 'InstName2' [element nodeid] [node] 9 | % ... } 10 | CSetNum = 0; % Total number of CSELSets. 11 | PSetNum = 0; % Total number of PSELSets. 12 | WSetNum = 0; 13 | TNodeNum = 0; 14 | TCidNum = 0; 15 | for i = 1:length(ElSet) 16 | for j = 1:length(Instance) 17 | if strcmp(Instance(j).name, ElSet(i).element{1, 1}) 18 | break 19 | end 20 | end 21 | if strcmp(Instance(j).element{1, 1}, 'B31') 22 | CSetNum = CSetNum + 1; 23 | WSetNum = WSetNum + 1; 24 | WSELSet(WSetNum).type = 'pile'; 25 | WSELSet(WSetNum).name = ElSet(i).name; 26 | WSELSet(WSetNum).element = ElSet(i).element; 27 | elseif strcmp(Instance(j).element{1, 1}, 'T3D2') 28 | PSetNum = PSetNum + 1; 29 | WSetNum = WSetNum + 1; 30 | WSELSet(WSetNum).type = 'cable'; 31 | WSELSet(WSetNum).name = ElSet(i).name; 32 | WSELSet(WSetNum).element = ElSet(i).element; 33 | end 34 | end 35 | %-----------------Load node coordinates to CSELSet and PSELSet------- 36 | for i = 1:WSetNum 37 | for j = 1:length(WSELSet(i).element(:, 1)) 38 | for k = 1:length(Instance) 39 | if strcmp(Instance(k).name, WSELSet(i).element{j, 1}) 40 | WSELSet(i).element{j, 3} = Instance(k).node; 41 | end 42 | end 43 | end 44 | end 45 | %===============Export wire shaped SELs==================== 46 | if WSetNum > 0 47 | PileID = 0; 48 | CableID = 0; 49 | TPnsegNum = 0; 50 | TCnsegNum = 0; 51 | for i = 1:WSetNum 52 | FileName = sprintf('%s%s', WSELSet(i).name, '.dat'); 53 | fid = fopen(FileName, 'w'); 54 | IDNum = length(WSELSet(i).element(:, 1)); 55 | PileFlag = 0; 56 | if strcmp(WSELSet(i).type, 'pile') 57 | PileFlag = 1; 58 | formatspec = '; creating %d piles(rockbolts)\r\n'; 59 | fprintf(fid, formatspec, IDNum); 60 | PCIDStart = TPnsegNum + 1; 61 | for j = 1:IDNum 62 | PileID = PileID + 1; 63 | formatspec1 = 'SEL pile id %d begin %10.5f %10.5f %10.5f '; 64 | formatspec2 = 'end %10.5f %10.5f %10.5f nseg %d\r\n'; 65 | formatspec = sprintf('%s%s', formatspec1, formatspec2); 66 | nseg = length(WSELSet(i).element{j, 2}); 67 | TPnsegNum = TPnsegNum + nseg; 68 | NodeNum = length(WSELSet(i).element{j, 3}(:, 1)); 69 | TCidNum = TCidNum + nseg; 70 | TNodeNum = TNodeNum + NodeNum; 71 | NStart = WSELSet(i).element{j, 3}(1, :); 72 | NEnd = WSELSet(i).element{j, 3}(NodeNum, :); 73 | fprintf(fid, formatspec, PileID, NStart, NEnd, nseg); 74 | end 75 | elseif strcmp(WSELSet(i).type, 'cable') 76 | formatspec = '; creating %d cables\r\n'; 77 | fprintf(fid, formatspec, IDNum); 78 | CCIDStart = TCnsegNum + 1; 79 | for j = 1:IDNum 80 | CableID = CableID + 1; 81 | formatspec1 = 'SEL cable id %d begin %10.5f %10.5f %10.5f '; 82 | formatspec2 = 'end %10.5f %10.5f %10.5f nseg %d\r\n'; 83 | formatspec = sprintf('%s%s', formatspec1, formatspec2); 84 | nseg = length(WSELSet(i).element{j, 2}); 85 | TCnsegNum = TCnsegNum + nseg; 86 | NodeNum = length(WSELSet(i).element{j, 3}(:, 1)); 87 | TCidNum = TCidNum + nseg; 88 | TNodeNum = TNodeNum + NodeNum; 89 | NStart = WSELSet(i).element{j, 3}(1, :); 90 | NEnd = WSELSet(i).element{j, 3}(NodeNum, :); 91 | fprintf(fid, formatspec, CableID, NStart, NEnd, nseg); 92 | end 93 | end 94 | if PileFlag == 1 95 | fprintf(fid, '\r\n\r\n;----------------\r\n'); 96 | fprintf(fid, 'SEL pile prop rockbolt on\r\n'); 97 | fprintf(fid, '\r\n;------------------------------\r\n'); 98 | % fprintf(fid, 'SEL group %s range cid %d %d\r\n', ... 99 | % WSELSet(i).name, PCIDStart, TPnsegNum); 100 | % else 101 | end 102 | fclose(fid); 103 | end 104 | end 105 | end 106 | 107 | --------------------------------------------------------------------------------