Exemplo n.º 1
0
    def setUp(self):
        if not hasattr(self, "name"):
            # return immediately when the setup method is being called on the based class and NOT the
            # classes created using parametrized
            # this will happen when training, but will hopefully be fixed down the line
            return
        super().setUp()

        options = copy.copy(adflowDefOpts)
        options["outputdirectory"] = os.path.join(baseDir, options["outputdirectory"])
        options.update(self.options)

        self.ffdFile = os.path.join(baseDir, "../../input_files/mdo_tutorial_ffd.fmt")

        mesh_options = copy.copy(IDWarpDefOpts)
        mesh_options.update({"gridFile": options["gridfile"]})

        self.ap = copy.deepcopy(self.aero_prob)

        # Setup aeroproblem
        self.ap.evalFuncs = self.evalFuncs

        # add the default dvs to the problem
        for dv in defaultAeroDVs:
            self.ap.addDV(dv)

        self.CFDSolver = ADFLOW_C(options=options, debug=True)

        self.CFDSolver.setMesh(USMesh_C(options=mesh_options))
        self.CFDSolver.setDVGeo(setDVGeo(self.ffdFile, cmplx=True))

        # propagates the values from the restart file throughout the code
        self.CFDSolver.getResidual(self.ap)
Exemplo n.º 2
0
def eval_warp(handler, test_name, meshOptions, iscomplex):
    # --- Create warping object ---
    if iscomplex:
        # Checking if the complex verision of the code has been built:
        try:
            from idwarp import idwarp_cs  # noqa: F401

            h = 1e-40
            mesh = USMesh_C(options=meshOptions, debug=True)
        except ImportError:
            raise unittest.SkipTest(
                "Skipping because you do not have complex idwarp compiled")
    else:
        try:
            from idwarp import idwarp  # noqa: F401

            mesh = USMesh(options=meshOptions)
        except ImportError:
            raise unittest.SkipTest(
                "Skipping because you do not have real idwarp compiled")

    # --- Extract Surface Coordinates ---
    coords0 = mesh.getSurfaceCoordinates()

    vCoords = mesh.getCommonGrid()
    val = MPI.COMM_WORLD.reduce(numpy.sum(vCoords.flatten()), op=MPI.SUM)
    handler.root_add_val(f"{test_name} - Sum of vCoords Inital:",
                         val,
                         tol=1e-8)

    new_coords = coords0.copy()

    # --- Setting the coordinates displacement for surface mesh ---
    if test_name == "Test_inflate_cube":
        # This specific test displaces the surface in every direction
        for i in range(len(coords0)):
            new_coords[i, 0] *= 1.1
            new_coords[i, 1] *= 1.2
            new_coords[i, 2] *= 1.3
    else:
        # Do a shearing sweep deflection:
        for i in range(len(coords0)):
            span = coords0[i, 2]
            new_coords[i, 0] += 0.05 * span

    # --- Reset the newly computed surface coordiantes
    mesh.setSurfaceCoordinates(new_coords)
    mesh.warpMesh()

    # --- Get the sum of the warped coordinates ---
    vCoords = mesh.getWarpGrid()

    val = MPI.COMM_WORLD.reduce(numpy.sum(vCoords.flatten()), op=MPI.SUM)
    handler.root_add_val(f"{test_name} - Sum of vCoords Warped:",
                         val,
                         tol=1e-8)

    # --- Create a dXv vector to do test the mesh warping with ---
    dXv_warp = numpy.linspace(0, 1.0, mesh.warp.griddata.warpmeshdof)

    if not iscomplex:
        # --- Computing Warp Derivatives ---
        mesh.warpDeriv(dXv_warp, solverVec=False)
        dXs = mesh.getdXs()

        val = MPI.COMM_WORLD.reduce(numpy.sum(dXs.flatten()), op=MPI.SUM)

        # --- Verifying Warp Deriv ---
        mesh.verifyWarpDeriv(dXv_warp, solverVec=False, dofStart=0, dofEnd=5)

    else:
        # add a complex perturbation on all surface nodes simultaneously:
        for i in range(len(coords0)):
            new_coords[i, :] += h * 1j

        # Reset the newly computed surface coordiantes
        mesh.setSurfaceCoordinates(new_coords)
        mesh.warpMesh()

        vCoords = mesh.getWarpGrid()
        deriv = numpy.imag(vCoords) / h
        deriv = numpy.dot(dXv_warp, deriv)
        val = MPI.COMM_WORLD.reduce(numpy.sum(deriv), op=MPI.SUM)

    handler.root_add_val(f"{test_name} - Sum of dxs:", val, tol=1e-8)
