首页 > 其他分享 >【Matlab函数】提取inp文件中的节点、单元数据并保留集合信息

【Matlab函数】提取inp文件中的节点、单元数据并保留集合信息

时间:2023-07-14 13:34:02浏览次数:41  
标签:end lines text inp Matlab line data 节点

功能

  • 提取hypermesh2020(其他版本也可以)中的节点、单元信息,并保留elem set信息。
  • 返回的是一个结构体

输入输出参数

输入:

  • inp文件路径,如:'example.inp'、"inp\ex.inp"

输出:

  • 一个结构体,包含节点信息、单元信息、单元集合信息、部件名字。
Struct
 -- Name
 -- Nodes
 -- ElemSets

matlab代码

% --------------------------------------------------------------- %
% Loads the inp(generated by HM2020) data to a parts struct array %
% --------------------------------------------------------------- %

function part = loadinp_GeByHm2020(inp)
    % inp='SmallLXJ_TETmesh_size2mm-20230704.inp';

    % Get and process text from the file
    text = fileread(inp);         % read all the text
    text = strtrim(text);         % remove leading and trailing whitespaces
    text = strrep(text, ' ', ''); % remove any in-between whitespaces
    text = lower(text);           % lower the case
    text = inpremcom(text);       % remove comment lines from inp text data
    
    % get nodes infomation
    data =strsplit(text, '*element')';% split char vector at '*element'——>n X 1 的cell array;
    
    % create struct :part
    name=strsplit(inp,'.');
    part.Name=name{1};
    
    % Extract nodes data
    nodes=data{1};
    part.Nodes=getnodes(nodes);
    % Extract set data
    % create a cell array ,contain each elemset struct
    ElementSets=cell(size(data,1)-1,1);
    numOftet=0;

    for i=1:1:size(ElementSets,1)
        % a char vector including element define info: setname,elemtype,elem label,connectivity
        elemsetInfo=data{i+1};   
        ElementSets{i}=getelementOFset(elemsetInfo);
        numOftet=numOftet+size(ElementSets{i}.Elements,1);
    end
    part.ElemSets=ElementSets;
    %show number of tet elements
    disp(['**number of tet =',num2str(numOftet)])
end

function output = inpremcom(text) 
    
    % ---------------------------------------- %
    % Removes comment lines from inp text data %
    % ---------------------------------------- %
    
    text = splitlines(text);% split string at the actual \n ,rather than char \n。
    
    output = {};
    j = 1;
    
    for i = 1:1:size(text, 1)
        if ~startsWith(text{i}, '**')
            output{j, 1} = text{i};
            j = j + 1;
        end
    end
    % 文本\n 会转换为实际的换行符
    output = strjoin(output, '\n');%将元胞数组中的字符向量联接为一个字符向量。指定\n作为分隔符。
    
end

function Nodes = getnodes(nodes)
    
    % --------------------------------------------------------------------------- %
    % Gets the nodes from the *node data,return a containers.Map var called Nodes %
    % --------------------------------------------------------------------------- %
    %create a empty Map var
    Nodes=containers.Map('KeyType','double','ValueType','any');
    % loop *node data
    lines = splitlines(nodes);
    for i = 1:1:size(lines, 1)
        line = lines{i};
        if contains(line, '*node')
            for j = (i + 1):1:size(lines, 1)
                line = lines{j};
                if contains(line, '*') || isempty(line)
                    return
                else
                    data = str2num(line);
                    % key: node label
                    % value: 1X1 cell array ,contain coordinates value
                    Nodes(data(1)) = {data(2:end)};
                end
            end
        end
    end
    
end

function ElemSet = getelementOFset(elemdata)
    
    % --------------------------------------------------------- %
    % Gets the elements from the *element data ,return a struct %
    % ----------------------------------------------------------%
    
    ElemSet=struct;
    %create a empty Map var
    Els=containers.Map('KeyType','double','ValueType','any');
    
    lines = splitlines(elemdata);
    
    % read elemsert's name and elemtype
    if contains(lines{1},'elset')
        line_1=strsplit(lines{1},',');
        for i=2:1:size(line_1,2)
            tempcell=strsplit(line_1{i},'=');
            if strcmp( tempcell{1},'type')
                ElemSet.ElemType=tempcell{2};
            elseif strcmp(tempcell{1},'elset')
                ElemSet.SetName=tempcell{2};
            end
        end
    end
    
    % read element's label and connectivity 
    for i = 2:1:size(lines, 1)
        line = lines{i};
        if contains(line, '*') || isempty(line)
            break;
        else
            data = str2num(line);
            % key: elem label
            % value: 1X1 cell array ,contain elem connectivity
            Els(data(1)) = {data(2:end)};
        end
    end
    
    ElemSet.Elements=Els;
