Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. setting Boundary condition X^2-Y^2 for solving Laplace equation for NxN grid.

setting Boundary condition X^2-Y^2 for solving Laplace equation for NxN grid.

Scheduled Pinned Locked Moved C / C++ / MFC
pythoncsshelptutorial
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • U Offline
    U Offline
    User 13593623
    wrote on last edited by
    #1

    i am trying to write a code to solve Laplace equation using Successive

    Over relaxation(SOR)on a NXN matrix boundary condition is X^2-y^2 i dont know how to set this boundary condition on the Mesh created by me here is the code

    import numpy as np
    from pylab import *
    import sys
    import copy
    import matplotlib.pyplot as plt
    import matplotlib.ticker as ticker
    L =[[]for i in range(2)]
    N=int(input("Enter a number N for N x N grid: "))
    h=1/N
    def clear_list1():
    L[1].clear()
    L[0].clear()
    iterat=0
    error=0.75
    clear_list1()
    xx=np.arange(0,N,h)
    yy=np.arange(0,N,h)
    x,y = np.meshgrid(xx,yy)
    phi= copy.deepcopy((x**2-y**2))
    phi[1:-1,1:-1]=0
    phi_new = copy.deepcopy(phi)
    resid=np.zeros((N,N))

    while True:
    if iterat<21:

       for w in np.linspace(1,2,11):
           for i in range(1,N-1):
               for j in range(1,N-1):
                   phi1=(phi\[i+1,j\]+phi\[i-1,j\]+phi\[i,j+1\]+phi\[i,j-1\])/4
                   phi\[i,j\]=w\*phi1+(1-w)\*phi1
                   
       Sumresidual=0
       for i in range(1,N-1):
           for j in range(1,N-1):
               resid\[i,j\]= -4\*phi\[i,j\]+phi\[i+1,j\]+phi\[i-1,j\]+phi\[i,j+1\]+phi\[i,j-1\]
               Sumresidual=Sumresidual+(resid\[i,j\])\*\*2
    else:
        break
    iterat=iterat+1
    p=np.sqrt(Sumresidual)
    L\[0\].append(p)
    L\[1\].append(w)
    

    ax = plt.axes()
    ax.xaxis.set_major_locator(ticker.MaxNLocator(5))

    plt.plot(L[0],L[1])
    plt.yscale('log')
    plt.xlabel('w')
    plt.ylabel('|| residual ||')
    plt.title('effect of w on residual')
    plt.show()

    V 1 Reply Last reply
    0
    • U User 13593623

      i am trying to write a code to solve Laplace equation using Successive

      Over relaxation(SOR)on a NXN matrix boundary condition is X^2-y^2 i dont know how to set this boundary condition on the Mesh created by me here is the code

      import numpy as np
      from pylab import *
      import sys
      import copy
      import matplotlib.pyplot as plt
      import matplotlib.ticker as ticker
      L =[[]for i in range(2)]
      N=int(input("Enter a number N for N x N grid: "))
      h=1/N
      def clear_list1():
      L[1].clear()
      L[0].clear()
      iterat=0
      error=0.75
      clear_list1()
      xx=np.arange(0,N,h)
      yy=np.arange(0,N,h)
      x,y = np.meshgrid(xx,yy)
      phi= copy.deepcopy((x**2-y**2))
      phi[1:-1,1:-1]=0
      phi_new = copy.deepcopy(phi)
      resid=np.zeros((N,N))

      while True:
      if iterat<21:

         for w in np.linspace(1,2,11):
             for i in range(1,N-1):
                 for j in range(1,N-1):
                     phi1=(phi\[i+1,j\]+phi\[i-1,j\]+phi\[i,j+1\]+phi\[i,j-1\])/4
                     phi\[i,j\]=w\*phi1+(1-w)\*phi1
                     
         Sumresidual=0
         for i in range(1,N-1):
             for j in range(1,N-1):
                 resid\[i,j\]= -4\*phi\[i,j\]+phi\[i+1,j\]+phi\[i-1,j\]+phi\[i,j+1\]+phi\[i,j-1\]
                 Sumresidual=Sumresidual+(resid\[i,j\])\*\*2
      else:
          break
      iterat=iterat+1
      p=np.sqrt(Sumresidual)
      L\[0\].append(p)
      L\[1\].append(w)
      

      ax = plt.axes()
      ax.xaxis.set_major_locator(ticker.MaxNLocator(5))

      plt.plot(L[0],L[1])
      plt.yscale('log')
      plt.xlabel('w')
      plt.ylabel('|| residual ||')
      plt.title('effect of w on residual')
      plt.show()

      V Offline
      V Offline
      Victor Nijegorodov
      wrote on last edited by
      #2

      And what does your code have to do with the C / C++ / MFC Forum?

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups