def test_hex27_hex27_0(self):
   fixture_setup()
   scalarDimension = 0
   eMesh = PerceptMesh()
   p_size = eMesh.get_parallel_size()
   gmesh_spec = "1x1x" + str(p_size) + "|bbox:0,0,0,1,1," + str(p_size)
   eMesh.new_mesh(GMeshSpec(gmesh_spec))
   
   proc_rank_field = eMesh.add_field("proc_rank", eMesh.element_rank(), scalarDimension)
   breaker = Refiner(eMesh, HEX8_HEX27_1, proc_rank_field)
   eMesh.commit()
   eMesh.print_info()
   eMesh.save_as("hex27_hex27_cube1x1x" + str(p_size) + "-orig.e")
   breaker.setRemoveOldElements(True)
   breaker.doBreak()
   eMesh.save_as("hex27_hex27_cube1x1x" + str(p_size) + "_0.e")
   
   em1 = PerceptMesh(3)
   p_size = em1.get_parallel_size()
   em1.open("hex27_hex27_cube1x1x" + str(p_size) + "_0.e")
   proc_rank_field = em1.add_field("proc_rank", eMesh.element_rank(), scalarDimension)
   breaker = Refiner(em1, HEX27_HEX27_8, proc_rank_field)
   em1.commit()
   breaker.setIgnoreSideSets(True)
   breaker.setRemoveOldElements(True)
   breaker.doBreak()
   em1.save_as("hex27_hex27_cube1x1x" + str(p_size) + "_1.e")
    def test_fieldFunction_demo_2(self):   
       eMesh = PerceptMesh()
       eMesh.new_mesh(GMeshSpec("3x3x3|bbox:0,0,0,1,1,1"))

       vectorDimension = 0
       eMesh.add_field("coords_mag_field", FEMMetaData.NODE_RANK, vectorDimension)
       eMesh.commit()

       f_coords = eMesh.get_field("coordinates")
       coords_mag_field = eMesh.get_field("coords_mag_field")

       ff_coords = FieldFunction("ff_coords", f_coords, eMesh, 3, 3)
       eval_vec3_print(0.1,0.1,0.1,0.0,ff_coords)
       
       coords_mag_sf = StringFunction("sqrt(x*x + y*y + z*z)" , "coords_mag_sf", 3, 1)
       x = 0.123
       y = 0.234
       z = 0.345
       vv = sqrt(x*x + y*y + z*z)
       v1 = eval_func(x,y,z,0,coords_mag_sf)
       print "vv = ", vv, "== v1 = ", v1
       self.assertEqual(vv, v1)
       
       coords_mag_field_function = FieldFunction("coords_mag_field_function", coords_mag_field, eMesh, 3, 1)

       coords_mag_field_function.interpolateFrom(coords_mag_sf)

       eMesh.save_as("./cubehex8_withCoordMag_out.e")

       ff_coords.add_alias("mc")
       
       sfcm = StringFunction("sqrt(mc[0]*mc[0]+mc[1]*mc[1]+mc[2]*mc[2])", "sfcm", 3, 1)
Example #3
0
    def test_hex27_hex27_0(self):
        fixture_setup()
        scalarDimension = 0
        eMesh = PerceptMesh()
        p_size = eMesh.get_parallel_size()
        gmesh_spec = "1x1x" + str(p_size) + "|bbox:0,0,0,1,1," + str(p_size)
        eMesh.new_mesh(GMeshSpec(gmesh_spec))

        proc_rank_field = eMesh.add_field("proc_rank", eMesh.element_rank(),
                                          scalarDimension)
        breaker = Refiner(eMesh, HEX8_HEX27_1, proc_rank_field)
        eMesh.commit()
        eMesh.print_info()
        eMesh.save_as("hex27_hex27_cube1x1x" + str(p_size) + "-orig.e")
        breaker.setRemoveOldElements(True)
        breaker.doBreak()
        eMesh.save_as("hex27_hex27_cube1x1x" + str(p_size) + "_0.e")

        em1 = PerceptMesh(3)
        p_size = em1.get_parallel_size()
        em1.open("hex27_hex27_cube1x1x" + str(p_size) + "_0.e")
        proc_rank_field = em1.add_field("proc_rank", eMesh.element_rank(),
                                        scalarDimension)
        breaker = Refiner(em1, HEX27_HEX27_8, proc_rank_field)
        em1.commit()
        breaker.setIgnoreSideSets(True)
        breaker.setRemoveOldElements(True)
        breaker.doBreak()
        em1.save_as("hex27_hex27_cube1x1x" + str(p_size) + "_1.e")
Example #4
0
   def test_use_case_1(self):

    pMesh = PerceptMesh()
    pMesh.new_mesh(GMeshSpec("3x3x3|bbox:0,0,0,2,2,2"))
    field = pMesh.add_field("coordinates", 1)
    pMesh.commit()

    input_array = array([1.0, 0.5, 0.5])
    input_array_2 = array([1.0, 1.5, 1.5])

    ff = FieldFunction("ff", field, pMesh, 3, 3)
    ff.add_alias("myalias")
    ff_output = ff.evaluate(input_array)

    f2 = FieldFunction("f2", field, pMesh, 3, 3)
    f2_output = f2.evaluate(input_array_2)    

    sf = StringFunction("x+y+z", "myname", 3, 1)
    sf_output = sf.evaluate(input_array)

    sf_diff = StringFunction("ff-f2", "myname") 

    norm = L1Norm(pMesh.get_bulk_data())
    value = norm.evaluate(ff)
    diffnorm = norm.evaluate(sf_diff) 
