diff --git a/example/PDE-OPT/0ld/stefan-boltzmann/CMakeLists.txt b/example/PDE-OPT/0ld/stefan-boltzmann/CMakeLists.txt index aaf59a309..8a7abd471 100644 --- a/example/PDE-OPT/0ld/stefan-boltzmann/CMakeLists.txt +++ b/example/PDE-OPT/0ld/stefan-boltzmann/CMakeLists.txt @@ -1,5 +1,5 @@ -IF(${PROJECT_NAME}_ENABLE_Intrepid AND +IF(${PROJECT_NAME}_ENABLE_Intrepid AND ${PROJECT_NAME}_ENABLE_Epetra AND ${PROJECT_NAME}_ENABLE_Amesos AND ${PROJECT_NAME}_ENABLE_Amesos2 AND @@ -17,7 +17,6 @@ IF(${PROJECT_NAME}_ENABLE_Intrepid AND # ARGS PrintItAll # NUM_MPI_PROCS 4 # NUM_TOTAL_CORES_USED 4 -# CATEGORIES CONTINUOUS # PASS_REGULAR_EXPRESSION "TEST PASSED" # ADD_DIR_TO_NAME # ) @@ -28,7 +27,6 @@ IF(${PROJECT_NAME}_ENABLE_Intrepid AND # ARGS PrintItAll # NUM_MPI_PROCS 4 # NUM_TOTAL_CORES_USED 4 -# CATEGORIES CONTINUOUS # PASS_REGULAR_EXPRESSION "TEST PASSED" # ADD_DIR_TO_NAME # ) diff --git a/example/PDE-OPT/TEST/CMakeLists.txt b/example/PDE-OPT/TEST/CMakeLists.txt index 818440948..549809721 100644 --- a/example/PDE-OPT/TEST/CMakeLists.txt +++ b/example/PDE-OPT/TEST/CMakeLists.txt @@ -1,6 +1,5 @@ -IF(${PROJECT_NAME}_ENABLE_Intrepid AND - ${PROJECT_NAME}_ENABLE_Epetra ) +IF(${PROJECT_NAME}_ENABLE_Intrepid) ROL_ADD_EXECUTABLE_AND_TEST( test_01 @@ -92,6 +91,98 @@ IF(${PROJECT_NAME}_ENABLE_Intrepid AND ENDIF() +IF(${PROJECT_NAME}_ENABLE_Intrepid2) + + ROL_ADD_EXECUTABLE_AND_TEST( + test_01_Kokkos + SOURCES test_01K.cpp + ARGS PrintItAll + NUM_MPI_PROCS 1 + NUM_TOTAL_CORES_USED 1 + PASS_REGULAR_EXPRESSION "TEST PASSED" + ADD_DIR_TO_NAME + ) + + ROL_ADD_EXECUTABLE_AND_TEST( + test_02_Kokkos + SOURCES test_02K.cpp + ARGS PrintItAll + NUM_MPI_PROCS 1 + NUM_TOTAL_CORES_USED 1 + PASS_REGULAR_EXPRESSION "TEST PASSED" + ADD_DIR_TO_NAME + ) + + ROL_ADD_EXECUTABLE_AND_TEST( + test_03_Kokkos + SOURCES test_03K.cpp + ARGS PrintItAll + NUM_MPI_PROCS 1 + NUM_TOTAL_CORES_USED 1 + PASS_REGULAR_EXPRESSION "TEST PASSED" + ADD_DIR_TO_NAME + ) + + ROL_ADD_EXECUTABLE_AND_TEST( + test_04_Kokkos + SOURCES test_04K.cpp + ARGS PrintItAll + NUM_MPI_PROCS 1 + NUM_TOTAL_CORES_USED 1 + PASS_REGULAR_EXPRESSION "TEST PASSED" + ADD_DIR_TO_NAME + ) + + ROL_ADD_EXECUTABLE_AND_TEST( + test_05_Kokkos + SOURCES test_05K.cpp + ARGS PrintItAll + NUM_MPI_PROCS 1 + NUM_TOTAL_CORES_USED 1 + PASS_REGULAR_EXPRESSION "TEST PASSED" + ADD_DIR_TO_NAME + ) + + ROL_ADD_EXECUTABLE_AND_TEST( + test_07_Kokkos + SOURCES test_07K.cpp + ARGS PrintItAll + NUM_MPI_PROCS 1 + NUM_TOTAL_CORES_USED 1 + PASS_REGULAR_EXPRESSION "TEST PASSED" + ADD_DIR_TO_NAME + ) + + ROL_ADD_EXECUTABLE_AND_TEST( + test_08_Kokkos + SOURCES test_08K.cpp + ARGS PrintItAll + NUM_MPI_PROCS 1 + NUM_TOTAL_CORES_USED 1 + PASS_REGULAR_EXPRESSION "TEST PASSED" + ADD_DIR_TO_NAME + ) + + ROL_ADD_EXECUTABLE_AND_TEST( + test_09_Kokkos + SOURCES test_09K.cpp + ARGS PrintItAll + NUM_MPI_PROCS 1 + NUM_TOTAL_CORES_USED 1 + PASS_REGULAR_EXPRESSION "TEST PASSED" + ADD_DIR_TO_NAME + ) + + ROL_COPY_FILES_TO_BINARY_DIR( + TestDataCopyK + SOURCE_FILES + input_01.xml input_02.xml input_03.xml input_04.xml input_05.xml input_07.xml input_08.xml input_09.xml cube.txt L-cubes.txt + SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}" + DEST_DIR "${CMAKE_CURRENT_BINARY_DIR}" + ) + +ENDIF() + #IF(${PROJECT_NAME}_ENABLE_Sacado) # ROL_ADD_EXECUTABLE_AND_TEST( @@ -104,6 +195,3 @@ ENDIF() # ADD_DIR_TO_NAME # ) #ENDIF() - - - diff --git a/example/PDE-OPT/TEST/test_01K.cpp b/example/PDE-OPT/TEST/test_01K.cpp new file mode 100644 index 000000000..b347a1539 --- /dev/null +++ b/example/PDE-OPT/TEST/test_01K.cpp @@ -0,0 +1,166 @@ +// @HEADER +// ***************************************************************************** +// Rapid Optimization Library (ROL) Package +// +// Copyright 2014 NTESS and the ROL contributors. +// SPDX-License-Identifier: BSD-3-Clause +// ***************************************************************************** +// @HEADER + +/*! \file test_01.cpp + \brief Unit test for the mesh manager and the degree-of-freedom manager. + Mesh type: RECTANGLE with QUAD CELLS and HGRAD SPACE. +*/ + +#include "ROL_Algorithm.hpp" +#include "ROL_BoundConstraint_SimOpt.hpp" +#include "ROL_Vector_SimOpt.hpp" + +#include "ROL_Stream.hpp" +#include "ROL_GlobalMPISession.hpp" +#include "Teuchos_XMLParameterListHelpers.hpp" + +#include "Intrepid2_HGRAD_QUAD_C1_FEM.hpp" +#include "Intrepid2_HGRAD_QUAD_C2_FEM.hpp" + +#include + +#include +#include + +#include "../TOOLS/meshmanagerK.hpp" +#include "../TOOLS/dofmanagerK.hpp" + +using RealT = double; +using DeviceT = Kokkos::HostSpace; + +using scalar_view = typename MeshManager::scalar_view; +using int_view = typename MeshManager::int_view; +using basis_ptr = Intrepid2::BasisPtr; + +int main(int argc, char *argv[]) { + + ROL::GlobalMPISession mpiSession(&argc, &argv); + Kokkos::ScopeGuard kokkosScope(argc, argv); + // This little trick lets us print to std::cout only if a (dummy) command-line argument is provided. + int iprint = argc - 1; + ROL::Ptr outStream; + ROL::nullstream bhs; // outputs nothing + if (iprint > 0) + outStream = ROL::makePtrFromRef(std::cout); + else + outStream = ROL::makePtrFromRef(bhs); + + int errorFlag = 0; + + // *** Example body. + try { + + /*** Read in XML input ***/ + std::string filename = "input_01.xml"; + Teuchos::RCP parlist + = Teuchos::rcp( new Teuchos::ParameterList() ); + Teuchos::updateParametersFromXmlFile( filename, parlist.ptr() ); + + /*** Initialize mesh / degree-of-freedom manager. ***/ + MeshManager_Rectangle meshmgr(*parlist); + scalar_view nodes = meshmgr.getNodes(); + int_view cellToNodeMap = meshmgr.getCellToNodeMap(); + int_view cellToEdgeMap = meshmgr.getCellToEdgeMap(); + ROL::Ptr > > > sideSetsPtr = meshmgr.getSideSets(); + + std::vector > > &sideSets = *sideSetsPtr; + *outStream << "Number of nodes = " << meshmgr.getNumNodes() << std::endl; // << nodes; + *outStream << "Number of cells = " << meshmgr.getNumCells() << std::endl; // << cellToNodeMap; + *outStream << "Number of edges = " << meshmgr.getNumEdges() << std::endl; // << cellToEdgeMap; + // Print mesh info to file. + std::ofstream meshfile; + meshfile.open("cells.txt"); + for (int i=0; i(sideSets.size()); ++i) { + for (int j=0; j(sideSets[i].size()); ++j) { + if (sideSets[i][j].size() > 0) { + for (int k=0; k(sideSets[i][j].size()); ++k) { + meshfile << sideSets[i][j][k] << std::endl; + } + } + meshfile << std::endl << std::endl; + } + } + meshfile.close(); + + basis_ptr basisPtrQ1 = ROL::makePtr>(); + basis_ptr basisPtrQ2 = ROL::makePtr>(); + + std::vector basisPtrs(3, ROL::nullPtr); + basisPtrs[0] = basisPtrQ2; + basisPtrs[1] = basisPtrQ1; + basisPtrs[2] = basisPtrQ2; + + ROL::Ptr > meshmgrPtr = ROL::makePtrFromRef(meshmgr); + + DofManager dofmgr(meshmgrPtr, basisPtrs); + + *outStream << "Number of node dofs = " << dofmgr.getNumNodeDofs() << std::endl; // << dofmgr.getNodeDofs(); + *outStream << "Number of edge dofs = " << dofmgr.getNumEdgeDofs() << std::endl; // << dofmgr.getEdgeDofs(); + *outStream << "Number of face dofs = " << dofmgr.getNumFaceDofs() << std::endl; // << dofmgr.getFaceDofs(); + *outStream << "Number of void dofs = " << dofmgr.getNumVoidDofs() << std::endl; // << dofmgr.getVoidDofs(); + *outStream << "Total number of dofs = " << dofmgr.getNumDofs() << std::endl; // << dofmgr.getCellDofs(); + + std::vector> fieldPattern = dofmgr.getFieldPattern(); + for (int i=0; i +#include + +#include "../TOOLS/meshmanagerK.hpp" +#include "../TOOLS/dofmanagerK.hpp" + +using RealT = double; +using DeviceT = Kokkos::HostSpace; + +using scalar_view = typename MeshManager::scalar_view; +using int_view = typename MeshManager::int_view; +using basis_ptr = Intrepid2::BasisPtr; + +int main(int argc, char *argv[]) { + + ROL::GlobalMPISession mpiSession(&argc, &argv); + Kokkos::ScopeGuard kokkosScope(argc, argv); + // This little trick lets us print to std::cout only if a (dummy) command-line argument is provided. + int iprint = argc - 1; + ROL::Ptr outStream; + ROL::nullstream bhs; // outputs nothing + if (iprint > 0) + outStream = ROL::makePtrFromRef(std::cout); + else + outStream = ROL::makePtrFromRef(bhs); + + int errorFlag = 0; + + // *** Example body. + try { + + /*** Read in XML input ***/ + std::string filename = "input_02.xml"; + Teuchos::RCP parlist + = Teuchos::rcp( new Teuchos::ParameterList() ); + Teuchos::updateParametersFromXmlFile( filename, parlist.ptr() ); + + /*** Initialize mesh / degree-of-freedom manager. ***/ + MeshManager_BackwardFacingStepChannel meshmgr(*parlist); + scalar_view nodes = meshmgr.getNodes(); + int_view cellToNodeMap = meshmgr.getCellToNodeMap(); + int_view cellToEdgeMap = meshmgr.getCellToEdgeMap(); + ROL::Ptr > > > sideSetsPtr = meshmgr.getSideSets(); + + std::vector > > &sideSets = *sideSetsPtr; + *outStream << "Number of nodes = " << meshmgr.getNumNodes() << std::endl; // << nodes; + *outStream << "Number of cells = " << meshmgr.getNumCells() << std::endl; // << cellToNodeMap; + *outStream << "Number of edges = " << meshmgr.getNumEdges() << std::endl; // << cellToEdgeMap; + // Print mesh info to file. + std::ofstream meshfile; + meshfile.open("cells.txt"); + for (int i=0; i(sideSets.size()); ++i) { + for (int j=0; j(sideSets[i].size()); ++j) { + if (sideSets[i][j].size() > 0) { + for (int k=0; k(sideSets[i][j].size()); ++k) { + meshfile << sideSets[i][j][k] << std::endl; + } + } + meshfile << std::endl << std::endl; + } + } + meshfile.close(); + + basis_ptr basisPtrQ1 = ROL::makePtr>();; + basis_ptr basisPtrQ2 = ROL::makePtr>();; + + std::vector basisPtrs(3, ROL::nullPtr); + basisPtrs[0] = basisPtrQ2; + basisPtrs[1] = basisPtrQ1; + basisPtrs[2] = basisPtrQ2; + + ROL::Ptr> meshmgrPtr = ROL::makePtrFromRef(meshmgr); + + DofManager dofmgr(meshmgrPtr, basisPtrs); + + *outStream << "Number of node dofs = " << dofmgr.getNumNodeDofs() << std::endl; // << *(dofmgr.getNodeDofs()); + *outStream << "Number of edge dofs = " << dofmgr.getNumEdgeDofs() << std::endl; // << *(dofmgr.getEdgeDofs()); + *outStream << "Number of face dofs = " << dofmgr.getNumFaceDofs() << std::endl; // << *(dofmgr.getFaceDofs()); + *outStream << "Number of void dofs = " << dofmgr.getNumVoidDofs() << std::endl; // << *(dofmgr.getVoidDofs()); + *outStream << "Total number of dofs = " << dofmgr.getNumDofs() << std::endl; // << *(dofmgr.getCellDofs()); + + std::vector> fieldPattern = dofmgr.getFieldPattern(); + for (int i=0; i +#include + +#include "../TOOLS/meshmanagerK.hpp" +#include "../TOOLS/dofmanagerK.hpp" + +using RealT = double; +using DeviceT = Kokkos::HostSpace; +using basis_ptr = Intrepid2::BasisPtr; +using scalar_view = typename MeshManager::scalar_view; +using int_view = typename MeshManager::int_view; + +int main(int argc, char *argv[]) { + + ROL::GlobalMPISession mpiSession(&argc, &argv); + Kokkos::ScopeGuard kokkosScope(argc, argv); + // This little trick lets us print to std::cout only if a (dummy) command-line argument is provided. + int iprint = argc - 1; + ROL::Ptr outStream; + ROL::nullstream bhs; // outputs nothing + if (iprint > 0) + outStream = ROL::makePtrFromRef(std::cout); + else + outStream = ROL::makePtrFromRef(bhs); + + int errorFlag = 0; + + // *** Example body. + try { + + /*** Read in XML input ***/ + std::string filename = "input_03.xml"; + Teuchos::RCP parlist + = Teuchos::rcp( new Teuchos::ParameterList() ); + Teuchos::updateParametersFromXmlFile( filename, parlist.ptr() ); + + /*** Initialize mesh / degree-of-freedom manager. ***/ + MeshManager_Brick meshmgr(*parlist); + scalar_view nodes = meshmgr.getNodes(); + int_view cellToNodeMap = meshmgr.getCellToNodeMap(); + int_view cellToEdgeMap = meshmgr.getCellToEdgeMap(); + ROL::Ptr > > > sideSetsPtr = meshmgr.getSideSets(); + + std::vector > > &sideSets = *sideSetsPtr; + *outStream << "Number of nodes = " << meshmgr.getNumNodes() << std::endl; // << nodes; + *outStream << "Number of cells = " << meshmgr.getNumCells() << std::endl; // << cellToNodeMap; + *outStream << "Number of edges = " << meshmgr.getNumEdges() << std::endl; // << cellToEdgeMap; + // Print mesh info to file. + std::ofstream meshfile; + meshfile.open("cells.txt"); + for (int i=0; i(sideSets.size()); ++i) { + for (int j=0; j(sideSets[i].size()); ++j) { + if (sideSets[i][j].size() > 0) { + for (int k=0; k(sideSets[i][j].size()); ++k) { + meshfile << sideSets[i][j][k] << std::endl; + } + } + meshfile << std::endl << std::endl; + } + } + meshfile.close(); + + basis_ptr basisPtrNedelec1 = ROL::makePtr>(); + + std::vector basisPtrs(1, ROL::nullPtr); + basisPtrs[0] = basisPtrNedelec1; + + ROL::Ptr> meshmgrPtr = ROL::makePtrFromRef(meshmgr); + + DofManager dofmgr(meshmgrPtr, basisPtrs); + + *outStream << "Number of node dofs = " << dofmgr.getNumNodeDofs() << std::endl; // << *(dofmgr.getNodeDofs()); + *outStream << "Number of edge dofs = " << dofmgr.getNumEdgeDofs() << std::endl; // << *(dofmgr.getEdgeDofs()); + *outStream << "Number of face dofs = " << dofmgr.getNumFaceDofs() << std::endl; // << *(dofmgr.getFaceDofs()); + *outStream << "Number of void dofs = " << dofmgr.getNumVoidDofs() << std::endl; // << *(dofmgr.getVoidDofs()); + *outStream << "Total number of dofs = " << dofmgr.getNumDofs() << std::endl; // << *(dofmgr.getCellDofs()); + + std::vector > fieldPattern = dofmgr.getFieldPattern(); + for (int i=0; i; +using scalar_view = typename MeshManager::scalar_view; +using int_view = typename MeshManager::int_view; + +int main(int argc, char *argv[]) { + + ROL::GlobalMPISession mpiSession(&argc, &argv); + Kokkos::ScopeGuard kokkosScope(argc, argv); + // This little trick lets us print to std::cout only if a (dummy) command-line argument is provided. + int iprint = argc - 1; + ROL::Ptr outStream; + ROL::nullstream bhs; // outputs nothing + if (iprint > 0) + outStream = ROL::makePtrFromRef(std::cout); + else + outStream = ROL::makePtrFromRef(bhs); + + int errorFlag = 0; + + // *** Example body. + try { + + /*** Read in XML input ***/ + std::string filename = "input_04.xml"; + Teuchos::RCP parlist + = Teuchos::rcp( new Teuchos::ParameterList() ); + Teuchos::updateParametersFromXmlFile( filename, parlist.ptr() ); + + /*** Initialize mesh / degree-of-freedom manager. ***/ + MeshManager_Rectangle meshmgr(*parlist); + scalar_view nodes = meshmgr.getNodes(); + int_view cellToNodeMap = meshmgr.getCellToNodeMap(); + + *outStream << "Number of nodes = " << meshmgr.getNumNodes() << std::endl; + *outStream << "Number of cells = " << meshmgr.getNumCells() << std::endl; + *outStream << "Number of edges = " << meshmgr.getNumEdges() << std::endl; + + ROL::Ptr> meshmgrPtr = ROL::makePtrFromRef(meshmgr); + + // Basis. + basis_ptr basis = ROL::makePtr>(); + // Cubature. + ROL::Ptr> cubature; + shards::CellTopology cellType = basis->getBaseCellTopology(); // get the cell type from any basis + Intrepid2::DefaultCubatureFactory cubFactory; // create cubature factory + int cubDegree = 4; // set cubature degree, e.g., 2 + cubature = cubFactory.create(cellType, cubDegree); // create default cubature + // Cell nodes. + scalar_view cellNodes("cellNodes", meshmgr.getNumCells(), cellType.getNodeCount(), cellType.getDimension()); + for (int i=0; i fe(cellNodes, basis, cubature); + + // Check integration. + scalar_view feVals1("feVals1", meshmgr.getNumCells(), cubature->getNumPoints()); + scalar_view feVals2("feVals2", meshmgr.getNumCells(), cubature->getNumPoints()); + scalar_view feGrads1("feGrads1", meshmgr.getNumCells(), cubature->getNumPoints(), cubature->getDimension()); + scalar_view feGrads2("feGrads2", meshmgr.getNumCells(), cubature->getNumPoints(), cubature->getDimension()); + scalar_view feCoeffs1("feCoeffs1", meshmgr.getNumCells(), basis->getCardinality()); + scalar_view feCoeffs2("feCoeffs2", meshmgr.getNumCells(), basis->getCardinality()); + scalar_view feIntegral("feIntegral", meshmgr.getNumCells()); + // values + Kokkos::deep_copy(feCoeffs1, static_cast(1)); + Kokkos::deep_copy(feCoeffs2, static_cast(2)); + fe.evaluateValue(feVals1, feCoeffs1); + fe.evaluateValue(feVals2, feCoeffs2); + fe.computeIntegral(feIntegral, feVals1, feVals2); + RealT valval(0); + for (int i=0; i(1000)) > std::sqrt(ROL::ROL_EPSILON())) { + errorFlag = -1; + } + // gradients + scalar_view dofCoords("dofCoords", meshmgr.getNumCells(), basis->getCardinality(), cubature->getDimension()); + fe.computeDofCoords(dofCoords, cellNodes); + for (int i=0; igetCardinality(); ++j) { + RealT x = dofCoords(i,j,0); + RealT y = dofCoords(i,j,1); + feCoeffs1(i,j) = x + y; + feCoeffs2(i,j) = static_cast(2)*x + static_cast(3)*y; + } + } + fe.evaluateGradient(feGrads1, feCoeffs1); + fe.evaluateGradient(feGrads2, feCoeffs2); + fe.computeIntegral(feIntegral, feGrads1, feGrads2); + RealT gradgrad(0); + for (int i=0; i(2500)) > std::sqrt(ROL::ROL_EPSILON())) { + errorFlag = -1; + } + *outStream << std::setprecision(14) << "\nvalvalIntegral=" << valval << " " << "gradgradIntegral=" << gradgrad << std::endl; + + } + catch (std::logic_error& err) { + *outStream << err.what() << "\n"; + errorFlag = -1000; + }; // end try + + if (errorFlag != 0) + std::cout << "End Result: TEST FAILED\n"; + else + std::cout << "End Result: TEST PASSED\n"; + + return 0; +} diff --git a/example/PDE-OPT/TEST/test_05K.cpp b/example/PDE-OPT/TEST/test_05K.cpp new file mode 100644 index 000000000..6aee95b49 --- /dev/null +++ b/example/PDE-OPT/TEST/test_05K.cpp @@ -0,0 +1,139 @@ +// @HEADER +// ***************************************************************************** +// Rapid Optimization Library (ROL) Package +// +// Copyright 2014 NTESS and the ROL contributors. +// SPDX-License-Identifier: BSD-3-Clause +// ***************************************************************************** +// @HEADER + +/*! \file test_04.cpp + \brief Unit test for the FE_CURL class. +*/ + +#include "ROL_Types.hpp" + +#include "ROL_Stream.hpp" +#include "ROL_GlobalMPISession.hpp" +#include "Teuchos_XMLParameterListHelpers.hpp" + +#include "Intrepid2_HCURL_HEX_I1_FEM.hpp" +#include "Intrepid2_DefaultCubatureFactory.hpp" + +#include "../TOOLS/meshmanagerK.hpp" +#include "../TOOLS/dofmanagerK.hpp" +#include "../TOOLS/feK_curl.hpp" + +using RealT = double; +using DeviceT = Kokkos::HostSpace; +using basis_ptr = Intrepid2::BasisPtr; +using scalar_view = typename MeshManager::scalar_view; +using int_view = typename MeshManager::int_view; + +int main(int argc, char *argv[]) { + + ROL::GlobalMPISession mpiSession(&argc, &argv); + Kokkos::ScopeGuard kokkosScope(argc, argv); + // This little trick lets us print to std::cout only if a (dummy) command-line argument is provided. + int iprint = argc - 1; + ROL::Ptr outStream; + ROL::nullstream bhs; // outputs nothing + if (iprint > 0) + outStream = ROL::makePtrFromRef(std::cout); + else + outStream = ROL::makePtrFromRef(bhs); + + int errorFlag = 0; + + // *** Example body. + try { + + /*** Read in XML input ***/ + std::string filename = "input_05.xml"; + Teuchos::RCP parlist + = Teuchos::rcp( new Teuchos::ParameterList() ); + Teuchos::updateParametersFromXmlFile( filename, parlist.ptr() ); + + /*** Initialize mesh / degree-of-freedom manager. ***/ + MeshManager_Brick meshmgr(*parlist); + scalar_view nodes = meshmgr.getNodes(); + int_view cellToNodeMap = meshmgr.getCellToNodeMap(); + + *outStream << "Number of nodes = " << meshmgr.getNumNodes() << std::endl; + *outStream << "Number of cells = " << meshmgr.getNumCells() << std::endl; + *outStream << "Number of edges = " << meshmgr.getNumEdges() << std::endl; + + ROL::Ptr> meshmgrPtr = ROL::makePtrFromRef(meshmgr); + + // Basis. + basis_ptr basis = ROL::makePtr>(); + // Cubature. + ROL::Ptr> cubature; + shards::CellTopology cellType = basis->getBaseCellTopology(); // get the cell type from any basis + Intrepid2::DefaultCubatureFactory cubFactory; // create cubature factory + int cubDegree = 4; // set cubature degree, e.g., 2 + cubature = cubFactory.create(cellType, cubDegree); // create default cubature + // Cell nodes. + scalar_view cellNodes("cellNodes", meshmgr.getNumCells(), cellType.getNodeCount(), cellType.getDimension()); + for (int i=0; i fe(cellNodes, basis, cubature); + + // Check integration. + scalar_view feVals1("feVals1", meshmgr.getNumCells(), cubature->getNumPoints(), cubature->getDimension()); + scalar_view feVals2("feVals2", meshmgr.getNumCells(), cubature->getNumPoints(), cubature->getDimension()); + scalar_view feCurls1("feCurls1", meshmgr.getNumCells(), cubature->getNumPoints(), cubature->getDimension()); + scalar_view feCurls2("feCurls2", meshmgr.getNumCells(), cubature->getNumPoints(), cubature->getDimension()); + scalar_view feCoeffs1("feCoeffs1", meshmgr.getNumCells(), basis->getCardinality()); + scalar_view feCoeffs2("feCoeffs2", meshmgr.getNumCells(), basis->getCardinality()); + scalar_view feIntegral("feIntegral", meshmgr.getNumCells()); + // values + Kokkos::deep_copy(feCoeffs1,static_cast(0)); + Kokkos::deep_copy(feCoeffs2,static_cast(0)); + for (int i=0; i(1); + feCoeffs2(i, 0) = static_cast(1); + } + fe.evaluateValue(feVals1, feCoeffs1); + fe.evaluateValue(feVals2, feCoeffs2); + fe.computeIntegral(feIntegral, feVals1, feVals2); + RealT valval(0); + for (int i=0; i(4)/static_cast(9)) > std::sqrt(ROL::ROL_EPSILON())) { + errorFlag = -1; + } + // curls + fe.evaluateCurl(feCurls1, feCoeffs1); + fe.evaluateCurl(feCurls2, feCoeffs2); + fe.computeIntegral(feIntegral, feCurls1, feCurls2); + RealT curlcurl(0); + for (int i=0; i(8)/static_cast(3)) > std::sqrt(ROL::ROL_EPSILON())) { + errorFlag = -1; + } + *outStream << std::setprecision(14) << "\nvalvalIntegral=" << valval << " " + << "curlcurlIntegral=" << curlcurl << std::endl; + + } + catch (std::logic_error& err) { + *outStream << err.what() << "\n"; + errorFlag = -1000; + }; // end try + + if (errorFlag != 0) + std::cout << "End Result: TEST FAILED\n"; + else + std::cout << "End Result: TEST PASSED\n"; + + return 0; +} diff --git a/example/PDE-OPT/TEST/test_07K.cpp b/example/PDE-OPT/TEST/test_07K.cpp new file mode 100644 index 000000000..c137c7cec --- /dev/null +++ b/example/PDE-OPT/TEST/test_07K.cpp @@ -0,0 +1,137 @@ +// @HEADER +// ***************************************************************************** +// Rapid Optimization Library (ROL) Package +// +// Copyright 2014 NTESS and the ROL contributors. +// SPDX-License-Identifier: BSD-3-Clause +// ***************************************************************************** +// @HEADER + +/*! \file test_07.cpp + \brief Unit test for the MeshReader mesh manager. +*/ + +#include "ROL_Stream.hpp" +#include "ROL_GlobalMPISession.hpp" +#include "Teuchos_XMLParameterListHelpers.hpp" + +#include "Intrepid2_HGRAD_HEX_C1_FEM.hpp" +#include "Intrepid2_HGRAD_HEX_C2_FEM.hpp" + +#include "../TOOLS/meshreaderK.hpp" +#include "../TOOLS/dofmanagerK.hpp" + +using RealT = double; +using DeviceT = Kokkos::HostSpace; +using basis_ptr = Intrepid2::BasisPtr; +using scalar_view = typename MeshManager::scalar_view; +using int_view = typename MeshManager::int_view; + +int main(int argc, char *argv[]) { + + ROL::GlobalMPISession mpiSession(&argc, &argv); + Kokkos::ScopeGuard kokkosScope(argc, argv); + // This little trick lets us print to std::cout only if a (dummy) command-line argument is provided. + int iprint = argc - 1; + ROL::Ptr outStream; + ROL::nullstream bhs; // outputs nothing + if (iprint > 0) + outStream = ROL::makePtrFromRef(std::cout); + else + outStream = ROL::makePtrFromRef(bhs); + + int errorFlag = 0; + + // *** Example body. + try { + + /*** Read in XML input ***/ + std::string filename = "input_07.xml"; + Teuchos::RCP parlist + = Teuchos::rcp( new Teuchos::ParameterList() ); + Teuchos::updateParametersFromXmlFile( filename, parlist.ptr() ); + + /*** Initialize mesh / degree-of-freedom manager. ***/ + MeshReader meshmgr(*parlist); + + scalar_view nodes = meshmgr.getNodes(); + int_view cellToNodeMap = meshmgr.getCellToNodeMap(); + int_view cellToEdgeMap = meshmgr.getCellToEdgeMap(); + int_view cellToFaceMap = meshmgr.getCellToFaceMap(); + ROL::Ptr > > > sideSetsPtr = meshmgr.getSideSets(); + + std::vector > > &sideSets = *sideSetsPtr; + *outStream << "Number of nodes = " << meshmgr.getNumNodes() << std::endl; // << nodes; + *outStream << "Number of cells = " << meshmgr.getNumCells() << std::endl; // << cellToNodeMap; + *outStream << "Number of edges = " << meshmgr.getNumEdges() << std::endl; // << cellToEdgeMap; + *outStream << "Number of faces = " << meshmgr.getNumFaces() << std::endl; // << cellToFaceMap; + // Print sideset info to file. + std::ofstream meshfile; + meshfile.open("sideset.txt"); + for (int i=0; i(sideSets.size()); ++i) { + for (int j=0; j(sideSets[i].size()); ++j) { + if (sideSets[i][j].size() > 0) { + for (int k=0; k(sideSets[i][j].size()); ++k) { + meshfile << i << " " << j << " " << k << " " << sideSets[i][j][k] << std::endl; + } + } + meshfile << std::endl; + } + meshfile << std::endl << std::endl; + } + meshfile.close(); + + basis_ptr basisPtrQ1 = ROL::makePtr>(); + basis_ptr basisPtrQ2 = ROL::makePtr>(); + + std::vector basisPtrs(3, ROL::nullPtr); + basisPtrs[0] = basisPtrQ2; + basisPtrs[1] = basisPtrQ1; + basisPtrs[2] = basisPtrQ2; + + ROL::Ptr> meshmgrPtr = ROL::makePtrFromRef(meshmgr); + + DofManager dofmgr(meshmgrPtr, basisPtrs); + + *outStream << "Number of node dofs = " << dofmgr.getNumNodeDofs() << std::endl; // << *(dofmgr.getNodeDofs()); + *outStream << "Number of edge dofs = " << dofmgr.getNumEdgeDofs() << std::endl; // << *(dofmgr.getEdgeDofs()); + *outStream << "Number of face dofs = " << dofmgr.getNumFaceDofs() << std::endl; // << *(dofmgr.getFaceDofs()); + *outStream << "Number of void dofs = " << dofmgr.getNumVoidDofs() << std::endl; // << *(dofmgr.getVoidDofs()); + *outStream << "Total number of dofs = " << dofmgr.getNumDofs() << std::endl; // << *(dofmgr.getCellDofs()); + + std::vector > fieldPattern = dofmgr.getFieldPattern(); + for (int i=0; i; +using scalar_view = typename MeshManager::scalar_view; +using int_view = typename MeshManager::int_view; + +int main(int argc, char *argv[]) { + + ROL::GlobalMPISession mpiSession(&argc, &argv); + Kokkos::ScopeGuard kokkosScope(argc, argv); + // This little trick lets us print to std::cout only if a (dummy) command-line argument is provided. + int iprint = argc - 1; + ROL::Ptr outStream; + ROL::nullstream bhs; // outputs nothing + if (iprint > 0) + outStream = ROL::makePtrFromRef(std::cout); + else + outStream = ROL::makePtrFromRef(bhs); + + int errorFlag = 0; + + // *** Example body. + try { + + /*** Read in XML input ***/ + std::string filename = "input_08.xml"; + Teuchos::RCP parlist + = Teuchos::rcp( new Teuchos::ParameterList() ); + Teuchos::updateParametersFromXmlFile( filename, parlist.ptr() ); + + /*** Initialize mesh / degree-of-freedom manager. ***/ + MeshReader meshmgr(*parlist); + scalar_view nodes = meshmgr.getNodes(); + int_view cellToNodeMap = meshmgr.getCellToNodeMap(); + + *outStream << "Number of nodes = " << meshmgr.getNumNodes() << std::endl; + *outStream << "Number of cells = " << meshmgr.getNumCells() << std::endl; + *outStream << "Number of edges = " << meshmgr.getNumEdges() << std::endl; + *outStream << "Number of edges = " << meshmgr.getNumFaces() << std::endl; + + ROL::Ptr> meshmgrPtr = ROL::makePtrFromRef(meshmgr); + + // Basis. + basis_ptr basis = ROL::makePtr>(); + // Cubature. + ROL::Ptr> cubature; + shards::CellTopology cellType = basis->getBaseCellTopology(); // get the cell type from any basis + Intrepid2::DefaultCubatureFactory cubFactory; // create cubature factory + int cubDegree = 6; // set cubature degree, e.g., 2 + cubature = cubFactory.create(cellType, cubDegree); // create default cubature + // Cell nodes. + scalar_view cellNodes("cellNodes", meshmgr.getNumCells(), cellType.getNodeCount(), cellType.getDimension()); + for (int i=0; i fe(cellNodes, basis, cubature); + + // Check integration. + scalar_view feVals1("feVals1", meshmgr.getNumCells(), cubature->getNumPoints()); + scalar_view feVals2("feVals2", meshmgr.getNumCells(), cubature->getNumPoints()); + scalar_view feGrads1("feGrads1", meshmgr.getNumCells(), cubature->getNumPoints(), cubature->getDimension()); + scalar_view feGrads2("feGrads2", meshmgr.getNumCells(), cubature->getNumPoints(), cubature->getDimension()); + scalar_view feCoeffs1("feCoeffs1", meshmgr.getNumCells(), basis->getCardinality()); + scalar_view feCoeffs2("feCoeffs2", meshmgr.getNumCells(), basis->getCardinality()); + scalar_view feIntegral("feIntegral", meshmgr.getNumCells()); + // values + Kokkos::deep_copy(feCoeffs1,static_cast(1)); + Kokkos::deep_copy(feCoeffs2,static_cast(2)); + fe.evaluateValue(feVals1, feCoeffs1); + fe.evaluateValue(feVals2, feCoeffs2); + fe.computeIntegral(feIntegral, feVals1, feVals2); + RealT valval(0); + for (int i=0; i(6)) > std::sqrt(ROL::ROL_EPSILON())) { + errorFlag = -1; + } + // gradients + scalar_view dofCoords("dofCoords", meshmgr.getNumCells(), basis->getCardinality(), cubature->getDimension()); + fe.computeDofCoords(dofCoords, cellNodes); + for (int i=0; igetCardinality(); ++j) { + RealT x = dofCoords(i,j,0); + RealT y = dofCoords(i,j,1); + RealT z = dofCoords(i,j,2); + feCoeffs1(i,j) = x + y + z; + feCoeffs2(i,j) = static_cast(2)*x + static_cast(3)*y + static_cast(4)*z; + } + } + fe.evaluateGradient(feGrads1, feCoeffs1); + fe.evaluateGradient(feGrads2, feCoeffs2); + fe.computeIntegral(feIntegral, feGrads1, feGrads2); + RealT gradgrad(0); + for (int i=0; i(27)) > std::sqrt(ROL::ROL_EPSILON())) { + errorFlag = -1; + } + *outStream << std::setprecision(14) << "\nvalvalIntegral=" << valval << " " << "gradgradIntegral=" << gradgrad << std::endl; + + } + catch (std::logic_error& err) { + *outStream << err.what() << "\n"; + errorFlag = -1000; + }; // end try + + if (errorFlag != 0) + std::cout << "End Result: TEST FAILED\n"; + else + std::cout << "End Result: TEST PASSED\n"; + + return 0; +} diff --git a/example/PDE-OPT/TEST/test_09K.cpp b/example/PDE-OPT/TEST/test_09K.cpp new file mode 100644 index 000000000..745c2f9f1 --- /dev/null +++ b/example/PDE-OPT/TEST/test_09K.cpp @@ -0,0 +1,139 @@ +// @HEADER +// ***************************************************************************** +// Rapid Optimization Library (ROL) Package +// +// Copyright 2014 NTESS and the ROL contributors. +// SPDX-License-Identifier: BSD-3-Clause +// ***************************************************************************** +// @HEADER + +/*! \file test_09.cpp + \brief Unit test for the mesh manager and the degree-of-freedom manager. + Mesh type: INTERVAL with LINE CELLS and HGRAD SPACE. +*/ + +#include "ROL_Algorithm.hpp" +#include "ROL_BoundConstraint_SimOpt.hpp" +#include "ROL_Vector_SimOpt.hpp" + +#include "ROL_Stream.hpp" +#include "ROL_GlobalMPISession.hpp" +#include "Teuchos_XMLParameterListHelpers.hpp" + +#include "Intrepid2_HGRAD_LINE_Cn_FEM.hpp" + +#include +#include + +#include "../TOOLS/meshmanagerK.hpp" +#include "../TOOLS/dofmanagerK.hpp" + +using RealT = double; +using DeviceT = Kokkos::HostSpace; +using basis_ptr = Intrepid2::BasisPtr; +using scalar_view = typename MeshManager::scalar_view; +using int_view = typename MeshManager::int_view; + +int main(int argc, char *argv[]) { + + ROL::GlobalMPISession mpiSession(&argc, &argv); + Kokkos::ScopeGuard kokkosScope(argc, argv); + // This little trick lets us print to std::cout only if a (dummy) command-line argument is provided. + int iprint = argc - 1; + ROL::Ptr outStream; + ROL::nullstream bhs; // outputs nothing + if (iprint > 0) + outStream = ROL::makePtrFromRef(std::cout); + else + outStream = ROL::makePtrFromRef(bhs); + + int errorFlag = 0; + + // *** Example body. + try { + + /*** Read in XML input ***/ + std::string filename = "input_09.xml"; + Teuchos::RCP parlist + = Teuchos::rcp( new Teuchos::ParameterList() ); + Teuchos::updateParametersFromXmlFile( filename, parlist.ptr() ); + + /*** Initialize mesh / degree-of-freedom manager. ***/ + MeshManager_Interval meshmgr(*parlist); + scalar_view nodes = meshmgr.getNodes(); + int_view cellToNodeMap = meshmgr.getCellToNodeMap(); + ROL::Ptr > > > sideSetsPtr = meshmgr.getSideSets(); + + std::vector > > &sideSets = *sideSetsPtr; + // *outStream << "Number of nodes = " << meshmgr.getNumNodes() << std::endl << nodes; + // *outStream << "Number of cells = " << meshmgr.getNumCells() << std::endl << cellToNodeMap; + // Print mesh info to file. + std::ofstream meshfile; + meshfile.open("sideset.txt"); + for (int i=0; i(sideSets.size()); ++i) { + for (int j=0; j(sideSets[i].size()); ++j) { + if (sideSets[i][j].size() > 0) { + for (int k=0; k(sideSets[i][j].size()); ++k) { + meshfile << sideSets[i][j][k] << std::endl; + } + } + meshfile << std::endl << std::endl; + } + } + meshfile.close(); + + basis_ptr basisPtrL1 = ROL::makePtr>(1, Intrepid2::POINTTYPE_EQUISPACED); + + basis_ptr basisPtrL2 = ROL::makePtr>(2, Intrepid2::POINTTYPE_EQUISPACED); + + std::vector basisPtrs(3, ROL::nullPtr); + basisPtrs[0] = basisPtrL2; + basisPtrs[1] = basisPtrL1; + basisPtrs[2] = basisPtrL2; + + ROL::Ptr > meshmgrPtr = ROL::makePtrFromRef(meshmgr); + + DofManager dofmgr(meshmgrPtr, basisPtrs); + + *outStream << "Number of node dofs = " << dofmgr.getNumNodeDofs() << std::endl; // << *(dofmgr.getNodeDofs()); + *outStream << "Number of edge dofs = " << dofmgr.getNumEdgeDofs() << std::endl; // << *(dofmgr.getEdgeDofs()); + *outStream << "Number of face dofs = " << dofmgr.getNumFaceDofs() << std::endl; // << *(dofmgr.getFaceDofs()); + *outStream << "Number of void dofs = " << dofmgr.getNumVoidDofs() << std::endl; // << *(dofmgr.getVoidDofs()); + *outStream << "Total number of dofs = " << dofmgr.getNumDofs() << std::endl; // << *(dofmgr.getCellDofs()); + + std::vector > fieldPattern = dofmgr.getFieldPattern(); + for (int i=0; i(basis_->getBaseCellTopology()); // Compute dimensions of multidimensional array members. - c_ = cellNodes_->extent_int(0); + c_ = cellNodes_.extent_int(0); f_ = basis_->getCardinality(); p_ = cubature_->getNumPoints(); d_ = cellTopo_->getDimension(); @@ -126,7 +126,7 @@ class FE_CURL { fst::computeCellMeasure(cellWeightedMeasure_, cellJacDet_, cubWeights_); // Transform reference values into physical space. - fst::HCURLtransformVALUE(valPhysical_, valReference_); + fst::HCURLtransformVALUE(valPhysical_, cellJacInv_, valReference_); // Multiply with weighted measure to get weighted values in physical space. fst::multiplyMeasure(valPhysicalWeighted_, cellWeightedMeasure_, valPhysical_); @@ -135,7 +135,7 @@ class FE_CURL { fst::HCURLtransformCURL(curlPhysical_, cellJac_, cellJacDet_, curlReference_); // Multiply with weighted measure to get weighted curls in physical space. - fst::multiplyMeasure::multiplyMeasure(curlPhysicalWeighted_, cellWeightedMeasure_, curlPhysical_); + fst::multiplyMeasure(curlPhysicalWeighted_, cellWeightedMeasure_, curlPhysical_); // Compute curl-curl matrices. fst::integrate(curlcurlMats_, curlPhysical_, curlPhysicalWeighted_); @@ -307,7 +307,7 @@ class FE_CURL { f2Weighted = scalar_view("f2Weighted", f2.extent(0), f2.extent(1)); } fst::scalarMultiplyDataData(f2Weighted, cellWeightedMeasure_, f2); // multiply with weighted measure - + fst::integrate(integral, f1, f2Weighted, sumInto); // compute integral of f1*f2 } diff --git a/example/PDE-OPT/TOOLS/meshreaderK.hpp b/example/PDE-OPT/TOOLS/meshreaderK.hpp index f97cd4d63..56c35fa01 100644 --- a/example/PDE-OPT/TOOLS/meshreaderK.hpp +++ b/example/PDE-OPT/TOOLS/meshreaderK.hpp @@ -499,7 +499,7 @@ class MeshReader : public MeshManager { ROL::Ptr > > > getSideSets ( const bool verbose = false, - std::ostream & outStream = std::cout) const { + std::ostream & outStream = std::cout) const override { if (verbose) { for (int i=0; i - + @@ -152,7 +152,7 @@ - + @@ -164,7 +164,7 @@ - + diff --git a/example/PDE-OPT/stefan-boltzmann/CMakeLists.txt b/example/PDE-OPT/stefan-boltzmann/CMakeLists.txt index a11df5df9..a4df0d42a 100644 --- a/example/PDE-OPT/stefan-boltzmann/CMakeLists.txt +++ b/example/PDE-OPT/stefan-boltzmann/CMakeLists.txt @@ -17,7 +17,6 @@ IF(${PROJECT_NAME}_ENABLE_Intrepid AND ARGS PrintItAll NUM_MPI_PROCS 4 NUM_TOTAL_CORES_USED 4 - CATEGORIES CONTINUOUS PASS_REGULAR_EXPRESSION "TEST PASSED" ADD_DIR_TO_NAME ) @@ -28,7 +27,6 @@ IF(${PROJECT_NAME}_ENABLE_Intrepid AND ARGS PrintItAll NUM_MPI_PROCS 4 NUM_TOTAL_CORES_USED 4 - CATEGORIES CONTINUOUS PASS_REGULAR_EXPRESSION "TEST PASSED" ADD_DIR_TO_NAME ) @@ -39,7 +37,6 @@ IF(${PROJECT_NAME}_ENABLE_Intrepid AND ARGS PrintItAll NUM_MPI_PROCS 4 NUM_TOTAL_CORES_USED 4 - CATEGORIES CONTINUOUS PASS_REGULAR_EXPRESSION "TEST PASSED" ADD_DIR_TO_NAME ) @@ -84,7 +81,6 @@ IF(${PROJECT_NAME}_ENABLE_Intrepid2 AND ARGS PrintItAll NUM_MPI_PROCS 4 NUM_TOTAL_CORES_USED 4 - CATEGORIES CONTINUOUS PASS_REGULAR_EXPRESSION "TEST PASSED" ADD_DIR_TO_NAME ) @@ -95,7 +91,6 @@ IF(${PROJECT_NAME}_ENABLE_Intrepid2 AND ARGS PrintItAll NUM_MPI_PROCS 4 NUM_TOTAL_CORES_USED 4 - CATEGORIES CONTINUOUS PASS_REGULAR_EXPRESSION "TEST PASSED" ADD_DIR_TO_NAME ) @@ -106,7 +101,6 @@ IF(${PROJECT_NAME}_ENABLE_Intrepid2 AND ARGS PrintItAll NUM_MPI_PROCS 4 NUM_TOTAL_CORES_USED 4 - CATEGORIES CONTINUOUS PASS_REGULAR_EXPRESSION "TEST PASSED" ADD_DIR_TO_NAME ) diff --git a/example/topology-optimization/CMakeLists.txt b/example/topology-optimization/CMakeLists.txt index 5ad1e4782..b8fb999bc 100644 --- a/example/topology-optimization/CMakeLists.txt +++ b/example/topology-optimization/CMakeLists.txt @@ -1,7 +1,7 @@ ROL_ADD_EXECUTABLE( example_02 - SOURCES example_02.cpp + SOURCES example_02.cpp ADD_DIR_TO_NAME ) @@ -24,7 +24,6 @@ if( ${lower_build_type} STREQUAL "release" ) SOURCES example_01.cpp ARGS PrintItAll NUM_MPI_PROCS 1 - CATEGORIES CONTINUOUS PASS_REGULAR_EXPRESSION "TEST PASSED" ADD_DIR_TO_NAME ) @@ -33,7 +32,7 @@ else() ROL_ADD_EXECUTABLE( example_01 - SOURCES example_01.cpp + SOURCES example_01.cpp ADD_DIR_TO_NAME ) diff --git a/src/step/krylov/ROL_GMRES.hpp b/src/step/krylov/ROL_GMRES.hpp index 74ba97ceb..7e924359a 100644 --- a/src/step/krylov/ROL_GMRES.hpp +++ b/src/step/krylov/ROL_GMRES.hpp @@ -22,6 +22,48 @@ namespace ROL { +template +class VectorArray { +private: + std::vector>> data_; + unsigned size_; + +public: + VectorArray() : size_(0u) {} + + void allocate(const Vector &x, unsigned numVec) { + data_.clear(); + for (unsigned i = 0u; i < numVec; ++i) + data_.push_back(x.clone()); + size_ = numVec; + } + + const Ptr> get(const Vector &x, unsigned ind) { + if (ind < size_) { + return data_[ind]; + } + else if (ind == size_) { + data_.push_back(x.clone()); + size_++; + return data_[ind]; + } + else { + throw Exception::NotImplemented(">>> GMRES : Index out of range!"); + return nullPtr; + } + } + + const Ptr> get(unsigned ind) { + if (size_ > 0u) { + return get(*data_[0],ind); + } + else { + throw Exception::NotImplemented(">>> GMRES : No vectors allocated!"); + return nullPtr; + } + } +}; + template class GMRES : public Krylov { @@ -30,30 +72,31 @@ class GMRES : public Krylov { private: - ROL::Ptr > r_; - ROL::Ptr > z_; - ROL::Ptr > w_; + Ptr> r_; + Ptr> z_; + Ptr> w_; - ROL::Ptr H_; // quasi-Hessenberg matrix - ROL::Ptr cs_; // Givens Rotations cosine components - ROL::Ptr sn_; // Givens Rotations sine components - ROL::Ptr s_; - ROL::Ptr y_; - ROL::Ptr cnorm_; + Ptr H_; // quasi-Hessenberg matrix + Ptr cs_; // Givens Rotations cosine components + Ptr sn_; // Givens Rotations sine components + Ptr s_; + Ptr y_; + Ptr cnorm_; - ROL::Ptr > res_; + Ptr> res_; + Ptr> V_, Z_; bool isInitialized_; bool useInexact_; bool useInitialGuess_; // If false, inital x will be ignored and zero vec used bool printIters_; - ROL::Ptr outStream_; + Ptr outStream_; - ROL::LAPACK lapack_; + LAPACK lapack_; public: - GMRES( ROL::ParameterList &parlist ) : Krylov(parlist), isInitialized_(false), printIters_(false) { + GMRES( ParameterList &parlist ) : Krylov(parlist), isInitialized_(false), printIters_(false) { using std::vector; @@ -66,14 +109,16 @@ class GMRES : public Krylov { useInitialGuess_ = kList.get("Use Initial Guess",false); int maxit = Krylov::getMaximumIteration(); - H_ = ROL::makePtr( maxit+1, maxit ); - cs_ = ROL::makePtr( maxit ); - sn_ = ROL::makePtr( maxit ); - s_ = ROL::makePtr( maxit+1 ); - y_ = ROL::makePtr( maxit+1 ); - cnorm_ = ROL::makePtr( maxit ); - res_ = ROL::makePtr>(maxit+1,zero); + H_ = makePtr( maxit+1, maxit ); + cs_ = makePtr( maxit ); + sn_ = makePtr( maxit ); + s_ = makePtr( maxit+1 ); + y_ = makePtr( maxit+1 ); + cnorm_ = makePtr( maxit ); + res_ = makePtr>(maxit+1,zero); + V_ = makePtr>(); + Z_ = makePtr>(); } Real run( Vector &x, LinearOperator &A, const Vector &b, @@ -92,6 +137,9 @@ class GMRES : public Krylov { w_ = b.clone(); z_ = x.clone(); + V_->allocate(b,std::min(20u,static_cast(maxit))+1u); + Z_->allocate(x,std::min(20u,static_cast(maxit))); + isInitialized_ = true; } @@ -112,14 +160,10 @@ class GMRES : public Krylov { Real temp = 0; - std::vector > > V; - std::vector > > Z; - (*res_)[0] = r_->norm(); - if (printIters_) { + if (printIters_) *outStream_ << "GMRES Iteration " << 0 << ", Residual = " << (*res_)[0] << "\n"; - } // This should be a tolerance check Real rtol = std::min(absTol,relTol*(*res_)[0]); @@ -129,42 +173,36 @@ class GMRES : public Krylov { return (*res_)[0]; } - V.push_back(b.clone()); - (V[0])->set(*r_); - (V[0])->scale(one/(*res_)[0]); + V_->get(0)->set(*r_); + V_->get(0)->scale(one/(*res_)[0]); (*s_)(0) = (*res_)[0]; for( iter=0; iterget(iter)),*(V_->get(iter)),itol); // Apply operator - A.apply(*w_,*(Z[iter]),itol); + A.apply(*w_,*(Z_->get(iter)),itol); // Evaluate coefficients and orthogonalize using Gram-Schmidt for( int k=0; k<=iter; ++k ) { - (*H_)(k,iter) = w_->dot(*(V[k])); - w_->axpy( -(*H_)(k,iter), *(V[k]) ); + (*H_)(k,iter) = w_->dot(*(V_->get(k))); + w_->axpy( -(*H_)(k,iter), *(V_->get(k)) ); } (*H_)(iter+1,iter) = w_->norm(); - V.push_back( b.clone() ); - (V[iter+1])->set(*w_); - (V[iter+1])->scale(one/((*H_)(iter+1,iter))); + (V_->get(iter+1))->set(*w_); + (V_->get(iter+1))->scale(one/((*H_)(iter+1,iter))); // Apply Givens rotations for( int k=0; k<=iter-1; ++k ) { temp = (*cs_)(k)*(*H_)(k,iter) + (*sn_)(k)*(*H_)(k+1,iter); - (*H_)(k+1,iter) = -(*sn_)(k)*(*H_)(k,iter) + (*cs_)(k)*(*H_)(k+1,iter); + (*H_)(k+1,iter) = -(*sn_)(k)*(*H_)(k,iter) + (*cs_)(k)*(*H_)(k+1,iter); (*H_)(k,iter) = temp; } @@ -209,7 +247,7 @@ class GMRES : public Krylov { z_->zero(); for( int k=0; k<=iter;++k ) { - z_->axpy((*y_)(k),*(Z[k])); + z_->axpy((*y_)(k),*(Z_->get(k))); } if( (*res_)[iter+1] <= rtol ) {