def __init__(self, source_sites, polynomial_order, weighting_power=2, epsilon_multiplier=1.5): self.last_target_site = np.zeros((1, )) self.kokkos_obj = pycompadre.KokkosParser() assert len( source_sites.shape ) == 2, "2D array must be given to GMLS for source_sites (#sites x spatial dimension)" self.input_dimensions = source_sites.shape[1] self.polynomial_order = polynomial_order # initialize 3rd order reconstruction using 2nd order basis in 3D (GMLS) self.gmls_obj = pycompadre.GMLS(polynomial_order, self.input_dimensions, "QR", "STANDARD") self.gmls_obj.setWeightingPower(weighting_power) self.weighting_power = weighting_power self.gmls_obj.setWeightingType("power") # neighbor search self.epsilon_multiplier = epsilon_multiplier self.gmls_helper = pycompadre.ParticleHelper(self.gmls_obj) self.gmls_helper.generateKDTree(source_sites) self.gmls_obj.addTargets( pycompadre.TargetOperation.ScalarPointEvaluation) self.gmls_obj.addTargets( pycompadre.TargetOperation.PartialXOfScalarPointEvaluation) self.gmls_obj.addTargets( pycompadre.TargetOperation.PartialYOfScalarPointEvaluation)
import pycompadre import numpy as np import matplotlib.pyplot as plt from matplotlib.widgets import Slider, Button, RadioButtons, CheckButtons ''' Interactive example of weighting kernels in pycompadre The weighting kernels used in the GMLS class in the function Wab allow users to vary two parameters. This tool gives users the ability to vary these two parameters and weighting type and see the effect visually. ''' # initialize Kokkos kp = pycompadre.KokkosParser() # initialize parameters wt = pycompadre.WeightingFunctionType.Power x = np.linspace(-2.0, 2.0, 700) h = 1.0 p = 2 n = 1 def approximate(wt, h, p, n): y = np.array([pycompadre.Wab(xin,h,wt,p,n) for xin in x], dtype='f8') return y # get initial data y = approximate(wt, h, p, n) # plot initial data fig, ax = plt.subplots()
def setUpClass(cls): KokkosTestCase.instances += 1 if KokkosTestCase.instances == 1: KokkosTestCase.shared_resource = pycompadre.KokkosParser(sys.argv)
def safe_instantiate_kokkos(): if KokkosDevice.instance_count == 0: KokkosDevice.kokkos_obj=pycompadre.KokkosParser() KokkosDevice.instance_count += 1
from unittest import TestCase import numpy as np import math import random import pycompadre kokkos_obj=pycompadre.KokkosParser() # function used to generate sample data def exact(coord,order,dimension): x = coord[0] y = coord[1] if (dimension>1) else 0 z = coord[2] if (dimension>2) else 0 if order==1: return 1 + x + y + z elif order==2: return 1 + x + y + z + x*x + x*y + x*z + y*y + y*z + z*z elif order==3: return 1 + x + y + z + x*x + x*y + x*z + y*y + y*z + z*z + x*x*x + x*x*y + x*x*z + x*y*y + x*y*z + x*z*z + y*y*y + y*y*z + y*z*z + z*z*z # function used to get analytic gradient def grad_exact(coord,component,order,dimension): x = coord[0] y = coord[1] if (dimension>1) else 0 z = coord[2] if (dimension>2) else 0 if (component==0): if order==1: return 1 elif order==2: return 1 + 2*x + y + z elif order==3: