⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 read_input_data.m

📁 matlab实例
💻 M
字号:
%***********************************************************************
%  function read_input_data
%
%  read input data for problem from data file
%***********************************************************************
function [Geom, BCs, error] = read_input_data(Geom)

error = 0;
% get file name
finput = -1;
while finput < 0                     % repeat until valid file name entered
  disp('')
  inputfile = input('Enter name of input data file: ','s')
  if isempty(inputfile)              % if simply press return
    inputfile = uigetfile('*.*');    % then get GUI file picker...
  end 
  disp('')
  finput = fopen(inputfile,'rt');    % read only; text mode
  if finput < 0, disp('! File not found or file sharing problem !'), end
end

% project title
Geom.title = fgetl(finput);

% node coordinates
junk  = fgetl(finput);                    % skip text line
Geom.nnodes = fscanf(finput, '%d ', 1);   % read number of nodes and dimensions
Geom.dim = fscanf(finput, '%d ', 1);      % spacial dimension of the problem

for inode = 1:Geom.nnodes
  Geom.Nodes(inode).nodeID = fscanf(finput, '%d ', 1);    % node ID given by user.
  for jdir = 1:Geom.dim
    Geom.Nodes(inode).coord(jdir) = fscanf(finput, '%f ', 1);
  end
end

% element data and connectivity
junk  = fgetl(finput);                   % skip text line
Geom.nelems = fscanf(finput, '%d ', 1);   % read number of elements

for iel = 1:Geom.nelems
    Geom.ElemData(iel).elemID   = fscanf(finput, '%d ', 1);       % element ID given by user
    elemType = fscanf(finput, '%s ', 1);       % element type
    if strcmpi(elemType, 'spring1d')
        Geom.ElemData(iel).elemType = Geom.ETags.spring1d;
    elseif strcmpi(elemType, 'truss2d')
        Geom.ElemData(iel).elemType = Geom.ETags.truss2d;
    elseif strcmpi(elemType, 'pBar2')
        Geom.ElemData(iel).elemType = Geom.ETags.pBar2;
    elseif strcmpi(elemType, 'pBar3')
        Geom.ElemData(iel).elemType = Geom.ETags.pBar3;
    elseif strcmpi(elemType, 'pBar4')
        Geom.ElemData(iel).elemType = Geom.ETags.pBar4;
    elseif strcmpi(elemType, 'pBar5')
        Geom.ElemData(iel).elemType = Geom.ETags.pBar5;
    else
        disp('read_input_data: Invalid element type found. ');
        elemType
        error = 1;
        return
    end
    Geom.ElemData(iel).propID   = fscanf(finput, '%d ', 1);       % element property ID
    for jnode = 1:Geom.ElemType( Geom.ElemData(iel).elemType ).nnodes 
        Geom.ElemData(iel).connect(jnode) = fscanf(finput, '%d ', 1);  % connectivities
    end
end
%Geom.ElemData

% element properties
junk  = fgetl(finput);                    % skip text line
Geom.nprops = fscanf(finput, '%d ', 1);   % read number of properties

for ipro = 1:Geom.nprops
  Geom.Prop(ipro).propID = fscanf(finput, '%d ', 1);  % property ID given by user
  propType = fscanf(finput, '%s ', 1);
  
  if strcmpi( propType, 'MatSpring' )
    Geom.Prop(ipro).propType = propType;
    Geom.Prop(ipro).properties(1) = fscanf(finput, '%f ', 1);
  elseif strcmpi( propType, 'MatTruss' )
    Geom.Prop(ipro).propType = propType;
    Geom.Prop(ipro).properties(1) = fscanf(finput, '%f ', 1); % E
    Geom.Prop(ipro).properties(2) = fscanf(finput, '%f ', 1); % A
  elseif strcmpi( propType, 'MatpBar' )
    Geom.Prop(ipro).propType = propType;
    Geom.Prop(ipro).properties(1) = fscanf(finput, '%f ', 1); % E
    Geom.Prop(ipro).properties(2) = fscanf(finput, '%f ', 1); % A
    Geom.Prop(ipro).properties(3) = fscanf(finput, '%f ', 1); % C
    Geom.Prop(ipro).properties(4) = fscanf(finput, '%f ', 1); % bf_fun
  else
    disp('read_input_data: Invalid property type found. ');
    propType
    error = 1;
    return
  end
end
%Geom.Prop

% constraints
junk  = fgetl(finput);                           % skip text line
BCs.nnodeConstraint = fscanf(finput, '%d ', 1);  % read number of node contraints

for i = 1:BCs.nnodeConstraint
  constrnum        = fscanf(finput, '%d ', 1);   % constraint ID (not used)
  BCs.NodeConstraint(i).nodeID = fscanf(finput, '%d ', 1);
  BCs.NodeConstraint(i).dof    = fscanf(finput, '%d ', 1);
  BCs.NodeConstraint(i).value  = fscanf(finput, '%f ', 1);
end

% point loads
junk  = fgetl(finput);                         % skip text line
BCs.npointLoads = fscanf(finput, '%d ', 1);    % read number of point loads

for i = 1:BCs.npointLoads
  loadnum        = fscanf(finput, '%d ', 1);   % load ID (not used)
  BCs.PointLoad(i).nodeID = fscanf(finput, '%d ', 1);
  BCs.PointLoad(i).dof    = fscanf(finput, '%d ', 1);
  BCs.PointLoad(i).value  = fscanf(finput, '%f ', 1);
end

fclose(finput);

% NOTE: Assuming that all nodes have the same number of dofs!
% Picking the number of dofs per node from the first element.
Geom.ndofs_node = Geom.ElemType(Geom.ElemData(1).elemType).ndofs_node;
Geom.ndofs      = Geom.nnodes * Geom.ndofs_node;


⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -