Main Page | Namespace List | Class Hierarchy | Class List | File List | Class Members | File Members

src/DataSource/ACLVISFieldDataSource.cpp

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 /***************************************************************************
00003  *
00004  * The IPPL Framework
00005  * 
00006  * This program was prepared by PSI. 
00007  * All rights in the program are reserved by PSI.
00008  * Neither PSI nor the author(s)
00009  * makes any warranty, express or implied, or assumes any liability or
00010  * responsibility for the use of this software
00011  *
00012  * Visit http://www.acl.lanl.gov/POOMS for more details
00013  *
00014  ***************************************************************************/
00015 
00016 // -*- C++ -*-
00017 /***************************************************************************
00018  *
00019  * The IPPL Framework
00020  * 
00021  *
00022  * Visit http://people.web.psi.ch/adelmann/ for more details
00023  *
00024  ***************************************************************************/
00025 
00026 // include files
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 // constructor: the name, the connection, the transfer method,
00038 // the field to connect, and the parent node.
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   // Inform dbgmsg("ACLVISFieldDataSource", INFORM_ALL_NODES);
00052   // dbgmsg << "Setting up new ACLVISFieldDataSource '" << nm << "'...";
00053   // dbgmsg << endl;
00054 
00055   // do general initialization
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     // only do connection on parent node
00071     // dbgmsg << "Doing viz field initialization on node " << Ippl::myNode();
00072     // dbgmsg << endl;
00073     if (dc->onConnectNode()) {
00074       // create a new ACLVIS structure to hold the data
00075       LocalData = new ReadFieldTool;
00076       object_name = new char[strlen(nm)+2];
00077       strcpy(object_name,nm);
00078 
00079       // ... then call ACLVIS API to register this data
00080       ACLVISConnection->getConnection()->connect((void *)this, (char *)nm,
00081                                                  LocalData, FieldDataType);
00082     }
00083   }
00084 }
00085 
00086 
00088 // destructor
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   // call ACLVIS API to unregister this data.
00096   if (ACLVISConnection->onConnectNode() && connected()) {
00097     // only do disconnection on parent node
00098 #ifdef IPPL_LUX
00099     ACLVISConnection->getConnection()->disconnect(object_name);
00100 #else  
00101     ACLVISConnection->getConnection()->disconnect((void *)this);
00102 #endif
00103 
00104     // delete ACLVIS storage
00105     if (LocalData != 0) {
00106       delete LocalData;
00107       if(object_name)
00108         delete [] object_name;
00109     }
00110   }
00111 }
00112 
00113 
00115 // a function to set the mesh characteristics of the ReadFieldTool
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   // only change mesh on parent node
00122   if (ACLVISConnection->onConnectNode() && connected()) {
00123     // set the dimension of each axis
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     // get the field mesh information
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     // store mesh data in ReadFieldTool
00143     LocalData->SetAspectRatio(spacing);
00144     LocalData->SetOrigin(origin);
00145   }
00146 }
00147 
00148 
00150 // Update the object, that is, make sure the receiver of the data has a
00151 // current and consistent snapshot of the current state.  Return success.
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     // tell the ACLVIS library what type and how much data to expect
00159     LocalData->GetVizData()->InitData(MyField.getDomain().size(),
00160                               ACLVISTraits<ReadFieldTool,T>::getType());
00161   }
00162 
00163   // update the mesh data
00164   set_mesh(MyField);
00165 
00166   // gather all the data into the vtk object
00167   gather_data();
00168 
00169   if (ACLVISConnection->onConnectNode() && connected()) {
00170     // give the data to the vtk data set
00171     LocalData->PrepareFinishedData();
00172 
00173     // on parent node, call ACLVIS API to update data
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 // Indicate to the receiver that we're allowing them time to manipulate the
00187 // data (e.g., for a viz program, to rotate it, change representation, etc.)
00188 // This should only return when the manipulation is done.
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   // on parent node, hand off control to ACLVIS API.  If a command string
00195   // is given, instead call the viz API function to execute it as an
00196   // interactive command.
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 // copy the data out of the given LField iterator (which is occupying the
00215 // given domain) and into the ACLVIS structure
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   // if we're not connected, just ignore the data
00226   if (! connected())
00227     return;
00228 
00229   // find the values needed to select where in the ACLVIS object to put the
00230   // data
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   // go through the data, and put it into the proper position
00242   for (unsigned items = dom.size(); items > 0; --items, ++rhs) {
00243     // copy the next element
00244     ACLVISTraits<ReadFieldTool,T>::setPoint(LocalData, indx, *rhs);
00245 
00246     // increment the index
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  * $RCSfile: ACLVISFieldDataSource.cpp,v $   $Author: adelmann $
00262  * $Revision: 1.1.1.1 $   $Date: 2003/01/23 07:40:24 $
00263  * IPPL_VERSION_ID: $Id: ACLVISFieldDataSource.cpp,v 1.1.1.1 2003/01/23 07:40:24 adelmann Exp $ 
00264  ***************************************************************************/

Generated on Fri Nov 2 01:25:55 2007 for IPPL by doxygen 1.3.5