vtf-logo

V3Visualizer.h

00001 // -*- C++ -*-
00002 
00003 // Copyright (C) 2002 Ralf Deiterding
00004 // Brandenburgische Universitaet Cottbus
00005 //
00006 // Copyright (C) 2003-2007 California Institute of Technology
00007 // Ralf Deiterding, ralf@amroc.net
00008 
00009 #ifndef AMROC_V3VISUALIZER_H
00010 #define AMROC_V3VISUALIZER_H
00011 
00020 #include <wsdepend.h>
00021 
00022 #include "HDFToV3/V3VisualGrid.h"
00023 #include "HDFToV3/FileEventhandler.h"  
00024 
00025 extern "C" {
00026  void V3SURFACE(int nsurf[][2], int surf[], int scel[][4], char tsurf[][20]);
00027  void V3GRID(float xyz[][3]);
00028  void V3SCAL(int *key, float v[]);
00029  void V3DRAW3D(int *istat);
00030  void V3EQUIV(int listequiv[][2]);
00031  void V3VECT (int *key, float v[][3]);
00032  void V3PEVENTS(int *iwin, int *type, int *xe, int *ye, int *state);
00033 }              
00034                   
00035 
00036 V3VisualGridBase *Grid;
00037 FileEventHandler FileEvents;
00038 
00039 
00052 class V3Visualizer {
00053 public:
00054   V3Visualizer() {}
00055   
00056   void Show(int step, std::string* solvername, std::string* inputname,
00057             std::string** filenames, int Nfilenames, V3VisualGridBase* gr) {
00058 
00059     remove(".Visual3.struc");
00060     Grid = gr;
00061     std::string sname;
00062     if (solvername) sname = *solvername;
00063     else sname = "solver.in";
00064     std::ifstream infile;
00065     infile.open(sname.c_str(), std::ios::in);
00066     if (!infile) {
00067       std::cerr << sname << " not found. Aborting." << std::endl;
00068       std::exit(-1);
00069     } 
00070     infile.close();
00071 
00072     ControlDevice DisplayCtrl(GetFileControlDevice(sname.c_str(),""));
00073     Grid->register_at(DisplayCtrl,"");
00074     DisplayCtrl.update();     
00075     Grid->SetUpdateName(inputname);
00076     Grid->update();  
00077 
00078     if (Grid->SetUp(step,filenames,Nfilenames) < 0) {
00079       std::cerr << "Nothing read in. Aborting." << std::endl;
00080       std::exit(-1);
00081     } 
00082     std::cerr << Grid->Size() << " Grids constructed from all levels."
00083               << std::endl;  
00084     FileEvents.SetStep(step);
00085     
00086     // The important declarations needed for Visual3;
00087     
00088     // Generating standard spec.col if file is missing; 
00089     std::ofstream outfile;
00090     int i;
00091     outfile.precision(4);
00092     infile.open("spec.col", std::ios::in);
00093     if (!infile) {
00094       outfile.open("spec.col", std::ios::out);
00095       outfile << 256 << "    " << 2 << std::endl;
00096       for(i=0;i<64;i++){
00097         outfile << "0.0000    " << i/64.0 << "    1.0000" << std::endl;
00098       }
00099 
00100       for(i=0;i<64;i++){
00101         outfile << "0.0000    1.0000    " << 1-i/64.0 << std::endl;
00102       }
00103 
00104       for(i=0;i<64;i++){
00105         outfile << i/64.0 << "    1.0000    0.0000" << std::endl;
00106       }
00107       for(i=1;i<65;i++){
00108         outfile << "1.0000    " << 1-i/64.0 << "    0.0000" << std::endl;
00109       }
00110       outfile << "0.0000    0.0000    0.0000" << std::endl;
00111       outfile << "1.0000    1.0000    1.0000" << std::endl;
00112 
00113       outfile.close();
00114     }
00115     else{
00116       infile.close();
00117     }
00118     
00119     
00120     char cmf[] = "spec.col";
00121     int len_cmf = std::strlen(cmf); 
00122     
00123     char titl[LEN_TKEYS];
00124     int len_titl = strcpn(titl, Grid->Title());
00125 
00126     int win3d = 1; 
00127     int num_keys = Grid->NKeys() + (Grid->Equiv() ? 1000 : 0);
00128 
00129     std::cerr << "Limits:" << std::endl;
00130 
00131     int lus = 99;    
00132     int iopt = 0; // steady grid and steady data   
00133     int mirror = 0;// no miyrroring  
00134     int knode = 0;// number of non-block nodes  
00135     int kcel1 = 0;// no tetrahedras  
00136     int kcel2 = 0; // no pyramids 
00137     int kcel3 = 0; // no prisms
00138     int kcel4 = 0;// hexahedras 
00139     int knptet = 0;// no poly-tetrahedral strips
00140     int kptet = 0;// no cells in any polytetrahedra
00141     int knblock = Grid->Size();// structured blocks
00142   
00143     int *blocks;          
00144     blocks = new int[3*knblock];// structured blocks definitions
00145     Grid->SetBlocks(blocks);    
00146     
00147     if (Grid->Equiv()) 
00148       Grid->FindNodePairs(); 
00149     int kequiv = (Grid->Equiv() ? Grid->Kequiv() : 0);
00150     
00151     std::cerr << " Found "  << kequiv << " matching node pairs." << std::endl;
00152     
00153     std::cerr << "my calculated ksurf: " << Grid->NFacetsOnSurface()
00154               << std::endl;
00155     int ksurf = Grid->NFacetsOnSurface(); // number of domain surfaces
00156     int knsurf = 6; // number of domain surface groups
00157     
00158     
00159     // call Visual3 
00160     // note string lengths are appended onto the stack as FORTRAN
00161     // expects them to be there.
00162     
00163     V3_INIT(titl, &iopt, cmf, &lus, &win3d, &num_keys, Grid->KeyboardKeys(),
00164             Grid->TitleKeys(), Grid->FunctionsKeys(), Grid->Mvals(), &mirror,
00165             &knode, &kequiv, &kcel1, &kcel2, &kcel3, &kcel4, &knptet, &kptet,
00166             &knblock, blocks, &ksurf, &knsurf, len_titl, len_cmf, LEN_TKEYS);
00167  
00168     delete [] blocks; 
00169   }
00170 };
00171 
00172 
00173 void V3SURFACE (int nsurf[][2], int surf[], int scel[][4], char tsurf[][20])
00174 { 
00175   Grid->SetSurfaces(nsurf, surf, scel, tsurf);
00176 }
00177   
00178 void V3GRID(float xyz[][3])
00179 { 
00180   Grid->SetGrid(xyz);  
00181 }
00182   
00183 void V3SCAL (int *key, float v[])
00184 {
00185   Grid->SetScal(key,v);
00186 }
00187 
00188 void V3VECT (int *key, float v[][3])
00189 {
00190   Grid->Vect(key,v);
00191 } 
00192   
00193 void V3DRAW3D(int* istat)
00194 {
00195   if (*istat == 0)  
00196     Grid->Draw3D();            
00197 }
00198 
00199 void V3EQUIV(int listequiv[][2])
00200 {  
00201   Grid->SetNodePairs(listequiv);
00202 } 
00203         
00204 void V3PEVENTS(int *iwin, int *type, int *xe, int *ye, int *state) {
00205   FileEvents.ProcessEvent(iwin, type, xe, ye, state);
00206 }
00207 
00208 #endif

Generated on Fri Aug 24 13:00:31 2007 for AMROC's HDF Tools - by  doxygen 1.4.7