How to create large data in MATLAB. For large array showing out of memory.

13 vues (au cours des 30 derniers jours)
Abhishek Saini
Abhishek Saini le 7 Nov 2018
Commenté : Abhishek Saini le 4 Déc 2018
I am trying to generate 3D mesh for my finite element simulation in MATLAB.But due to large number of nodes or array size it is giving error * "out of memory"*. The array size is more than 500 millions. I am using MATLAB in Linux system. How can I generate large data in MATLAB? Please guide me.
Thanks!
  2 commentaires
soni dana
soni dana le 1 Déc 2018
Hi, I am like you trying to generate 3D mesh for my finite element in MATLAB. I'm coding for one element that I put here but I don't know how the arrenge elemnet next toghether in 3 direction x,y,z. If you don't use my code please send me your code for generation 3D mesh. could you please guide me? Thanks for any help.
clc
clear all
close all;
T=2000;
%% coordinate for 8 node of element Fig1b(my assume)
Xw=[0 1 0 1 -0.2 1.2 -0.2 1.2];Xw=(Xw.*2)+2;
Yw=[0 0 1 1 0 0 1 1];Yw=(Yw.*2)+2;
Zw=[0 0 0 0 1 1 1 1];Zw=(Zw.*2)+2;
pwot3(Xw,Yw,Zw,'O')
% grid on
%% coordinate for center of element Fig1b
etac=(((Xw(1)+Xw(2))./2)+((Xw(3)+Xw(4))./2)+((Xw(5)+Xw(6))./2)+((Xw(7)+Xw(8))./2))./4;
betac=(((Yw(1)+Yw(2))./2)+((Yw(3)+Yw(4))./2)+((Yw(5)+Yw(6))./2)+((Yw(7)+Yw(8))./2))./4;
zetac=(((Zw(1)+Zw(2))./2)+((Zw(3)+Zw(4))./2)+((Zw(5)+Zw(6))./2)+((Zw(7)+Zw(8))./2))./4;
%% wenghth of element Fig1b
for w=1:length(Xw)
if etac>Xw(w)
etaq(w)=etac-Xw(w);
ewseif etac<Xw(w)
etaq(w)=Xw(w)-etac;
end
end
for w=1:length(Yw)
if betac>Yw(w)
betaq(w)=betac-Yw(w);
ewseif betac<Yw(w)
betaq(w)=Yw(w)-betac;
end
end
for w=1:length(Zw)
if zetac>Zw(w)
zetaq(w)=zetac-Zw(w);
ewseif betac<Zw(w)
zetaq(w)=Zw(w)-zetac;
end
end
%% local coordinate for element Fig1b base on tabwe A2 in the article
etaw=[-1 1 -1 1 -1 1 -1 1];
betaw=[-1 -1 1 1 -1 -1 1 1];
zetaw=[-1 -1 -1 -1 1 1 1 1];
%% function A11 in the article
syms eta beta zeta Fpqr Aij
for w=1:8
Nw(w)=(1/8).*(1+(etaw(w).*eta)).*(1+(betaw(w).*beta)).*(1+(zetaw(w).*zeta));
end
%% function A9 in the article
X=0;
for w=1:8
Xf=Nw(w).*Xw(w);
X=X+Xf;
end
Y=0;
for w=1:8
Yf=Nw(w).*Yw(w);
Y=Y+Yf;
end
Z=0;
for w=1:8
Zf=Nw(w).*Zw(w);
Z=Z+Zf;
end
%% function A10 in the article
ss=[diff(X,eta) diff(Y,eta) diff(Z,eta);diff(X,beta) diff(Y,beta) diff(Z,beta);diff(X,zeta) diff(Y,zeta) diff(Z,zeta)];
S=det(ss);
%% function A7 in the article
Fpqr=((Z./(((X.^2)+(Y.^2)+(Z.^2)).^(3./2))).*S);
Aij=T./(4.*pi).*Fpqr;
%% put (etaq,betaq,zetaq) instead of (eta,beta,zeta)
Aij1=subs (Aij,beta,betaq);
Aij2=subs (Aij1,eta,etaq);
for w=1:length(Xw)
Aij3(w)=doubwe(subs (Aij2(w),zeta,zetaq(w)))
end
Abhishek Saini
Abhishek Saini le 4 Déc 2018
You could use repmat to generated repeated mesh. Here is the code you could use. i hope this will help you.
%dx, dy, dz - spacing in each direction
dx=0.5; dy=0.5; dz=0.5;
% number of nodes in x, y and z directions
nx= 500; ny = 500; nz=500;
% mesh centre in each direction
cx=0; cy = 0; cz=0;
%define nodes
px = repmat( dx*( (1:nx)-(nx+1)/2 ).', [1,ny,nz])+cx;
py = repmat(dy*( (1:ny).'-(ny+1)/2).', [nx,1,nz] )+cy;
pz = repmat(dz*permute( (1:nz).'-(nz+1)/2,[2,3,1]), [nx,ny,1] )+cz;
px = reshape(px,[],1); py = reshape(py,[],1); pz = reshape(pz,[],1);
nodePos = [px(:), py(:), pz(:)].';
nEls = (nx-1)*(ny-1)*(nz-1); % total number of elements
n = 8; % cubic element
elNodes = zeros(n,nEls);
cubeNodes = zeros(8,1);
elCnt = 0;
for elCntZ = 1:(nz-1)
for elCntY = 1:(ny-1)
for elCntX = 1:(nx-1)
cubeNodes(1) = elCntX-1 + (elCntY-1)*nx + (elCntZ-1)*nx*ny;
cubeNodes(2) = elCntX + (elCntY-1)*nx + (elCntZ-1)*nx*ny;
cubeNodes(3) = elCntX + (elCntY )*nx + (elCntZ-1)*nx*ny;
cubeNodes(4) = elCntX-1 + (elCntY )*nx + (elCntZ-1)*nx*ny;
cubeNodes(5) = elCntX-1 + (elCntY-1)*nx + (elCntZ-1+1)*nx*ny;
cubeNodes(6) = elCntX + (elCntY-1)*nx + (elCntZ-1+1)*nx*ny;
cubeNodes(7) = elCntX + (elCntY )*nx + (elCntZ-1+1)*nx*ny;
cubeNodes(8) = elCntX-1 + (elCntY )*nx + (elCntZ-1+1)*nx*ny;
%hex:
elCnt = elCnt+1;
elNodes(1:8,elCnt) = cubeNodes(:);
end
end
end
elNodes = elNodes+1;

Connectez-vous pour commenter.

Réponses (2)

Caglar
Caglar le 7 Nov 2018
Modifié(e) : Caglar le 7 Nov 2018

Stephen23
Stephen23 le 7 Nov 2018
  2 commentaires
Abhishek Saini
Abhishek Saini le 8 Nov 2018
I am trying to store .mat data but showing error.
_Error using datastore (line 118) Cannot determine the datastore type for the specified location.
Specify the 'Type' name-value pair argument to indicate the type of datastore to create.
ds = datastore('filename.mat');
Walter Roberson
Walter Roberson le 8 Nov 2018
.mat files are not usually datastores themselves. You can use a custom read function to use them as a datastore but you need to tell it what kind of data is being processed.

Connectez-vous pour commenter.

Catégories

En savoir plus sur Images dans Help Center et File Exchange

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by