Exemplo n.º 1
0
def createLASolver():
    lasolver = superlu.daeCreateSuperLUSolver()
    options = lasolver.Options

    if lasolver.Name == 'SuperLU':
        # SuperLU options:
        options.ColPerm = superlu.COLAMD  # {NATURAL, MMD_ATA, MMD_AT_PLUS_A, COLAMD}
        #options.RowPerm         = superlu.NOROWPERM # {NOROWPERM, LargeDiag}
        #options.PrintStat       = superlu.YES       # {YES, NO}
        #options.DiagPivotThresh = 1.0               # Between 0.0 and 1.0
        #options.Equil           = superlu.NO        # {YES, NO}
        #options.PivotGrowth     = superlu.NO        # {YES, NO}
        #options.ConditionNumber = superlu.NO        # {YES, NO}

    elif lasolver.Name == 'SuperLU_MT':
        # SuperLU_MT options:
        # Leave nprocs to default (specified in daetools.cfg) or specify it manually
        #options.nprocs           = 4                 # No. of threads (= no. of CPUs/Cores)
        print('SuperLU_MT numThreads = %d' % options.nprocs)
        #options.PrintStat         = superlu.YES       # {YES, NO}
        #options.ColPerm           = superlu.COLAMD    # {NATURAL, MMD_ATA, MMD_AT_PLUS_A, COLAMD}
        #options.diag_pivot_thresh = 1.0               # Between 0.0 and 1.0
        #options.panel_size        = 8                 # Integer value
        #options.relax             = 6                 # Integer value
        #options.drop_tol          = 0.0               # Floating point value

    return lasolver
Exemplo n.º 2
0
def run(**kwargs):
    guiRun = kwargs.get('guiRun', False)
    
    simulation = simTutorial()

    # Create SuperLU LA solver
    lasolver = pySuperLU.daeCreateSuperLUSolver()

    # Create and setup two data reporters:
    datareporter = daeDelegateDataReporter()
    simName = simulation.m.Name + strftime(" [%d.%m.%Y %H:%M:%S]", localtime())
    if guiRun:
        results_folder = tempfile.mkdtemp(suffix = '-results', prefix = 'tutorial_deal_II_2-')
        daeQtMessage("deal.II", "The simulation results will be located in: %s" % results_folder)
    else:
        results_folder = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'tutorial_deal_II_2-results')
        print("The simulation results will be located in: %s" % results_folder)
    
    # 1. deal.II (exports only FE DOFs in .vtk format to the specified directory)
    feDataReporter = simulation.m.fe_system.CreateDataReporter()
    datareporter.AddDataReporter(feDataReporter)
    if not feDataReporter.Connect(results_folder, simName):
        sys.exit()
        
    # 2. TCP/IP
    tcpipDataReporter = daeTCPIPDataReporter()
    datareporter.AddDataReporter(tcpipDataReporter)
    if not tcpipDataReporter.Connect("", simName):
        sys.exit()

    return daeActivity.simulate(simulation, reportingInterval = 2, 
                                            timeHorizon       = 200,
                                            lasolver          = lasolver,
                                            datareporter      = datareporter,
                                            **kwargs)
Exemplo n.º 3
0
def run(**kwargs):
    simulation = simTutorial()
    relativeTolerance = 1e-07
    from daetools.solvers.superlu import pySuperLU as superlu
    lasolver = superlu.daeCreateSuperLUSolver()
    return daeActivity.simulate(simulation,
                                reportingInterval=60,
                                timeHorizon=3000,
                                lasolver=lasolver,
                                relativeTolerance=relativeTolerance,
                                **kwargs)
