Chaste Commit::baa90ac2819b962188b7562f2326be23c47859a7
SolidMechanicsProblemDefinition.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
37#include "SolidMechanicsProblemDefinition.hpp"
38#include "AbstractIncompressibleMaterialLaw.hpp"
39#include "AbstractCompressibleMaterialLaw.hpp"
40
41template<unsigned DIM>
47
48template<unsigned DIM>
49void SolidMechanicsProblemDefinition<DIM>::SetFixedNodes(std::vector<unsigned>& rFixedNodes, std::vector<c_vector<double,DIM> >& rFixedNodeLocations)
50{
51 assert(rFixedNodes.size()==rFixedNodeLocations.size());
52 this->mDirichletNodes = rFixedNodes;
53
54 this->mDirichletNodeValues.clear();
55 for (unsigned i=0; i<this->mDirichletNodes.size(); i++)
56 {
57 unsigned index = this->mDirichletNodes[i];
58 c_vector<double,DIM> displacement;
59 for (unsigned j=0; j<DIM; j++)
60 {
61 double location = rFixedNodeLocations[i](j);
62
63 // Compute the displacement, assuming the node is not free in this direction
64 if (location != this->FREE)
65 {
66 displacement(j) = location - this->mrMesh.GetNode(index)->rGetLocation()[j];
67 }
68 else
69 {
70 displacement(j) = this->FREE;
71 }
72 }
73 this->mDirichletNodeValues.push_back(displacement);
74 }
75}
76
77template<unsigned DIM>
78void SolidMechanicsProblemDefinition<DIM>::SetMaterialLaw(CompressibilityType compressibilityType,
79 AbstractMaterialLaw<DIM>* pMaterialLaw)
80{
81 mIsHomogeneousMaterial = true;
82 mCompressibilityType = compressibilityType;
83
84 mIncompressibleMaterialLaws.clear();
85 mCompressibleMaterialLaws.clear();
86
87 assert(pMaterialLaw);
88
89 if (compressibilityType == INCOMPRESSIBLE)
90 {
92 CheckCastSuccess(compressibilityType, p_law);
93 mIncompressibleMaterialLaws.push_back(p_law);
94 }
95 else
96 {
98 CheckCastSuccess(compressibilityType, p_law);
99 mCompressibleMaterialLaws.push_back(p_law);
100 }
101}
102
103template<unsigned DIM>
104void SolidMechanicsProblemDefinition<DIM>::SetMaterialLaw(CompressibilityType compressibilityType,
105 std::vector<AbstractMaterialLaw<DIM>*>& rMaterialLaws)
106{
107 mIsHomogeneousMaterial = false;
108 mCompressibilityType = compressibilityType;
109
110 mIncompressibleMaterialLaws.clear();
111 mCompressibleMaterialLaws.clear();
112
113 assert(this->mrMesh.GetNumElements() == rMaterialLaws.size());
114
115 if (compressibilityType == INCOMPRESSIBLE)
116 {
117 for (unsigned i=0; i<rMaterialLaws.size(); i++)
118 {
119 assert(rMaterialLaws[i]);
121 CheckCastSuccess(compressibilityType, p_law);
122 mIncompressibleMaterialLaws.push_back(p_law);
123 }
124 }
125 else
126 {
127 for (unsigned i=0; i<rMaterialLaws.size(); i++)
128 {
129 assert(rMaterialLaws[i]);
130 AbstractCompressibleMaterialLaw<DIM>* p_law = dynamic_cast<AbstractCompressibleMaterialLaw<DIM>*>(rMaterialLaws[i]);
131 CheckCastSuccess(compressibilityType, p_law);
132 mCompressibleMaterialLaws.push_back(p_law);
133 }
134 }
135}
136
137template<unsigned DIM>
139{
140 // If this fails, SetMaterialLaw() hasn't been called
141 assert(mIncompressibleMaterialLaws.size()!=0 || mCompressibleMaterialLaws.size()!=0 );
142 return mIsHomogeneousMaterial;
143}
144
145template<unsigned DIM>
147{
148 // If this fails, SetMaterialLaw() hasn't been called
149 assert(mIncompressibleMaterialLaws.size()!=0 || mCompressibleMaterialLaws.size()!=0 );
150 return mCompressibilityType;
151}
152
153template<unsigned DIM>
155{
156 assert(mCompressibilityType==INCOMPRESSIBLE);
157 assert(mIncompressibleMaterialLaws.size()>0);
158 assert(mCompressibleMaterialLaws.size()==0);
159
160 if (mIsHomogeneousMaterial)
161 {
162 return mIncompressibleMaterialLaws[0];
163 }
164 else
165 {
166 assert(elementIndex < this->mrMesh.GetNumNodes());
167 return mIncompressibleMaterialLaws[elementIndex];
168 }
169}
170
171template<unsigned DIM>
173{
174 assert(mCompressibilityType == COMPRESSIBLE);
175 assert(mIncompressibleMaterialLaws.size() == 0);
176 assert(mCompressibleMaterialLaws.size() > 0);
177
178 if (mIsHomogeneousMaterial)
179 {
180 return mCompressibleMaterialLaws[0];
181 }
182 else
183 {
184 assert(elementIndex < this->mrMesh.GetNumNodes());
185 return mCompressibleMaterialLaws[elementIndex];
186 }
187}
188
189template<unsigned DIM>
190void SolidMechanicsProblemDefinition<DIM>::CheckCastSuccess(CompressibilityType compressibilityType,
191 AbstractMaterialLaw<DIM>* pMaterialLaw)
192{
193 if ((compressibilityType==INCOMPRESSIBLE) && (pMaterialLaw==nullptr))
194 {
195 // then dynamic_cast to AbstractIncompressibleMaterialLaw failed
196 EXCEPTION("Compressibility type was declared as INCOMPRESSIBLE but a compressible material law was given");
197 }
198
199 if ((compressibilityType==COMPRESSIBLE) && (pMaterialLaw==nullptr))
200 {
201 // then dynamic_cast to AbstractCompressibleMaterialLaw failed
202 EXCEPTION("Incompressibility type was declared as COMPRESSIBLE but an incompressible material law was given");
203 }
204}
205
206template<unsigned DIM>
208{
210
211 if ((mIncompressibleMaterialLaws.size()==0) && (mCompressibleMaterialLaws.size()==0))
212 {
213 EXCEPTION("No material law has been set");
214 }
215}
216
217// Explicit instantiation
#define EXCEPTION(message)
AbstractIncompressibleMaterialLaw< DIM > * GetIncompressibleMaterialLaw(unsigned elementIndex)
void SetFixedNodes(std::vector< unsigned > &rFixedNodes, std::vector< c_vector< double, DIM > > &rFixedNodeLocation)
AbstractCompressibleMaterialLaw< DIM > * GetCompressibleMaterialLaw(unsigned elementIndex)
SolidMechanicsProblemDefinition(AbstractTetrahedralMesh< DIM, DIM > &rMesh)
void CheckCastSuccess(CompressibilityType compressibilityType, AbstractMaterialLaw< DIM > *pMaterialLaw)
void SetMaterialLaw(CompressibilityType compressibilityType, AbstractMaterialLaw< DIM > *pMaterialLaw)