SundanceGrouperBase.cpp
Go to the documentation of this file.
00001 /* @HEADER@ */
00002 // ************************************************************************
00003 // 
00004 //                             Sundance
00005 //                 Copyright 2011 Sandia Corporation
00006 // 
00007 // Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
00008 // the U.S. Government retains certain rights in this software.
00009 //
00010 // Redistribution and use in source and binary forms, with or without
00011 // modification, are permitted provided that the following conditions are
00012 // met:
00013 //
00014 // 1. Redistributions of source code must retain the above copyright
00015 // notice, this list of conditions and the following disclaimer.
00016 //
00017 // 2. Redistributions in binary form must reproduce the above copyright
00018 // notice, this list of conditions and the following disclaimer in the
00019 // documentation and/or other materials provided with the distribution.
00020 //
00021 // 3. Neither the name of the Corporation nor the names of the
00022 // contributors may be used to endorse or promote products derived from
00023 // this software without specific prior written permission.
00024 //
00025 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
00026 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00027 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
00028 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
00029 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
00030 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
00031 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
00032 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
00033 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
00034 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00035 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00036 //
00037 // Questions? Contact Kevin Long (kevin.long@ttu.edu)
00038 // 
00039 
00040 /* @HEADER@ */
00041 
00042 #include "SundanceGrouperBase.hpp"
00043 #include "SundanceOut.hpp"
00044 #include "PlayaTabs.hpp"
00045 #include "SundanceFuncWithBasis.hpp"
00046 #include "SundanceBasisFamily.hpp"
00047 #include "SundanceQuadratureFamily.hpp"
00048 #include "SundanceEquationSet.hpp"
00049 #include "SundanceUnknownFuncElement.hpp"
00050 #include "SundanceTestFuncElement.hpp"
00051 #include "SundanceUnknownFunction.hpp"
00052 #include "SundanceUnknownParameterElement.hpp"
00053 #include "SundanceTestFunction.hpp"
00054 
00055 using namespace Sundance;
00056 using namespace Sundance;
00057 using namespace Sundance;
00058 using namespace Sundance;
00059 using namespace Sundance;
00060 using namespace Sundance;
00061 using namespace Sundance;
00062 using namespace Teuchos;
00063 
00064 
00065 
00066 void GrouperBase::setVerb(
00067   int setupVerb,
00068   int integrationVerb,
00069   int transformVerb)
00070 {
00071   setupVerb_ = setupVerb;
00072   integrationVerb_ = integrationVerb;
00073   transformVerb_ = transformVerb;
00074 }
00075 
00076 
00077 
00078 void GrouperBase::extractWeakForm(const EquationSet& eqn,
00079   const MultipleDeriv& functionalDeriv,
00080   BasisFamily& varBasis, 
00081   BasisFamily& unkBasis,
00082   MultiIndex& miVar, MultiIndex& miUnk,
00083   int& rawVarID, int& rawUnkID,  
00084   int& reducedVarID, int& reducedUnkID,  
00085   int& testBlock, int& unkBlock, 
00086   int& rawParamID, int& reducedParamID, 
00087   bool& isOneForm, bool& hasParam) const
00088 {
00089   Tabs tab0(0);
00090 
00091   MultipleDeriv::const_iterator iter;
00092 
00093   isOneForm = false;  
00094   hasParam = false;
00095 
00096   if (functionalDeriv.size()==0) return;
00097 
00098   TEUCHOS_TEST_FOR_EXCEPTION(functionalDeriv.size() > 2, std::logic_error,
00099     "GrouperBase::extractWeakForm detected a functional "
00100     "derivative of order > 2: " 
00101     << functionalDeriv.toString());
00102 
00103   bool foundUnk = false;
00104   bool foundVar = false;
00105 
00106   SUNDANCE_MSG2(setupVerb(), 
00107     tab0 << "extracting weak form for functional derivative " 
00108     << functionalDeriv);
00109 
00110 
00111   for (iter = functionalDeriv.begin(); iter != functionalDeriv.end(); iter++)
00112   {
00113     Tabs tab;
00114     const Deriv& d = *iter;
00115       
00116     TEUCHOS_TEST_FOR_EXCEPTION(!d.isFunctionalDeriv(), std::logic_error,
00117       "GrouperBase::extractWeakForm "
00118       "detected a non-functional derivative: "
00119       << functionalDeriv.toString());
00120       
00121     const FunctionIdentifier& fid = d.fid();
00122       
00123     const SymbolicFuncElement* s = d.symbFuncElem();
00124 
00125     TEUCHOS_TEST_FOR_EXCEPTION(s==0, std::logic_error, 
00126       "GrouperBase::extractWeakForm failed to cast "
00127       "function to SymbolicFuncElement");
00128       
00129 
00130     int dofID = fid.dofID();
00131     int myIndex = fid.componentIndex();
00132 
00133     if (!foundVar && eqn.hasVarID(dofID))
00134     {
00135       TEUCHOS_TEST_FOR_EXCEPTION(d.isParameter(), std::logic_error,
00136         "Parameter not expected here");
00137       foundVar = true;
00138       reducedVarID = eqn.reducedVarID(dofID);
00139       rawVarID = dofID;
00140       testBlock = eqn.blockForVarID(dofID);
00141 
00142       SUNDANCE_MSG2(setupVerb(), 
00143         tab << "found varID=" << reducedVarID);
00144 
00145       const UnknownFuncElement* u
00146         = dynamic_cast<const UnknownFuncElement*>(s);
00147 
00148       const TestFuncElement* t
00149         = dynamic_cast<const TestFuncElement*>(s);
00150 
00151       TEUCHOS_TEST_FOR_EXCEPTION(u==0 && t==0, std::logic_error, 
00152         "GrouperBase::extractWeakForm could not cast "
00153         "variational function to either an "
00154         "UnknownFuncElement or a TestFuncElement");
00155 
00156       if (t != 0) 
00157       {
00158         varBasis = TestFunctionData::getData(t)->basis()[myIndex];
00159       }
00160       else 
00161       {
00162         varBasis = UnknownFunctionData::getData(u)->basis()[myIndex];
00163       }
00164       SUNDANCE_MSG2(setupVerb(), 
00165         tab << "found varBasis=" << varBasis);
00166 
00167       miVar = d.opOnFunc().mi();
00168       SUNDANCE_MSG2(setupVerb(), 
00169         tab << "found var multi index=" << miVar.toString());
00170     }
00171     else if (eqn.hasFixedParamID(dofID))
00172     {
00173       const UnknownParameterElement* upe
00174         = dynamic_cast<const UnknownParameterElement*>(s);
00175       TEUCHOS_TEST_FOR_EXCEPTION(upe==0, std::logic_error, 
00176         "GrouperBase::extractWeakForm could not cast "
00177         "unknown parameter to UnknownParameterElement");
00178       hasParam = true;
00179       rawParamID = dofID;
00180       reducedParamID = eqn.reducedFixedParamID(dofID);
00181     }
00182     else
00183     {
00184       TEUCHOS_TEST_FOR_EXCEPTION(d.isParameter(), std::logic_error,
00185         "Parameter not expected here");
00186       const UnknownFuncElement* u
00187         = dynamic_cast<const UnknownFuncElement*>(s);
00188       TEUCHOS_TEST_FOR_EXCEPTION(u==0, std::logic_error, 
00189         "GrouperBase::extractWeakForm could not cast "
00190         "unknown function to UnknownFuncElement");
00191       foundUnk = true;
00192       reducedUnkID = eqn.reducedUnkID(dofID);
00193       rawUnkID = dofID;
00194       unkBlock = eqn.blockForUnkID(dofID);
00195 
00196       SUNDANCE_MSG2(setupVerb(), 
00197         tab << "found reducedUnkID=" << reducedUnkID);
00198 
00199       unkBasis = UnknownFunctionData::getData(u)->basis()[myIndex];
00200       SUNDANCE_MSG2(setupVerb(), 
00201         tab << "found unkBasis=" << unkBasis);
00202 
00203       miUnk = d.opOnFunc().mi();
00204       SUNDANCE_MSG2(setupVerb(), 
00205         tab << "found unk multi index=" << miUnk.toString());
00206     }
00207   }
00208 
00209   if (!foundUnk) isOneForm = true;
00210 }

Site Contact