2D Finite element code that creates a mesh for voltage distribution [MATLAB] [on hold]












-1












$begingroup$


I am trying to create a finite element code that describes the voltage along a coaxial cable. I have pasted an image of where the boundaries are located but I do not think you need to know much about the finite element method.



Here is the code:



function FEM2D
%
% This function demonstrates how the 2D Laplace equation with prescribed
% essential boundary conditions is solved by the finite element method.
%

clc, clear, close all;

% geometric parameters of a rectangule domain
% These are in cm

% *** SPLITTING IN QUARTER SIZE REDUCES # OF ELEMENTS ***
% *** WHEN LEFT AS FULL SIZE AND IN mm # OF ELEMENTS CREATES A PROPER
% MESH**
Length = 12.5e-3;
Height = 10e-3;


% Element Size

ElementSize = .001;

% Number Of Elements

NumberOfElementInX = 2*(floor(0.5*Length/ElementSize)+1);
NumberOfElementInY = ceil(Height/ElementSize);

display(NumberOfElementInX);
display(NumberOfElementInY);

ElementSizeInX = Length/NumberOfElementInX;
ElementSizeInY = Height/NumberOfElementInY;

display(ElementSizeInX);
display(ElementSizeInY);

% Node coordinates

NumberOfNode = (NumberOfElementInX+1)*(NumberOfElementInY+1);
NumberOfElement = 2*NumberOfElementInX*NumberOfElementInY;

X = zeros(NumberOfNode,1);
Y = zeros(NumberOfNode,1);


for j = 1 : NumberOfElementInY+1
for i = 1 : NumberOfElementInX+1
n = (j-1)*(NumberOfElementInX+1)+i;
X(n) = (i-1)*ElementSizeInX;
Y(n) = (j-1)*ElementSizeInY;
end
end



% element node connectivity

ElementNode = zeros(NumberOfElement,3);
for j = 1 : NumberOfElementInY
for i = 1 : NumberOfElementInX
n = (j-1)*NumberOfElementInX+i;
if i <= NumberOfElementInX/2
ElementNode(2*n-1, 1) = (j-1)*(NumberOfElementInX+1)+i;
ElementNode(2*n-1, 2) = j*(NumberOfElementInX+1)+i+1;
ElementNode(2*n-1, 3) = j*(NumberOfElementInX+1)+i;
ElementNode(2*n, 1) = (j-1)*(NumberOfElementInX+1)+i;
ElementNode(2*n, 2) = (j-1)*(NumberOfElementInX+1)+i+1;
ElementNode(2*n, 3) = j*(NumberOfElementInX+1)+i+1;
else
ElementNode(2*n-1, 1) = (j-1)*(NumberOfElementInX+1)+i;
ElementNode(2*n-1, 2) = (j-1)*(NumberOfElementInX+1)+i+1;
ElementNode(2*n-1, 3) = j*(NumberOfElementInX+1)+i;
ElementNode(2*n, 1) = (j-1)*(NumberOfElementInX+1)+i+1;
ElementNode(2*n, 2) = j*(NumberOfElementInX+1)+i+1;
ElementNode(2*n, 3) = j*(NumberOfElementInX+1)+i;
end
end
end

% ElementNode = delaunay(X,Y.*(1+0.001*ElementSize*sin(pi*X/Length)));
% %ElementNode = delaunay(X,Y);

% show mesh

trimesh(ElementNode,X,Y);
axis equal

end


So here is the mesh I get:



enter image description here



The problem is that I need to find a way to create a rectangular hole in my mesh. This problem would be applicable to a normal plate if the boundaries were on the outsides of my square but in this problem the boundaries are restricted. Basically, how can I remove the smaller rectangle in my problem? I have posted a screenshot of the dimensions of the problem I'm analyzing. Any tips would be appreciated. enter image description here










share|improve this question







New contributor




Lil_TEE is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.







$endgroup$



put on hold as off-topic by 200_success, Jamal 1 hour ago


This question appears to be off-topic. The users who voted to close gave this specific reason:


  • "Code not implemented or not working as intended: Code Review is a community where programmers peer-review your working code to address issues such as security, maintainability, performance, and scalability. We require that the code be working correctly, to the best of the author's knowledge, before proceeding with a review." – 200_success, Jamal

