def inlet_vof_dirichlet(x, t): from proteus import Context ct = Context.get() level = wave.mwl + wave.eta(x,t) mesh = ct.domain.MeshOptions he, ecH = ct.domain.MeshOptions.he, ct.epsFact_consrv_heaviside H = smoothedHeaviside(ecH*he,x[vert_axis]-level) return H
def test_get(): from proteus import Context Context.set(ContextObject()) ct = Context.get() check_eq(ct) try: ct.T=11.0 except Exception as e: assert(type(e) is AttributeError)
def test_get(): from proteus import Context Context.set(ContextObject()) ct = Context.get() check_eq(ct) try: ct.T = 11.0 except Exception as e: assert (type(e) is AttributeError)
def test_setMutableFromModule(): import os from proteus import Context with open("context_module.py", "w") as f: f.write("nnx=11; T=10.0; g=9.8\n") sys.path.append(os.getcwd()) import context_module os.remove("context_module.py") Context.setFromModule(context_module, mutable=True) check_eq(Context.context) ct = Context.get() ct.T = 11.0 eq(ct.T, 11.0)
def test_setMutableFromModule(): import os from proteus import Context with open("context_module.py","w") as f: f.write("nnx=11; T=10.0; g=9.8\n") sys.path.append(os.getcwd()) import context_module os.remove("context_module.py") Context.setFromModule(context_module, mutable=True) check_eq(Context.context) ct = Context.get() ct.T=11.0 eq(ct.T,11.0)
def getContext(self, context=None): """ Gets context from proteus.Context or Parameters ---------- context: class, optional if set to None, the context will be created from proteus.Context """ if context: from proteus import Context self.ct = Context.get() else: self.ct = context
def twp_flowVelocity(x, t): from proteus import Context ct = Context.get() vert_axis = self.Shape.Domain.nd-1 waveHeight = self.waves.mwl+self.waves.eta(x, t) wavePhi = x[vert_axis]-waveHeight if wavePhi <= 0: waterSpeed = self.waves.u(x, t) else: x_max = np.copy(x) x_max[vert_axis] = waveHeight waterSpeed = self.waves.u(x_max, t) he, ech = ct.domain.MeshOptions.he, ct.epsFact_consrv_heaviside H = smoothedHeaviside(0.5*ech*he, wavePhi-0.5*ech*he) return H*self.windSpeed[i] + (1-H)*waterSpeed[i]
def ux_dirichlet(x, t): from proteus import Context ct = Context.get() waveHeight = wave.mwl+wave.eta(x, t) wavePhi = x[vert_axis]-waveHeight if wavePhi <= 0: waterSpeed = wave.u(x, t) else: x_max = list(x) x_max[vert_axis] = waveHeight waterSpeed = wave.u(x_max, t) he, ecH = ct.domain.MeshOptions.he, ct.epsFact_consrv_heaviside # smoothing only above wave, only on half the VOF smoothing length H = smoothedHeaviside(0.5*ecH*he, wavePhi-0.5*ecH*he) ux = H*windSpeed + (1-H)*waterSpeed return ux[i]
def inlet_p_advective(x, t): from proteus import Context ct = Context.get() # This is the normal velocity, based on the outwards boundary # orientation b_or # needs to be equal to -ux_dirichlet b_or = self._b_or[self._b_i] nd = len(b_or) waterSpeed = np.array(wave.u(x, t)) waveHeight = wave.mwl+wave.eta(x, t) wavePhi = x[vert_axis]-waveHeight he = ct.domain.MeshOptions.he if wavePhi <= 0: waterSpeed = wave.u(x, t) else: x_max = list(x) x_max[vert_axis] = waveHeight waterSpeed = wave.u(x_max, t) he, ecH = ct.domain.MeshOptions.he, ct.epsFact_consrv_heaviside # smoothing only above wave, only on half the VOF smoothing length H = smoothedHeaviside(0.5*ecH*he, wavePhi-0.5*ecH*he) U = H*windSpeed + (1-H)*waterSpeed u_p = np.sum(U[:nd]*b_or) return u_p
from proteus.default_n import * import ls_p as physics from proteus import (StepControl, TimeIntegration, NonlinearSolvers, LinearSolvers, LinearAlgebraTools) from proteus.mprans import NCLS from proteus import Context ct = Context.get() domain = ct.domain nd = ct.domain.nd mesh = domain.MeshOptions # time stepping runCFL = ct.runCFL if ct.timeIntegration == "VBDF": timeIntegration = TimeIntegration.VBDF timeOrder = 2 else: timeIntegration = TimeIntegration.BackwardEuler_cfl stepController = StepControl.Min_dt_controller # mesh options nLevels = ct.nLevels parallelPartitioningType = mesh.parallelPartitioningType nLayersOfOverlapForParallel = mesh.nLayersOfOverlapForParallel restrictFineSolutionToAllMeshes = mesh.restrictFineSolutionToAllMeshes triangleOptions = mesh.triangleOptions
from proteus import Context from proteus import Comm comm = Comm.get() ctx = Context.get() # simulation flags for error analysis # # simFlagsList is initialized in proteus.iproteus # simFlagsList[0]['errorQuantities']=['u'] simFlagsList[0]['errorTypes']= ['numericalSolution'] #compute error in soln and glob. mass bal simFlagsList[0]['errorNorms']= ['L1','LI'] #compute L2 norm in space or H0 or ... simFlagsList[0]['errorTimes']= ['Last'] #'All', 'Last' simFlagsList[0]['echo']=True simFlagsList[0]['echoRelativeErrors']=True # start quit
def test_unsteady_two_phase_velocity_inlet(self): from proteus.WaveTools import MonochromaticWaves b_or = [[0., -1., 0.]] b_i = 0 BC = create_BC(folder='mprans', b_or=b_or, b_i=b_i) # creating a wave period = 0.8 height = 0.029 mwl = depth = 0.9 direction = np.array([1., 0., 0.]) g = np.array([0., -9.81, 0.]) waves = MonochromaticWaves(period, height, mwl, depth, g, direction) # need to set epsFact and he with context as they are called in BC... from proteus import Context case = sys.modules[__name__] Context.setFromModule(case) ct = Context.get() ecH = ct.epsFact_consrv_heaviside he = ct.domain.MeshOptions.he from proteus.ctransportCoefficients import smoothedHeaviside #----- # set BC windSpeed = np.array([1., 2., 3.4]) BC.setUnsteadyTwoPhaseVelocityInlet(waves, vert_axis=1, windSpeed=windSpeed) u_dir, v_dir, w_dir, vof_dir, p_adv = [], [], [], [], [] u_calc, vof_calc, p_calc = [], [], [] t_list = get_time_array() for t in t_list: x = np.array(get_random_x()) u_dir += [BC.u_dirichlet(x, t)] v_dir += [BC.v_dirichlet(x, t)] w_dir += [BC.w_dirichlet(x, t)] vof_dir += [BC.vof_dirichlet(x, t)] p_adv += [BC.p_advective(x, t)] # calculations waveHeight = waves.mwl + waves.eta(x, t) wavePhi = x[1] - waveHeight if wavePhi <= 0: wave_u = waves.u(x, t) else: x_max = list(x) x_max[1] = waveHeight wave_u = waves.u(x_max, t) Hu = smoothedHeaviside(0.5 * ecH * he, wavePhi - 0.5 * ecH * he) U = Hu * windSpeed + (1 - Hu) * wave_u u_calc += [U] p_calc += [np.sum(U * b_or[b_i])] Hvof = smoothedHeaviside(ecH * he, wavePhi) vof_calc += [Hvof] u_calc = np.array(u_calc) vof_calc = np.array(vof_calc) npt.assert_equal(BC.p_dirichlet, None) npt.assert_equal(u_dir, u_calc[:, 0]) npt.assert_equal(v_dir, u_calc[:, 1]) npt.assert_equal(w_dir, u_calc[:, 2]) npt.assert_equal(vof_dir, vof_calc) npt.assert_equal(BC.k_dirichlet, None) npt.assert_equal(BC.dissipation_dirichlet, None) npt.assert_equal(p_adv, p_calc) npt.assert_equal(BC.u_advective, None) npt.assert_equal(BC.v_advective, None) npt.assert_equal(BC.w_advective, None) npt.assert_equal(BC.vof_advective, None) npt.assert_equal(BC.k_advective, None) npt.assert_equal(BC.dissipation_advective, None) npt.assert_equal(BC.u_diffusive, None) npt.assert_equal(BC.v_diffusive, None) npt.assert_equal(BC.w_diffusive, None) npt.assert_equal(BC.k_diffusive, None) npt.assert_equal(BC.dissipation_diffusive, None)
def test_get(): from proteus import Context Context.set(ContextObject()) ct = Context.get() check_eq(ct)
from proteus import Context from proteus import Comm comm = Comm.get() ctx = Context.get() # simulation flags for error analysis # # simFlagsList is initialized in proteus.iproteus # simFlagsList[0]['errorQuantities'] = ['u'] simFlagsList[0]['errorTypes'] = ['numericalSolution' ] #compute error in soln and glob. mass bal simFlagsList[0]['errorNorms'] = ['L2'] #compute L2 norm in space or H0 or ... simFlagsList[0]['errorTimes'] = ['Last'] #'All', 'Last' simFlagsList[0]['echo'] = True #simFlagsList[0]['echoRelativeErrors']=True # start quit
from proteus import * from proteus.default_p import * from tank import * from proteus.mprans import RANS3PF from proteus import Context ct = Context.get() LevelModelType = RANS3PF.LevelModel if ct.sedimentDynamics: VOS_model = 0 VOF_model = 1 LS_model = 2 RD_model = 3 MCORR_model = 4 SED_model = 5 V_model = 6 PINC_model = 7 PRESSURE_model = 8 PINIT_model = 9 else: VOS_model = None SED_model = None VOF_model = 0 LS_model = 1 RD_model = 2 MCORR_model = 3 V_model = 4 PINC_model = 5 PRESSURE_model = 6