Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Auto increment is a no-no?

Name: Anonymous 2010-07-21 13:45

Hello. I must confess that I am rather new at this. During my courses, I was taught to place an auto increment as an id field in my tables, when in need to.

However, recently, I heard someone comment that this is to be completely avoided. But I do not understand why. Perhaps anon could point me in the right direction?

Name: Anonymous 2010-07-21 21:18

there are perfectly valid implementations . . . but unless you there is no possible other solution a DB is major overkill.
but unless you there is no other solution

OH GOD WHAT'S THE ANSWER

Name: Anonymous 2010-07-21 22:44

%DEAR Anonymous:  I hope this program helps you better understand your quandry.  I programmed it myself, and hope you enjoy using it.  I can personally explain any questions you have with it.

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
clear;
home;
 
% Input Nodal Coordinates

NODES = [

    [0.0 0.0]
    [0.5 0.0]
    [1.0 0.0]
    [0.0 0.5]
    [0.7 0.7]
    [1.0 0.5]
    [0.0 1.0]
    [0.5 1.0]
    [1.0 1.0]];

YM = 29000;
PR = 0.3;
thick = 0.1;

ELEMS = [

    [1 2 5 4 YM PR thick]
    [2 3 6 5 YM PR thick]
    [4 5 8 7 YM PR thick]
    [5 6 9 8 YM PR thick]];

%TRACS = [
 %   [3 6 1 0]
%    [6 9 1 0];

%1 for x-direction, 0 for the y direction
%[nnumber direction value]

PLOADS = [
    [3 1 0.025]
    [6 1 .05]
    [9 1 0.025]];

%1 for x-direction, 0 for the y direction
%[nnumber direction value]

DBCS = [
    [1 1 0]
    [1 0 0]
    [2 0 0 ]
[3 0 0]
[4 1 0]
[7 1 0]];

% Define number of nodes & number of elements

nnodes = length(NODES(:,1));

nelems = length(ELEMS(:,1));

 

% Assemble the global stiffness matrix

KG = zeros(2*nnodes,2*nnodes);

 

% Define the integration points

npts = 2;

gpts = [-1/sqrt(3) 1/sqrt(3)];

gwts = [1 1];

 

AREA = 0;

IX   = 0;

IY   = 0;

   

for ielem = 1:nelems

   

    % Get the nodes for this element

    ns = ELEMS(ielem,1:4);

   

    % Get the x and y coordinates of the element nodes

    xs = NODES(ns,1);

    ys = NODES(ns,2);

   

    % Compute the element stiffness matrix

    KE = zeros(8,8);

    earea = 0;

   

    for ig = 1:npts

       for jg = 1:npts

           xci = gpts(ig);

           eta = gpts(jg);

          

           % Compute shape functions & derivatives

           N(1)  = (1-xci)*(1-eta)/4;

           Nx(1) = -(1-eta)/4;

           Ne(1) = -(1-xci)/4;

          

           N(2) = (1+xci)*(1-eta)/4;

           Nx(2) =  (1-eta)/4;

           Ne(2) = -(1+xci)/4;

          

           N(3) = (1+xci)*(1+eta)/4;

           Nx(3) =  (1+eta)/4;

           Ne(3) =  (1+xci)/4;

          

           N(4) = (1-xci)*(1+eta)/4;

           Nx(4) = -(1+eta)/4;

           Ne(4) =  (1-xci)/4;

          

           % Compute the jacobian matrix

           J = [

               [Nx*xs Nx*ys]

               [Ne*xs Ne*ys]];

           detJ = det(J);

          

           % Get the y value at the current integration point

           yy = N*ys;

           xx = N*xs;

          

           % Get element info

           E  = ELEMS(ielem,5);

           nu = ELEMS(ielem,6);

           t   = ELEMS(ielem,7)

          

           % Get this points contribution to element stiffness

           EMAT = E/(1-nu^2)*[1 nu 0; nu 1 0;0 0 (1-nu)/2];

          

           H = [1 0 0 0;0 0 0 1;0 1 1 0];

          

           G = zeros(4,4);

           G(1:2,1:2) = inv(J);

           G(3:4,3:4) = inv(J);

          

           DN = zeros(4,8);

           DN(1,[1 3 5 7]) = Nx;

           DN(2,[1 3 5 7]) = Ne;

           DN(3,[2 4 6 8]) = Nx;

           DN(4,[2 4 6 8]) = Ne;

          

           B = H*G*DN;

           integrand = B'*EMAT*B*detJ*t;

          

           % Update element stiffness matrix

           KE = KE + integrand*gwts(ig)*gwts(jg);

          

           % Update area and moment of inertias

           earea = earea + detJ*gwts(ig)*gwts(jg);

           IX = IX + yy^2*detJ*gwts(ig)*gwts(jg);

           IY = IY + xx^2*detJ*gwts(ig)*gwts(jg);

       end

    end

   

    % Define the local destination array for this element

    LDA = [(2*ns(1)-1) 2*ns(1) (2*ns(2)-1) 2*ns(2) ...
           (2*ns(3)-1) 2*ns(3) (2*ns(4)-1) 2*ns(4)];

          

    % Assemble element stiffness to the global stiffness

    KG(LDA,LDA) = KG(LDA,LDA) + KE;

   

    % As a check, print the element area

    AREA = AREA + earea;

    fprintf('The result for element %d is %f\n',ielem,earea);

   

   

end

FG=zeros(2*nnodes,1);

%ASSEMBLE THE GLOBAL FORCE VECTOR FROM GIVEN POINT LOADS
npl=length(PLOADS(:,1));
for iload=1:npl
    nd=PLOADS(iload,1);
    dir=PLOADS(iload,2);
    val=PLOADS(iload,3);
   
FG(nd*2-dir,1)=FG(nd*2-dir,1)+val;

end

%take care of the displacement boundary conditions
nbc=length(DBCS(:,1));
for iload=1:nbc
    nd=DBCS(iload,1);
    dir=DBCS(iload,2);
    val=DBCS(iload,3);
   
FG=FG-KG(:,2*nd-dir)*val;

KG(:,2*nd-dir)=0;

KG(2*nd-dir,2*nd-dir) = -1;
   
   
end

%solve for the degrees of freedom

sol = inv(KG)*FG;

fprintf('AREA %f  IX %f  IY %f\n',AREA,IX,IY);

Name: Anonymous 2010-07-21 23:39

>>41
Please OPTIMIZE your quotes!

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List