Panzer  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
user_app_NOXObserver_NeumannBCAnalyticSystemTest.hpp
Go to the documentation of this file.
1 // @HEADER
2 // ***********************************************************************
3 //
4 // Panzer: A partial differential equation assembly
5 // engine for strongly coupled complex multiphysics systems
6 // Copyright (2011) Sandia Corporation
7 //
8 // Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
9 // the U.S. Government retains certain rights in this software.
10 //
11 // Redistribution and use in source and binary forms, with or without
12 // modification, are permitted provided that the following conditions are
13 // met:
14 //
15 // 1. Redistributions of source code must retain the above copyright
16 // notice, this list of conditions and the following disclaimer.
17 //
18 // 2. Redistributions in binary form must reproduce the above copyright
19 // notice, this list of conditions and the following disclaimer in the
20 // documentation and/or other materials provided with the distribution.
21 //
22 // 3. Neither the name of the Corporation nor the names of the
23 // contributors may be used to endorse or promote products derived from
24 // this software without specific prior written permission.
25 //
26 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
27 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
30 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
31 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
32 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
33 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
34 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
35 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
36 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37 //
38 // Questions? Contact Roger P. Pawlowski (rppawlo@sandia.gov) and
39 // Eric C. Cyr (eccyr@sandia.gov)
40 // ***********************************************************************
41 // @HEADER
42 
43 #ifndef USER_APP_NOX_OBSERVER_NEUMANN_BC_ANALYTIC_SYSTEM_TEST_HPP
44 #define USER_APP_NOX_OBSERVER_NEUMANN_BC_ANALYTIC_SYSTEM_TEST_HPP
45 
46 #include "Panzer_config.hpp"
47 
48 #include "NOX_Abstract_PrePostOperator.H"
49 
50 #include "Teuchos_RCP.hpp"
51 #include "NOX_Thyra_Vector.H"
52 #include "Thyra_DefaultProductVector.hpp"
53 
54 namespace user_app {
55 
57 
58  public:
59 
61  {
62 
63  }
64 
65  void runPreIterate(const NOX::Solver::Generic& solver)
66  {
67 
68  }
69 
71  {
72 
73  }
74 
75  void runPreSolve(const NOX::Solver::Generic& solver)
76  {
77 
78  }
79 
80  void runPostSolve(const NOX::Solver::Generic& solver)
81  {
82  /*
83  The Neumann BC Analytic System Test is simple heat conduction
84  in the x-direction. By fixing the flux and thermal
85  conductivity, there is an analytic solution with a value of
86  2.0 for temperature on the left surface where the neumann
87  condition is applied. We will check exactly one node on this
88  boundary and make sure it is within the expected error
89  (accounting for discretization error).
90 
91  IMPORTANT: If the global dof numbering scheme changes in the
92  future, this test could fail by grabbing the wrong node.
93  */
94 
95  const NOX::Abstract::Vector& x = solver.getSolutionGroup().getX();
96  const NOX::Thyra::Vector* n_th_x = dynamic_cast<const NOX::Thyra::Vector*>(&x);
97  TEUCHOS_TEST_FOR_EXCEPTION(n_th_x == NULL, std::runtime_error, "Failed to dynamic_cast to NOX::Thyra::Vector!")
98  const ::Thyra::VectorBase<double>& th_x = n_th_x->getThyraVector();
99 
100  // Assume a single process job (enforced in CMakeLists.txt file)
101 
102  const ::Thyra::SpmdVectorBase<double>* th_spmd_x = dynamic_cast<const ::Thyra::SpmdVectorBase<double>* >(&th_x);
103 
104  TEUCHOS_TEST_FOR_EXCEPTION(th_spmd_x == NULL, std::runtime_error, "Failed to dynamic_cast to Thyra SPMD vector!");
105 
106  Teuchos::ArrayRCP<const double> local_values;
107 
108  th_spmd_x->getLocalData(outArg(local_values));
109 
110 // for (std::size_t i=0; i < local_values.size(); ++i)
111 // std::cout << "local_values[" << i << "] = " << local_values[i] << std::endl;
112 
113  // linear solve tolerance is 1e-10 and this is a linear problem with a linear basis
114  double tol = 1.0e-9;
115 
116  TEUCHOS_TEST_FOR_EXCEPTION( std::fabs(local_values[0] - 2.0) > tol, std::runtime_error, "Solution value for Neumann Condition is " << local_values[0] << " and should be 2.0. The tolerance condition, std::fabs(local_values[0] - 2.0) > tol, where tol is " << tol << " has been violated, causing the test to fail.");
117 
118  local_values = Teuchos::null;
119 
120  }
121 
122  };
123 }
124 
125 #endif
virtual ::Thyra::VectorBase< double > & getThyraVector()
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)