def test_bochev_pressure_cavity(load_cavity_problem, initialize_tp_pcd_options): initialize_tp_pcd_options ns = NumericalSolution.NS_base(load_cavity_problem[2], load_cavity_problem[0], load_cavity_problem[1], load_cavity_problem[2].sList, opts) assert ns.modelList[0].solver.solverList[ 0].linearSolver.null_space.get_name() == 'constant_pressure' ns.calculateSolution('bochev_pressure') script_dir = os.path.dirname(__file__) # relpath = 'comparison_files/twp_navier_stokes_cavity_2d.h5' # expected = tables.open_file(os.path.join(script_dir,relpath)) # actual = tables.open_file('twp_navier_stokes_cavity_2d.h5','r') ## assert numpy.allclose(expected.root.p_t1,actual.root.p_t1) # expected.close() actual = tables.open_file('twp_navier_stokes_cavity_2d.h5', 'r') expected_path = 'comparison_files/' + 'comparison_' + 'twp_navier_stokes_cavity_2d' + '_p_t1.csv' #write comparison file #np.array(actual.root.p_t1).tofile(os.path.join(script_dir, expected_path),sep=",") np.testing.assert_almost_equal(np.fromfile(os.path.join( script_dir, expected_path), sep=","), np.array(actual.root.p_t1).flatten(), decimal=8) actual.close() clean_up_directory()
def main(*args): opts, args = get_prog_opts(args, __doc__) comm = init_mpi_petsc(opts) problem_list = [ Poisson(), ] simulation_list = [default_s] numerics_list = [ C0P1_Poisson_Numerics(), ] numerics_list[0].periodicDirichletConditions = problem_list[ 0].periodicDirichletConditions numerics_list[0].T = problem_list[0].T simulation_name = problem_list[0].name + "_" + numerics_list[ 0].__class__.__name__ simulation_name_proc = simulation_name + "_" + repr(comm.rank()) simFlagsList = [{ 'simulationName': simulation_name, 'simulationNameProc': simulation_name_proc, 'dataFile': simulation_name_proc + '.dat', 'components': [ci for ci in range(problem_list[0].coefficients.nc)], }] so = default_so so.name = problem_list[0].name so.pnList = problem_list so.sList = [default_s] try: so.systemStepControllerType = numerics_list[0].systemStepControllerType except AttributeError: pass try: so.tnList = numerics_list[0].tnList so.archiveFlag = numerics_list[0].archiveFlag except AttributeError: pass runNumber = 0 runName = so.name + repr(runNumber) Profiling.procID = comm.rank() if simulation_list[0].logAllProcesses or opts.logAllProcesses: Profiling.logAllProcesses = True Profiling.flushBuffer = simulation_list[0].flushBuffer if opts.logLevel > 0: Profiling.openLog(runName + ".log", opts.logLevel) ns = NumericalSolution.NS_base(default_so, problem_list, numerics_list, simulation_list, opts, simFlagsList) ns.calculateSolution(runName)
def test_fallingCylinderIBM_sdf(self): from proteus import defaults from . import fallingCylinder importlib.reload(fallingCylinder) case = fallingCylinder case.m.rans2p.p.coefficients.use_ball_as_particle = 0. case.myTpFlowProblem.initializeAll() so = case.myTpFlowProblem.so so.name = 'fallingCylinderIBM2' pList = [] nList = [] for (pModule,nModule) in so.pnList: pList.append(pModule) nList.append(nModule) if so.sList == []: for i in range(len(so.pnList)): s = default_s so.sList.append(s) Profiling.logLevel = 7 Profiling.verbose = True # PETSc solver configuration OptDB = PETSc.Options() dirloc = os.path.dirname(os.path.realpath(__file__)) with open(os.path.join(dirloc, "petsc.options.superlu_dist")) as f: all = f.read().split() i=0 while i < len(all): if i < len(all)-1: if all[i+1][0]!='-': print("setting ", all[i].strip(), all[i+1]) OptDB.setValue(all[i].strip('-'),all[i+1]) i=i+2 else: print("setting ", all[i].strip(), "True") OptDB.setValue(all[i].strip('-'),True) i=i+1 else: print("setting ", all[i].strip(), "True") OptDB.setValue(all[i].strip('-'),True) i=i+1 ns = NumericalSolution.NS_base(so,pList,nList,so.sList,opts) ns.calculateSolution('fallingCylinderIBM2') pos = case.body.getPosition() npt.assert_almost_equal(pos, np.array([1.5, 1.98645, 0.]), decimal=5)
def load_simulation(context_options_str=None): """ Loads a two-phase step problem with settings Parameters ---------- settings: Returns: -------- """ from proteus import Context from proteus import default_s reload(PETSc) reload(iproteus) reload(default_p) reload(default_n) reload(default_s) Profiling.openLog("proteus.log",11) Profiling.verbose=True Context.contextOptionsString=context_options_str step2d_so = defaults.load_system('step2d_so',import_modules) twp_navier_stokes_step2d_p = defaults.load_physics('twp_navier_stokes_step2d_p',import_modules) twp_navier_stokes_step2d_n = defaults.load_numerics('twp_navier_stokes_step2d_n',import_modules) pList = [twp_navier_stokes_step2d_p] nList = [twp_navier_stokes_step2d_n] pList[0].name = 'step2d' so = step2d_so so.name = pList[0].name so.sList = pList[0].name so.sList = [default_s] _scriptdir = os.path.dirname(__file__) Profiling.logAllProcesses = False ns = NumericalSolution.NS_base(so, pList, nList, so.sList, opts) return ns