Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • podlesny/dune-tectonic
  • agnumpde/dune-tectonic
2 results
Show changes
Showing
with 163 additions and 0 deletions
from itertools import combinations
def square_distance(x, y):
return sum([(xi-yi)**2 for xi, yi in zip(x, y)])
def max_distance(points):
max_square_distance = 0
max_pair = (0, 0)
for pair in combinations(points, 2):
sq_dist = square_distance(*pair)
if sq_dist > max_square_distance:
max_square_distance = sq_dist
max_pair = pair
return max_pair
File added
from itertools import combinations
def square_distance(x, y):
return sum([(xi-yi)**2 for xi, yi in zip(x, y)])
def max_distance(points):
max_square_distance = 0
max_pair = (0, 0)
for pair in combinations(points, 2):
sq_dist = square_distance(*pair)
print(sq_dist)
if sq_dist > max_square_distance:
max_square_distance = sq_dist
max_pair = pair
return max_pair
import numpy as np
def max_velocity(x) :
return maximum(norm(x))
\ No newline at end of file
File added
import numpy as np
def max_velocity(x) :
size = x.shape
res = np.zeros(size[0])
for time_step in range(size[0]) :
for vertex in range(size[1]) :
res[time_step] = max(res[time_step], np.linalg.norm(x[time_step, vertex, :]))
return res
\ No newline at end of file
import numpy as np
def maximum(x):
size = x.shape
res = np.zeros(size[0])
for time_step in range(size[0]):
res[time_step] = max(res[time_step], max(x[time_step, :]))
return res
File added
import numpy as np
def maximum(x) :
size = x.shape
res = np.zeros(size[0])
for time_step in range(size[0]) :
for vertex in range(size[1]) :
res[time_step] = max(res[time_step], max(x[time_step, vertex]))
return res
\ No newline at end of file
import numpy as np
def norm(x):
size = x.shape
res = np.zeros((size[0], size[1]))
for time_step in range(size[0]):
for vertex in range(size[1]):
res[time_step, vertex] = np.linalg.norm(x[time_step, vertex, :])
return res
File added
import numpy as np
def norm(x) :
size = x.shape
res = np.zeros(size[0], size[1])
for time_step in range(size[0]) :
for vertex in range(size[1]) :
res[time_step, vertex] = np.linalg.norm(x[time_step, vertex, :])
return res
import array as ar
def slip_beginnings(x):
# returns indicies i for which x[i-1]=0 and x[i]>0
starts = ar.array('i', (0 for i in range(len(x))))
prev = False
length = 0
for i in range(len(x)):
if (not prev and x[i]):
starts[length] = i
length += 1
prev = x[i]
return starts[:length]
File added
import numpy as np
def slip_beginnings(x) :
# returns indicies i for which x[i-1]=0 and x[i]>0
starts = []
prev = False
for i in range(len(x)) :
if (not prev and x[i]) :
starts.append(i)
prev = x[i]
return starts
import array as ar
def slip_endings(x):
# returns indicies i for which x[i-1]>0 and x[i]=0
ends = ar.array('i', (0 for i in range(len(x))))
prev = False
length = 0
for i in range(len(x)):
if (prev and not x[i]):
ends[length] = i
length += 1
prev = x[i]
return ends[:length]
File added
import numpy as np
def slip_endings(x) :
# returns indicies i for which x[i-1]>0 and x[i]=0
starts = np.array([])
prev = False
for i in range(len(x)) :
if (prev and not x[i]) :
starts.append(i)
prev = x[i]
return starts
\ No newline at end of file
# x: vector of domain values
# y: vector of function values f(x)
def trapezoidal(x, y) :
# returns integral of (x, y = f(x)) calculated with trapezoidal rule
res = 0.0
for i in range(1, len(x)) :
res += (x[i] - x[i - 1]) * (y[i] + y[i - 1]) / 2.0
return res
\ No newline at end of file
# x: vector of domain values
# y: vector of function values f(x)
def trapezoidal(x, y) :
# returns integral of (x, y = f(x)) calculated with trapezoidal rule
res = 0.0
for i in range(1, len(x)) :
res += (x[i] - x[i - 1]) * (y[i] + y[i - 1]) / 2.0
return res
\ No newline at end of file