CmguiWriter.hpp

00001 /*
00002 
00003 Copyright (C) University of Oxford, 2005-2009
00004 
00005 University of Oxford means the Chancellor, Masters and Scholars of the
00006 University of Oxford, having an administrative office at Wellington
00007 Square, Oxford OX1 2JD, UK.
00008 
00009 This file is part of Chaste.
00010 
00011 Chaste is free software: you can redistribute it and/or modify it
00012 under the terms of the GNU Lesser General Public License as published
00013 by the Free Software Foundation, either version 2.1 of the License, or
00014 (at your option) any later version.
00015 
00016 Chaste is distributed in the hope that it will be useful, but WITHOUT
00017 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00018 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
00019 License for more details. The offer of Chaste under the terms of the
00020 License is subject to the License being interpreted in accordance with
00021 English Law and subject to any action against the University of Oxford
00022 being under the jurisdiction of the English Courts.
00023 
00024 You should have received a copy of the GNU Lesser General Public License
00025 along with Chaste. If not, see <http://www.gnu.org/licenses/>.
00026 
00027 */
00028 
00029 #ifndef CMGUIWRITER_HPP_
00030 #define CMGUIWRITER_HPP_
00031 
00032 #include "AbstractMeshWriter.hpp"
00033 
00034 
00035 static const char CmguiNodeFileHeader[] = " #Fields=1\n\
00036  1) coordinates, coordinate, rectangular cartesian, #Components=3\n\
00037    x.  Value index= 1, #Derivatives= 0\n\
00038    y.  Value index= 2, #Derivatives= 0\n\
00039    z.  Value index= 3, #Derivatives= 0\n";
00040    
00041 static const char CmguiElementFileHeader[] = "Shape.  Dimension=3, simplex(2;3)*simplex*simplex\n\
00042  #Scale factor sets= 0\n\
00043  #Nodes= 4\n\
00044  #Fields=1\n\
00045  1) coordinates, coordinate, rectangular cartesian, #Components=3\n\
00046    x.  l.simplex(2;3)*l.simplex*l.simplex, no modify, standard node based.\n\
00047      #Nodes= 4\n\
00048       1.  #Values=1\n\
00049        Value indices:     1\n\
00050        Scale factor indices:   1\n\
00051       2.  #Values=1\n\
00052        Value indices:     1\n\
00053        Scale factor indices:   2\n\
00054       3.  #Values=1\n\
00055        Value indices:     1\n\
00056        Scale factor indices:   3\n\
00057       4.  #Values=1\n\
00058        Value indices:     1\n\
00059        Scale factor indices:   4\n\
00060    y.  l.simplex(2;3)*l.simplex*l.simplex, no modify, standard node based.\n\
00061      #Nodes= 4\n\
00062       1.  #Values=1\n\
00063        Value indices:     1\n\
00064        Scale factor indices:   1\n\
00065       2.  #Values=1\n\
00066        Value indices:     1\n\
00067        Scale factor indices:   2\n\
00068       3.  #Values=1\n\
00069        Value indices:     1\n\
00070        Scale factor indices:   3\n\
00071       4.  #Values=1\n\
00072        Value indices:     1\n\
00073        Scale factor indices:   4\n\
00074    z.  l.simplex(2;3)*l.simplex*l.simplex, no modify, standard node based.\n\
00075      #Nodes= 4\n\
00076       1.  #Values=1\n\
00077        Value indices:     1\n\
00078        Scale factor indices:   1\n\
00079       2.  #Values=1\n\
00080        Value indices:     1\n\
00081        Scale factor indices:   2\n\
00082       3.  #Values=1\n\
00083        Value indices:     1\n\
00084        Scale factor indices:   3\n\
00085       4.  #Values=1\n\
00086        Value indices:     1\n\
00087        Scale factor indices:   4\n";
00088 
00089 
00101 class CmguiWriter : public AbstractMeshWriter<3,3>
00102 {
00103 public:
00104     CmguiWriter(const std::string &rDirectory,
00105                 const std::string &rBaseName,
00106                 const bool &rCleanDirectory=true);
00107     void WriteFiles();
00108     virtual ~CmguiWriter()
00109     {}
00110 };
00111 
00112 
00113 CmguiWriter::CmguiWriter(const std::string &rDirectory,
00114                          const std::string &rBaseName,
00115                          const bool &rCleanDirectory)
00116         : AbstractMeshWriter<3,3>(rDirectory, rBaseName, rCleanDirectory)
00117 {
00118     this->mIndexFromZero=false;
00119 }
00120 
00121 void CmguiWriter::WriteFiles()
00122 {
00124     // Write the exnode file
00126     std::string node_file_name = this->mBaseName+".exnode";
00127     out_stream p_node_file = this->mpOutputFileHandler->OpenOutputFile(node_file_name);
00128 
00129     //Write the node header
00130     *p_node_file << "Group name: " << this->mBaseName << "\n";
00131     *p_node_file << CmguiNodeFileHeader;
00132 
00133     //Write each node's data
00134     for (unsigned item_num=0; item_num<this->GetNumNodes(); item_num++)
00135     {
00136         std::vector<double> current_item = this->mNodeData[item_num];
00137 
00138         *p_node_file << "Node:\t" << item_num+1 << "\t"; 
00139         for (unsigned i=0;i<3;i++)
00140         {
00141             *p_node_file << current_item[i] << "\t";
00142         }
00143 
00144         *p_node_file << "\n";
00145     }
00146     p_node_file->close();
00147 
00149     // Write the exlem file
00151     std::string elem_file_name = this->mBaseName+".exelem";
00152     out_stream p_elem_file = this->mpOutputFileHandler->OpenOutputFile(elem_file_name);
00153 
00154     //Write the elem header
00155     *p_elem_file << "Group name: " << this->mBaseName << "\n";
00156     *p_elem_file << CmguiElementFileHeader;
00157 
00158     //Write each elements's data
00159     for (unsigned item_num=0; item_num<this->GetNumElements(); item_num++)
00160     {
00161         std::vector<unsigned> current_element = this->mElementData[item_num];
00162 
00163         *p_elem_file << "Element:\t" << item_num+1 << " 0 0 Nodes:\t"; 
00164         for (unsigned i=0; i<4; i++)
00165         {
00166             *p_elem_file << current_element[i]+1 << "\t";
00167         }
00168 
00169         *p_elem_file << "\n";
00170     }
00171     p_elem_file->close();
00172     
00173 }
00174 
00175 #endif /*CMGUIWRITER_HPP_*/

Generated on Wed Mar 18 12:51:56 2009 for Chaste by  doxygen 1.5.5