Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tempus: Utilize Teuchos Unit Test 'out' #12656

Merged
merged 1 commit into from
Jan 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 7 additions & 11 deletions packages/tempus/test/BDF2/Tempus_BDF2_ASA.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,6 @@ TEUCHOS_UNIT_TEST(BDF2, SinCos_ASA)
double order = 0.0;
Teuchos::RCP<const Teuchos::Comm<int> > comm =
Teuchos::DefaultComm<int>::getComm();
Teuchos::RCP<Teuchos::FancyOStream> my_out =
Teuchos::fancyOStream(Teuchos::rcpFromRef(std::cout));
my_out->setProcRankAndSize(comm->getRank(), comm->getSize());
my_out->setOutputToRootOnly(0);
for (int n=0; n<nTimeStepSizes; n++) {

// Read params from .xml file
Expand Down Expand Up @@ -183,17 +179,17 @@ TEUCHOS_UNIT_TEST(BDF2, SinCos_ASA)
L2norm = std::sqrt(L2norm);
ErrorNorm.push_back(L2norm);

//*my_out << " n = " << n << " dt = " << dt << " error = " << L2norm
// << std::endl;
//out << " n = " << n << " dt = " << dt << " error = " << L2norm
// << std::endl;
}

// Check the order and intercept
double slope = computeLinearRegressionLogLog<double>(StepSize, ErrorNorm);
*my_out << " Stepper = BDF2" << std::endl;
*my_out << " =========================" << std::endl;
*my_out << " Expected order: " << order << std::endl;
*my_out << " Observed order: " << slope << std::endl;
*my_out << " =========================" << std::endl;
out << " Stepper = BDF2" << std::endl;
out << " =========================" << std::endl;
out << " Expected order: " << order << std::endl;
out << " Observed order: " << slope << std::endl;
out << " =========================" << std::endl;
TEST_FLOATING_EQUALITY( slope, 1.95006, 0.015 );
TEST_FLOATING_EQUALITY( ErrorNorm[0], 0.0137394, 1.0e-4 );

Expand Down
18 changes: 7 additions & 11 deletions packages/tempus/test/BDF2/Tempus_BDF2_FSA.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,6 @@ void test_sincos_fsa(const bool use_combined_method,
double order = 0.0;
Teuchos::RCP<const Teuchos::Comm<int> > comm =
Teuchos::DefaultComm<int>::getComm();
Teuchos::RCP<Teuchos::FancyOStream> my_out =
Teuchos::fancyOStream(Teuchos::rcpFromRef(std::cout));
my_out->setProcRankAndSize(comm->getRank(), comm->getSize());
my_out->setOutputToRootOnly(0);
for (int n=0; n<nTimeStepSizes; n++) {

// Read params from .xml file
Expand Down Expand Up @@ -184,18 +180,18 @@ void test_sincos_fsa(const bool use_combined_method,
L2norm = std::sqrt(L2norm);
ErrorNorm.push_back(L2norm);

*my_out << " n = " << n << " dt = " << dt << " error = " << L2norm
<< std::endl;
out << " n = " << n << " dt = " << dt << " error = " << L2norm
<< std::endl;

}

// Check the order and intercept
double slope = computeLinearRegressionLogLog<double>(StepSize, ErrorNorm);
*my_out << " Stepper = BDF2" << std::endl;
*my_out << " =========================" << std::endl;
*my_out << " Expected order: " << order << std::endl;
*my_out << " Observed order: " << slope << std::endl;
*my_out << " =========================" << std::endl;
out << " Stepper = BDF2" << std::endl;
out << " =========================" << std::endl;
out << " Expected order: " << order << std::endl;
out << " Observed order: " << slope << std::endl;
out << " =========================" << std::endl;
TEST_FLOATING_EQUALITY( slope, 1.94162, 0.015 );
TEST_FLOATING_EQUALITY( ErrorNorm[0], 0.0143743, 1.0e-4 );

Expand Down
3 changes: 2 additions & 1 deletion packages/tempus/test/BDF2/Tempus_Test_BDF2_CDR.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,8 @@ void CDR_Test(const Comm& comm, const int commSize, Teuchos::FancyOStream &out,
writeOrderError("Tempus_BDF2_CDR-Error.dat",
stepper, StepSize,
solutions, xErrorNorm, xSlope,
solutionsDot, xDotErrorNorm, xDotSlope);
solutionsDot, xDotErrorNorm, xDotSlope,
out);
TEST_FLOATING_EQUALITY( xSlope, order, 0.35 );
TEST_COMPARE(xSlope, >, 0.95);
TEST_FLOATING_EQUALITY( xDotSlope, order, 0.35 );
Expand Down
3 changes: 2 additions & 1 deletion packages/tempus/test/BDF2/Tempus_Test_BDF2_SinCos.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,8 @@ TEUCHOS_UNIT_TEST(BDF2, SinCos)
writeOrderError(err_out_file_name,
stepper, StepSize,
solutions, xErrorNorm, xSlope,
solutionsDot, xDotErrorNorm, xDotSlope);
solutionsDot, xDotErrorNorm, xDotSlope,
out);

TEST_FLOATING_EQUALITY( xSlope, order, 0.01 );
TEST_FLOATING_EQUALITY( xDotSlope, order, 0.01 );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,8 @@ TEUCHOS_UNIT_TEST(BDF2, SinCosAdapt)
writeOrderError("Tempus_BDF2_SinCos-Error.dat",
stepper, StepSize,
solutions, xErrorNorm, xSlope,
solutionsDot, xDotErrorNorm, xDotSlope);
solutionsDot, xDotErrorNorm, xDotSlope,
out);

