VtkNonlinearElasticitySolutionWriter.cpp
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
00028
00029
00030
00031
00032
00033
00034
00035
00036 #include "VtkNonlinearElasticitySolutionWriter.hpp"
00037 #include "VtkMeshWriter.hpp"
00038
00039 template<unsigned DIM>
00040 void VtkNonlinearElasticitySolutionWriter<DIM>::Write()
00041 {
00042 if (mpSolver->mOutputDirectory=="")
00043 {
00044 EXCEPTION("No output directory was given to the mechanics solver");
00045 }
00046
00047 #ifdef CHASTE_VTK
00048 VtkMeshWriter<DIM, DIM> mesh_writer(mpSolver->mOutputDirectory + "/vtk", "solution", true);
00049
00050
00051 std::vector<c_vector<double,DIM> > displacement(mpSolver->mrQuadMesh.GetNumNodes());
00052 std::vector<c_vector<double,DIM> >& r_spatial_solution = mpSolver->rGetSpatialSolution();
00053 for(unsigned i=0; i<mpSolver->mrQuadMesh.GetNumNodes(); i++)
00054 {
00055 for(unsigned j=0; j<DIM; j++)
00056 {
00057 displacement[i](j) = r_spatial_solution[i](j)- mpSolver->mrQuadMesh.GetNode(i)->rGetLocation()[j];
00058 }
00059 }
00060 mesh_writer.AddPointData("Displacement", displacement);
00061
00062
00063 if (mpSolver->mCompressibilityType==INCOMPRESSIBLE)
00064 {
00065 mesh_writer.AddPointData("Pressure", mpSolver->rGetPressures());
00066 }
00067
00068
00069 std::vector<double> element_attribute;
00070 for(typename QuadraticMesh<DIM>::ElementIterator iter = mpSolver->mrQuadMesh.GetElementIteratorBegin();
00071 iter != mpSolver->mrQuadMesh.GetElementIteratorEnd();
00072 ++iter)
00073 {
00074 element_attribute.push_back(iter->GetAttribute());
00075 }
00076 mesh_writer.AddCellData("Attribute", element_attribute);
00077
00078
00079 if (mWriteElementWiseStrains)
00080 {
00081 mTensorData.clear();
00082 mTensorData.resize(mpSolver->mrQuadMesh.GetNumElements());
00083
00084 std::string name;
00085 switch(mElementWiseStrainType)
00086 {
00087 case DEFORMATION_GRADIENT_F:
00088 {
00089 name = "deformation_gradient_F";
00090 break;
00091 }
00092 case DEFORMATION_TENSOR_C:
00093 {
00094 name = "deformation_tensor_C";
00095 break;
00096 }
00097 case LAGRANGE_STRAIN_E:
00098 {
00099 name = "Lagrange_strain_E";
00100 break;
00101 }
00102 default:
00103 {
00104 NEVER_REACHED;
00105 }
00106 }
00107
00108 for (typename AbstractTetrahedralMesh<DIM,DIM>::ElementIterator iter = mpSolver->mrQuadMesh.GetElementIteratorBegin();
00109 iter != mpSolver->mrQuadMesh.GetElementIteratorEnd();
00110 ++iter)
00111 {
00112 mpSolver->GetElementCentroidStrain(mElementWiseStrainType, *iter, mTensorData[iter->GetIndex()]);
00113 }
00114
00115 mesh_writer.AddTensorCellData(name, mTensorData);
00116 }
00118
00119
00120
00121
00122
00123
00124
00125
00126 mesh_writer.WriteFilesUsingMesh(mpSolver->mrQuadMesh);
00127 #endif // CHASTE_VTK
00128 }
00129
00130
00132
00134
00135 template class VtkNonlinearElasticitySolutionWriter<2>;
00136 template class VtkNonlinearElasticitySolutionWriter<3>;
00137
00138