def example_setting(self, pre_setting):
        Context.contextOptionsString = pre_setting

        my_so = defaults.load_system("cylinder_so", modulepath)

        opts.profile = False
        opts.gatherArchive = True

        pList = []
        nList = []
        sList = []
        for (pModule, nModule) in my_so.pnList:
            pList.append(defaults.load_physics(pModule, modulepath))
            nList.append(defaults.load_numerics(nModule, modulepath))
            if pList[-1].name == None:
                pList[-1].name = pModule

        if my_so.sList == []:
            for i in range(len(my_so.pnList)):
                s = default_s
                sList.append(s)
        else:
            sList = my_so.sList

        my_so.name += "_sbm_mesh3D_" + self.compare_name  #save data with different filename
        ns = proteus.NumericalSolution.NS_base(my_so, pList, nList, sList,
                                               opts)
        ns.calculateSolution(my_so.name)

        expected_path = 'comparison_files/' + self.compare_name + '.h5'
        with tables.open_file(os.path.join(self._scriptdir, expected_path)) as expected, \
                tables.open_file( my_so.name + '.h5') as actual:
            assert np.allclose(expected.root.u_t2,
                               actual.root.u_t2,
                               atol=1e-10)
Beispiel #2
0
    def example_setting(self, pre_setting):
        Context.contextOptionsString = pre_setting

        my_so = defaults.load_system("cylinder_so", modulepath)

        opts.profile = False
        opts.gatherArchive = True

        pList = []
        nList = []
        sList = []
        for (pModule, nModule) in my_so.pnList:
            pList.append(defaults.load_physics(pModule, modulepath))
            nList.append(defaults.load_numerics(nModule, modulepath))
            if pList[-1].name == None:
                pList[-1].name = pModule

        if my_so.sList == []:
            for i in range(len(my_so.pnList)):
                s = default_s
                sList.append(s)
        else:
            sList = my_so.sList

        my_so.name += "_sbm_mesh3D_" + self.compare_name  #save data with different filename
        try:
            ns = proteus.NumericalSolution.NS_base(my_so, pList, nList, sList,
                                                   opts)
        except:
            assert 0, "NS setup failed"
        try:
            ns.calculateSolution(my_so.name)
        except:
            assert 0, "NS calculation failed"

        actual = tables.open_file(
            'cylinder_sbm_mesh3D_T001_P1_sbm_3Dmesh' + '.h5', 'r')
        expected_path = 'comparison_files/' + 'comparison_u_t2.csv'
        #write comparison file
        #np.array(actual.root.u_t2).tofile(os.path.join(self._scriptdir, expected_path),sep=",")
        np.testing.assert_almost_equal(np.fromfile(os.path.join(
            self._scriptdir, expected_path),
                                                   sep=","),
                                       np.array(actual.root.u_t2),
                                       decimal=10)

        actual.close()
 def test_AddedMass_3D(self):
     from proteus import defaults
     so = defaults.load_system('addedmass3D_so', modulepath)
     pList = []
     nList = []
     for (pModule,nModule) in so.pnList:
         log("Loading p module = "+pModule)
         pList.append(proteus.defaults.load_physics(pModule, modulepath))
         if pList[-1].name == None:
             pList[-1].name = pModule
         log("Loading n module = "+nModule)
         nList.append(proteus.defaults.load_numerics(nModule, modulepath))
     so.name = "addedmass3D"
     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('addedmass3D')
     Aij = ns.so.ct.body.Aij
     npt.assert_almost_equal(Aij[0,0], 284.27514069370471,decimal=5)
     npt.assert_almost_equal(Aij[1,1], 281.18940014728082,decimal=5)
     self.teardown_method(self)
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
    def example_setting(self, pre_setting):
        Context.contextOptionsString = pre_setting

        my_so = defaults.load_system("cylinder_so",modulepath)

        opts.profile = False
        opts.gatherArchive = True
        
        pList=[]
        nList=[]
        sList=[]
        for (pModule,nModule) in my_so.pnList:
            pList.append(defaults.load_physics(pModule,modulepath))
            nList.append(defaults.load_numerics(nModule,modulepath))
            if pList[-1].name == None:
                pList[-1].name = pModule

        if my_so.sList == []:
            for i in range(len(my_so.pnList)):
                s = default_s
                sList.append(s)
        else:
            sList = my_so.sList

        my_so.name += "_sbm_mesh3D_"+self.compare_name #save data with different filename
        ns = proteus.NumericalSolution.NS_base(my_so,
                                               pList,
                                               nList,
                                               sList,
                                               opts)
        ns.calculateSolution(my_so.name)

        expected_path = 'comparison_files/' + self.compare_name + '.h5'
        with tables.open_file(os.path.join(self._scriptdir, expected_path)) as expected, \
                tables.open_file( my_so.name + '.h5') as actual:
            assert np.allclose(expected.root.u_t2,
                               actual.root.u_t2,
                               atol=1e-10)
import os
import sys
import inspect
import numpy as np
import tables
import pickle
import pytest

from petsc4py import PETSc

TestTools.addSubFolders(inspect.currentframe())
from proteus import defaults
import_modules = os.path.join(os.path.dirname(os.path.abspath(__file__)),
                              'import_modules')
twp_navier_stokes_cavity_2d_so = defaults.load_system(
    'twp_navier_stokes_cavity_2d_so', import_modules)
twp_navier_stokes_cavity_2d_p = defaults.load_physics(
    'twp_navier_stokes_cavity_2d_p', import_modules)
twp_navier_stokes_cavity_2d_n = defaults.load_numerics(
    'twp_navier_stokes_cavity_2d_n', import_modules)


def clean_up_directory():
    FileList = [
        'forceHistory_p',
        'forceHistory_v',
        #'cavity2D',
        #'mesh',
        'momentHistory',
        'proteus',
        'wettedAreaHistory',