SundanceGrouperBase.cpp
Go to the documentation of this file.
00001 /* @HEADER@ */
00002 // ************************************************************************
00003 // 
00004 //                              Sundance
00005 //                 Copyright (2005) Sandia Corporation
00006 // 
00007 // Copyright (year first published) Sandia Corporation.  Under the terms 
00008 // of Contract DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government 
00009 // retains certain rights in this software.
00010 // 
00011 // This library is free software; you can redistribute it and/or modify
00012 // it under the terms of the GNU Lesser General Public License as
00013 // published by the Free Software Foundation; either version 2.1 of the
00014 // License, or (at your option) any later version.
00015 //  
00016 // This library is distributed in the hope that it will be useful, but
00017 // WITHOUT ANY WARRANTY; without even the implied warranty of
00018 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00019 // Lesser General Public License for more details.
00020 //                                                                                 
00021 // You should have received a copy of the GNU Lesser General Public
00022 // License along with this library; if not, write to the Free Software
00023 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
00024 // USA                                                                                
00025 // Questions? Contact Kevin Long (krlong@sandia.gov), 
00026 // Sandia National Laboratories, Livermore, California, USA
00027 // 
00028 // ************************************************************************
00029 /* @HEADER@ */
00030 
00031 #include "SundanceGrouperBase.hpp"
00032 #include "SundanceOut.hpp"
00033 #include "PlayaTabs.hpp"
00034 #include "SundanceFuncWithBasis.hpp"
00035 #include "SundanceBasisFamily.hpp"
00036 #include "SundanceQuadratureFamily.hpp"
00037 #include "SundanceEquationSet.hpp"
00038 #include "SundanceUnknownFuncElement.hpp"
00039 #include "SundanceTestFuncElement.hpp"
00040 #include "SundanceUnknownFunction.hpp"
00041 #include "SundanceUnknownParameterElement.hpp"
00042 #include "SundanceTestFunction.hpp"
00043 
00044 using namespace Sundance;
00045 using namespace Sundance;
00046 using namespace Sundance;
00047 using namespace Sundance;
00048 using namespace Sundance;
00049 using namespace Sundance;
00050 using namespace Sundance;
00051 using namespace Teuchos;
00052 
00053 
00054 
00055 void GrouperBase::setVerb(
00056   int setupVerb,
00057   int integrationVerb,
00058   int transformVerb)
00059 {
00060   setupVerb_ = setupVerb;
00061   integrationVerb_ = integrationVerb;
00062   transformVerb_ = transformVerb;
00063 }
00064 
00065 
00066 
00067 void GrouperBase::extractWeakForm(const EquationSet& eqn,
00068   const MultipleDeriv& functionalDeriv,
00069   BasisFamily& varBasis, 
00070   BasisFamily& unkBasis,
00071   MultiIndex& miVar, MultiIndex& miUnk,
00072   int& rawVarID, int& rawUnkID,  
00073   int& reducedVarID, int& reducedUnkID,  
00074   int& testBlock, int& unkBlock, 
00075   int& rawParamID, int& reducedParamID, 
00076   bool& isOneForm, bool& hasParam) const
00077 {
00078   Tabs tab0(0);
00079 
00080   MultipleDeriv::const_iterator iter;
00081 
00082   isOneForm = false;  
00083   hasParam = false;
00084 
00085   if (functionalDeriv.size()==0) return;
00086 
00087   TEUCHOS_TEST_FOR_EXCEPTION(functionalDeriv.size() > 2, std::logic_error,
00088     "GrouperBase::extractWeakForm detected a functional "
00089     "derivative of order > 2: " 
00090     << functionalDeriv.toString());
00091 
00092   bool foundUnk = false;
00093   bool foundVar = false;
00094 
00095   SUNDANCE_MSG2(setupVerb(), 
00096     tab0 << "extracting weak form for functional derivative " 
00097     << functionalDeriv);
00098 
00099 
00100   for (iter = functionalDeriv.begin(); iter != functionalDeriv.end(); iter++)
00101   {
00102     Tabs tab;
00103     const Deriv& d = *iter;
00104       
00105     TEUCHOS_TEST_FOR_EXCEPTION(!d.isFunctionalDeriv(), std::logic_error,
00106       "GrouperBase::extractWeakForm "
00107       "detected a non-functional derivative: "
00108       << functionalDeriv.toString());
00109       
00110     const FunctionIdentifier& fid = d.fid();
00111       
00112     const SymbolicFuncElement* s = d.symbFuncElem();
00113 
00114     TEUCHOS_TEST_FOR_EXCEPTION(s==0, std::logic_error, 
00115       "GrouperBase::extractWeakForm failed to cast "
00116       "function to SymbolicFuncElement");
00117       
00118 
00119     int dofID = fid.dofID();
00120     int myIndex = fid.componentIndex();
00121 
00122     if (!foundVar && eqn.hasVarID(dofID))
00123     {
00124       TEUCHOS_TEST_FOR_EXCEPTION(d.isParameter(), std::logic_error,
00125         "Parameter not expected here");
00126       foundVar = true;
00127       reducedVarID = eqn.reducedVarID(dofID);
00128       rawVarID = dofID;
00129       testBlock = eqn.blockForVarID(dofID);
00130 
00131       SUNDANCE_MSG2(setupVerb(), 
00132         tab << "found varID=" << reducedVarID);
00133 
00134       const UnknownFuncElement* u
00135         = dynamic_cast<const UnknownFuncElement*>(s);
00136 
00137       const TestFuncElement* t
00138         = dynamic_cast<const TestFuncElement*>(s);
00139 
00140       TEUCHOS_TEST_FOR_EXCEPTION(u==0 && t==0, std::logic_error, 
00141         "GrouperBase::extractWeakForm could not cast "
00142         "variational function to either an "
00143         "UnknownFuncElement or a TestFuncElement");
00144 
00145       if (t != 0) 
00146       {
00147         varBasis = TestFunctionData::getData(t)->basis()[myIndex];
00148       }
00149       else 
00150       {
00151         varBasis = UnknownFunctionData::getData(u)->basis()[myIndex];
00152       }
00153       SUNDANCE_MSG2(setupVerb(), 
00154         tab << "found varBasis=" << varBasis);
00155 
00156       miVar = d.opOnFunc().mi();
00157       SUNDANCE_MSG2(setupVerb(), 
00158         tab << "found var multi index=" << miVar.toString());
00159     }
00160     else if (eqn.hasFixedParamID(dofID))
00161     {
00162       const UnknownParameterElement* upe
00163         = dynamic_cast<const UnknownParameterElement*>(s);
00164       TEUCHOS_TEST_FOR_EXCEPTION(upe==0, std::logic_error, 
00165         "GrouperBase::extractWeakForm could not cast "
00166         "unknown parameter to UnknownParameterElement");
00167       hasParam = true;
00168       rawParamID = dofID;
00169       reducedParamID = eqn.reducedFixedParamID(dofID);
00170     }
00171     else
00172     {
00173       TEUCHOS_TEST_FOR_EXCEPTION(d.isParameter(), std::logic_error,
00174         "Parameter not expected here");
00175       const UnknownFuncElement* u
00176         = dynamic_cast<const UnknownFuncElement*>(s);
00177       TEUCHOS_TEST_FOR_EXCEPTION(u==0, std::logic_error, 
00178         "GrouperBase::extractWeakForm could not cast "
00179         "unknown function to UnknownFuncElement");
00180       foundUnk = true;
00181       reducedUnkID = eqn.reducedUnkID(dofID);
00182       rawUnkID = dofID;
00183       unkBlock = eqn.blockForUnkID(dofID);
00184 
00185       SUNDANCE_MSG2(setupVerb(), 
00186         tab << "found reducedUnkID=" << reducedUnkID);
00187 
00188       unkBasis = UnknownFunctionData::getData(u)->basis()[myIndex];
00189       SUNDANCE_MSG2(setupVerb(), 
00190         tab << "found unkBasis=" << unkBasis);
00191 
00192       miUnk = d.opOnFunc().mi();
00193       SUNDANCE_MSG2(setupVerb(), 
00194         tab << "found unk multi index=" << miUnk.toString());
00195     }
00196   }
00197 
00198   if (!foundUnk) isOneForm = true;
00199 }

Site Contact