|
Thyra Package Browser (Single Doxygen Collection)
Version of the Day
|
00001 /* 00002 // @HEADER 00003 // *********************************************************************** 00004 // 00005 // Thyra: Interfaces and Support for Abstract Numerical Algorithms 00006 // Copyright (2004) Sandia Corporation 00007 // 00008 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive 00009 // license for use of this work by or on behalf of the U.S. Government. 00010 // 00011 // Redistribution and use in source and binary forms, with or without 00012 // modification, are permitted provided that the following conditions are 00013 // met: 00014 // 00015 // 1. Redistributions of source code must retain the above copyright 00016 // notice, this list of conditions and the following disclaimer. 00017 // 00018 // 2. Redistributions in binary form must reproduce the above copyright 00019 // notice, this list of conditions and the following disclaimer in the 00020 // documentation and/or other materials provided with the distribution. 00021 // 00022 // 3. Neither the name of the Corporation nor the names of the 00023 // contributors may be used to endorse or promote products derived from 00024 // this software without specific prior written permission. 00025 // 00026 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY 00027 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00028 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 00029 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE 00030 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 00031 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 00032 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 00033 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 00034 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 00035 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 00036 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00037 // 00038 // Questions? Contact Roscoe A. Bartlett (bartlettra@ornl.gov) 00039 // 00040 // *********************************************************************** 00041 // @HEADER 00042 */ 00043 00044 00045 #include "Simple2DTpetraModelEvaluator.hpp" 00046 00047 #include "Teuchos_UnitTestHarness.hpp" 00048 00049 00050 namespace { 00051 00052 00053 using Teuchos::null; 00054 using Teuchos::RCP; 00055 typedef Thyra::ModelEvaluatorBase MEB; 00056 00057 00058 // 00059 // Unit tests 00060 // 00061 00062 00063 TEUCHOS_UNIT_TEST_TEMPLATE_1_DECL( Simple2DTpetraModelEvaluator, construct, Scalar ) 00064 { 00065 RCP<Simple2DTpetraModelEvaluator<Scalar> > model = simple2DTpetraModelEvaluator<Scalar>(); 00066 TEST_ASSERT(model != null); 00067 TEST_EQUALITY(model->Np(), 0); 00068 TEST_EQUALITY(model->Ng(), 0); 00069 TEST_ASSERT(model->get_x_space() != null); 00070 TEST_EQUALITY(model->get_x_space()->dim(), 2); 00071 TEST_ASSERT(model->get_f_space() != null); 00072 TEST_EQUALITY(model->get_f_space()->dim(), 2); 00073 TEST_ASSERT(nonnull(model->getNominalValues().get_x())); 00074 TEST_ASSERT(model->create_W_op() != null); 00075 //TEST_ASSERT(model->get_W_factory() != null); 00076 MEB::InArgs<Scalar> inArgs = model->createInArgs(); 00077 TEST_ASSERT(inArgs.supports(MEB::IN_ARG_x)); 00078 TEST_EQUALITY(inArgs.Np(), 0); 00079 } 00080 00081 #if !defined(HAVE_TPETRA_EXPLICIT_INSTANTIATION) || defined(HAVE_TPETRA_INST_DOUBLE) 00082 TEUCHOS_UNIT_TEST_TEMPLATE_1_INSTANT_DOUBLE( 00083 Simple2DTpetraModelEvaluator, construct ) 00084 #endif 00085 00086 #if !defined(HAVE_TPETRA_EXPLICIT_INSTANTIATION) || defined(HAVE_TPETRA_INST_FLOAT) 00087 TEUCHOS_UNIT_TEST_TEMPLATE_1_INSTANT_FLOAT( 00088 Simple2DTpetraModelEvaluator, construct ) 00089 #endif 00090 00091 00092 TEUCHOS_UNIT_TEST_TEMPLATE_1_DECL( Simple2DTpetraModelEvaluator, eval, Scalar ) 00093 { 00094 00095 using Teuchos::tuple; 00096 using Teuchos::ArrayView; 00097 using Teuchos::ArrayRCP; 00098 using Teuchos::as; 00099 using Teuchos::rcp_dynamic_cast; 00100 typedef Teuchos::ScalarTraits<Scalar> ST; 00101 typedef typename ST::magnitudeType ScalarMag; 00102 typedef Teuchos::ScalarTraits<ScalarMag> SMT; 00103 using Thyra::VectorBase; 00104 using Thyra::LinearOpBase; 00105 typedef Thyra::TpetraOperatorVectorExtraction<Scalar,int> ConverterT; 00106 00107 RCP<Simple2DTpetraModelEvaluator<Scalar> > model = simple2DTpetraModelEvaluator<Scalar>(); 00108 00109 const Scalar d = 7.0; 00110 model->set_d(d); 00111 00112 const Scalar p_0 = 2.0, p_1 = 6.0; 00113 model->set_p(tuple<Scalar>(p_0, p_1)); 00114 00115 const Scalar x_0 = 3.0, x_1 = 4.0; 00116 model->set_x0(tuple<Scalar>(x_0, x_1)); 00117 00118 MEB::InArgs<Scalar> inArgs = model->getNominalValues(); 00119 MEB::OutArgs<Scalar> outArgs = model->createOutArgs(); 00120 const RCP<VectorBase<Scalar> > f = createMember(model->get_f_space()); 00121 const RCP<LinearOpBase<Scalar> > W_op = model->create_W_op(); 00122 outArgs.set_f(f); 00123 outArgs.set_W_op(W_op); 00124 model->evalModel(inArgs, outArgs); 00125 00126 const ScalarMag tol = 100.0 * SMT::eps(); 00127 00128 const RCP<const Tpetra::Vector<Scalar,int> > f_tpetra = 00129 ConverterT::getConstTpetraVector(f); 00130 00131 const ArrayRCP<const Scalar> f_tpetra_vals = f_tpetra->get1dView(); 00132 TEST_FLOATING_EQUALITY(f_tpetra_vals[0], as<Scalar>(x_0 + x_1*x_1 - p_0), tol); 00133 TEST_FLOATING_EQUALITY(f_tpetra_vals[1], as<Scalar>(d * (x_0*x_0 - x_1 - p_1)), tol); 00134 00135 const RCP<const Tpetra::CrsMatrix<Scalar,int> > W_tpetra = 00136 rcp_dynamic_cast<Tpetra::CrsMatrix<Scalar,int> >( 00137 ConverterT::getTpetraOperator(W_op)); 00138 00139 ArrayView<const int> row_indices; 00140 ArrayView<const Scalar> row_values; 00141 00142 W_tpetra->getLocalRowView(0, row_indices, row_values); 00143 TEST_EQUALITY( row_indices[0], 0 ); 00144 TEST_EQUALITY( row_indices[1], 1 ); 00145 TEST_FLOATING_EQUALITY( row_values[0], as<Scalar>(1.0), tol ); 00146 TEST_FLOATING_EQUALITY( row_values[1], as<Scalar>(2.0*x_1), tol ); 00147 00148 W_tpetra->getLocalRowView(1, row_indices, row_values); 00149 TEST_EQUALITY( row_indices[0], 0 ); 00150 TEST_EQUALITY( row_indices[1], 1 ); 00151 TEST_FLOATING_EQUALITY( row_values[0], as<Scalar>(d*2.0*x_0), tol ); 00152 TEST_FLOATING_EQUALITY( row_values[1], as<Scalar>(-d), tol ); 00153 00154 } 00155 00156 #if !defined(HAVE_TPETRA_EXPLICIT_INSTANTIATION) || defined(HAVE_TPETRA_INST_DOUBLE) 00157 TEUCHOS_UNIT_TEST_TEMPLATE_1_INSTANT_DOUBLE( 00158 Simple2DTpetraModelEvaluator, eval ) 00159 #endif 00160 00161 #if !defined(HAVE_TPETRA_EXPLICIT_INSTANTIATION) || defined(HAVE_TPETRA_INST_FLOAT) 00162 TEUCHOS_UNIT_TEST_TEMPLATE_1_INSTANT_FLOAT( 00163 Simple2DTpetraModelEvaluator, eval ) 00164 #endif 00165 00166 00167 00168 } // namespace
1.7.6.1