TEST_FLOATING_EQUALITY( xSlope, 1.932, 0.01 );
TEST_FLOATING_EQUALITY( xDotSlope, 1.932, 0.01 );
Expand Down
18 changes: 7 additions & 11 deletions packages/tempus/test/BackwardEuler/Tempus_BackwardEuler_ASA.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,6 @@ TEUCHOS_UNIT_TEST(BackwardEuler, SinCos_ASA)
double order = 0.0;
Teuchos::RCP<const Teuchos::Comm<int> > comm =
Teuchos::DefaultComm<int>::getComm();
Teuchos::RCP<Teuchos::FancyOStream> my_out =
Teuchos::fancyOStream(Teuchos::rcpFromRef(std::cout));
my_out->setProcRankAndSize(comm->getRank(), comm->getSize());
my_out->setOutputToRootOnly(0);
for (int n=0; n<nTimeStepSizes; n++) {

// Read params from .xml file
Expand Down Expand Up @@ -195,18 +191,18 @@ TEUCHOS_UNIT_TEST(BackwardEuler, SinCos_ASA)
L2norm = std::sqrt(L2norm);
ErrorNorm.push_back(L2norm);

//*my_out << " n = " << n << " dt = " << dt << " error = " << L2norm
// << std::endl;
//out << " n = " << n << " dt = " << dt << " error = " << L2norm
// << std::endl;

}

// Check the order and intercept
double slope = computeLinearRegressionLogLog<double>(StepSize, ErrorNorm);
*my_out << " Stepper = BackwardEuler" << std::endl;
*my_out << " =========================" << std::endl;
*my_out << " Expected order: " << order << std::endl;
*my_out << " Observed order: " << slope << std::endl;
*my_out << " =========================" << std::endl;
out << " Stepper = BackwardEuler" << std::endl;
out << " =========================" << std::endl;
out << " Expected order: " << order << std::endl;
out << " Observed order: " << slope << std::endl;
out << " =========================" << std::endl;
TEST_FLOATING_EQUALITY( slope, order, 0.015 );
TEST_FLOATING_EQUALITY( ErrorNorm[0], 0.142525, 1.0e-4 );