Example #5
0
    def test_fieldFunction_readMesh_createField_interpolateFrom(self):
       num_x = 3
       num_y = 3
       num_z = 3
       config_mesh = str(num_x) + "x" + str(num_y) + "x" + str(num_z) + "|bbox:0,0,0,1,1,1"

       eMesh = PerceptMesh()
       eMesh.new_mesh(GMeshSpec(config_mesh))
       vectorDimension = 0
       eMesh.add_field("coords_mag_field", FEMMetaData.NODE_RANK, vectorDimension)
       eMesh.commit()

       #p_rank = eMesh.get_bulk_data().parallel_rank()
       #setRank(p_rank)        
          #from Util 
       f_coords = eMesh.get_field(FEMMetaData.NODE_RANK, "coordinates")

       coords_mag_field = eMesh.get_field(FEMMetaData.NODE_RANK, "coords_mag_field")
       #VERIFY_OP_ON      Here the unit test does something
       
       ff_coords = FieldFunction("ff_coords", f_coords, eMesh, 3, 3, FieldFunction.SIMPLE_SEARCH)

       #here we could evaluate the function
       #eval_vec3_print(0.1,0.2,0.3,0.0,ff_coords)
       
       coords_mag_sf = StringFunction("sqrt(x*x + y*y + z*z)", "coords_mag_sf", 3, 1)
       coords_mag_field_function = FieldFunction("coords_mag_field_function", coords_mag_field, eMesh, 3, 3, FieldFunction.SIMPLE_SEARCH)
       coords_mag_field_function.interpolateFrom(coords_mag_sf)

       #The following is not doable from Python
      
       checkCoordMag = CheckCoordMag()
       #eMesh.nodalOpLoop(checkCoordMag, coords_mag_field)
       print checkCoordMag.error   

       ff_coords.add_alias("mc")
       sfcm = StringFunction("sqrt(mc[0]*mc[0]+mc[1]*mc[1]+mc[2]*mc[2])", "sfcm", Dimensions(3), Dimensions(1))
      
       tol1 = 1.e-12
      
       vv = eval_vec3(0.1, 0.2, 0.3, 0.0, ff_coords)
       print 
       print "0.1 == vv[0] = ", vv[0], "passed"
       print "0.2 == vv[1] = ", vv[1], "passed"
       print "0.3 == vv[2] = ", vv[2], "passed"

       self.assertAlmostEqual(.1, vv[0], delta=tol1)
       self.assertAlmostEqual(.2, vv[1], delta=tol1)
       self.assertAlmostEqual(.3, vv[2], delta=tol1)

       vv = eval_func(0.1, 0.2, 0.3, 0.0, sfcm)
       v_expect = sqrt(0.1*0.1+0.2*0.2+0.3*0.3)

       if ((vv-v_expect) < tol1):
          print "vv = ", vv, " == v_expect = ", v_expect, "passed"

       coords_mag_field_function.interpolateFrom(sfcm)
Example #6
0
    def fixture_setup_0(self):
       eMesh = PerceptMesh()

       p_size = eMesh.get_parallel_size()
      
       gmesh_spec = "4x4x" + str((4*p_size)) + "|bbox:0,0,0,1,1,1"
       eMesh.new_mesh(GMeshSpec(gmesh_spec))
       eMesh.commit()
       eMesh.save_as("./exodus_files/hex_fixture.e")
    def fixture_setup_0(self):
        eMesh = PerceptMesh()

        p_size = eMesh.get_parallel_size()

        gmesh_spec = "4x4x" + str((4 * p_size)) + "|bbox:0,0,0,1,1,1"
        eMesh.new_mesh(GMeshSpec(gmesh_spec))
        eMesh.commit()
        eMesh.save_as("./exodus_files/hex_fixture.e")
    def test_fieldFunction_readMesh_createField_interpolateFrom(self):
       num_x = 3
       num_y = 3
       num_z = 3
       config_mesh = str(num_x) + "x" + str(num_y) + "x" + str(num_z) + "|bbox:0,0,0,1,1,1"

       eMesh = PerceptMesh()
       eMesh.new_mesh(GMeshSpec(config_mesh))
       vectorDimension = 0
       eMesh.add_field("coords_mag_field", FEMMetaData.NODE_RANK, vectorDimension)
       eMesh.commit()

       #p_rank = eMesh.get_bulk_data().parallel_rank()
       #setRank(p_rank)        
          #from Util 
       f_coords = eMesh.get_field("coordinates")

       coords_mag_field = eMesh.get_field("coords_mag_field")
       #VERIFY_OP_ON      Here the unit test does something
       
       ff_coords = FieldFunction("ff_coords", f_coords, eMesh, 3, 3, FieldFunction.SIMPLE_SEARCH)

       #here we could evaluate the function
       #eval_vec3_print(0.1,0.2,0.3,0.0,ff_coords)
       
       coords_mag_sf = StringFunction("sqrt(x*x + y*y + z*z)", "coords_mag_sf", 3, 1)
       coords_mag_field_function = FieldFunction("coords_mag_field_function", coords_mag_field, eMesh, 3, 3, FieldFunction.SIMPLE_SEARCH)
       coords_mag_field_function.interpolateFrom(coords_mag_sf)

       #The following is not doable from Python
      
       checkCoordMag = CheckCoordMag()
       #eMesh.nodalOpLoop(checkCoordMag, coords_mag_field)
       print checkCoordMag.error   

       ff_coords.add_alias("mc")
       sfcm = StringFunction("sqrt(mc[0]*mc[0]+mc[1]*mc[1]+mc[2]*mc[2])", "sfcm", Dimensions(3), Dimensions(1))
      
       tol1 = 1.e-12
      
       vv = eval_vec3(0.1, 0.2, 0.3, 0.0, ff_coords)
       print 
       print "0.1 == vv[0] = ", vv[0], "passed"
       print "0.2 == vv[1] = ", vv[1], "passed"
       print "0.3 == vv[2] = ", vv[2], "passed"

       self.assertAlmostEqual(.1, vv[0], delta=tol1)
       self.assertAlmostEqual(.2, vv[1], delta=tol1)
       self.assertAlmostEqual(.3, vv[2], delta=tol1)

       vv = eval_func(0.1, 0.2, 0.3, 0.0, sfcm)
       v_expect = sqrt(0.1*0.1+0.2*0.2+0.3*0.3)

       if ((vv-v_expect) < tol1):
          print "vv = ", vv, " == v_expect = ", v_expect, "passed"

       coords_mag_field_function.interpolateFrom(sfcm)
