00001
00002
00003
00004
00005
00006
00007 #include "Albany_Catalyst_EpetraDataArray.hpp"
00008
00009 #include <Shards_BasicTopologies.hpp>
00010
00011 #include <Teuchos_TestForException.hpp>
00012
00013 #include <vtkIdList.h>
00014 #include <vtkIdTypeArray.h>
00015 #include <vtkObjectFactory.h>
00016 #include <vtkVariantCast.h>
00017
00018 namespace Albany {
00019 namespace Catalyst {
00020
00021 vtkStandardNewMacro(EpetraDataArray)
00022
00023 void EpetraDataArray::PrintSelf(ostream &os, vtkIndent indent)
00024 {
00025 this->Superclass::PrintSelf(os, indent);
00026 }
00027
00028 void EpetraDataArray::SetEpetraVector(const Epetra_Vector &vector)
00029 {
00030 this->Data = &vector;
00031 this->NumberOfComponents = 1;
00032 this->Size = static_cast<vtkIdType>(vector.MyLength());
00033 this->MaxId = this->Size - 1;
00034 }
00035
00036 void EpetraDataArray::Initialize()
00037 {
00038 this->Data = NULL;
00039 this->Size = 0;
00040 this->MaxId = -1;
00041 }
00042
00043 void EpetraDataArray::GetTuples(vtkIdList *ptIds, vtkAbstractArray *output)
00044 {
00045 vtkDataArray *da = vtkDataArray::FastDownCast(output);
00046 TEUCHOS_TEST_FOR_EXCEPTION(!da, std::runtime_error,
00047 "GetTuples must be given a vtkDataArray arg.");
00048
00049 da->Reset();
00050 da->SetNumberOfComponents(1);
00051 da->Allocate(ptIds->GetNumberOfIds());
00052
00053 vtkIdType *begin = ptIds->GetPointer(0);
00054 vtkIdType *end = ptIds->GetPointer(ptIds->GetNumberOfIds());
00055 while (begin != end)
00056 da->InsertNextTuple1((*this->Data)[*(begin++)]);
00057 }
00058
00059 void EpetraDataArray::GetTuples(vtkIdType p1, vtkIdType p2,
00060 vtkAbstractArray *output)
00061 {
00062 vtkDataArray *da = vtkDataArray::FastDownCast(output);
00063 TEUCHOS_TEST_FOR_EXCEPTION(!da, std::runtime_error,
00064 "GetTuples must be given a vtkDataArray arg.");
00065
00066 da->Reset();
00067 da->SetNumberOfComponents(1);
00068 da->Allocate(p2 - p1 + 1);
00069
00070 while (p1 <= p2)
00071 da->InsertNextTuple1((*this->Data)[p1++]);
00072 }
00073
00074 void EpetraDataArray::Squeeze()
00075 {
00076 }
00077
00078 vtkArrayIterator *EpetraDataArray::NewIterator()
00079 {
00080 TEUCHOS_TEST_FOR_EXCEPTION(true, std::runtime_error,
00081 "Method not implemented.");
00082 return NULL;
00083 }
00084
00085 vtkIdType EpetraDataArray::LookupValue(vtkVariant value)
00086 {
00087 bool valid = false;
00088 double tmp = vtkVariantCast<double>(value, &valid);
00089 if (valid)
00090 return this->Lookup(tmp, 0);
00091 return -1;
00092 }
00093
00094 void EpetraDataArray::LookupValue(vtkVariant value, vtkIdList *ids)
00095 {
00096 bool valid = false;
00097 double tmp = vtkVariantCast<double>(value, &valid);
00098 ids->Reset();
00099 if (valid) {
00100 vtkIdType index = 0;
00101 while ((index = this->Lookup(tmp, index)) >= 0)
00102 ids->InsertNextId(index++);
00103 }
00104 }
00105
00106 vtkVariant EpetraDataArray::GetVariantValue(vtkIdType idx)
00107 {
00108 return vtkVariant((*this->Data)[idx]);
00109 }
00110
00111 void EpetraDataArray::ClearLookup()
00112 {
00113
00114 }
00115
00116 double *EpetraDataArray::GetTuple(vtkIdType i)
00117 {
00118 this->TmpDouble = (*this->Data)[i];
00119 return &this->TmpDouble;
00120 }
00121
00122 void EpetraDataArray::GetTuple(vtkIdType i, double *tuple)
00123 {
00124 *tuple = (*this->Data)[i];
00125 }
00126
00127 vtkIdType EpetraDataArray::LookupTypedValue(ValueType value)
00128 {
00129 return this->Lookup(value, 0);
00130 }
00131
00132 void EpetraDataArray::LookupTypedValue(ValueType value, vtkIdList *ids)
00133 {
00134 ids->Reset();
00135 vtkIdType index = 0;
00136 while ((index = this->Lookup(value, index)) >= 0)
00137 ids->InsertNextId(index++);
00138 }
00139
00140 int EpetraDataArray::Allocate(vtkIdType sz, vtkIdType ext)
00141 {
00142 TEUCHOS_TEST_FOR_EXCEPTION(true, std::runtime_error, "Read-only container.");
00143 return 0;
00144 }
00145
00146 int EpetraDataArray::Resize(vtkIdType numTuples)
00147 {
00148 TEUCHOS_TEST_FOR_EXCEPTION(true, std::runtime_error, "Read-only container.");
00149 return 0;
00150 }
00151
00152 void EpetraDataArray::SetNumberOfTuples(vtkIdType number)
00153 {
00154 TEUCHOS_TEST_FOR_EXCEPTION(true, std::runtime_error, "Read-only container.");
00155 }
00156
00157 void EpetraDataArray::SetTuple(vtkIdType i, vtkIdType j,
00158 vtkAbstractArray *source)
00159 {
00160 TEUCHOS_TEST_FOR_EXCEPTION(true, std::runtime_error, "Read-only container.");
00161 }
00162
00163 void EpetraDataArray::SetTuple(vtkIdType i, const float *source)
00164 {
00165 TEUCHOS_TEST_FOR_EXCEPTION(true, std::runtime_error, "Read-only container.");
00166 }
00167
00168 void EpetraDataArray::SetTuple(vtkIdType i, const double *source)
00169 {
00170 TEUCHOS_TEST_FOR_EXCEPTION(true, std::runtime_error, "Read-only container.");
00171 }
00172
00173 void EpetraDataArray::InsertTuple(vtkIdType i, vtkIdType j,
00174 vtkAbstractArray *source)
00175 {
00176 TEUCHOS_TEST_FOR_EXCEPTION(true, std::runtime_error, "Read-only container.");
00177 }
00178
00179 void EpetraDataArray::InsertTuple(vtkIdType i, const float *source)
00180 {
00181 TEUCHOS_TEST_FOR_EXCEPTION(true, std::runtime_error, "Read-only container.");
00182 }
00183
00184 void EpetraDataArray::InsertTuple(vtkIdType i, const double *source)
00185 {
00186 TEUCHOS_TEST_FOR_EXCEPTION(true, std::runtime_error, "Read-only container.");
00187 }
00188
00189 void EpetraDataArray::InsertTuples(vtkIdList *dstIds, vtkIdList *srcIds,
00190 vtkAbstractArray *source)
00191 {
00192 TEUCHOS_TEST_FOR_EXCEPTION(true, std::runtime_error, "Read-only container.");
00193 }
00194
00195 vtkIdType EpetraDataArray::InsertNextTuple(vtkIdType j,
00196 vtkAbstractArray *source)
00197 {
00198 TEUCHOS_TEST_FOR_EXCEPTION(true, std::runtime_error, "Read-only container.");
00199 return -1;
00200 }
00201
00202 vtkIdType EpetraDataArray::InsertNextTuple(const float *source)
00203 {
00204 TEUCHOS_TEST_FOR_EXCEPTION(true, std::runtime_error, "Read-only container.");
00205 return -1;
00206 }
00207
00208 vtkIdType EpetraDataArray::InsertNextTuple(const double *source)
00209 {
00210 TEUCHOS_TEST_FOR_EXCEPTION(true, std::runtime_error, "Read-only container.");
00211 return -1;
00212 }
00213
00214 void EpetraDataArray::DeepCopy(vtkAbstractArray *aa)
00215 {
00216 TEUCHOS_TEST_FOR_EXCEPTION(true, std::runtime_error, "Read-only container.");
00217 }
00218
00219 void EpetraDataArray::DeepCopy(vtkDataArray *da)
00220 {
00221 TEUCHOS_TEST_FOR_EXCEPTION(true, std::runtime_error, "Read-only container.");
00222 }
00223
00224 void EpetraDataArray::InterpolateTuple(vtkIdType i, vtkIdList *ptIndices,
00225 vtkAbstractArray *source,
00226 double *weights)
00227 {
00228 TEUCHOS_TEST_FOR_EXCEPTION(true, std::runtime_error, "Read-only container.");
00229 }
00230
00231 void EpetraDataArray::InterpolateTuple(vtkIdType i, vtkIdType id1,
00232 vtkAbstractArray *source1, vtkIdType id2,
00233 vtkAbstractArray *source2, double t)
00234 {
00235 TEUCHOS_TEST_FOR_EXCEPTION(true, std::runtime_error, "Read-only container.");
00236 }
00237
00238 void EpetraDataArray::SetVariantValue(vtkIdType idx, vtkVariant value)
00239 {
00240 TEUCHOS_TEST_FOR_EXCEPTION(true, std::runtime_error, "Read-only container.");
00241 }
00242
00243 void EpetraDataArray::RemoveTuple(vtkIdType id)
00244 {
00245 TEUCHOS_TEST_FOR_EXCEPTION(true, std::runtime_error, "Read-only container.");
00246 }
00247
00248 void EpetraDataArray::RemoveFirstTuple()
00249 {
00250 TEUCHOS_TEST_FOR_EXCEPTION(true, std::runtime_error, "Read-only container.");
00251 }
00252
00253 void EpetraDataArray::RemoveLastTuple()
00254 {
00255 TEUCHOS_TEST_FOR_EXCEPTION(true, std::runtime_error, "Read-only container.");
00256 }
00257
00258 void EpetraDataArray::SetTupleValue(vtkIdType i, const ValueType *t)
00259 {
00260 TEUCHOS_TEST_FOR_EXCEPTION(true, std::runtime_error, "Read-only container.");
00261 }
00262
00263 void EpetraDataArray::InsertTupleValue(vtkIdType i, const ValueType *t)
00264 {
00265 TEUCHOS_TEST_FOR_EXCEPTION(true, std::runtime_error, "Read-only container.");
00266 }
00267
00268 vtkIdType EpetraDataArray::InsertNextTupleValue(const ValueType *t)
00269 {
00270 TEUCHOS_TEST_FOR_EXCEPTION(true, std::runtime_error, "Read-only container.");
00271 return -1;
00272 }
00273
00274 void EpetraDataArray::SetValue(vtkIdType idx, ValueType value)
00275 {
00276 TEUCHOS_TEST_FOR_EXCEPTION(true, std::runtime_error, "Read-only container.");
00277 }
00278
00279 vtkIdType EpetraDataArray::InsertNextValue(ValueType v)
00280 {
00281 TEUCHOS_TEST_FOR_EXCEPTION(true, std::runtime_error, "Read-only container.");
00282 return -1;
00283 }
00284
00285 void EpetraDataArray::InsertValue(vtkIdType idx, ValueType v)
00286 {
00287 TEUCHOS_TEST_FOR_EXCEPTION(true, std::runtime_error, "Read-only container.");
00288 }
00289
00290 EpetraDataArray::EpetraDataArray()
00291 : Data(NULL)
00292 {
00293 }
00294
00295 EpetraDataArray::~EpetraDataArray()
00296 {
00297 }
00298
00299 vtkIdType EpetraDataArray::Lookup(double val, vtkIdType index)
00300 {
00301 while (index <= this->MaxId) {
00302 if ((*this->Data)[index] == val)
00303 return index;
00304 ++index;
00305 }
00306 return -1;
00307 }
00308
00309 }
00310 }