Expand Down
18 changes: 7 additions & 11 deletions packages/tempus/test/BackwardEuler/Tempus_BackwardEuler_FSA.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,6 @@ void test_sincos_fsa(const bool use_combined_method,
double order = 0.0;
Teuchos::RCP<const Teuchos::Comm<int> > comm =
Teuchos::DefaultComm<int>::getComm();
Teuchos::RCP<Teuchos::FancyOStream> my_out =
Teuchos::fancyOStream(Teuchos::rcpFromRef(std::cout));
my_out->setProcRankAndSize(comm->getRank(), comm->getSize());
my_out->setOutputToRootOnly(0);
for (int n=0; n<nTimeStepSizes; n++) {

// Read params from .xml file
Expand Down Expand Up @@ -182,18 +178,18 @@ void test_sincos_fsa(const bool use_combined_method,
L2norm = std::sqrt(L2norm);
ErrorNorm.push_back(L2norm);

*my_out << " n = " << n << " dt = " << dt << " error = " << L2norm
<< std::endl;
out << " n = " << n << " dt = " << dt << " error = " << L2norm
<< std::endl;

}

// Check the order and intercept
double slope = computeLinearRegressionLogLog<double>(StepSize, ErrorNorm);
*my_out << " Stepper = BackwardEuler" << std::endl;
*my_out << " =========================" << std::endl;
*my_out << " Expected order: " << order << std::endl;
*my_out << " Observed order: " << slope << std::endl;
*my_out << " =========================" << std::endl;
out << " Stepper = BackwardEuler" << std::endl;
out << " =========================" << std::endl;
out << " Expected order: " << order << std::endl;
out << " Observed order: " << slope << std::endl;
out << " =========================" << std::endl;
TEST_FLOATING_EQUALITY( slope, order, 0.015 );
TEST_FLOATING_EQUALITY( ErrorNorm[0], 0.163653, 1.0e-4 );

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,8 @@ void CDR_Test(const Comm& comm, const int commSize, Teuchos::FancyOStream &out,
writeOrderError("Tempus_BackwardEuler_CDR-Error.dat",
stepper, StepSize,
solutions, xErrorNorm, xSlope,
solutionsDot, xDotErrorNorm, xDotSlope);
solutionsDot, xDotErrorNorm, xDotSlope,
out);

TEST_FLOATING_EQUALITY( xSlope, 1.32213, 0.01 );
TEST_FLOATING_EQUALITY( xErrorNorm[0], 0.116919, 1.0e-4 );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,8 @@ TEUCHOS_UNIT_TEST(BackwardEuler, SinCos)
writeOrderError("Tempus_BackwardEuler_SinCos-Error.dat",
stepper, StepSize,
solutions, xErrorNorm, xSlope,
solutionsDot, xDotErrorNorm, xDotSlope);
solutionsDot, xDotErrorNorm, xDotSlope,
out);

TEST_FLOATING_EQUALITY( xSlope, order, 0.01 );
TEST_FLOATING_EQUALITY( xErrorNorm[0], 0.0486418, 1.0e-4 );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,8 @@ TEUCHOS_UNIT_TEST(BackwardEuler, VanDerPol)
writeOrderError("Tempus_BackwardEuler_VanDerPol-Error.dat",
stepper, StepSize,
solutions, xErrorNorm, xSlope,
solutionsDot, xDotErrorNorm, xDotSlope);
solutionsDot, xDotErrorNorm, xDotSlope,
out);

TEST_FLOATING_EQUALITY( xSlope, order, 0.10 );
TEST_FLOATING_EQUALITY( xErrorNorm[0], 0.571031, 1.0e-4 );
Expand Down
54 changes: 28 additions & 26 deletions packages/tempus/test/DIRK/Tempus_DIRKTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -186,9 +186,9 @@ TEUCHOS_UNIT_TEST(DIRK, ParameterList)

bool pass = haveSameValuesSorted(*stepperPL, *defaultPL, true);
if (!pass) {
std::cout << std::endl;
std::cout << "stepperPL -------------- \n" << *stepperPL << std::endl;
std::cout << "defaultPL -------------- \n" << *defaultPL << std::endl;
out << std::endl;
out << "stepperPL -------------- \n" << *stepperPL << std::endl;
out << "defaultPL -------------- \n" << *defaultPL << std::endl;
}
TEST_ASSERT(pass)
}
Expand Down Expand Up @@ -287,16 +287,16 @@ TEUCHOS_UNIT_TEST(DIRK, ConstructingFromDefaults)
Thyra::V_StVpStV(xdiff.ptr(), 1.0, *x_exact, -1.0, *(x));

