00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042 #include "SundanceDiscreteFunctionData.hpp"
00043 #include "SundanceOut.hpp"
00044 #include "PlayaTabs.hpp"
00045 #include "SundanceMaximalCellFilter.hpp"
00046 #include "SundanceCellFilter.hpp"
00047 #include "SundanceCellSet.hpp"
00048 #include "SundanceSubtypeEvaluator.hpp"
00049
00050
00051 #ifndef HAVE_TEUCHOS_EXPLICIT_INSTANTIATION
00052 #include "PlayaVectorImpl.hpp"
00053 #endif
00054
00055
00056 using namespace Sundance;
00057 using namespace Teuchos;
00058
00059
00060
00061
00062 DiscreteFunctionData::DiscreteFunctionData(const DiscreteSpace& space)
00063 : DiscreteFuncDataStub(),
00064 space_(space),
00065 vector_(space_.createVector()),
00066 ghostView_(),
00067 ghostsAreValid_(false)
00068 {}
00069
00070 DiscreteFunctionData::DiscreteFunctionData(const DiscreteSpace& space,
00071 const double& constantValue)
00072 : DiscreteFuncDataStub(),
00073 space_(space),
00074 vector_(space_.createVector()),
00075 ghostView_(),
00076 ghostsAreValid_(false)
00077 {
00078 vector_.setToConstant(constantValue);
00079 }
00080
00081 DiscreteFunctionData::DiscreteFunctionData(const DiscreteSpace& space,
00082 const Vector<double>& vector)
00083 : DiscreteFuncDataStub(),
00084 space_(space),
00085 vector_(vector),
00086 ghostView_(),
00087 ghostsAreValid_(false)
00088 {}
00089
00090 const DiscreteFunctionData* DiscreteFunctionData::getData(const DiscreteFuncElement* dfe)
00091 {
00092 TEUCHOS_TEST_FOR_EXCEPTION(dfe==0, std::runtime_error, "null argument to DiscreteFunctionData::getData()");
00093 RCP<const DiscreteFunctionData> rtn
00094 = rcp_dynamic_cast<const DiscreteFunctionData>(dfe->commonData());
00095 TEUCHOS_TEST_FOR_EXCEPTION(rtn.get()==0, std::runtime_error,
00096 "cast to DiscreteFunctionData* failed for "
00097 "discrete function element " << dfe->toXML());
00098 return rtn.get();
00099 }
00100
00101 DiscreteFunctionData* DiscreteFunctionData::getData(DiscreteFuncElement* dfe)
00102 {
00103 TEUCHOS_TEST_FOR_EXCEPTION(dfe==0, std::runtime_error, "null argument to DiscreteFunctionData::getData()");
00104 DiscreteFunctionData* rtn
00105 = dynamic_cast<DiscreteFunctionData*>(dfe->commonData());
00106 TEUCHOS_TEST_FOR_EXCEPTION(rtn==0, std::runtime_error,
00107 "cast to DiscreteFunctionData* failed for "
00108 "discrete function element " << dfe->toXML());
00109 return rtn;
00110 }
00111
00112 void DiscreteFunctionData::setVector(const Vector<double>& vec)
00113 {
00114 ghostsAreValid_ = false;
00115 vector_ = vec;
00116 }
00117
00118 void DiscreteFunctionData::updateGhosts() const
00119 {
00120 if (!ghostsAreValid_)
00121 {
00122 space_.importGhosts(vector_, ghostView_);
00123 ghostsAreValid_ = true;
00124 }
00125 }
00126
00127
00128 RCP<const MapStructure> DiscreteFunctionData
00129 ::getLocalValues(int cellDim,
00130 const Array<int>& cellLID,
00131 Array<Array<double> >& localValues) const
00132 {
00133 Tabs tab;
00134
00135 if (Evaluator::classVerbosity() > 3)
00136 {
00137 Out::os() << tab << "getting DF local values" << std::endl;
00138 }
00139 updateGhosts();
00140
00141 const RCP<DOFMapBase>& map = space_.map();
00142 Array<Array<int> > dofs;
00143 Array<int> nNodes;
00144
00145 RCP<const Set<int> > requestedFuncs = map->allowedFuncsOnCellBatch(cellDim,
00146 cellLID);
00147
00148 RCP<const MapStructure> s = map->getDOFsForCellBatch(cellDim, cellLID,
00149 *requestedFuncs,
00150 dofs, nNodes, Evaluator::classVerbosity());
00151 localValues.resize(s->numBasisChunks());
00152
00153
00154 if (space_.getTransformation()->validTransformation())
00155 {
00156 SUNDANCE_OUT( Evaluator::classVerbosity() > 3 , "DiscreteFunctionData::getLocalValues() VALID TRAFO FOUND ... ")
00157 for (int b=0; b<nNodes.size(); b++)
00158 {
00159 int nFuncs = s->numFuncs(b);
00160 Array<int> functionIDs = s->funcs(b);
00161 localValues[b].resize(nFuncs*nNodes[b]*cellLID.size());
00162
00163
00164 ghostView_->getElements(&(dofs[b][0]), dofs[b].size(), localValues[b]);
00165
00166
00167
00168 space_.getTransformation()->getDoFsWithTransformation(
00169 dofs[b] , functionIDs , b , nNodes[b] , nFuncs , cellDim, cellLID ,ghostView_ , localValues[b] );
00170 }
00171 }
00172 else
00173 {
00174 SUNDANCE_OUT( Evaluator::classVerbosity() > 3 , "DiscreteFunctionData::getLocalValues() NO VALID TRAFO ... ")
00175 for (int b=0; b<nNodes.size(); b++)
00176 {
00177 int nFuncs = s->numFuncs(b);
00178 localValues[b].resize(nFuncs*nNodes[b]*cellLID.size());
00179 ghostView_->getElements(&(dofs[b][0]), dofs[b].size(), localValues[b]);
00180 }
00181 }
00182
00183 return s;
00184 }
00185
00186
00187