Example #9
0
    def test_fieldFunction_point_eval_timing(self):
        num_x = 3
        num_y = 3
        num_z = 3
        config_mesh = str(num_x) + "x" + str(num_y) + "x" + str(
            num_z) + "|bbox:0,0,0,1,1,1"

        eMesh = PerceptMesh()
        eMesh.new_mesh(GMeshSpec(config_mesh))
        eMesh.commit()

        #FIXME
        #p_size = eMesh.get_bulk_data->parallel_size()

        f_coords = eMesh.get_field("coordinates")

        for iSearchType in range(2):
            if iSearchType == 0:
                search_type = FieldFunction.SIMPLE_SEARCH
                search_type_name = "SIMPLE_SEARCH"
            else:
                search_type = FieldFunction.STK_SEARCH
                search_type_name = "STK_SEARCH"
            ff_coords = FieldFunction("ff_coords", f_coords, eMesh,
                                      Dimensions(3), Dimensions(3),
                                      search_type)

            t1st = time.time()
            val1 = eval_vec3(0.2, 0.3, 0.4, 0.0, ff_coords)
            val1 = eval_vec3(0.2, 0.3, 0.4, 0.0,
                             ff_coords)  #evaluated twice???
            t1st = time.time() - t1st

            numIter = 10000
            random.seed(12345)
            total_time = time.time()
            max_rand = 32767

            for iter in range(numIter):
                num0 = random.randint(1, max_rand) * 1.0
                num1 = random.randint(1, max_rand) * 1.0
                num2 = random.randint(1, max_rand) * 1.0
                pts = array([(num0 / max_rand), (num1 / max_rand),
                             (num2 / max_rand)])
                output_pts = array([0.0, 0.0, 0.0])
                output_pts = ff_coords.value(pts, output_pts, 0.0)

            total_time = time.time() - total_time

            print "TEST::function::fieldFunction_point_eval_timing: "
            print " for search_type= ", search_type_name
            print "    time for 1st eval= ", t1st
            print "    for ", numIter, "iterations, evaluating field(x,y,z) time = ", total_time
            print "    average per point lookup and eval time = ", (
                total_time / numIter)
 def test_hex8_hex8_8_1(self):
   fixture_setup()
   eMesh = PerceptMesh()
   p_size = eMesh.get_parallel_size()
   gmesh_spec = "4x4x"+str(4*p_size)+"|bbox:0,0,0,1,1,1"
   eMesh.new_mesh(GMeshSpec(gmesh_spec))
   scalarDimension = 0
   proc_rank_field = eMesh.add_field("proc_rank", eMesh.element_rank(), scalarDimension)
   breaker = Refiner(eMesh, HEX8_HEX8_8, proc_rank_field)
   eMesh.commit()
   breaker.doBreak
 def test_hex8_hex8_8_1(self):
   fixture_setup()
   eMesh = PerceptMesh()
   p_size = eMesh.get_parallel_size()
   gmesh_spec = "4x4x"+str(4*p_size)+"|bbox:0,0,0,1,1,1"
   eMesh.new_mesh(GMeshSpec(gmesh_spec))
   scalarDimension = 0
   proc_rank_field = eMesh.add_field("proc_rank", eMesh.element_rank(), scalarDimension)
   breaker = Refiner(eMesh, HEX8_HEX8_8, proc_rank_field)
   eMesh.commit()
   breaker.doBreak
 def test_hex8_tet4_6_12_1(self):
   fixture_setup()
   eMesh = PerceptMesh(3)
   p_size = eMesh.get_parallel_size() 
   gmesh_spec = "1x1x" + str(p_size) + "|bbox:0,0,0,1,1," + str(p_size)
   eMesh.new_mesh(GMeshSpec(gmesh_spec))
   scalarDimension = 0
   proc_rank_field = eMesh.add_field("proc_rank", eMesh.element_rank(), scalarDimension)
   breaker = Refiner(eMesh, HEX8_TET4_6_12, proc_rank_field)
   eMesh.commit()
   eMesh.print_info()
   breaker.setRemoveOldElements(True)
   breaker.doBreak()
   eMesh.save_as("hex_tet_6_12_cube1x1x1.e")
 def test_hex8_tet4_6_12_1(self):
   fixture_setup()
   eMesh = PerceptMesh(3)
   p_size = eMesh.get_parallel_size() 
   gmesh_spec = "1x1x" + str(p_size) + "|bbox:0,0,0,1,1," + str(p_size)
   eMesh.new_mesh(GMeshSpec(gmesh_spec))
   scalarDimension = 0
   proc_rank_field = eMesh.add_field("proc_rank", eMesh.element_rank(), scalarDimension)
   breaker = Refiner(eMesh, HEX8_TET4_6_12, proc_rank_field)
   eMesh.commit()
   eMesh.print_info()
   breaker.setRemoveOldElements(True)
   breaker.doBreak()
   eMesh.save_as("hex_tet_6_12_cube1x1x1.e")
    def test_fieldFunction_point_eval_timing(self):
       num_x = 3
       num_y = 3
       num_z = 3
       config_mesh = str(num_x) + "x" + str(num_y) + "x" + str(num_z) + "|bbox:0,0,0,1,1,1"

       eMesh = PerceptMesh()
       eMesh.new_mesh(GMeshSpec(config_mesh))
       eMesh.commit()

       #FIXME
       #p_size = eMesh.get_bulk_data->parallel_size()

       f_coords = eMesh.get_field("coordinates")

       for iSearchType in range(2):
          if iSearchType == 0:
             search_type = FieldFunction.SIMPLE_SEARCH
             search_type_name = "SIMPLE_SEARCH"
          else:
             search_type = FieldFunction.STK_SEARCH
             search_type_name = "STK_SEARCH"
          ff_coords = FieldFunction("ff_coords", f_coords, eMesh, Dimensions(3), Dimensions(3), search_type)
         
          t1st = time.time()
          val1 = eval_vec3(0.2,0.3,0.4,0.0,ff_coords)
          val1 = eval_vec3(0.2,0.3,0.4,0.0,ff_coords) #evaluated twice???
          t1st = time.time() - t1st

          numIter = 10000
          random.seed(12345)      
          total_time = time.time()
          max_rand = 32767

          for iter in range(numIter):
             num0 = random.randint(1, max_rand)*1.0
             num1 = random.randint(1, max_rand)*1.0
             num2 = random.randint(1, max_rand)*1.0
             pts = array([(num0/max_rand), (num1/max_rand), (num2/max_rand)])
             output_pts = array([0.0,0.0,0.0])
             output_pts = ff_coords.value(pts, output_pts, 0.0)

          total_time = time.time() - total_time

          print "TEST::function::fieldFunction_point_eval_timing: "
          print " for search_type= ", search_type_name
          print "    time for 1st eval= ", t1st
          print "    for ", numIter, "iterations, evaluating field(x,y,z) time = ", total_time
          print "    average per point lookup and eval time = ", (total_time/numIter)