// Check the order and intercept
std::cout << " Stepper = " << stepper->description()
<< " with " << option << std::endl;
std::cout << " =========================" << std::endl;
std::cout << " Exact solution : " << get_ele(*(x_exact), 0) << " "
<< get_ele(*(x_exact), 1) << std::endl;
std::cout << " Computed solution: " << get_ele(*(x ), 0) << " "
<< get_ele(*(x ), 1) << std::endl;
std::cout << " Difference : " << get_ele(*(xdiff ), 0) << " "
<< get_ele(*(xdiff ), 1) << std::endl;
std::cout << " =========================" << std::endl;
out << " Stepper = " << stepper->description()
<< " with " << option << std::endl;
out << " =========================" << std::endl;
out << " Exact solution : " << get_ele(*(x_exact), 0) << " "
<< get_ele(*(x_exact), 1) << std::endl;
out << " Computed solution: " << get_ele(*(x ), 0) << " "
<< get_ele(*(x ), 1) << std::endl;
out << " Difference : " << get_ele(*(xdiff ), 0) << " "
<< get_ele(*(xdiff ), 1) << std::endl;
out << " =========================" << std::endl;
TEST_FLOATING_EQUALITY(get_ele(*(x), 0), 0.841470, 1.0e-4 );
TEST_FLOATING_EQUALITY(get_ele(*(x), 1), 0.540304, 1.0e-4 );
}
Expand Down Expand Up @@ -374,16 +374,16 @@ TEUCHOS_UNIT_TEST(DIRK, useFSAL_false)
Thyra::V_StVpStV(xdiff.ptr(), 1.0, *x_exact, -1.0, *(x));

// Check the order and intercept
std::cout << " Stepper = " << stepper->description()
<< "\n with " << "useFSAL=false" << std::endl;
std::cout << " =========================" << std::endl;
std::cout << " Exact solution : " << get_ele(*(x_exact), 0) << " "
<< get_ele(*(x_exact), 1) << std::endl;
std::cout << " Computed solution: " << get_ele(*(x ), 0) << " "
<< get_ele(*(x ), 1) << std::endl;
std::cout << " Difference : " << get_ele(*(xdiff ), 0) << " "
<< get_ele(*(xdiff ), 1) << std::endl;
std::cout << " =========================" << std::endl;
out << " Stepper = " << stepper->description()
<< "\n with " << "useFSAL=false" << std::endl;
out << " =========================" << std::endl;
out << " Exact solution : " << get_ele(*(x_exact), 0) << " "
<< get_ele(*(x_exact), 1) << std::endl;
out << " Computed solution: " << get_ele(*(x ), 0) << " "
<< get_ele(*(x ), 1) << std::endl;
out << " Difference : " << get_ele(*(xdiff ), 0) << " "
<< get_ele(*(xdiff ), 1) << std::endl;
out << " =========================" << std::endl;
if (RKMethods[m] == "EDIRK 2 Stage Theta Method") {
TEST_FLOATING_EQUALITY(get_ele(*(x), 0), 0.841021, 1.0e-4 );
TEST_FLOATING_EQUALITY(get_ele(*(x), 1), 0.541002, 1.0e-4 );
Expand Down Expand Up @@ -560,7 +560,8 @@ TEUCHOS_UNIT_TEST(DIRK, SinCos)
writeOrderError("Tempus_"+RKMethod+"_SinCos-Error.dat",
stepper, StepSize,
solutions, xErrorNorm, xSlope,
solutionsDot, xDotErrorNorm, xDotSlope);
solutionsDot, xDotErrorNorm, xDotSlope,
out);

TEST_FLOATING_EQUALITY( xSlope, order, 0.01 );
TEST_FLOATING_EQUALITY( xErrorNorm[0], RKMethodErrors[m], 5.0e-4 );
Expand Down Expand Up @@ -660,7 +661,8 @@ TEUCHOS_UNIT_TEST(DIRK, VanDerPol)
writeOrderError("Tempus_"+RKMethod+"_VanDerPol-Error.dat",
stepper, StepSize,
solutions, xErrorNorm, xSlope,
solutionsDot, xDotErrorNorm, xDotSlope);
solutionsDot, xDotErrorNorm, xDotSlope,
out);

TEST_FLOATING_EQUALITY( xSlope, order, 0.06 );
TEST_FLOATING_EQUALITY( xErrorNorm[0], 1.07525e-05, 1.0e-4 );
Expand All @@ -685,7 +687,7 @@ TEUCHOS_UNIT_TEST(DIRK, EmbeddedVanDerPol)