Exemplo n.º 4
0
def run(**kwargs):
    guiRun = kwargs.get('guiRun', False)

    simulation = simTutorial()

    # Create SuperLU LA solver
    lasolver = pySuperLU.daeCreateSuperLUSolver()

    # Create and setup two data reporters:
    datareporter = daeDelegateDataReporter()
    simName = simulation.m.Name + strftime(" [%d.%m.%Y %H:%M:%S]", localtime())
    if guiRun:
        results_folder_c = tempfile.mkdtemp(suffix='-results_c',
                                            prefix='tutorial_deal_II_8-')
        results_folder_cs = tempfile.mkdtemp(suffix='-results_cs',
                                             prefix='tutorial_deal_II_8-')
        daeQtMessage(
            "deal.II", "The simulation results will be located in: %s and %s" %
            (results_folder_c, results_folder_cs))
    else:
        results_folder_c = os.path.join(
            os.path.dirname(os.path.abspath(__file__)),
            'tutorial_deal_II_8-results-c')
        results_folder_cs = os.path.join(
            os.path.dirname(os.path.abspath(__file__)),
            'tutorial_deal_II_8-results-cs')
        print("The simulation results will be located in: %s and %s" %
              (results_folder_c, results_folder_cs))

    # 1. deal.II for c
    feDataReporter_c = simulation.m.fe_system_c.CreateDataReporter()
    datareporter.AddDataReporter(feDataReporter_c)
    if not feDataReporter_c.Connect(results_folder_c, simName):
        sys.exit()

    # 2. deal.II for cs
    feDataReporter_cs = simulation.m.fe_system_cs.CreateDataReporter()
    datareporter.AddDataReporter(feDataReporter_cs)
    if not feDataReporter_cs.Connect(results_folder_cs, simName):
        sys.exit()

    # 3. TCP/IP
    tcpipDataReporter = daeTCPIPDataReporter()
    datareporter.AddDataReporter(tcpipDataReporter)
    if not tcpipDataReporter.Connect("", simName):
        sys.exit()

    return daeActivity.simulate(simulation,
                                reportingInterval=0.05,
                                timeHorizon=2,
                                lasolver=lasolver,
                                datareporter=datareporter,
                                **kwargs)
Exemplo n.º 5
0
def run_simulation(ndD_s, ndD_e, tScale, outdir):
    # Create Log, Solver, DataReporter and Simulation object
    log = dae.daePythonStdOutLog()
    daesolver = dae.daeIDAS()
    simulation = sim.SimMPET(ndD_s, ndD_e, tScale)
    datareporter = data_reporting.setup_data_reporters(simulation, outdir)

    # Use SuperLU direct sparse LA solver
    lasolver = pySuperLU.daeCreateSuperLUSolver()
#    lasolver = pyTrilinos.daeCreateTrilinosSolver("Amesos_Umfpack", "")
    daesolver.SetLASolver(lasolver)

    # Enable reporting of all variables
    simulation.m.SetReportingOn(True)

    # Set relative tolerances
    daesolver.RelativeTolerance = ndD_s["relTol"]

    # Set the time horizon and the reporting interval
    simulation.TimeHorizon = ndD_s["tend"]
    # The list of reporting times excludes the first index (zero, which is implied)
    simulation.ReportingTimes = list(np.linspace(0, ndD_s["tend"], ndD_s["tsteps"] + 1))[1:]
    # Example logspacing for output times:
    # simulation.ReportingTimes = list(
    #     np.logspace(-4, np.log10(simulation.TimeHorizon), ndD_s['tsteps']))

    # Connect data reporter
    simName = simulation.m.Name + time.strftime(
        " [%d.%m.%Y %H:%M:%S]", time.localtime())
    if not datareporter.Connect("", simName):
        sys.exit()

    # Initialize the simulation
    simulation.Initialize(daesolver, datareporter, log)

    # Solve at time=0 (initialization)
    simulation.SolveInitial()

    # Run
    try:
        simulation.Run()
    except Exception as e:
        print(str(e))
        simulation.ReportData(simulation.CurrentTime)
        raise
    except KeyboardInterrupt:
        print("\nphi_applied at ctrl-C:",
              simulation.m.phi_applied.GetValue(), "\n")
        simulation.ReportData(simulation.CurrentTime)
    simulation.Finalize()
Exemplo n.º 6
0
def run(**kwargs):
    simulation = simTutorial()

    # Equation EvaluationMode can be one of:
    #  - eEvaluationTree_OpenMP
    #  - eComputeStack_OpenMP
    #simulation.EvaluationMode = eComputeStack_External

    # External compute stack evaluators can be set using SetComputeStackEvaluator function.
    # Here, the evaluation mode is set to eComputeStack_External.
    # Evaluators can be also set using the computeStackEvaluator argument of daeActivity.simulate function.
    # Available OpenCL platforms/devices can be obtained using the following functions:
    openclPlatforms = pyEvaluator_OpenCL.AvailableOpenCLPlatforms()
    openclDevices = pyEvaluator_OpenCL.AvailableOpenCLDevices()
    print('Available OpenCL platforms:')
    for platform in openclPlatforms:
        print('  Platform: %s' % platform.Name)
        print('    PlatformID: %d' % platform.PlatformID)
        print('    Vendor:     %s' % platform.Vendor)
        print('    Version:    %s' % platform.Version)
        #print('    Profile:    %s' % platform.Profile)
        #print('    Extensions: %s' % platform.Extensions)
        print('')
    print('Available OpenCL devices:')
    for device in openclDevices:
        print('  Device: %s' % device.Name)
        print('    PlatformID:      %d' % device.PlatformID)
        print('    DeviceID:        %d' % device.DeviceID)
        print('    DeviceVersion:   %s' % device.DeviceVersion)
        print('    DriverVersion:   %s' % device.DriverVersion)
        print('    OpenCLVersion:   %s' % device.OpenCLVersion)
        print('    MaxComputeUnits: %d' % device.MaxComputeUnits)
        print('')

    # OpenCL evaluators can use a single or multiple OpenCL devices.
    #   a) Single OpenCL device:
    computeStackEvaluator = pyEvaluator_OpenCL.CreateComputeStackEvaluator(
        platformID=0, deviceID=0)
    #   b) Multiple OpenCL devices (for heterogenous computing):
    #computeStackEvaluator = pyEvaluator_OpenCL.CreateComputeStackEvaluator( [(0, 0, 0.6), (1, 1, 0.4)] )
    simulation.SetComputeStackEvaluator(computeStackEvaluator)

    # Create LA solver
    lasolver = pySuperLU.daeCreateSuperLUSolver()

    return daeActivity.simulate(simulation,
                                reportingInterval=5,
                                timeHorizon=500,
                                lasolver=lasolver,
                                **kwargs)
Exemplo n.º 7
0
def simulate(Nx, Ny, **kwargs):
    # Create Log, Solver, DataReporter and Simulation object
    log = daePythonStdOutLog()
    daesolver = daeIDAS()
    datareporter = daeDelegateDataReporter()
    simulation = simTutorial(Nx, Ny)

    # Do no print progress
    log.PrintProgress = False

    lasolver = pySuperLU.daeCreateSuperLUSolver()

    # Enable reporting of time derivatives for all reported variables
    simulation.ReportTimeDerivatives = True

    # 1. TCP/IP
    tcpipDataReporter = daeTCPIPDataReporter()
    datareporter.AddDataReporter(tcpipDataReporter)
    simName = simulation.m.Name + strftime(" [%d.%m.%Y %H:%M:%S]", localtime())
    if not tcpipDataReporter.Connect("", simName):
        sys.exit()

    # 2. Data
    dr = daeNoOpDataReporter()
    datareporter.AddDataReporter(dr)

    daeActivity.simulate(simulation,
                         reportingInterval=2.0,
                         timeHorizon=90.0,
                         log=log,
                         lasolver=lasolver,
                         datareporter=datareporter,
                         **kwargs)

    ###########################################
    #  Data                                   #
    ###########################################
    results = dr.Process.dictVariables
    uvar = results[simulation.m.Name + '.u']
    vvar = results[simulation.m.Name + '.v']
    umvar = results[simulation.m.Name + '.um']
    vmvar = results[simulation.m.Name + '.vm']
    times = uvar.TimeValues
    u = uvar.Values[-1, :, :]  # 3D array [t,x,y]
    v = vvar.Values[-1, :, :]  # 3D array [t,x,y]
    um = umvar.Values[-1, :, :]  # 3D array [t,x,y]
    vm = vmvar.Values[-1, :, :]  # 3D array [t,x,y]

    return times, u, v, um, vm, simulation
Exemplo n.º 8
0
def simulate(Nx, **kwargs):
    # Create Log, Solver, DataReporter and Simulation object
    log = daePythonStdOutLog()
    daesolver = daeIDAS()
    datareporter = daeDelegateDataReporter()
    simulation = simTutorial(Nx)

    # Do no print progress
    log.PrintProgress = False

    lasolver = pySuperLU.daeCreateSuperLUSolver()

    daesolver.RelativeTolerance = 1e-7

    # 1. TCP/IP
    tcpipDataReporter = daeTCPIPDataReporter()
    datareporter.AddDataReporter(tcpipDataReporter)
    simName = simulation.m.Name + strftime(" [%d.%m.%Y %H:%M:%S]", localtime())
    if not tcpipDataReporter.Connect("", simName):
        sys.exit()

    # 2. Data
    dr = daeNoOpDataReporter()
    datareporter.AddDataReporter(dr)

    daeActivity.simulate(simulation,
                         reportingInterval=0.02,
                         timeHorizon=dt,
                         log=log,
                         lasolver=lasolver,
                         datareporter=datareporter,
                         **kwargs)

    ###########################################
    #  Data                                   #
    ###########################################
    results = dr.Process.dictVariables

    cvar = results[simulation.m.Name + '.c']
    c = cvar.Values[-1, :]  # 2D array [t,x]

    return simulation.m.x.Points, c, simulation
Exemplo n.º 9
0
def simulate(mesh, quadratureFormulaOrder):
    # Create Log, Solver, DataReporter and Simulation object
    log = daePythonStdOutLog()
    daesolver = daeIDAS()
    datareporter = daeDelegateDataReporter()
    simulation = simTutorial(mesh, quadratureFormulaOrder)

    # Do no print progress
    log.PrintProgress = False

    lasolver = pySuperLU.daeCreateSuperLUSolver()
    daesolver.SetLASolver(lasolver)

    simName = simulation.m.Name + strftime(" [%d.%m.%Y %H:%M:%S]", localtime())
    results_folder = os.path.join(os.path.dirname(os.path.abspath(__file__)),
                                  'tutorial_cv_5-results')

    # Create three data reporters:
    # 1. DealII
    feDataReporter = simulation.m.fe_system.CreateDataReporter()
    datareporter.AddDataReporter(feDataReporter)
    if not feDataReporter.Connect(results_folder, simName):
        sys.exit()

    # 2. TCP/IP
    tcpipDataReporter = daeTCPIPDataReporter()
    datareporter.AddDataReporter(tcpipDataReporter)
    if not tcpipDataReporter.Connect("", simName):
        sys.exit()

    # 3. Data
    dr = daeNoOpDataReporter()
    datareporter.AddDataReporter(dr)

    # Enable reporting of all variables
    simulation.m.SetReportingOn(True)

    # Set the time horizon and the reporting interval
    simulation.ReportingInterval = 3600
    simulation.TimeHorizon = 20 * 3600

    # Initialize the simulation
    simulation.Initialize(daesolver, datareporter, log)

    # Save the model report and the runtime model report
    simulation.m.fe_model.SaveModelReport(simulation.m.Name + ".xml")
    #simulation.m.fe_model.SaveRuntimeModelReport(simulation.m.Name + "-rt.xml")

    # Solve at time=0 (initialization)
    simulation.SolveInitial()

    # Run
    simulation.Run()
    simulation.Finalize()

    ###########################################
    #  Plots and data                         #
    ###########################################
    results = dr.Process.dictVariables
    Tvar = results[simulation.m.Name + '.HeatConduction.T']
    uvar = results[simulation.m.Name + '.u']
    Nx = simulation.m.x.NumberOfPoints
    L = simulation.m.L
    times = numpy.linspace(0, L, Nx)
    T = Tvar.Values[-1, :]  # 2D array [t,x]
    u = uvar.Values[-1, :]  # 2D array [t,x]

    return times, T, u