Example #15
0
    def test_fieldFunction_demo_1_0_0(self):
        eMesh = PerceptMesh(3)
        eMesh.new_mesh(GMeshSpec("3x3x3|bbox:0,0,0,1,1,1"))
        eMesh.commit()
        eMesh.print_info("fieldFunction_demo_1_0_0", 2)

        f_coords = eMesh.get_field("coordinates")

        ff_coords = FieldFunction("ff_coords", f_coords, eMesh, 3, 3)
        x = 0.123
        y = 0.234
        z = 0.345
        time = 0.0

        eval_vec3_print(x, y, z, time, ff_coords)
    def test_fieldFunction_demo_1_0_0(self):
       eMesh = PerceptMesh(3)
       eMesh.new_mesh(GMeshSpec("3x3x3|bbox:0,0,0,1,1,1"))
       eMesh.commit()
       eMesh.print_info("fieldFunction_demo_1_0_0", 2)

       f_coords = eMesh.get_field("coordinates")

       ff_coords = FieldFunction("ff_coords", f_coords, eMesh, 3, 3)
       x = 0.123
       y = 0.234
       z = 0.345
       time = 0.0

       eval_vec3_print(x, y, z, time, ff_coords)
Example #17
0
 def test_break_hex8_tet4_24_1(self):
   fixture_setup()
   pm = MPI.COMM_WORLD
   p_size = parallel_machine_size(pm)
   eMesh = PerceptMesh(3)
   gmesh_spec = "1x1x" + str(p_size) + "|bbox:0,0,0,1,1," + str(p_size)
   eMesh.new_mesh(GMeshSpec(gmesh_spec))
   scalarDimension = 0
   proc_rank_field = eMesh.add_field("proc_rank", stk::topology::ELEMENT_RANK, scalarDimension)
   breaker = Refiner(eMesh, HEX8_TET4_24, proc_rank_field)
   eMesh.commit()
   eMesh.print_info()
   breaker.setRemoveOldElements(True)
   breaker.doBreak()
   eMesh.save_as("hex_tet_24_cube1x1x1.e")
Example #18
0
 def test_hex8_hex8_8_1_unit1(self):
   fixture_setup()
   eMesh = PerceptMesh(3)
   p_size = eMesh.get_parallel_size()
   gmesh_spec = "1x1x" + str(p_size) + "|bbox:0,0,0,1,1," + str(p_size)
   eMesh.new_mesh(GMeshSpec(gmesh_spec))
   scalarDimension = 0
   proc_rank_field = eMesh.add_field("proc_rank", stk::topology::ELEMENT_RANK, scalarDimension)
   breaker = Refiner(eMesh, HEX8_HEX8_8, proc_rank_field) 
   eMesh.commit()
   eMesh.print_info()
   eMesh.save_as("hex_hex_cube1x1x" + str(p_size) + "-orig.e")
   breaker.setRemoveOldElements(True)
   breaker.doBreak()
   eMesh.save_as( "hex_hex_cube1x1x" + str(p_size)+".e")
Example #19
0
    def test_fieldFunction_demo_2(self):
        eMesh = PerceptMesh()
        eMesh.new_mesh(GMeshSpec("3x3x3|bbox:0,0,0,1,1,1")
                       )  # use a fixture to generate a 3x3x3 hex mesh

        vectorDimension = 0
        # add a field
        eMesh.add_field("coords_mag_field", FEMMetaData.NODE_RANK,
                        vectorDimension)
        eMesh.commit()

        f_coords = eMesh.get_field("coordinates")  # get pre-existing field
        coords_mag_field = eMesh.get_field(
            "coords_mag_field")  # get the field we just created

        ff_coords = FieldFunction("ff_coords", f_coords, eMesh, 3,
                                  3)  # define a field function
        eval_vec3_print(
            0.1, 0.1, 0.1, 0.0, ff_coords
        )  # evaluate and print the field function a point {0.1, 0.1, 0.1} time=0.0

        coords_mag_sf = StringFunction(
            "sqrt(x*x + y*y + z*z)", "coords_mag_sf", 3,
            1)  # define coordinate magnitude function
        x = 0.123
        y = 0.234
        z = 0.345
        vv = sqrt(x * x + y * y + z * z)
        v1 = eval_func(x, y, z, 0, coords_mag_sf)
        print "vv = ", vv, "== v1 = ", v1
        self.assertEqual(vv, v1)  # ensure correctness of string function

        # define a field function
        coords_mag_field_function = FieldFunction("coords_mag_field_function",
                                                  coords_mag_field, eMesh, 3,
                                                  1)

        # interpolate the function onto the mesh
        coords_mag_field_function.interpolateFrom(coords_mag_sf)

        eMesh.save_as("./cubehex8_withCoordMag_out.e")

        # demonstrate how to usa an alias
        ff_coords.add_alias("mc")

        sfcm = StringFunction("sqrt(mc[0]*mc[0]+mc[1]*mc[1]+mc[2]*mc[2])",
                              "sfcm", 3, 1)
    def test_fieldFunction_demo_1(self):
       gms = Gmesh_STKmesh_Fixture(MPI.COMM_WORLD, "3x3x3|bbox:0,0,0,1,1,1")
       print "gms = ", gms
       print "gms= end"

       eMesh = PerceptMesh()
       eMesh.new_mesh(GMeshSpec("3x3x3|bbox:0,0,0,1,1,1"))
       eMesh.commit()

       f_coords = eMesh.get_field("coordinates")
       ff_coords = FieldFunction("ff_coords", f_coords, eMesh, 3, 3)

       x = 0.123
       y = 0.234
       z = 0.345
       time = 0.0
       eval_vec3_print(x,y,z,time,ff_coords)
def fixture_setup_0():
  eMesh = PerceptMesh()
  p_size = eMesh.get_parallel_size()
  gmesh_spec = "4x4x"+str(4*p_size)+"|bbox:0,0,0,1,1,1"
  eMesh.new_mesh(GMeshSpec(gmesh_spec))
  eMesh.commit()
  eMesh.save_as("hex_fixture.e")

  eMesh = PerceptMesh()
  eMesh.open("exodus_files/"+input_files_loc+"hex_fixture.e")
  scalarDimension = 0
  proc_rank_field = eMesh.add_field("proc_rank", eMesh.element_rank(), scalarDimension)
  breaker = Refiner(eMesh, HEX8_TET4_24, proc_rank_field)
  eMesh.commit()

  breaker.doBreak()
  eMesh.save_as("tet_fixture.e")
def fixture_setup_0():
  eMesh = PerceptMesh()
  p_size = eMesh.get_parallel_size()
  gmesh_spec = "4x4x"+str(4*p_size)+"|bbox:0,0,0,1,1,1"
  eMesh.new_mesh(GMeshSpec(gmesh_spec))
  eMesh.commit()
  eMesh.save_as("hex_fixture.e")

  eMesh = PerceptMesh()
  eMesh.open("exodus_files/"+input_files_loc+"hex_fixture.e")
  scalarDimension = 0
  proc_rank_field = eMesh.add_field("proc_rank", eMesh.element_rank(), scalarDimension)
  breaker = Refiner(eMesh, HEX8_TET4_24, proc_rank_field)
  eMesh.commit()

  breaker.doBreak()
  eMesh.save_as("tet_fixture.e")
Example #23
0
class LocalFixture:
  
  def __init__(self, num_xyz, num_y, num_z):
    
    self.eMesh = PerceptMesh()
    self.num_x = num_xyz
    self.num_y = num_y
    self.num_z = num_z
    config_mesh = str(self.num_x) + "x" + str(self.num_y) + "x" + str(self.num_z) + "|bbox:-0.5,-0.5,-0.5,0.5,0.5,0.5"

    self.eMesh.new_mesh(GMeshSpec(config_mesh))
    self.eMesh.commit()
    self.metaData = self.eMesh.get_fem_meta_data()
    self.bulkData = self.eMesh.get_bulk_data()
    self.coords_field = self.metaData.get_field("coordinates")
    self.sfx = StringFunction("x", "sfx", Dimensions(3), Dimensions(1))
    self.sfx_res = ConstantFunction(0.0, "sfx_res")
Example #24
0
class LocalFixture:
    def __init__(self, num_xyz, num_y, num_z):

        self.eMesh = PerceptMesh()
        self.num_x = num_xyz
        self.num_y = num_y
        self.num_z = num_z
        config_mesh = str(self.num_x) + "x" + str(self.num_y) + "x" + str(
            self.num_z) + "|bbox:-0.5,-0.5,-0.5,0.5,0.5,0.5"

        self.eMesh.new_mesh(GMeshSpec(config_mesh))
        self.eMesh.commit()
        self.metaData = self.eMesh.get_fem_meta_data()
        self.bulkData = self.eMesh.get_bulk_data()
        self.coords_field = self.metaData.get_field("coordinates")
        self.sfx = StringFunction("x", "sfx", Dimensions(3), Dimensions(1))
        self.sfx_res = ConstantFunction(0.0, "sfx_res")
Example #25
0
    def test_fieldFunction_demo_1(self):
        gms = Gmesh_STKmesh_Fixture(MPI.COMM_WORLD, "3x3x3|bbox:0,0,0,1,1,1")
        print "gms = ", gms
        print "gms= end"

        eMesh = PerceptMesh()
        eMesh.new_mesh(GMeshSpec("3x3x3|bbox:0,0,0,1,1,1"))
        eMesh.commit()

        f_coords = eMesh.get_field("coordinates")
        ff_coords = FieldFunction("ff_coords", f_coords, eMesh, 3, 3)

        x = 0.123
        y = 0.234
        z = 0.345
        time = 0.0
        eval_vec3_print(x, y, z, time, ff_coords)
Example #26
0
    def test_fieldFunction_demo_2(self):   
       eMesh = PerceptMesh()
       eMesh.new_mesh(GMeshSpec("3x3x3|bbox:0,0,0,1,1,1"))

       vectorDimension = 0
       eMesh.add_field("coords_mag_field", FEMMetaData.NODE_RANK, vectorDimension)
       eMesh.commit()

       f_coords = eMesh.get_field(FEMMetaData.NODE_RANK, "coordinates")
       coords_mag_field = eMesh.get_field(FEMMetaData.NODE_RANK, "coords_mag_field")

       ff_coords = FieldFunction("ff_coords", f_coords, eMesh, 3, 3)
       eval_vec3_print(0.1,0.1,0.1,0.0,ff_coords)
       
       coords_mag_sf = StringFunction("sqrt(x*x + y*y + z*z)" , "coords_mag_sf", 3, 1)
       x = 0.123
       y = 0.234
       z = 0.345
       vv = sqrt(x*x + y*y + z*z)
       v1 = eval_func(x,y,z,0,coords_mag_sf)
       print "vv = ", vv, "== v1 = ", v1
       self.assertEqual(vv, v1)
       
       coords_mag_field_function = FieldFunction("coords_mag_field_function", coords_mag_field, eMesh, 3, 1)

       coords_mag_field_function.interpolateFrom(coords_mag_sf)

       eMesh.save_as("./cubehex8_withCoordMag_out.e")

       ff_coords.add_alias("mc")
       
       sfcm = StringFunction("sqrt(mc[0]*mc[0]+mc[1]*mc[1]+mc[2]*mc[2])", "sfcm", 3, 1)
       vv = eval_func(0.1,0.1,0.1,0.0, sfcm)
       print "expected = ", sqrt(3*0.1*0.1), " actual= " , vv

       sfcm = StringFunction("sqrt(ff_coords[0]*ff_coords[0]+ff_coords[1]*ff_coords[1]+ff_coords[2]*ff_coords[2])", "sfcm", 3, 1)
       vv = eval_func(0.1,0.1,0.1,0.0, sfcm)
       print "expected = ", sqrt(3*0.1*0.1), " actual= " , vv
Example #27
0
    def test_fieldFunction_point_eval_verify(self):
        num_x = 3
        num_y = 3
        num_z = 3
        config_mesh = str(num_x) + "x" + str(num_y) + "x" + str(
            num_z) + "|bbox:0,0,0,1,1,1"

        eMesh = PerceptMesh()
        eMesh.new_mesh(GMeshSpec(config_mesh))
        eMesh.commit()

        f_coords = eMesh.get_field("coordinates")

        ff_coords = FieldFunction("ff_coords", f_coords, eMesh, Dimensions(3),
                                  Dimensions(3), FieldFunction.SIMPLE_SEARCH)

        val1 = eval_vec3_print(0.2, 0.3, 0.4, 0.0, ff_coords)

        bulkData = eMesh.get_bulk_data()

        try:
            val10 = eval_print_vec3(1.2, 1.3, 1.4, 0.0, ff_coords)
        except:
            print "expected to catch this exception: "

        pts = array([0.2, 0.3, 0.4])
        output_pts = array([0.0, 0.0, 0.0])
        output_pts = ff_coords.value(pts, output_pts)

        tol = 1.e-9

        print "output(0) = ", pts[0], " == output_pts(0) = ", output_pts[0]
        print "output(1) = ", pts[1], " == output_pts(1) = ", output_pts[1]
        print "output(2) = ", pts[2], " == output_pts(2) = ", output_pts[2]

        self.assertAlmostEqual(pts[0], output_pts[0], delta=tol)
        self.assertAlmostEqual(pts[1], output_pts[1], delta=tol)
        self.assertAlmostEqual(pts[2], output_pts[2], delta=tol)
Example #28
0
    def test_fieldFunction_demo_2(self):   
        eMesh = PerceptMesh()
        eMesh.new_mesh(GMeshSpec("3x3x3|bbox:0,0,0,1,1,1"))      # use a fixture to generate a 3x3x3 hex mesh

        vectorDimension = 0
        # add a field
        eMesh.add_field("coords_mag_field", FEMMetaData.NODE_RANK, vectorDimension)  
        eMesh.commit()

        f_coords = eMesh.get_field("coordinates")                # get pre-existing field
        coords_mag_field = eMesh.get_field("coords_mag_field")   # get the field we just created

        ff_coords = FieldFunction("ff_coords", f_coords, eMesh, 3, 3)  # define a field function
        eval_vec3_print(0.1,0.1,0.1,0.0,ff_coords)  # evaluate and print the field function a point {0.1, 0.1, 0.1} time=0.0

        coords_mag_sf = StringFunction("sqrt(x*x + y*y + z*z)" , "coords_mag_sf", 3, 1)  # define coordinate magnitude function
        x = 0.123
        y = 0.234
        z = 0.345
        vv = sqrt(x*x + y*y + z*z)
        v1 = eval_func(x,y,z,0,coords_mag_sf)
        print "vv = ", vv, "== v1 = ", v1
        self.assertEqual(vv, v1)               # ensure correctness of string function

        # define a field function
        coords_mag_field_function = FieldFunction("coords_mag_field_function", coords_mag_field, eMesh, 3, 1)

        # interpolate the function onto the mesh
        coords_mag_field_function.interpolateFrom(coords_mag_sf)

        eMesh.save_as("./cubehex8_withCoordMag_out.e")

        # demonstrate how to usa an alias
        ff_coords.add_alias("mc")

        sfcm = StringFunction("sqrt(mc[0]*mc[0]+mc[1]*mc[1]+mc[2]*mc[2])", "sfcm", 3, 1)
    def test_fieldFunction_point_eval_verify(self):
       num_x = 3
       num_y = 3
       num_z = 3
       config_mesh = str(num_x) + "x" + str(num_y) + "x" + str(num_z) + "|bbox:0,0,0,1,1,1"

       eMesh = PerceptMesh()
       eMesh.new_mesh(GMeshSpec(config_mesh))
       eMesh.commit()

       f_coords = eMesh.get_field("coordinates") 
       
       ff_coords = FieldFunction("ff_coords", f_coords, eMesh, Dimensions(3), Dimensions(3), FieldFunction.SIMPLE_SEARCH)

       val1 = eval_vec3_print(0.2,0.3,0.4,0.0,ff_coords)

       bulkData = eMesh.get_bulk_data()

       try:
          val10 = eval_print_vec3(1.2, 1.3, 1.4, 0.0, ff_coords)
       except:
          print "expected to catch this exception: "

       pts = array([0.2, 0.3, 0.4])
       output_pts = array([0.0, 0.0, 0.0])
       output_pts = ff_coords.value(pts, output_pts)
       
       tol = 1.e-9
         
       print "output(0) = ", pts[0], " == output_pts(0) = ", output_pts[0]
       print "output(1) = ", pts[1], " == output_pts(1) = ", output_pts[1]
       print "output(2) = ", pts[2], " == output_pts(2) = ", output_pts[2]

       self.assertAlmostEqual(pts[0], output_pts[0], delta = tol)
       self.assertAlmostEqual(pts[1], output_pts[1], delta = tol)
       self.assertAlmostEqual(pts[2], output_pts[2], delta = tol)
Example #30
0
    def test_fieldFunction_multiplePoints(self):
        print "start..."
        num_x = 3
        num_y = 3
        num_z = 3
        config_mesh = str(num_x) + "x" + str(num_y) + "x" + str(
            num_z) + "|bbox:0,0,0,1,1,1"

        eMesh = PerceptMesh()
        eMesh.new_mesh(GMeshSpec(config_mesh))
        vectorDimension = 0
        eMesh.add_field("coords_mag_field", FEMMetaData.NODE_RANK,
                        vectorDimension)
        eMesh.commit()
        f_coords = eMesh.get_field("coordinates")
        ff_coords = FieldFunction("ff_coords", f_coords, eMesh, Dimensions(3),
                                  Dimensions(3), FieldFunction.SIMPLE_SEARCH)
        val1 = eval_vec3(0.2, 0.3, 0.4, 0.0, ff_coords)
        print "val1= ", val1

        points = zeros(shape=(4, 3))
        output_expect = zeros(shape=(4, 3))
        output = zeros(shape=(4, 3))

        print "here 1"
        i = 0
        for xyzt in self.testpoints:
            x = xyzt[0]
            y = xyzt[1]
            z = xyzt[2]
            t = xyzt[3]
            points[i][0] = x
            points[i][1] = y
            points[i][2] = z

            vec = eval_vec3(x, y, z, t, ff_coords)

            tol0 = fabs(1.e-5 * x)
            tol1 = fabs(1.e-5 * y)
            tol2 = fabs(1.e-5 * z)

            print "vec(0) = ", vec[0], " == x = ", x
            print "vec(1) = ", vec[1], " == y = ", y
            print "vec(2) = ", vec[2], " == z = ", z

            self.assertAlmostEqual(x, vec[0], delta=tol0)
            self.assertAlmostEqual(y, vec[1], delta=tol1)
            self.assertAlmostEqual(z, vec[2], delta=tol2)

            output_expect[i][0] = x
            output_expect[i][1] = y
            output_expect[i][2] = z
            i = i + 1

        print "field_op: NPTS= 4"
        ff_coords.setDomainDimensions(Dimensions(3))
        ff_coords.setCodomainDimensions(Dimensions(3))
        #output = ff_coords.evaluate(points)
        # pass in the output array to ensure result is properly dimensioned
        output = ff_coords.value(points, output)
        print "here 2, output= ", output

        for j in range(4):  #NLM
            output_expect_j = output_expect[j][0]
            output_j = output[j][0]

            tol = 1.e-5 * (fabs(output_expect_j))
            print "output[j] = ", output_j, " == output_expect[j] = ", output_expect_j, " points[j] = ", points[
                j]
            self.assertAlmostEqual(output_j, output_expect_j, delta=tol)
        print "start...done"
    def test_fieldFunction_multiplePoints(self):
       print "start..."
       num_x = 3
       num_y = 3
       num_z = 3
       config_mesh = str(num_x) + "x" + str(num_y) + "x" + str(num_z) + "|bbox:0,0,0,1,1,1"

       eMesh = PerceptMesh()
       eMesh.new_mesh(GMeshSpec(config_mesh))
       vectorDimension = 0
       eMesh.add_field("coords_mag_field", FEMMetaData.NODE_RANK, vectorDimension)
       eMesh.commit()
       f_coords = eMesh.get_field("coordinates")
       ff_coords = FieldFunction("ff_coords", f_coords, eMesh, Dimensions(3), Dimensions(3), FieldFunction.SIMPLE_SEARCH)
       val1 = eval_vec3(0.2, 0.3, 0.4, 0.0, ff_coords)
       print "val1= ", val1
     
       points = zeros(shape=(4,3))
       output_expect = zeros(shape=(4,3))    
       output = zeros(shape=(4,3))
       
       print "here 1"
       i = 0 
       for xyzt in self.testpoints:
          x = xyzt[0]
          y = xyzt[1]
          z = xyzt[2]
          t = xyzt[3]
          points[i][0] = x
          points[i][1] = y
          points[i][2] = z

          vec = eval_vec3(x,y,z,t,ff_coords)

          tol0 = fabs(1.e-5*x)
          tol1 = fabs(1.e-5*y)
          tol2 = fabs(1.e-5*z)

          print "vec(0) = ", vec[0], " == x = ", x
          print "vec(1) = ", vec[1], " == y = ", y
          print "vec(2) = ", vec[2], " == z = ", z
          
          self.assertAlmostEqual(x, vec[0], delta=tol0)
          self.assertAlmostEqual(y, vec[1], delta=tol1)
          self.assertAlmostEqual(z, vec[2], delta=tol2)         

          output_expect[i][0] = x
          output_expect[i][1] = y
          output_expect[i][2] = z
          i = i + 1

       print "field_op: NPTS= 4"
       ff_coords.setDomainDimensions(Dimensions(3))
       ff_coords.setCodomainDimensions(Dimensions(3))
       #output = ff_coords.evaluate(points)
       # pass in the output array to ensure result is properly dimensioned
       output = ff_coords.value(points, output)
       print "here 2, output= ", output
 
       for j in range(4): #NLM
           output_expect_j = output_expect[j][0]
           output_j = output[j][0]

           tol = 1.e-5*(fabs(output_expect_j))
           print "output[j] = ", output_j, " == output_expect[j] = ", output_expect_j  , " points[j] = ", points[j]
           self.assertAlmostEqual(output_j, output_expect_j, delta = tol) 
       print "start...done"