### New version: Added redistancing, corrected major bug for very high order,...

New version: Added redistancing, corrected major bug for very high order, updated documentation, added test cases. Warning: use the new meshes from this version on.
parent 521259b8
Pipeline #4230 passed with stage
in 10 seconds
 ... ... @@ -5,7 +5,7 @@ # ============================================================================== # Pythonic interfacing constraints (safety barrier) # ============================================================================== __all__ = ["BarycentricBasis","BarycentricGradients"] __all__ = ["BarycentricBasis", "BarycentricGradients"] # ============================================================================== # Preliminary imports ... ... @@ -63,9 +63,6 @@ def BarycentricGradients(Nele, Type, Order, points, n, vol): else: raise(ValueError("Error: Barycentric basis functions are not yet implemented for elements having "+str(Nele)+"edges. Abortion.")) ################################################################################ ################################################################################ # ============================================================================== # Technical routines for the basis functions computations # ============================================================================== ... ... @@ -93,6 +90,7 @@ def SimplicialBasis(Type, Order, points): # Generate the basis functions according to the wished order (automatically) if Type == "B": # ------ Generate the permutations # Generate the indices of the vertices involved in the generation of the barycentric coordinates BaryIndex = np.arange(3) # Generate the combinations corresponding to each barycentric coordinate to select in the monomial generation ... ... @@ -100,10 +98,34 @@ def SimplicialBasis(Type, Order, points): # Initilalising the basis function according to the number of basis functions EvaluatedBase = np.zeros((points.shape, len(ConsideredIndices))) # ------ Compute the basis functions # Compute the basis function in their general form for (i,Cind) in enumerate(ConsideredIndices): EvaluatedBase[:, i] = (np.math.factorial(Order)/np.prod([np.math.factorial(Cind.count(e)) for e in set(Cind)]))*np.prod(points[:,Cind], axis=1) # ------ Reorder the basis functions # Map the functions to match the Barycentric coordinates initiated by the MeshStructure (Laborious but working) # Find the order on each edge Reordering = np.zeros(len(ConsideredIndices), dtype=int); Reordering = 1 Tmp1 = np.zeros(Order+1); Tmp1 = 1; for j in range(1, Order+1): Tmp1[j] = Tmp1[j-1] + j Tmp2 = np.zeros(Order); Tmp2 = 1; for j in range(1, Order): Tmp2[j] = Tmp2[j-1] + j+1; # Assigning the reordering associated to the Meshstrcture Reordering[0:Order+1] = Tmp1 Reordering[Order+1:2*Order+1] = np.arange(Reordering[Order]+1, len(ConsideredIndices)+1) Reordering[2*Order+1:3*Order] = Tmp2[::-1][:-1] # Assigning the reordering associated to the internal basis functions Index = np.setdiff1d(np.arange(len(ConsideredIndices))+1,Reordering) Reordering[int(3*Order):] = Index Reordering = Reordering-1 # Reorder the basis function accordingly EvaluatedBase = EvaluatedBase[:, Reordering] # Safety check else: raise NotImplementedError("The type of wished basis function is not implemented yet. Abortion.") ... ... @@ -144,6 +166,7 @@ def SimplicialGradients(Type, Order, points, n, vol): # Generate the basis functions according to the wished order (automatically) if Type == "B": # ------ Generate the permutations # Generate the indices of the vertices involved in the generation of the barycentric coordinates BaryIndex = np.arange(3) # Generate the combinations corresponding to each barycentric coordinate to select in the monomial generation ... ... @@ -152,6 +175,7 @@ def SimplicialGradients(Type, Order, points, n, vol): EvaluatedGradient = np.zeros((points.shape, len(ConsideredIndices), 3)) Grad = np.zeros((points.shape, 2, len(ConsideredIndices))) # ------ Compute the components involved in each gradient # Compute the derivatives of the basis function in their general form for (j,Cind) in enumerate(ConsideredIndices): for k in range(3): ... ... @@ -160,6 +184,30 @@ def SimplicialGradients(Type, Order, points, n, vol): Ccind.remove(k) EvaluatedGradient[:, j, k] = np.array([(np.math.factorial(Order)/np.prod([np.math.factorial(Ccind.count(e)) for e in set(Ccind)]))*np.prod(points[:,Ccind], axis=1)]) # ------ Reorder the gradients functions # Map the functions to match the Barycentric coordinates initiated by the MeshStructure (Laborious but working) # Find the order on each edge Reordering = np.zeros(len(ConsideredIndices), dtype=int); Reordering = 1 Tmp1 = np.zeros(Order+1); Tmp1 = 1; for j in range(1, Order+1): Tmp1[j] = Tmp1[j-1] + j Tmp2 = np.zeros(Order); Tmp2 = 1; for j in range(1, Order): Tmp2[j] = Tmp2[j-1] + j+1; # Assigning the reordering associated to the Meshstrcture Reordering[0:Order+1] = Tmp1 Reordering[Order+1:2*Order+1] = np.arange(Reordering[Order]+1, len(ConsideredIndices)+1) Reordering[2*Order+1:3*Order] = Tmp2[::-1][:-1] # Assigning the reordering associated to the internal basis functions Index = np.setdiff1d(np.arange(len(ConsideredIndices))+1,Reordering) Reordering[int(3*Order):] = Index Reordering = Reordering-1 # Reorder the basis function accordingly EvaluatedGradient = EvaluatedGradient[:, Reordering,:] # ------ Adapt the gradients to the geometry # Scale the values to the geometry Grad = np.dot(np.swapaxes(np.array([EvaluatedGradient[:,:,0]-EvaluatedGradient[:,:,2], EvaluatedGradient[:,:,1]-EvaluatedGradient[:,:,2]]),0,2),\ ... ...
 """ .. |bs| unicode:: U+00A0 .. NO-BREAK SPACE | Module that computes the solution of any equation of the type \frac{\partial \phi}{\partial t} + H(\phi, t) = 0 over a given Cartesian domain. It implements the WENO scheme for Cartesian grids for HJB equations, following the work of Peng and Jian, "Weighted ENO schemes for HJB equations, PII: S106482759732455X", and uses a simple forward euler method in time. """ # ============================================================================== # Preliminary imports # ============================================================================== import copy import numpy as np import matplotlib.pyplot as plt # ============================================================================== # WENO tools # ============================================================================== # --- Interate the equation (7) until the BregmanInitTime by the Weno 5th order scheme for the residuals, and Euler explicit in time (one iteration) # Defining a consistant flux with H, here Global LFX def Hh(dxP, dxM, dyP, dyM, H, Hx, Hy): alph = np.max([np.max(Hx(dxP, dyP)), np.max(Hx(dxP, dyM)), np.max(Hx(dxM, dyP)), np.max(Hx(dxM, dyM))]) bet = np.max([np.max(Hx(dxP, dyP)), np.max(Hx(dxP, dyM)), np.max(Hx(dxM, dyP)), np.max(Hx(dxM, dyM))]) Val = H(0.5*(dxP+dxM), 0.5*(dyP+dyM)) - alph*(0.5*(dxP-dxM)) - bet*(0.5*(dyP-dyM)) return(Val) # Defining the Weno approximation function def W(a,b,c,d, eps): alph0 = 1/((eps+13*(a-b)**2+3*(a-3*b)**2)**2) alph1 = 6/((eps+13*(b-c)**2+3*(b+c)**2)**2) alph2 = 3/((eps+13*(c-d)**2+3*(3*c-d)**2)**2) w0 = alph0/(alph0+alph1+alph2) w2 = alph2/(alph0+alph1+alph2) return(1/3*w0*(a-2*b+c)+1/6*(w2-0.5)*(b-2*c+d)) # ============================================================================== # Actual routine # ============================================================================== def Iterate(xx, yy, InitVal, Tmax, cfl, eps, H, Hx, Hy): # Retrieving the grid size DeltaX = np.abs(xx-xx) DeltaY = np.abs(yy-yy) # Initialising the iterated value Val = copy.deepcopy(InitVal[:,:]) t=0 while t
File deleted
File deleted
File deleted
File deleted
This diff is collapsed.
File deleted
This diff is collapsed.
No preview for this file type
This diff is collapsed.
No preview for this file type
This diff is collapsed.
This diff is collapsed.
File deleted
File deleted
No preview for this file type
File deleted
No preview for this file type
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment