How do I use low level FEM?












3












$begingroup$


How do I simulate the following partial differential equation using Low level FEM in Mathematica?



D[u[x,y], x] - D[u[x,y], y] = x Sin[x y] - y Sin[x y]


The answer is Cos[x y]



added)



The region is [-1,1] for x and [-1,1] for y.



The boundary condition is u[-1,y]=Cos[-y]



Here is my tried code:



delta[x_, a_] := Block[{}, If[x == a, 1, 0]];
mesh = Table[PDF[NormalDistribution[a, z], x]*
PDF[NormalDistribution[b, z], y], {a, -1, 1, 0.1},
{b, -1, 1, 0.1}];
mesh = Flatten[mesh];
cofs = Table[ToExpression[StringJoin[ToString[c],
ToString[a], ToString[b]]], {a, 0, 20}, {b, 0, 20}];
cofs = Flatten[cofs];
weights = Table[delta[x, a]*delta[y, b], {a, -1, 1, 0.05},
{b, -1, 1, 0.05}];
weights = Flatten[weights];
expr = cofs . mesh;
residual = D[expr, x] - D[expr, y] - (x*Sin[x*y] -
y*Sin[x*y]);
integrated = residual*Plus @@ weights;
toMinimize = Plus @@ Flatten[Table[integrated,
{x, -1, 1, 0.1}, {y, -1, 1, 0.1}]];
toMinimize = toMinimize^2;
cofs = Append[cofs, z];
conds = Abs[(expr /. {x -> 0, y -> 0}) - 1];
opt = NMinimize[{toMinimize + conds}, cofs,
Method -> {Automatic, PerformanceGoal -> "Speed"}];
u = expr /. Last[opt];
ListPlot3D[Table[u*Plus @@ weights /. {x -> a, y -> b},
{a, -1, 1, 0.1}, {b, -1, 1, 0.1}]]









share|improve this question











$endgroup$












  • $begingroup$
    In what sense is this a differential equation? Normally you are looking for an unknown function that is defined through a differential equation. What is the unknown function?
    $endgroup$
    – Hugh
    8 hours ago










  • $begingroup$
    my code was wrong.at first,I did used Cos(xy) for creating PDE and solve by FEM. the unknown function is u[x,y]
    $endgroup$
    – Xminer
    8 hours ago










  • $begingroup$
    Do you have a region on which you wish to solve the equation and boundary conditions?
    $endgroup$
    – Hugh
    8 hours ago










  • $begingroup$
    region is {x,-1,1} and{y,-1,1}. Boundary Condition is u[-1,y]=Cos[-y]
    $endgroup$
    – Xminer
    8 hours ago






  • 1




    $begingroup$
    Can you specify what problem you encountered? Otherwise there is an entire tutorial on FiniteElementProgramming.
    $endgroup$
    – user21
    8 hours ago
















3












$begingroup$


How do I simulate the following partial differential equation using Low level FEM in Mathematica?



D[u[x,y], x] - D[u[x,y], y] = x Sin[x y] - y Sin[x y]


The answer is Cos[x y]



added)



The region is [-1,1] for x and [-1,1] for y.



The boundary condition is u[-1,y]=Cos[-y]



Here is my tried code:



delta[x_, a_] := Block[{}, If[x == a, 1, 0]];
mesh = Table[PDF[NormalDistribution[a, z], x]*
PDF[NormalDistribution[b, z], y], {a, -1, 1, 0.1},
{b, -1, 1, 0.1}];
mesh = Flatten[mesh];
cofs = Table[ToExpression[StringJoin[ToString[c],
ToString[a], ToString[b]]], {a, 0, 20}, {b, 0, 20}];
cofs = Flatten[cofs];
weights = Table[delta[x, a]*delta[y, b], {a, -1, 1, 0.05},
{b, -1, 1, 0.05}];
weights = Flatten[weights];
expr = cofs . mesh;
residual = D[expr, x] - D[expr, y] - (x*Sin[x*y] -
y*Sin[x*y]);
integrated = residual*Plus @@ weights;
toMinimize = Plus @@ Flatten[Table[integrated,
{x, -1, 1, 0.1}, {y, -1, 1, 0.1}]];
toMinimize = toMinimize^2;
cofs = Append[cofs, z];
conds = Abs[(expr /. {x -> 0, y -> 0}) - 1];
opt = NMinimize[{toMinimize + conds}, cofs,
Method -> {Automatic, PerformanceGoal -> "Speed"}];
u = expr /. Last[opt];
ListPlot3D[Table[u*Plus @@ weights /. {x -> a, y -> b},
{a, -1, 1, 0.1}, {b, -1, 1, 0.1}]]









share|improve this question











$endgroup$












  • $begingroup$
    In what sense is this a differential equation? Normally you are looking for an unknown function that is defined through a differential equation. What is the unknown function?
    $endgroup$
    – Hugh
    8 hours ago










  • $begingroup$
    my code was wrong.at first,I did used Cos(xy) for creating PDE and solve by FEM. the unknown function is u[x,y]
    $endgroup$
    – Xminer
    8 hours ago










  • $begingroup$
    Do you have a region on which you wish to solve the equation and boundary conditions?
    $endgroup$
    – Hugh
    8 hours ago










  • $begingroup$
    region is {x,-1,1} and{y,-1,1}. Boundary Condition is u[-1,y]=Cos[-y]
    $endgroup$
    – Xminer
    8 hours ago






  • 1




    $begingroup$
    Can you specify what problem you encountered? Otherwise there is an entire tutorial on FiniteElementProgramming.
    $endgroup$
    – user21
    8 hours ago














3












3








3





$begingroup$


How do I simulate the following partial differential equation using Low level FEM in Mathematica?



D[u[x,y], x] - D[u[x,y], y] = x Sin[x y] - y Sin[x y]


The answer is Cos[x y]



added)



The region is [-1,1] for x and [-1,1] for y.



The boundary condition is u[-1,y]=Cos[-y]



Here is my tried code:



delta[x_, a_] := Block[{}, If[x == a, 1, 0]];
mesh = Table[PDF[NormalDistribution[a, z], x]*
PDF[NormalDistribution[b, z], y], {a, -1, 1, 0.1},
{b, -1, 1, 0.1}];
mesh = Flatten[mesh];
cofs = Table[ToExpression[StringJoin[ToString[c],
ToString[a], ToString[b]]], {a, 0, 20}, {b, 0, 20}];
cofs = Flatten[cofs];
weights = Table[delta[x, a]*delta[y, b], {a, -1, 1, 0.05},
{b, -1, 1, 0.05}];
weights = Flatten[weights];
expr = cofs . mesh;
residual = D[expr, x] - D[expr, y] - (x*Sin[x*y] -
y*Sin[x*y]);
integrated = residual*Plus @@ weights;
toMinimize = Plus @@ Flatten[Table[integrated,
{x, -1, 1, 0.1}, {y, -1, 1, 0.1}]];
toMinimize = toMinimize^2;
cofs = Append[cofs, z];
conds = Abs[(expr /. {x -> 0, y -> 0}) - 1];
opt = NMinimize[{toMinimize + conds}, cofs,
Method -> {Automatic, PerformanceGoal -> "Speed"}];
u = expr /. Last[opt];
ListPlot3D[Table[u*Plus @@ weights /. {x -> a, y -> b},
{a, -1, 1, 0.1}, {b, -1, 1, 0.1}]]









share|improve this question











$endgroup$




How do I simulate the following partial differential equation using Low level FEM in Mathematica?



D[u[x,y], x] - D[u[x,y], y] = x Sin[x y] - y Sin[x y]


The answer is Cos[x y]



added)



The region is [-1,1] for x and [-1,1] for y.



The boundary condition is u[-1,y]=Cos[-y]



Here is my tried code:



delta[x_, a_] := Block[{}, If[x == a, 1, 0]];
mesh = Table[PDF[NormalDistribution[a, z], x]*
PDF[NormalDistribution[b, z], y], {a, -1, 1, 0.1},
{b, -1, 1, 0.1}];
mesh = Flatten[mesh];
cofs = Table[ToExpression[StringJoin[ToString[c],
ToString[a], ToString[b]]], {a, 0, 20}, {b, 0, 20}];
cofs = Flatten[cofs];
weights = Table[delta[x, a]*delta[y, b], {a, -1, 1, 0.05},
{b, -1, 1, 0.05}];
weights = Flatten[weights];
expr = cofs . mesh;
residual = D[expr, x] - D[expr, y] - (x*Sin[x*y] -
y*Sin[x*y]);
integrated = residual*Plus @@ weights;
toMinimize = Plus @@ Flatten[Table[integrated,
{x, -1, 1, 0.1}, {y, -1, 1, 0.1}]];
toMinimize = toMinimize^2;
cofs = Append[cofs, z];
conds = Abs[(expr /. {x -> 0, y -> 0}) - 1];
opt = NMinimize[{toMinimize + conds}, cofs,
Method -> {Automatic, PerformanceGoal -> "Speed"}];
u = expr /. Last[opt];
ListPlot3D[Table[u*Plus @@ weights /. {x -> a, y -> b},
{a, -1, 1, 0.1}, {b, -1, 1, 0.1}]]