Exemplo n.º 3
0
def test1():
    # Test the Ahmed body openfoam mesh
    sys.stdout.flush()
    #change directory to the correct test case
    os.chdir('./input/ahmedBodyMesh/')

    file_name = os.getcwd()

    meshOptions = copy.deepcopy(defOpts)

    meshOptions.update({
        'gridFile': file_name,
        'fileType': 'openfoam',
        'symmetryPlanes': [[[0, 0, 0], [0, 1, 0]]],
    })
    # Create warping object
    mesh = USMesh(options=meshOptions, debug=True)

    # Extract Surface Coordinates
    coords0 = mesh.getSurfaceCoordinates()

    vCoords = mesh.getCommonGrid()
    val = MPI.COMM_WORLD.reduce(numpy.sum(vCoords.flatten()), op=MPI.SUM)
    if MPI.COMM_WORLD.rank == 0:
        print('Sum of vCoords Inital:')
        reg_write(val, 1e-8, 1e-8)

    new_coords = coords0.copy()
    # Do a stretch:
    for i in range(len(coords0)):
        length = coords0[i, 2]
        new_coords[i, 0] += .05 * length

    # Reset the newly computed surface coordiantes
    mesh.setSurfaceCoordinates(new_coords)
    mesh.warpMesh()

    vCoords = mesh.getWarpGrid()
    val = MPI.COMM_WORLD.reduce(numpy.sum(vCoords.flatten()), op=MPI.SUM)
    if MPI.COMM_WORLD.rank == 0:
        print('Sum of vCoords Warped:')
        reg_write(val, 1e-8, 1e-8)

    # Create a dXv vector to do test the mesh warping with:
    dXv_warp = numpy.linspace(0, 1.0, mesh.warp.griddata.warpmeshdof)

    if not 'complex' in sys.argv:

        if MPI.COMM_WORLD.rank == 0:
            print('Computing Warp Deriv')
        mesh.warpDeriv(dXv_warp, solverVec=False)
        dXs = mesh.getdXs()

        val = MPI.COMM_WORLD.reduce(numpy.sum(dXs.flatten()), op=MPI.SUM)
        if MPI.COMM_WORLD.rank == 0:
            print('Sum of dxs:')
            reg_write(val, 1e-8, 1e-8)
    else:

        # add a complex perturbation on all surface nodes simultaneously:
        for i in range(len(coords0)):
            new_coords[i, :] += h * 1j

        # Reset the newly computed surface coordiantes
        mesh.setSurfaceCoordinates(new_coords)
        mesh.warpMesh()

        vCoords = mesh.getWarpGrid()
        deriv = numpy.imag(vCoords) / h
        deriv = numpy.dot(dXv_warp, deriv)
        val = MPI.COMM_WORLD.reduce(numpy.sum(deriv), op=MPI.SUM)

        if MPI.COMM_WORLD.rank == 0:
            print('Sum of dxs:')
            reg_write(val, 1e-8, 1e-8)

    del mesh
    #os.system('rm -fr *.cgns *.dat')
    #change back to the original directory
    os.chdir('../../')
Exemplo n.º 4
0
def test3():
    # Test the mdo tutorial o mesh
    file_name = '../input_files/o_mesh.cgns'

    meshOptions = copy.deepcopy(defOpts)

    meshOptions.update({'gridFile': file_name, 'fileType': 'cgns'})
    # Create warping object
    mesh = USMesh(options=meshOptions)

    # Extract Surface Coordinates
    coords0 = mesh.getSurfaceCoordinates()

    vCoords = mesh.getCommonGrid()
    val = MPI.COMM_WORLD.reduce(numpy.sum(vCoords.flatten()), op=MPI.SUM)
    if MPI.COMM_WORLD.rank == 0:
        print('Sum of vCoords Inital:')
        reg_write(val, 1e-8, 1e-8)

    new_coords = coords0.copy()
    # Do a shearing sweep deflection:
    for i in range(len(coords0)):
        span = coords0[i, 2]
        new_coords[i, 0] += .05 * span

    # Reset the newly computed surface coordiantes
    mesh.setSurfaceCoordinates(new_coords)
    mesh.warpMesh()

    # Get the sum of the warped coordinates
    #vCoords = mesh.getSolverGrid()
    vCoords = mesh.getWarpGrid()

    val = MPI.COMM_WORLD.reduce(numpy.sum(vCoords.flatten()), op=MPI.SUM)
    if MPI.COMM_WORLD.rank == 0:
        print('Sum of vCoords Warped:')
        reg_write(val, 1e-8, 1e-8)

    # Create a dXv vector to do test the mesh warping with:
    dXv_warp = numpy.linspace(0, 1.0, mesh.warp.griddata.warpmeshdof)

    if not 'complex' in sys.argv:
        if MPI.COMM_WORLD.rank == 0:
            print('Computing Warp Deriv')
        mesh.warpDeriv(dXv_warp, solverVec=False)
        dXs = mesh.getdXs()

        val = MPI.COMM_WORLD.reduce(numpy.sum(dXs.flatten()), op=MPI.SUM)
        if MPI.COMM_WORLD.rank == 0:
            print('Sum of dxs:')
            reg_write(val, 1e-8, 1e-8)
    else:

        # add a complex perturbation on all surface nodes simultaneously:
        for i in range(len(coords0)):
            new_coords[i, :] += h * 1j

        # Reset the newly computed surface coordiantes
        mesh.setSurfaceCoordinates(new_coords)
        mesh.warpMesh()

        vCoords = mesh.getWarpGrid()
        deriv = numpy.imag(vCoords) / h
        deriv = numpy.dot(dXv_warp, deriv)
        val = MPI.COMM_WORLD.reduce(numpy.sum(deriv), op=MPI.SUM)

        if MPI.COMM_WORLD.rank == 0:
            print('Sum of dxs:')
            reg_write(val, 1e-8, 1e-8)