• Main Page
  • Related Pages
  • Namespaces
  • Classes
  • Files
  • File List
  • File Members

TimeTracBC_Def.hpp

Go to the documentation of this file.
00001 //*****************************************************************//
00002 //    Albany 2.0:  Copyright 2012 Sandia Corporation               //
00003 //    This Software is released under the BSD license detailed     //
00004 //    in the file "license.txt" in the top-level Albany directory  //
00005 //*****************************************************************//
00006 
00007 #include "Teuchos_TestForException.hpp"
00008 #include "Phalanx_DataLayout.hpp"
00009 #include <string>
00010 
00011 
00012 namespace LCM {
00013 
00014 //**********************************************************************
00015 template<typename EvalT, typename Traits>
00016 TimeTracBC_Base<EvalT, Traits>::
00017 TimeTracBC_Base(Teuchos::ParameterList& p) :
00018   PHAL::Neumann<EvalT, Traits>(p) {
00019 
00020   timeValues = p.get<Teuchos::Array<RealType> >("Time Values").toVector();
00021   BCValues = p.get<Teuchos::TwoDArray<RealType> >("BC Values");
00022 
00023   if(this->bc_type == PHAL::NeumannBase<EvalT, Traits>::COORD)
00024 
00025     TEUCHOS_TEST_FOR_EXCEPTION( !(this->cellDims == BCValues.getNumCols()),
00026             Teuchos::Exceptions::InvalidParameter,
00027             "Dimension of the current problem and \"BC Values\" do not match" );
00028 
00029   TEUCHOS_TEST_FOR_EXCEPTION( !(timeValues.size() == BCValues.getNumRows()),
00030             Teuchos::Exceptions::InvalidParameter,
00031             "Dimension of \"Time Values\" and \"BC Values\" do not match" );
00032 
00033 }
00034 
00035 //**********************************************************************
00036 template<typename EvalT, typename Traits>
00037 void
00038 TimeTracBC_Base<EvalT, Traits>::
00039 computeVal(RealType time)
00040 {
00041 
00042   TEUCHOS_TEST_FOR_EXCEPTION( time > timeValues.back(),
00043             Teuchos::Exceptions::InvalidParameter,
00044             "Time is growing unbounded!" );
00045   ScalarT Val;
00046   RealType slope;
00047   unsigned int Index(0);
00048 
00049   while( timeValues[Index] < time )
00050     Index++;
00051 
00052   if (Index == 0)
00053       this->const_val = BCValues(0, Index);
00054   else
00055   {
00056       slope = ( BCValues(0, Index) - BCValues(0, Index - 1) ) / ( timeValues[Index] - timeValues[Index - 1] );
00057       this->const_val = BCValues(0, Index-1) + slope * ( time - timeValues[Index - 1] );
00058   }
00059 
00060   return;
00061 
00062 }
00063 
00064 template<typename EvalT, typename Traits>
00065 void
00066 TimeTracBC_Base<EvalT, Traits>::
00067 computeCoordVal(RealType time)
00068 {
00069   TEUCHOS_TEST_FOR_EXCEPTION( time > timeValues.back(),
00070             Teuchos::Exceptions::InvalidParameter,
00071             "Time is growing unbounded!" );
00072   ScalarT Val;
00073   RealType slope;
00074   unsigned int Index(0);
00075 
00076   while( timeValues[Index] < time )
00077     Index++;
00078 
00079   if (Index == 0)
00080     for(int dim = 0; dim < this->cellDims; dim++)
00081       this->dudx[dim] = BCValues(dim, Index);
00082   else
00083   {
00084     for(size_t dim = 0; dim < this->cellDims; dim++){
00085       slope = ( BCValues(dim, Index) - BCValues(dim, Index - 1) ) / ( timeValues[Index] - timeValues[Index - 1] );
00086       this->dudx[dim] = BCValues(dim, Index-1) + slope * ( time - timeValues[Index - 1] );
00087     }
00088   }
00089 
00090   return;
00091 
00092 }
00093 
00094 template<typename EvalT, typename Traits>
00095 TimeTracBC<EvalT,Traits>::
00096 TimeTracBC(Teuchos::ParameterList& p)
00097   : TimeTracBC_Base<EvalT,Traits>(p)
00098 {
00099 }
00100 
00101 template<typename EvalT, typename Traits>
00102 void TimeTracBC<EvalT, Traits>::
00103 evaluateFields(typename Traits::EvalData workset)
00104 {
00105 
00106   RealType time = workset.current_time;
00107 
00108   switch(this->bc_type){
00109 
00110     case PHAL::NeumannBase<EvalT, Traits>::INTJUMP:
00111     case PHAL::NeumannBase<EvalT, Traits>::PRESS:
00112     case PHAL::NeumannBase<EvalT, Traits>::NORMAL:
00113     // calculate scalar value of BC based on current time
00114 
00115       this->computeVal(time);
00116       break;
00117 
00118     case PHAL::NeumannBase<EvalT, Traits>::COORD:
00119     // calculate a value of BC for each coordinate based on current time
00120 
00121       this->computeCoordVal(time);
00122       break;
00123 
00124     default:
00125 
00126       TEUCHOS_TEST_FOR_EXCEPTION( true,
00127             std::logic_error,
00128             "Time dependent Neumann boundary condition of type - " << this->bc_type << " is not supported");
00129       break;
00130 
00131   }
00132 
00133   PHAL::Neumann<EvalT, Traits>::evaluateFields(workset);
00134 
00135 }
00136 
00137 }

Generated on Wed Mar 26 2014 18:36:45 for Albany: a Trilinos-based PDE code by  doxygen 1.7.1