finite-element-method






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited 10 mins ago









Peter Mortensen

32627




32627










asked 8 hours ago









XminerXminer

766




766












  • $begingroup$
    In what sense is this a differential equation? Normally you are looking for an unknown function that is defined through a differential equation. What is the unknown function?
    $endgroup$
    – Hugh
    8 hours ago










  • $begingroup$
    my code was wrong.at first,I did used Cos(xy) for creating PDE and solve by FEM. the unknown function is u[x,y]
    $endgroup$
    – Xminer
    8 hours ago










  • $begingroup$
    Do you have a region on which you wish to solve the equation and boundary conditions?
    $endgroup$
    – Hugh
    8 hours ago










  • $begingroup$
    region is {x,-1,1} and{y,-1,1}. Boundary Condition is u[-1,y]=Cos[-y]
    $endgroup$
    – Xminer
    8 hours ago






  • 1




    $begingroup$
    Can you specify what problem you encountered? Otherwise there is an entire tutorial on FiniteElementProgramming.
    $endgroup$
    – user21
    8 hours ago


















  • $begingroup$
    In what sense is this a differential equation? Normally you are looking for an unknown function that is defined through a differential equation. What is the unknown function?
    $endgroup$
    – Hugh
    8 hours ago










  • $begingroup$
    my code was wrong.at first,I did used Cos(xy) for creating PDE and solve by FEM. the unknown function is u[x,y]
    $endgroup$
    – Xminer
    8 hours ago










  • $begingroup$
    Do you have a region on which you wish to solve the equation and boundary conditions?
    $endgroup$
    – Hugh
    8 hours ago










  • $begingroup$
    region is {x,-1,1} and{y,-1,1}. Boundary Condition is u[-1,y]=Cos[-y]
    $endgroup$
    – Xminer
    8 hours ago






  • 1




    $begingroup$
    Can you specify what problem you encountered? Otherwise there is an entire tutorial on FiniteElementProgramming.
    $endgroup$
    – user21
    8 hours ago
















$begingroup$
In what sense is this a differential equation? Normally you are looking for an unknown function that is defined through a differential equation. What is the unknown function?
$endgroup$
– Hugh
8 hours ago




$begingroup$
In what sense is this a differential equation? Normally you are looking for an unknown function that is defined through a differential equation. What is the unknown function?
$endgroup$
– Hugh
8 hours ago












$begingroup$
my code was wrong.at first,I did used Cos(xy) for creating PDE and solve by FEM. the unknown function is u[x,y]
$endgroup$
– Xminer
8 hours ago




$begingroup$
my code was wrong.at first,I did used Cos(xy) for creating PDE and solve by FEM. the unknown function is u[x,y]
$endgroup$
– Xminer
8 hours ago












$begingroup$
Do you have a region on which you wish to solve the equation and boundary conditions?
$endgroup$
– Hugh
8 hours ago




$begingroup$
Do you have a region on which you wish to solve the equation and boundary conditions?
$endgroup$
– Hugh
8 hours ago












$begingroup$
region is {x,-1,1} and{y,-1,1}. Boundary Condition is u[-1,y]=Cos[-y]
$endgroup$
– Xminer
8 hours ago




$begingroup$
region is {x,-1,1} and{y,-1,1}. Boundary Condition is u[-1,y]=Cos[-y]
$endgroup$
– Xminer
8 hours ago




1




1




$begingroup$
Can you specify what problem you encountered? Otherwise there is an entire tutorial on FiniteElementProgramming.
$endgroup$
– user21
8 hours ago




$begingroup$
Can you specify what problem you encountered? Otherwise there is an entire tutorial on FiniteElementProgramming.
$endgroup$
– user21
8 hours ago










1 Answer
1






active

oldest

votes


















10












$begingroup$

I am not a 100% sure I understand your question, here is what I think could help you.



