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 #include "DataSource/ACLVISFieldDataSource.h"
00028 #include "DataSource/ACLVISOperations.h"
00029 #include "DataSource/ACLVISDataConnect.h"
00030 #include "Field/Field.h"
00031 #include "Message/Communicate.h"
00032 #include "Utility/IpplInfo.h"
00033 #include "Utility/Pstring.h"
00034
00035
00037
00038
00039 template<class T, unsigned Dim, class M, class C>
00040 ACLVISFieldDataSource<T,Dim,M,C>::ACLVISFieldDataSource(const char *nm,
00041 DataConnect *dc,
00042 int tm,
00043 Field<T,Dim,M,C>& F)
00044 : FieldDataSource<T,Dim,M,C>(nm, dc, tm, F) {
00045
00046 TAU_TYPE_STRING(taustr, "void (char *, DataConnect *, int, " + CT(F) +
00047 ", unsigned)");
00048 TAU_PROFILE("ACLVISFieldDataSource::ACLVISFieldDataSource()", taustr,
00049 TAU_VIZ);
00050
00051
00052
00053
00054
00055
00056 LocalData = 0;
00057 object_name = (char *)NULL;
00058 string filestring = "aclvis";
00059 if (string(dc->ID()) != filestring) {
00060 ERRORMSG("Illegal DataConnect object for ACLVIS Data Object." << endl);
00061 ACLVISConnection = 0;
00062 Connection = 0;
00063 } else if (tm != DataSource::OUTPUT) {
00064 ERRORMSG("ACLVIS data connections may only be of type OUTPUT." << endl);
00065 ACLVISConnection = 0;
00066 Connection = 0;
00067 } else {
00068 ACLVISConnection = (ACLVISDataConnect *)dc;
00069
00070
00071
00072
00073 if (dc->onConnectNode()) {
00074
00075 LocalData = new ReadFieldTool;
00076 object_name = new char[strlen(nm)+2];
00077 strcpy(object_name,nm);
00078
00079
00080 ACLVISConnection->getConnection()->connect((void *)this, (char *)nm,
00081 LocalData, FieldDataType);
00082 }
00083 }
00084 }
00085
00086
00088
00089 template<class T, unsigned Dim, class M, class C>
00090 ACLVISFieldDataSource<T,Dim,M,C>::~ACLVISFieldDataSource() {
00091 TAU_TYPE_STRING(taustr, CT(*this) + " void ()");
00092 TAU_PROFILE("ACLVISFieldDataSource::~ACLVISFieldDataSource()", taustr,
00093 TAU_VIZ);
00094
00095
00096 if (ACLVISConnection->onConnectNode() && connected()) {
00097
00098 #ifdef IPPL_LUX
00099 ACLVISConnection->getConnection()->disconnect(object_name);
00100 #else
00101 ACLVISConnection->getConnection()->disconnect((void *)this);
00102 #endif
00103
00104
00105 if (LocalData != 0) {
00106 delete LocalData;
00107 if(object_name)
00108 delete [] object_name;
00109 }
00110 }
00111 }
00112
00113
00115
00116 template<class T, unsigned Dim, class M, class C>
00117 void ACLVISFieldDataSource<T,Dim,M,C>::set_mesh(Field<T,Dim,M,C>& F) {
00118 TAU_TYPE_STRING(taustr, CT(*this) + " set_mesh (" + CT(F) + ")");
00119 TAU_PROFILE("ACLVISFieldDataSource::set_mesh()", taustr, TAU_VIZ);
00120
00121
00122 if (ACLVISConnection->onConnectNode() && connected()) {
00123
00124 int size[3];
00125 for (unsigned i=0; i < 3; i++)
00126 size[i] = (i < Dim ? F.getDomain()[i].length() : 1);
00127 LocalData->SetDimensions(size);
00128
00129
00130 unsigned int sdim;
00131 float spacing[3], origin[3];
00132 NDIndex<Dim> mo;
00133 for (sdim=0; sdim < Dim; ++sdim)
00134 mo[sdim] = Index(1);
00135 typename M::MeshVektor_t morigin = F.get_mesh().get_origin();
00136 typename M::MeshVektor_t mspacing = F.get_mesh().getDeltaVertex(mo);
00137 for (sdim=0; sdim < 3; ++sdim) {
00138 origin[sdim] = (sdim < Dim ? (float)(morigin[sdim]) : 0.0);
00139 spacing[sdim] = (sdim < Dim ? (float)(mspacing[sdim]) : 0.0);
00140 }
00141
00142
00143 LocalData->SetAspectRatio(spacing);
00144 LocalData->SetOrigin(origin);
00145 }
00146 }
00147
00148
00150
00151
00152 template<class T, unsigned Dim, class M, class C>
00153 bool ACLVISFieldDataSource<T,Dim,M,C>::update() {
00154 TAU_TYPE_STRING(taustr, CT(*this) + " bool ()");
00155 TAU_PROFILE("ACLVISFieldDataSource::update()", taustr, TAU_VIZ);
00156
00157 if (ACLVISConnection->onConnectNode() && connected()) {
00158
00159 LocalData->GetVizData()->InitData(MyField.getDomain().size(),
00160 ACLVISTraits<ReadFieldTool,T>::getType());
00161 }
00162
00163
00164 set_mesh(MyField);
00165
00166
00167 gather_data();
00168
00169 if (ACLVISConnection->onConnectNode() && connected()) {
00170
00171 LocalData->PrepareFinishedData();
00172
00173
00174 #ifdef IPPL_LUX
00175 ACLVISConnection->getConnection()->update(object_name);
00176 #else
00177 ACLVISConnection->getConnection()->update((void *)this);
00178 #endif
00179 }
00180
00181 return true;
00182 }
00183
00184
00186
00187
00188
00189 template<class T, unsigned Dim, class M, class C>
00190 void ACLVISFieldDataSource<T,Dim,M,C>::interact(const char *str) {
00191 TAU_TYPE_STRING(taustr, CT(*this) + " void ()");
00192 TAU_PROFILE("ACLVISFieldDataSource::interact()", taustr, TAU_VIZ);
00193
00194
00195
00196
00197 if (ACLVISConnection->onConnectNode() && connected()) {
00198 if (str != 0 && *str != 0) {
00199 #ifndef IPPL_LUX
00200 ACLVISConnection->getConnection()->InterpretCommand(str);
00201 #endif
00202 } else {
00203 #ifdef IPPL_LUX
00204 ACLVISConnection->getConnection()->Interact();
00205 #else
00206 ACLVISConnection->getConnection()->Interact(1);
00207 #endif
00208 }
00209 }
00210 }
00211
00212
00214
00215
00216 template<class T, unsigned Dim, class M, class C >
00217 void ACLVISFieldDataSource<T,Dim,M,C>::insert_data(
00218 const NDIndex<Dim>& dom,
00219 CompressedBrickIterator<T,Dim> rhs) {
00220
00221 TAU_TYPE_STRING(taustr, CT(*this) + " void (" + CT(dom) + ", " +
00222 CT(rhs) + " )" );
00223 TAU_PROFILE("ACLVISFieldDataSource::insert_data()", taustr, TAU_VIZ);
00224
00225
00226 if (! connected())
00227 return;
00228
00229
00230
00231 int Stride[Dim], Length[Dim], Count[Dim], i;
00232 int indx = 0, n = 1;
00233 for (i=0; i < Dim; ++i) {
00234 Count[i] = 0;
00235 Stride[i] = n;
00236 Length[i] = dom[i].length();
00237 indx += n*(dom[i].first() - (MyField.getDomain())[i].first());
00238 n *= (MyField.getDomain())[i].length();
00239 }
00240
00241
00242 for (unsigned items = dom.size(); items > 0; --items, ++rhs) {
00243
00244 ACLVISTraits<ReadFieldTool,T>::setPoint(LocalData, indx, *rhs);
00245
00246
00247 for (i=0; i < Dim; ++i) {
00248 indx += Stride[i];
00249 if (++Count[i] == Length[i]) {
00250 Count[i] = 0;
00251 indx -= (Stride[i] * Length[i]);
00252 } else {
00253 break;
00254 }
00255 }
00256 }
00257 }
00258
00259
00260
00261
00262
00263
00264