for(auto integratorChoice : IntegratorList){

std::cout << "Using Integrator: " << integratorChoice << " !!!" << std::endl;
out << "Using Integrator: " << integratorChoice << " !!!" << std::endl;

// Read params from .xml file
RCP<ParameterList> pList =
Expand Down
18 changes: 7 additions & 11 deletions packages/tempus/test/DIRK/Tempus_DIRK_ASA.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,6 @@ TEUCHOS_UNIT_TEST(DIRK, SinCos_ASA)

Teuchos::RCP<const Teuchos::Comm<int> > comm =
Teuchos::DefaultComm<int>::getComm();
Teuchos::RCP<Teuchos::FancyOStream> my_out =
Teuchos::fancyOStream(Teuchos::rcpFromRef(std::cout));
my_out->setProcRankAndSize(comm->getRank(), comm->getSize());
my_out->setOutputToRootOnly(0);

for(std::vector<std::string>::size_type m = 0; m != RKMethods.size(); m++) {

Expand Down Expand Up @@ -228,8 +224,8 @@ TEUCHOS_UNIT_TEST(DIRK, SinCos_ASA)
L2norm = std::sqrt(L2norm);
ErrorNorm.push_back(L2norm);

//*my_out << " n = " << n << " dt = " << dt << " error = " << L2norm
// << std::endl;
//out << " n = " << n << " dt = " << dt << " error = " << L2norm
// << std::endl;
}

if (comm->getRank() == 0) {
Expand All @@ -252,11 +248,11 @@ TEUCHOS_UNIT_TEST(DIRK, SinCos_ASA)

// Check the order and intercept
double slope = computeLinearRegressionLogLog<double>(StepSize, ErrorNorm);
*my_out << " Stepper = " << RKMethods[m] << std::endl;
*my_out << " =========================" << std::endl;
*my_out << " Expected order: " << order << std::endl;
*my_out << " Observed order: " << slope << std::endl;
*my_out << " =========================" << std::endl;
out << " Stepper = " << RKMethods[m] << std::endl;
out << " =========================" << std::endl;
out << " Expected order: " << order << std::endl;
out << " Observed order: " << slope << std::endl;
out << " =========================" << std::endl;
TEST_FLOATING_EQUALITY( slope, order, 0.03 );
TEST_FLOATING_EQUALITY( ErrorNorm[0], RKMethodErrors[m], 5.0e-4 );

Expand Down
18 changes: 7 additions & 11 deletions packages/tempus/test/DIRK/Tempus_DIRK_FSA.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,10 +110,6 @@ void test_sincos_fsa(const std::string& method_name,

Teuchos::RCP<const Teuchos::Comm<int> > comm =
Teuchos::DefaultComm<int>::getComm();
Teuchos::RCP<Teuchos::FancyOStream> my_out =
Teuchos::fancyOStream(Teuchos::rcpFromRef(std::cout));
my_out->setProcRankAndSize(comm->getRank(), comm->getSize());
my_out->setOutputToRootOnly(0);

for(std::vector<std::string>::size_type m = 0; m != RKMethods.size(); m++) {

Expand Down Expand Up @@ -265,8 +261,8 @@ void test_sincos_fsa(const std::string& method_name,
L2norm = std::sqrt(L2norm);
ErrorNorm.push_back(L2norm);

//*my_out << " n = " << n << " dt = " << dt << " error = " << L2norm
// << std::endl;
//out << " n = " << n << " dt = " << dt << " error = " << L2norm
// << std::endl;
}

if (comm->getRank() == 0) {
Expand All @@ -289,11 +285,11 @@ void test_sincos_fsa(const std::string& method_name,

// Check the order and intercept
double slope = computeLinearRegressionLogLog<double>(StepSize, ErrorNorm);
*my_out << " Stepper = " << RKMethods[m] << std::endl;
*my_out << " =========================" << std::endl;
*my_out << " Expected order: " << order << std::endl;
*my_out << " Observed order: " << slope << std::endl;
*my_out << " =========================" << std::endl;
out << " Stepper = " << RKMethods[m] << std::endl;
out << " =========================" << std::endl;
out << " Expected order: " << order << std::endl;
out << " Observed order: " << slope << std::endl;
out << " =========================" << std::endl;

// Can only seem to get at most 4th order when using staggered method
double order_expected = use_combined_method ? order : std::min(order,4.0);
Expand Down
Loading