The finite element method is, strictly speaking, not a method to solve PDEs. What it does it takes a continuous PDE and converts it to an approximate equivalent matrix and vector. The matrix and vector are discrete representations of the PDE. When you solve this set of equations you will get an approximate solution to the PDE.



We set up an equation:



Needs["NDSolve`FEM`"]
{state} =
NDSolve`ProcessEquations[{Laplacian[u[x, y], {x, y}] == 1,
DirichletCondition[u[x, y] == 0, True]}, u, {x, 0, 1}, {y, 0, 1},
Method -> {"FiniteElement"}];


Now we extract some data from the NDSolve state data object.



femdata = state["FiniteElementData"]
femdata["Properties"]
methodData = femdata["FEMMethodData"];
bcData = femdata["BoundaryConditionData"];
pdeData = femdata["PDECoefficientData"];
variableData = state["VariableData"];
solutionData = state["SolutionData"][[1]];


If you do not want to / can not use NDSolve`ProcessEquations you may need to look at InitializePDECoefficients and such functions.



If you look at pdeData, that now contains the coefficients of the equations given in NDSolve:



pdeData["All"]

{{{{1}}, {{{{0}, {0}}}}}, {{{{{-1,
0}, {0, -1}}}}, {{{{0}, {0}}}}, {{{{0,
0}}}}, {{0}}}, {{{0}}}, {{{0}}}}


Now, the finite element method is applied. This converts the continuous PDE into a system of discrete matrices:



discretePDE = DiscretizePDE[pdeData, methodData, solutionData]
{load, stiffness, damping, mass} = discretePDE["SystemMatrices"]


You can look at the matrices:



MatrixPlot[stiffness]


The same conversion is done for the boundary conditions:



discreteBCs = 
DiscretizeBoundaryConditions[bcData, methodData, solutionData];


All the finite element method does is done now. The rest is linear algebra.



We now put the discrete boundary conditions into the discrete matrices:



DeployBoundaryConditions[{load, stiffness}, discreteBCs]


Solve:



solution = LinearSolve[stiffness, load];


Generate an Interpolating function:



mesh = methodData["ElementMesh"];
ifun = ElementMeshInterpolation[{mesh}, solution]


And visualize:



Plot3D[ifun[x, y], {x, y} [Element] mesh]


Hope this helps a bit.






share|improve this answer











