36 #include "CmguiDeformedSolutionsWriter.hpp"
39 template<
unsigned DIM>
43 CmguiMeshWriteType writeType)
45 mpQuadraticMesh(&rQuadraticMesh),
51 if(p_quad_mesh == NULL)
53 EXCEPTION(
"CmguiDeformedSolutionsWriter only supports use of a QuadraticMesh");
58 if (writeType==WRITE_QUADRATIC_MESH)
93 unsigned reordering[6] = {0,5,1,4,3,2};
94 for (
unsigned i=0; i<6; i++)
111 unsigned reordering[10] = {0,4,1,6,5,2,7,8,9,3};
112 for (
unsigned i=0; i<10; i++)
126 template<
unsigned DIM>
129 std::string saved_base_name = this->mBaseName;
132 this->mBaseName = this->mBaseName +
"_0";
136 this->mBaseName = fileName;
138 this->WriteFilesUsingMesh(*mpQuadraticMesh);
139 this->mBaseName = saved_base_name;
142 template<
unsigned DIM>
146 if (mpQuadraticMesh->GetNumNodes() != rDeformedPositions.size() )
148 EXCEPTION(
"The size of rDeformedPositions does not match the number of nodes in the mesh");
151 mFinalCounter = counter;
152 std::stringstream node_file_name_stringstream;
153 node_file_name_stringstream << this->mBaseName <<
"_" << counter <<
".exnode";
155 out_stream p_node_file = this->mpOutputFileHandler->OpenOutputFile(node_file_name_stringstream.str());
157 this->WriteNodeFileHeader(p_node_file);
160 for (
unsigned index=0; index<this->GetNumNodes(); index++)
162 *p_node_file <<
"Node:\t" << index+1 <<
"\t";
164 for (
unsigned i=0; i<DIM; i++)
166 *p_node_file << rDeformedPositions[index](i) <<
"\t";
168 *p_node_file <<
"\n";
170 p_node_file->close();
173 template<
unsigned DIM>
176 std::string field_string =
"";
177 if (fieldBaseName !=
"")
179 field_string =
" gfx read node " + fieldBaseName +
"_$i time $i\n";
182 out_stream p_script_file = this->mpOutputFileHandler->OpenOutputFile(
"LoadSolutions.com");
183 *p_script_file <<
"#\n# Cmgui script automatically generated by Chaste\n#\n";
185 if(undeformedBaseName !=
"")
187 *p_script_file <<
"gfx read node " << undeformedBaseName <<
" time -1\n";
190 *p_script_file <<
"for ($i=0; $i<=" << mFinalCounter <<
"; $i++) { \n"
191 <<
" gfx read node " << this->mBaseName <<
"_$i time $i\n"
195 if(undeformedBaseName !=
"")
197 for (
unsigned region_index=0; region_index<this->mRegionNames.size(); region_index++)
199 *p_script_file <<
"gfx read ele " << this->mRegionNames[region_index] <<
"\n";
204 *p_script_file <<
"gfx read ele " << this->mBaseName <<
"_0\n";
206 *p_script_file <<
"gfx define faces egroup "<<this->mBaseName<<
"\n";
207 *p_script_file <<
"gfx modify g_element "<<this->mBaseName<<
" lines select_on material default spectrum default selected_material default_selected;\n";
208 *p_script_file <<
"gfx cr win\n\n";
209 p_script_file->close();
212 template<
unsigned DIM>
214 std::string inputFileBaseName,
215 unsigned finalCounter)
220 std::vector<c_vector<double,DIM> > deformed_position(mpQuadraticMesh->GetNumNodes(), zero_vector<double>(DIM));
222 for (
unsigned i=1; i<=finalCounter; i++)
224 std::stringstream in_file_stream;
225 in_file_stream << inputDirectory <<
"/" << inputFileBaseName <<
"_" << i <<
".nodes";
227 std::ifstream ifs(in_file_stream.str().c_str());
230 EXCEPTION(
"Could not open file: " + in_file_stream.str());
235 for (
unsigned index=0; index<mpQuadraticMesh->GetNumNodes(); index++)
237 for (
unsigned j=0; j<DIM; j++)
242 EXCEPTION(
"Error occurred when reading file " << in_file_stream.str()
243 <<
". Expected " << mpQuadraticMesh->GetNumNodes() <<
" rows and "
244 << DIM <<
" columns");
246 deformed_position[index](j) = data;
253 WriteDeformationPositions(deformed_position, i);
std::string mAdditionalFieldHeader
#define EXCEPTION(message)
virtual unsigned GetNumNodes() const
std::string mCoordinatesFileHeader
virtual unsigned GetNumVertices() const
std::string mElementFileHeader
unsigned mNumNodesPerElement
std::vector< unsigned > mReordering