If this question can be reworded to fit the rules in the help center, please edit the question.





















    -1












    $begingroup$


    I am trying to create a finite element code that describes the voltage along a coaxial cable. I have pasted an image of where the boundaries are located but I do not think you need to know much about the finite element method.



    Here is the code:



    function FEM2D
    %
    % This function demonstrates how the 2D Laplace equation with prescribed
    % essential boundary conditions is solved by the finite element method.
    %

    clc, clear, close all;

    % geometric parameters of a rectangule domain
    % These are in cm

    % *** SPLITTING IN QUARTER SIZE REDUCES # OF ELEMENTS ***
    % *** WHEN LEFT AS FULL SIZE AND IN mm # OF ELEMENTS CREATES A PROPER
    % MESH**
    Length = 12.5e-3;
    Height = 10e-3;


    % Element Size

    ElementSize = .001;

    % Number Of Elements

    NumberOfElementInX = 2*(floor(0.5*Length/ElementSize)+1);
    NumberOfElementInY = ceil(Height/ElementSize);

    display(NumberOfElementInX);
    display(NumberOfElementInY);

    ElementSizeInX = Length/NumberOfElementInX;
    ElementSizeInY = Height/NumberOfElementInY;

    display(ElementSizeInX);
    display(ElementSizeInY);

    % Node coordinates

    NumberOfNode = (NumberOfElementInX+1)*(NumberOfElementInY+1);
    NumberOfElement = 2*NumberOfElementInX*NumberOfElementInY;

    X = zeros(NumberOfNode,1);
    Y = zeros(NumberOfNode,1);


    for j = 1 : NumberOfElementInY+1
    for i = 1 : NumberOfElementInX+1
    n = (j-1)*(NumberOfElementInX+1)+i;
    X(n) = (i-1)*ElementSizeInX;
    Y(n) = (j-1)*ElementSizeInY;
    end
    end



    % element node connectivity

    ElementNode = zeros(NumberOfElement,3);
    for j = 1 : NumberOfElementInY
    for i = 1 : NumberOfElementInX
    n = (j-1)*NumberOfElementInX+i;
    if i <= NumberOfElementInX/2
    ElementNode(2*n-1, 1) = (j-1)*(NumberOfElementInX+1)+i;
    ElementNode(2*n-1, 2) = j*(NumberOfElementInX+1)+i+1;
    ElementNode(2*n-1, 3) = j*(NumberOfElementInX+1)+i;
    ElementNode(2*n, 1) = (j-1)*(NumberOfElementInX+1)+i;
    ElementNode(2*n, 2) = (j-1)*(NumberOfElementInX+1)+i+1;
    ElementNode(2*n, 3) = j*(NumberOfElementInX+1)+i+1;
    else
    ElementNode(2*n-1, 1) = (j-1)*(NumberOfElementInX+1)+i;
    ElementNode(2*n-1, 2) = (j-1)*(NumberOfElementInX+1)+i+1;
    ElementNode(2*n-1, 3) = j*(NumberOfElementInX+1)+i;
    ElementNode(2*n, 1) = (j-1)*(NumberOfElementInX+1)+i+1;
    ElementNode(2*n, 2) = j*(NumberOfElementInX+1)+i+1;
    ElementNode(2*n, 3) = j*(NumberOfElementInX+1)+i;
    end
    end
    end

    % ElementNode = delaunay(X,Y.*(1+0.001*ElementSize*sin(pi*X/Length)));
    % %ElementNode = delaunay(X,Y);

    % show mesh

    trimesh(ElementNode,X,Y);
    axis equal

    end


    So here is the mesh I get:



    enter image description here



    The problem is that I need to find a way to create a rectangular hole in my mesh. This problem would be applicable to a normal plate if the boundaries were on the outsides of my square but in this problem the boundaries are restricted. Basically, how can I remove the smaller rectangle in my problem? I have posted a screenshot of the dimensions of the problem I'm analyzing. Any tips would be appreciated. enter image description here










    share|improve this question







    New contributor




    Lil_TEE is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
    Check out our Code of Conduct.







    $endgroup$



    put on hold as off-topic by 200_success, Jamal 1 hour ago


    This question appears to be off-topic. The users who voted to close gave this specific reason:


    • "Code not implemented or not working as intended: Code Review is a community where programmers peer-review your working code to address issues such as security, maintainability, performance, and scalability. We require that the code be working correctly, to the best of the author's knowledge, before proceeding with a review." – 200_success, Jamal

    If this question can be reworded to fit the rules in the help center, please edit the question.



















      -1












      -1








      -1





      $begingroup$


      I am trying to create a finite element code that describes the voltage along a coaxial cable. I have pasted an image of where the boundaries are located but I do not think you need to know much about the finite element method.



      Here is the code:



      function FEM2D
      %
      % This function demonstrates how the 2D Laplace equation with prescribed
      % essential boundary conditions is solved by the finite element method.
      %

      clc, clear, close all;

      % geometric parameters of a rectangule domain
      % These are in cm

      % *** SPLITTING IN QUARTER SIZE REDUCES # OF ELEMENTS ***
      % *** WHEN LEFT AS FULL SIZE AND IN mm # OF ELEMENTS CREATES A PROPER
      % MESH**
      Length = 12.5e-3;
      Height = 10e-3;


      % Element Size

      ElementSize = .001;

      % Number Of Elements

      NumberOfElementInX = 2*(floor(0.5*Length/ElementSize)+1);
      NumberOfElementInY = ceil(Height/ElementSize);

      display(NumberOfElementInX);
      display(NumberOfElementInY);

      ElementSizeInX = Length/NumberOfElementInX;
      ElementSizeInY = Height/NumberOfElementInY;

      display(ElementSizeInX);
      display(ElementSizeInY);

      % Node coordinates

      NumberOfNode = (NumberOfElementInX+1)*(NumberOfElementInY+1);
      NumberOfElement = 2*NumberOfElementInX*NumberOfElementInY;

      X = zeros(NumberOfNode,1);
      Y = zeros(NumberOfNode,1);


      for j = 1 : NumberOfElementInY+1
      for i = 1 : NumberOfElementInX+1
      n = (j-1)*(NumberOfElementInX+1)+i;
      X(n) = (i-1)*ElementSizeInX;
      Y(n) = (j-1)*ElementSizeInY;
      end
      end



      % element node connectivity

      ElementNode = zeros(NumberOfElement,3);
      for j = 1 : NumberOfElementInY
      for i = 1 : NumberOfElementInX
      n = (j-1)*NumberOfElementInX+i;
      if i <= NumberOfElementInX/2
      ElementNode(2*n-1, 1) = (j-1)*(NumberOfElementInX+1)+i;
      ElementNode(2*n-1, 2) = j*(NumberOfElementInX+1)+i+1;
      ElementNode(2*n-1, 3) = j*(NumberOfElementInX+1)+i;
      ElementNode(2*n, 1) = (j-1)*(NumberOfElementInX+1)+i;
      ElementNode(2*n, 2) = (j-1)*(NumberOfElementInX+1)+i+1;
      ElementNode(2*n, 3) = j*(NumberOfElementInX+1)+i+1;
      else
      ElementNode(2*n-1, 1) = (j-1)*(NumberOfElementInX+1)+i;
      ElementNode(2*n-1, 2) = (j-1)*(NumberOfElementInX+1)+i+1;
      ElementNode(2*n-1, 3) = j*(NumberOfElementInX+1)+i;
      ElementNode(2*n, 1) = (j-1)*(NumberOfElementInX+1)+i+1;
      ElementNode(2*n, 2) = j*(NumberOfElementInX+1)+i+1;
      ElementNode(2*n, 3) = j*(NumberOfElementInX+1)+i;
      end
      end
      end

      % ElementNode = delaunay(X,Y.*(1+0.001*ElementSize*sin(pi*X/Length)));
      % %ElementNode = delaunay(X,Y);

      % show mesh

      trimesh(ElementNode,X,Y);
      axis equal

      end


      So here is the mesh I get:



      enter image description here



      The problem is that I need to find a way to create a rectangular hole in my mesh. This problem would be applicable to a normal plate if the boundaries were on the outsides of my square but in this problem the boundaries are restricted. Basically, how can I remove the smaller rectangle in my problem? I have posted a screenshot of the dimensions of the problem I'm analyzing. Any tips would be appreciated. enter image description here










      share|improve this question







      New contributor




      Lil_TEE is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.







      $endgroup$




      I am trying to create a finite element code that describes the voltage along a coaxial cable. I have pasted an image of where the boundaries are located but I do not think you need to know much about the finite element method.



      Here is the code:



      function FEM2D
      %
      % This function demonstrates how the 2D Laplace equation with prescribed
      % essential boundary conditions is solved by the finite element method.
      %

      clc, clear, close all;

      % geometric parameters of a rectangule domain
      % These are in cm

      % *** SPLITTING IN QUARTER SIZE REDUCES # OF ELEMENTS ***
      % *** WHEN LEFT AS FULL SIZE AND IN mm # OF ELEMENTS CREATES A PROPER
      % MESH**
      Length = 12.5e-3;
      Height = 10e-3;


      % Element Size

      ElementSize = .001;

      % Number Of Elements

      NumberOfElementInX = 2*(floor(0.5*Length/ElementSize)+1);
      NumberOfElementInY = ceil(Height/ElementSize);

      display(NumberOfElementInX);
      display(NumberOfElementInY);

      ElementSizeInX = Length/NumberOfElementInX;
      ElementSizeInY = Height/NumberOfElementInY;

      display(ElementSizeInX);
      display(ElementSizeInY);

      % Node coordinates

      NumberOfNode = (NumberOfElementInX+1)*(NumberOfElementInY+1);
      NumberOfElement = 2*NumberOfElementInX*NumberOfElementInY;

      X = zeros(NumberOfNode,1);
      Y = zeros(NumberOfNode,1);


      for j = 1 : NumberOfElementInY+1
      for i = 1 : NumberOfElementInX+1
      n = (j-1)*(NumberOfElementInX+1)+i;
      X(n) = (i-1)*ElementSizeInX;
      Y(n) = (j-1)*ElementSizeInY;
      end
      end



      % element node connectivity

      ElementNode = zeros(NumberOfElement,3);
      for j = 1 : NumberOfElementInY
      for i = 1 : NumberOfElementInX
      n = (j-1)*NumberOfElementInX+i;
      if i <= NumberOfElementInX/2
      ElementNode(2*n-1, 1) = (j-1)*(NumberOfElementInX+1)+i;
      ElementNode(2*n-1, 2) = j*(NumberOfElementInX+1)+i+1;
      ElementNode(2*n-1, 3) = j*(NumberOfElementInX+1)+i;
      ElementNode(2*n, 1) = (j-1)*(NumberOfElementInX+1)+i;
      ElementNode(2*n, 2) = (j-1)*(NumberOfElementInX+1)+i+1;
      ElementNode(2*n, 3) = j*(NumberOfElementInX+1)+i+1;
      else
      ElementNode(2*n-1, 1) = (j-1)*(NumberOfElementInX+1)+i;
      ElementNode(2*n-1, 2) = (j-1)*(NumberOfElementInX+1)+i+1;
      ElementNode(2*n-1, 3) = j*(NumberOfElementInX+1)+i;
      ElementNode(2*n, 1) = (j-1)*(NumberOfElementInX+1)+i+1;
      ElementNode(2*n, 2) = j*(NumberOfElementInX+1)+i+1;
      ElementNode(2*n, 3) = j*(NumberOfElementInX+1)+i;
      end
      end
      end

      % ElementNode = delaunay(X,Y.*(1+0.001*ElementSize*sin(pi*X/Length)));
      % %ElementNode = delaunay(X,Y);

      % show mesh

      trimesh(ElementNode,X,Y);
      axis equal

      end


      So here is the mesh I get:



      enter image description here



      The problem is that I need to find a way to create a rectangular hole in my mesh. This problem would be applicable to a normal plate if the boundaries were on the outsides of my square but in this problem the boundaries are restricted. Basically, how can I remove the smaller rectangle in my problem? I have posted a screenshot of the dimensions of the problem I'm analyzing. Any tips would be appreciated. enter image description here







      numerical-methods matlab






      share|improve this question







      New contributor




      Lil_TEE is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.











      share|improve this question







      New contributor




      Lil_TEE is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.









      share|improve this question




      share|improve this question






      New contributor




      Lil_TEE is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.









      asked 2 hours ago









      Lil_TEELil_TEE

      1




      1




      New contributor




      Lil_TEE is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.





      New contributor





      Lil_TEE is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.






      Lil_TEE is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.




      put on hold as off-topic by 200_success, Jamal 1 hour ago


      This question appears to be off-topic. The users who voted to close gave this specific reason:


      • "Code not implemented or not working as intended: Code Review is a community where programmers peer-review your working code to address issues such as security, maintainability, performance, and scalability. We require that the code be working correctly, to the best of the author's knowledge, before proceeding with a review." – 200_success, Jamal

      If this question can be reworded to fit the rules in the help center, please edit the question.







      put on hold as off-topic by 200_success, Jamal 1 hour ago


      This question appears to be off-topic. The users who voted to close gave this specific reason:


      • "Code not implemented or not working as intended: Code Review is a community where programmers peer-review your working code to address issues such as security, maintainability, performance, and scalability. We require that the code be working correctly, to the best of the author's knowledge, before proceeding with a review." – 200_success, Jamal

      If this question can be reworded to fit the rules in the help center, please edit the question.






















          0






          active

          oldest

          votes

















          0






          active

          oldest

          votes








          0






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes

          Popular posts from this blog

          How to make a Squid Proxy server?

          Is this a new Fibonacci Identity?

          19世紀