$endgroup$













    Your Answer





    StackExchange.ifUsing("editor", function () {
    return StackExchange.using("mathjaxEditing", function () {
    StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix) {
    StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["$", "$"], ["\\(","\\)"]]);
    });
    });
    }, "mathjax-editing");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "387"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: false,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: null,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmathematica.stackexchange.com%2fquestions%2f189595%2fhow-do-i-use-low-level-fem%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    10












    $begingroup$

    I am not a 100% sure I understand your question, here is what I think could help you.



    The finite element method is, strictly speaking, not a method to solve PDEs. What it does it takes a continuous PDE and converts it to an approximate equivalent matrix and vector. The matrix and vector are discrete representations of the PDE. When you solve this set of equations you will get an approximate solution to the PDE.



    We set up an equation:



    Needs["NDSolve`FEM`"]
    {state} =
    NDSolve`ProcessEquations[{Laplacian[u[x, y], {x, y}] == 1,
    DirichletCondition[u[x, y] == 0, True]}, u, {x, 0, 1}, {y, 0, 1},
    Method -> {"FiniteElement"}];


    Now we extract some data from the NDSolve state data object.



    femdata = state["FiniteElementData"]
    femdata["Properties"]
    methodData = femdata["FEMMethodData"];
    bcData = femdata["BoundaryConditionData"];
    pdeData = femdata["PDECoefficientData"];
    variableData = state["VariableData"];
    solutionData = state["SolutionData"][[1]];


    If you do not want to / can not use NDSolve`ProcessEquations you may need to look at InitializePDECoefficients and such functions.



    If you look at pdeData, that now contains the coefficients of the equations given in NDSolve:



    pdeData["All"]

    {{{{1}}, {{{{0}, {0}}}}}, {{{{{-1,
    0}, {0, -1}}}}, {{{{0}, {0}}}}, {{{{0,
    0}}}}, {{0}}}, {{{0}}}, {{{0}}}}


    Now, the finite element method is applied. This converts the continuous PDE into a system of discrete matrices:



    discretePDE = DiscretizePDE[pdeData, methodData, solutionData]
    {load, stiffness, damping, mass} = discretePDE["SystemMatrices"]


    You can look at the matrices:



    MatrixPlot[stiffness]


    The same conversion is done for the boundary conditions:



    discreteBCs = 
    DiscretizeBoundaryConditions[bcData, methodData, solutionData];


    All the finite element method does is done now. The rest is linear algebra.



    We now put the discrete boundary conditions into the discrete matrices:



    DeployBoundaryConditions[{load, stiffness}, discreteBCs]


    Solve:



    solution = LinearSolve[stiffness, load];


    Generate an Interpolating function:



    mesh = methodData["ElementMesh"];
    ifun = ElementMeshInterpolation[{mesh}, solution]


    And visualize:



    Plot3D[ifun[x, y], {x, y} [Element] mesh]


    Hope this helps a bit.






    share|improve this answer











    $endgroup$


















      10












      $begingroup$

      I am not a 100% sure I understand your question, here is what I think could help you.



      The finite element method is, strictly speaking, not a method to solve PDEs. What it does it takes a continuous PDE and converts it to an approximate equivalent matrix and vector. The matrix and vector are discrete representations of the PDE. When you solve this set of equations you will get an approximate solution to the PDE.



      We set up an equation:



      Needs["NDSolve`FEM`"]
      {state} =
      NDSolve`ProcessEquations[{Laplacian[u[x, y], {x, y}] == 1,
      DirichletCondition[u[x, y] == 0, True]}, u, {x, 0, 1}, {y, 0, 1},
      Method -> {"FiniteElement"}];


      Now we extract some data from the NDSolve state data object.



      femdata = state["FiniteElementData"]
      femdata["Properties"]
      methodData = femdata["FEMMethodData"];
      bcData = femdata["BoundaryConditionData"];
      pdeData = femdata["PDECoefficientData"];
      variableData = state["VariableData"];
      solutionData = state["SolutionData"][[1]];


      If you do not want to / can not use NDSolve`ProcessEquations you may need to look at InitializePDECoefficients and such functions.



      If you look at pdeData, that now contains the coefficients of the equations given in NDSolve:



      pdeData["All"]

      {{{{1}}, {{{{0}, {0}}}}}, {{{{{-1,
      0}, {0, -1}}}}, {{{{0}, {0}}}}, {{{{0,
      0}}}}, {{0}}}, {{{0}}}, {{{0}}}}


      Now, the finite element method is applied. This converts the continuous PDE into a system of discrete matrices:



      discretePDE = DiscretizePDE[pdeData, methodData, solutionData]
      {load, stiffness, damping, mass} = discretePDE["SystemMatrices"]


      You can look at the matrices:



      MatrixPlot[stiffness]


      The same conversion is done for the boundary conditions:



      discreteBCs = 
      DiscretizeBoundaryConditions[bcData, methodData, solutionData];


      All the finite element method does is done now. The rest is linear algebra.



      We now put the discrete boundary conditions into the discrete matrices:



      DeployBoundaryConditions[{load, stiffness}, discreteBCs]


      Solve:



      solution = LinearSolve[stiffness, load];


      Generate an Interpolating function:



      mesh = methodData["ElementMesh"];
      ifun = ElementMeshInterpolation[{mesh}, solution]


      And visualize:



      Plot3D[ifun[x, y], {x, y} [Element] mesh]


      Hope this helps a bit.






      share|improve this answer











      $endgroup$
















        10












        10








        10





        $begingroup$

        I am not a 100% sure I understand your question, here is what I think could help you.



        The finite element method is, strictly speaking, not a method to solve PDEs. What it does it takes a continuous PDE and converts it to an approximate equivalent matrix and vector. The matrix and vector are discrete representations of the PDE. When you solve this set of equations you will get an approximate solution to the PDE.



        We set up an equation:



        Needs["NDSolve`FEM`"]
        {state} =
        NDSolve`ProcessEquations[{Laplacian[u[x, y], {x, y}] == 1,
        DirichletCondition[u[x, y] == 0, True]}, u, {x, 0, 1}, {y, 0, 1},
        Method -> {"FiniteElement"}];


        Now we extract some data from the NDSolve state data object.



        femdata = state["FiniteElementData"]
        femdata["Properties"]
        methodData = femdata["FEMMethodData"];
        bcData = femdata["BoundaryConditionData"];
        pdeData = femdata["PDECoefficientData"];
        variableData = state["VariableData"];
        solutionData = state["SolutionData"][[1]];


        If you do not want to / can not use NDSolve`ProcessEquations you may need to look at InitializePDECoefficients and such functions.



        If you look at pdeData, that now contains the coefficients of the equations given in NDSolve:



        pdeData["All"]

        {{{{1}}, {{{{0}, {0}}}}}, {{{{{-1,
        0}, {0, -1}}}}, {{{{0}, {0}}}}, {{{{0,
        0}}}}, {{0}}}, {{{0}}}, {{{0}}}}


        Now, the finite element method is applied. This converts the continuous PDE into a system of discrete matrices:



        discretePDE = DiscretizePDE[pdeData, methodData, solutionData]
        {load, stiffness, damping, mass} = discretePDE["SystemMatrices"]


        You can look at the matrices:



        MatrixPlot[stiffness]


        The same conversion is done for the boundary conditions:



        discreteBCs = 
        DiscretizeBoundaryConditions[bcData, methodData, solutionData];


        All the finite element method does is done now. The rest is linear algebra.



        We now put the discrete boundary conditions into the discrete matrices:



        DeployBoundaryConditions[{load, stiffness}, discreteBCs]


        Solve:



        solution = LinearSolve[stiffness, load];


        Generate an Interpolating function:



        mesh = methodData["ElementMesh"];
        ifun = ElementMeshInterpolation[{mesh}, solution]


        And visualize:



        Plot3D[ifun[x, y], {x, y} [Element] mesh]


        Hope this helps a bit.






        share|improve this answer











        $endgroup$



        I am not a 100% sure I understand your question, here is what I think could help you.



        The finite element method is, strictly speaking, not a method to solve PDEs. What it does it takes a continuous PDE and converts it to an approximate equivalent matrix and vector. The matrix and vector are discrete representations of the PDE. When you solve this set of equations you will get an approximate solution to the PDE.



        We set up an equation:



        Needs["NDSolve`FEM`"]
        {state} =
        NDSolve`ProcessEquations[{Laplacian[u[x, y], {x, y}] == 1,
        DirichletCondition[u[x, y] == 0, True]}, u, {x, 0, 1}, {y, 0, 1},
        Method -> {"FiniteElement"}];


        Now we extract some data from the NDSolve state data object.



        femdata = state["FiniteElementData"]
        femdata["Properties"]
        methodData = femdata["FEMMethodData"];
        bcData = femdata["BoundaryConditionData"];
        pdeData = femdata["PDECoefficientData"];
        variableData = state["VariableData"];
        solutionData = state["SolutionData"][[1]];


        If you do not want to / can not use NDSolve`ProcessEquations you may need to look at InitializePDECoefficients and such functions.



        If you look at pdeData, that now contains the coefficients of the equations given in NDSolve:



        pdeData["All"]

        {{{{1}}, {{{{0}, {0}}}}}, {{{{{-1,
        0}, {0, -1}}}}, {{{{0}, {0}}}}, {{{{0,
        0}}}}, {{0}}}, {{{0}}}, {{{0}}}}


        Now, the finite element method is applied. This converts the continuous PDE into a system of discrete matrices:



        discretePDE = DiscretizePDE[pdeData, methodData, solutionData]
        {load, stiffness, damping, mass} = discretePDE["SystemMatrices"]


        You can look at the matrices:



        MatrixPlot[stiffness]


        The same conversion is done for the boundary conditions:



        discreteBCs = 
        DiscretizeBoundaryConditions[bcData, methodData, solutionData];


        All the finite element method does is done now. The rest is linear algebra.



        We now put the discrete boundary conditions into the discrete matrices:



        DeployBoundaryConditions[{load, stiffness}, discreteBCs]


        Solve:



        solution = LinearSolve[stiffness, load];


        Generate an Interpolating function:



        mesh = methodData["ElementMesh"];
        ifun = ElementMeshInterpolation[{mesh}, solution]


        And visualize:



        Plot3D[ifun[x, y], {x, y} [Element] mesh]


        Hope this helps a bit.







        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited 6 hours ago

























        answered 7 hours ago









        user21user21

        19.7k44983




        19.7k44983






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Mathematica Stack Exchange!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            Use MathJax to format equations. MathJax reference.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmathematica.stackexchange.com%2fquestions%2f189595%2fhow-do-i-use-low-level-fem%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Magento 2 controller redirect on button click in phtml file

            Polycentropodidae