Chaste Commit::baa90ac2819b962188b7562f2326be23c47859a7
VtkNonlinearElasticitySolutionWriter.cpp
1/*
2
3Copyright (c) 2005-2024, University of Oxford.
4All rights reserved.
5
6University of Oxford means the Chancellor, Masters and Scholars of the
7University of Oxford, having an administrative office at Wellington
8Square, Oxford OX1 2JD, UK.
9
10This file is part of Chaste.
11
12Redistribution and use in source and binary forms, with or without
13modification, are permitted provided that the following conditions are met:
14 * Redistributions of source code must retain the above copyright notice,
15 this list of conditions and the following disclaimer.
16 * Redistributions in binary form must reproduce the above copyright notice,
17 this list of conditions and the following disclaimer in the documentation
18 and/or other materials provided with the distribution.
19 * Neither the name of the University of Oxford nor the names of its
20 contributors may be used to endorse or promote products derived from this
21 software without specific prior written permission.
22
23THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
24AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
27LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
28CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
29GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
32OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33
34*/
35
36#include "VtkNonlinearElasticitySolutionWriter.hpp"
37#include "VtkMeshWriter.hpp"
38
39template<unsigned DIM>
41{
42 if (mpSolver->mOutputDirectory=="")
43 {
44 EXCEPTION("No output directory was given to the mechanics solver");
45 }
46
47#ifdef CHASTE_VTK
48 VtkMeshWriter<DIM, DIM> mesh_writer(mpSolver->mOutputDirectory + "/vtk", "solution", true);
49
50 // write the displacement
51 std::vector<c_vector<double,DIM> > displacement(mpSolver->mrQuadMesh.GetNumNodes());
52 std::vector<c_vector<double,DIM> >& r_spatial_solution = mpSolver->rGetSpatialSolution();
53 for (unsigned i=0; i<mpSolver->mrQuadMesh.GetNumNodes(); i++)
54 {
55 for (unsigned j=0; j<DIM; j++)
56 {
57 displacement[i](j) = r_spatial_solution[i](j)- mpSolver->mrQuadMesh.GetNode(i)->rGetLocation()[j];
58 }
59 }
60 mesh_writer.AddPointData("Displacement", displacement);
61
62 // write pressures
63 if (mpSolver->mCompressibilityType==INCOMPRESSIBLE)
64 {
65 mesh_writer.AddPointData("Pressure", mpSolver->rGetPressures());
66 }
67
68 // write the element attribute as cell data.
69 std::vector<double> element_attribute;
70 for (typename QuadraticMesh<DIM>::ElementIterator iter = mpSolver->mrQuadMesh.GetElementIteratorBegin();
71 iter != mpSolver->mrQuadMesh.GetElementIteratorEnd();
72 ++iter)
73 {
74 element_attribute.push_back(iter->GetAttribute());
75 }
76 mesh_writer.AddCellData("Attribute", element_attribute);
77
78 // write strains if requested
79 if (mWriteElementWiseStrains)
80 {
81 mTensorData.clear();
82 mTensorData.resize(mpSolver->mrQuadMesh.GetNumElements());
83
84 std::string name;
85 switch(mElementWiseStrainType)
86 {
87 case DEFORMATION_GRADIENT_F:
88 {
89 name = "deformation_gradient_F";
90 break;
91 }
92 case DEFORMATION_TENSOR_C:
93 {
94 name = "deformation_tensor_C";
95 break;
96 }
97 case LAGRANGE_STRAIN_E:
98 {
99 name = "Lagrange_strain_E";
100 break;
101 }
102 default:
103 {
105 }
106 }
107
108 for (typename AbstractTetrahedralMesh<DIM,DIM>::ElementIterator iter = mpSolver->mrQuadMesh.GetElementIteratorBegin();
109 iter != mpSolver->mrQuadMesh.GetElementIteratorEnd();
110 ++iter)
111 {
112 mpSolver->GetElementCentroidStrain(mElementWiseStrainType, *iter, mTensorData[iter->GetIndex()]);
113 }
114
115 mesh_writer.AddTensorCellData(name, mTensorData);
116 }
118// if (mWriteNodeWiseStresses)
119// {
120// std::vector<c_matrix<double,DIM,DIM> > tensor_data;
121// // use recoverer
122// mesh_writer.AddTensorCellData("Stress_NAME_ME", tensor_data);
123// }
124
125 // final write
126 mesh_writer.WriteFilesUsingMesh(mpSolver->mrQuadMesh);
127#endif // CHASTE_VTK
128}
129
130// Explicit instantiation
#define EXCEPTION(message)
#define NEVER_REACHED
void AddPointData(std::string name, std::vector< double > data)
void AddTensorCellData(std::string name, std::vector< c_vector< double, SPACE_DIM *(SPACE_DIM+1)/2 > > data)
void AddCellData(std::string name, std::vector< double > data)
void WriteFilesUsingMesh(AbstractTetrahedralMesh< ELEMENT_DIM, SPACE_DIM > &rMesh, bool keepOriginalElementIndexing=true)