end

标签:end,lines,text,inp,Matlab,line,data,节点
From: https://www.cnblogs.com/aksoam/p/17553443.html

相关文章

  • bpmn.js修改默认节点颜色
    从node_modules依赖中找到定义图形颜色的js文件bpmn-js/lib/draw/BpmnRenderer.js找到BpmnRenderer.js文件的以下代码: 这里是代码:找到BpmnRenderer.js文件的以下代码:vardefaultFillColor=config&&config.defaultFillColor,  defaultStrokeColor=config&&config......
  • 获取input[type="checkbox"]:checked 所在tr中特定元素
    1.要求如下 2.html源码<divclass="btn"><buttontype="button"onclick="getYuan()">获取</button></div><divclass="forms"><table><tbody>......
  • antd from 表单中的key 不能绑定input中的字段 Input.js:207 Uncaught (in promise)
    <Formclass="NewVersion"ref="formRef"name="NewVersion":model="formData"><Spacev-for="(newPg,index)informData.version":key="index"style="dis......
  • 面试题 02.01. 移除重复节点
    编写代码,移除未排序链表中的重复节点。保留最开始出现的节点。示例1:输入:[1,2,3,3,2,1]输出:[1,2,3]示例2:输入:[1,1,1,1,2]输出:[1,2]提示:链表长度在[0,20000]范围内。链表元素在[0,20000]范围内。进阶:如果不得使用临时缓冲区,该怎么解决?来源:力扣(LeetCode)......
  • m完整的SC-FDE单载波频域均衡通信链路matlab仿真,包括UW序列,QPSK,定时同步,载波同步,
    1.算法仿真效果matlab2022a仿真结果如下:    2.算法涉及理论知识概要        完整的SC-FDE单载波频域均衡通信链路的设计和实现,包括UW序列的设计、QPSK调制、帧同步、定时同步、载波同步、SNR估计和MMSE信道估计等环节。本文首先介绍了SC-FDE通信系统的基本......
  • react-d3-tree自定义节点使用案例
    react-d3-tree主要API及其中文解释:Tree组件的props:这些API提供了丰富的配置选项,可以用来定制树的外观和行为。例如,可以使用nodeSize属性调整节点的大小,使用pathFunc属性绘制自定义的连线,使用onClick属性处理节点的点击事件等等。data:树的数据对象。zoomable:指......
  • c# 读取json字符串节点内容
    c#读取json字符串节点内容stringjsonstr="{\"voiceprompt_callback\":{\"result\":\"1\",\"accept_time\":\"0\"}}";varty=JsonConvert.DeserializeObject(jsonstr);Newtonsoft.Json.Linq.JOb......
  • 符合input子系统的字符设备驱动之按键驱动(一)
    作者:Bright-Ho联系方式:[email protected]符合input子系统的设备驱动之按键驱动(一)前面章节,我们分析了input子系统的软件框架;说到要学习字符驱动得分为两方面:第一方面,了解硬件工作原理,硬件协议,学会看电路图,时序等等;第二方面:了解驱动框架;了解驱动框架的目的是哪些事情是由我......
  • 符合input子系统的设备驱动之按键驱动(二)
    作者:Bright-Ho联系方式:[email protected]符合input子系统的设备驱动之按键驱动(二)上一节,我们大概的回顾了裸板按键驱动的方法,这一节,我们继续回顾,不带input子系统的按键字符设备驱动是怎么实现的? 这里直接上流程:(1)构造file_operstions结构; staticstructfile_opera......
  • 符合input子系统的设备驱动之按键驱动(三)
    作者:Bright-Ho联系方式:[email protected]符合input子系统的设备驱动之按键驱动(三)前两节我们回顾了按键实现的硬件原理,这一节我们就实现input系统的设备硬件层的内容;(1)首先看入口函数做了哪些事情?46staticstructinput_dev*buttons_dev;47staticstructpin_......