xref: /libCEED/python/tests/test-0-ceed.py (revision 9c774eddf8c0b4f5416196d32c5355c9591a7190)
10ef72598Sjeremylt# Copyright (c) 2017, Lawrence Livermore National Security, LLC. Produced at
20ef72598Sjeremylt# the Lawrence Livermore National Laboratory. LLNL-CODE-734707. All Rights
30ef72598Sjeremylt# reserved. See files LICENSE and NOTICE for details.
40ef72598Sjeremylt#
50ef72598Sjeremylt# This file is part of CEED, a collection of benchmarks, miniapps, software
60ef72598Sjeremylt# libraries and APIs for efficient high-order finite element and spectral
70ef72598Sjeremylt# element discretizations for exascale applications. For more information and
80ef72598Sjeremylt# source code availability see http://github.com/ceed.
90ef72598Sjeremylt#
100ef72598Sjeremylt# The CEED research is supported by the Exascale Computing Project 17-SC-20-SC,
110ef72598Sjeremylt# a collaborative effort of two U.S. Department of Energy organizations (Office
120ef72598Sjeremylt# of Science and the National Nuclear Security Administration) responsible for
130ef72598Sjeremylt# the planning and preparation of a capable exascale ecosystem, including
140ef72598Sjeremylt# software, applications, hardware, advanced system engineering and early
150ef72598Sjeremylt# testbed platforms, in support of the nation's exascale computing imperative.
160ef72598Sjeremylt
170ef72598Sjeremylt# @file
180ef72598Sjeremylt# Test Ceed functionality
190ef72598Sjeremylt
200ef72598Sjeremyltimport libceed
210ef72598Sjeremyltimport pytest
220ef72598Sjeremylt
230ef72598Sjeremylt# -------------------------------------------------------------------------------
240ef72598Sjeremylt# Test creation and destruction of a Ceed object
250ef72598Sjeremylt# -------------------------------------------------------------------------------
260ef72598Sjeremylt
270ef72598Sjeremylt
280ef72598Sjeremyltdef test_000(ceed_resource):
290ef72598Sjeremylt    ceed = libceed.Ceed(ceed_resource)
300ef72598Sjeremylt
310ef72598Sjeremylt# -------------------------------------------------------------------------------
320ef72598Sjeremylt# Test return of Ceed backend prefered memory type
330ef72598Sjeremylt# -------------------------------------------------------------------------------
340ef72598Sjeremylt
350ef72598Sjeremylt
360ef72598Sjeremyltdef test_001(ceed_resource):
370ef72598Sjeremylt    ceed = libceed.Ceed(ceed_resource)
380ef72598Sjeremylt
390ef72598Sjeremylt    memtype = ceed.get_preferred_memtype()
400ef72598Sjeremylt
410ef72598Sjeremylt    assert memtype != "error"
420ef72598Sjeremylt
430ef72598Sjeremylt# -------------------------------------------------------------------------------
440ef72598Sjeremylt# Test return of a CEED object full resource name
450ef72598Sjeremylt# -------------------------------------------------------------------------------
460ef72598Sjeremylt
470ef72598Sjeremylt
480ef72598Sjeremyltdef test_002(ceed_resource):
490ef72598Sjeremylt    ceed = libceed.Ceed(ceed_resource)
500ef72598Sjeremylt
510ef72598Sjeremylt    resource = ceed.get_resource()
520ef72598Sjeremylt
530ef72598Sjeremylt    assert resource == ceed_resource
540ef72598Sjeremylt
550ef72598Sjeremylt# -------------------------------------------------------------------------------
560ef72598Sjeremylt# Test viewing of a CEED object
570ef72598Sjeremylt# -------------------------------------------------------------------------------
580ef72598Sjeremylt
590ef72598Sjeremylt
600ef72598Sjeremyltdef test_003(ceed_resource):
610ef72598Sjeremylt    ceed = libceed.Ceed(ceed_resource)
620ef72598Sjeremylt
630ef72598Sjeremylt    print(ceed)
640ef72598Sjeremylt
650ef72598Sjeremylt# -------------------------------------------------------------------------------
660ef72598Sjeremylt# Test CEED object error handling
670ef72598Sjeremylt# -------------------------------------------------------------------------------
680ef72598Sjeremylt
690ef72598Sjeremylt
700ef72598Sjeremyltdef test_005(ceed_resource):
710ef72598Sjeremylt    ceed = libceed.Ceed(ceed_resource)
720ef72598Sjeremylt
730ef72598Sjeremylt    vec = ceed.Vector(5)
74*9c774eddSJeremy L Thompson    vec.set_value(0.0)
750ef72598Sjeremylt    array1 = vec.get_array()
760ef72598Sjeremylt
770ef72598Sjeremylt    exception_raised = False
780ef72598Sjeremylt    try:
790ef72598Sjeremylt        array2 = vec.get_array()
800ef72598Sjeremylt    except BaseException:
810ef72598Sjeremylt        exception_raised = True
820ef72598Sjeremylt
830ef72598Sjeremylt    assert exception_raised
840ef72598Sjeremylt
850ef72598Sjeremylt    vec.restore_array()
860ef72598Sjeremylt
870ef72598Sjeremylt# -------------------------------------------------------------------------------
88