Exemplo n.º 10
0
def simulate(Nx):
    # Create Log, Solver, DataReporter and Simulation object
    log          = daePythonStdOutLog()
    daesolver    = daeIDAS()
    datareporter = daeDelegateDataReporter()
    simulation   = simTutorial(Nx)

    daesolver.RelativeTolerance = 1E-6
    
    # Do no print progress
    log.PrintProgress = False

    lasolver = pySuperLU.daeCreateSuperLUSolver()
    daesolver.SetLASolver(lasolver)

    simName = simulation.m.Name + 'Nx=%d'%Nx + strftime(" [%d.%m.%Y %H:%M:%S]", localtime())
    results_folder = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'tutorial_cv_9-results(Nx=%d)' % Nx)

    # Create three data reporters:
    # 1. DealII
    feDataReporter = simulation.m.fe_system.CreateDataReporter()
    datareporter.AddDataReporter(feDataReporter)
    if not feDataReporter.Connect(results_folder, simName):
        sys.exit()

    # 2. TCP/IP
    tcpipDataReporter = daeTCPIPDataReporter()
    datareporter.AddDataReporter(tcpipDataReporter)
    if not tcpipDataReporter.Connect("", simName):
        sys.exit()

    # 3. Data
    dr = daeNoOpDataReporter()
    datareporter.AddDataReporter(dr)

    # Enable reporting of all variables
    simulation.m.SetReportingOn(True)

    # Set the time horizon and the reporting interval
    simulation.ReportingInterval = 2*numpy.pi / 100
    simulation.TimeHorizon = 2*numpy.pi

    # Initialize the simulation
    simulation.Initialize(daesolver, datareporter, log)

    # Save the model report and the runtime model report
    #simulation.m.fe_model.SaveModelReport(simulation.m.Name + ".xml")
    #simulation.m.fe_model.SaveRuntimeModelReport(simulation.m.Name + "-rt.xml")

    # Solve at time=0 (initialization)
    simulation.SolveInitial()

    # Run
    simulation.Run()
    simulation.Finalize()
    
    ###########################################
    #  Plots and data                         #
    ###########################################
    results = dr.Process.dictVariables
    cvar = results[simulation.m.Name + '.SolidBodyRotation.c']
    points = cvar.Domains[0].Points
    c       = cvar.Values[-1,:] # 2D array [t,omega]
    # After t = 2pi system returned to the initial position
    c_exact = cvar.Values[0,:] # 2D array [t,omega]
   
    return points, c, c_exact
Exemplo n.º 11
0
def createLASolver(lasolverIndex):
    lasolver = None

    if lasolverIndex == laSundialsLU:
        pass

    elif lasolverIndex == laSuperLU:
        from daetools.solvers.superlu import pySuperLU
        lasolver = pySuperLU.daeCreateSuperLUSolver()

    elif lasolverIndex == laSuperLU_MT:
        from daetools.solvers.superlu_mt import pySuperLU_MT
        lasolver = pySuperLU_MT.daeCreateSuperLUSolver()

    elif lasolverIndex == laAmesos_Klu:
        from daetools.solvers.trilinos import pyTrilinos
        lasolver = pyTrilinos.daeCreateTrilinosSolver("Amesos_Klu", "")

    elif lasolverIndex == laAmesos_Superlu:
        from daetools.solvers.trilinos import pyTrilinos
        lasolver = pyTrilinos.daeCreateTrilinosSolver("Amesos_Superlu", "")

    elif lasolverIndex == laAmesos_Umfpack:
        from daetools.solvers.trilinos import pyTrilinos
        lasolver = pyTrilinos.daeCreateTrilinosSolver("Amesos_Umfpack", "")

    elif lasolverIndex == laAmesos_Lapack:
        from daetools.solvers.trilinos import pyTrilinos
        lasolver = pyTrilinos.daeCreateTrilinosSolver("Amesos_Lapack", "")

    elif lasolverIndex == laAztecOO:
        from daetools.solvers.trilinos import pyTrilinos
        lasolver = pyTrilinos.daeCreateTrilinosSolver("AztecOO", "ILUT")

    elif lasolverIndex == laPardiso:
        from daetools.solvers.pardiso import pyPardiso
        lasolver = pyPardiso.daeCreatePardisoSolver()

    elif lasolverIndex == laIntelPardiso:
        from daetools.solvers.intel_pardiso import pyIntelPardiso
        lasolver = pyIntelPardiso.daeCreateIntelPardisoSolver()

    elif lasolverIndex == laIntelMKL:
        from daetools.solvers import pyIntelMKL
        lasolver = pyIntelMKL.daeCreateLapackSolver()

    elif lasolverIndex == laAmdACML:
        from daetools.solvers import pyAmdACML
        lasolver = pyAmdACML.daeCreateLapackSolver()

    elif lasolverIndex == laLapack:
        from daetools.solvers import pyLapack
        lasolver = pyLapack.daeCreateLapackSolver()

    elif lasolverIndex == laMagmaLapack:
        from daetools.solvers import pyMagma
        lasolver = pyMagma.daeCreateLapackSolver()

    elif lasolverIndex == laSuperLU_CUDA:
        from daetools.solvers.superlu_cuda import pySuperLU_CUDA
        lasolver = pySuperLU_CUDA.daeCreateSuperLUSolver()

    elif lasolverIndex == laCUSP:
        from daetools.solvers import pyCUSP
        lasolver = pyCUSP.daeCreateCUSPSolver()

    else:
        raise RuntimeError("Unsupported LA Solver selected")

    return lasolver