Chaste Commit::f2ff7ee04e70ac9d06c57344df8d017dbb12b97b
ContinuumMechanicsNeumannBcsAssembler.hpp
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#ifndef CONTINUUMMECHANICSNEUMANNBCSASSEMBLER_HPP_
37#define CONTINUUMMECHANICSNEUMANNBCSASSEMBLER_HPP_
38
39#include "AbstractFeAssemblerInterface.hpp"
40#include "AbstractTetrahedralMesh.hpp"
41#include "QuadraticMesh.hpp"
42#include "DistributedQuadraticMesh.hpp"
43#include "LinearBasisFunction.hpp"
44#include "QuadraticBasisFunction.hpp"
45#include "ReplicatableVector.hpp"
46#include "DistributedVector.hpp"
47#include "PetscTools.hpp"
48#include "PetscVecTools.hpp"
49#include "PetscMatTools.hpp"
50#include "GaussianQuadratureRule.hpp"
51#include "ContinuumMechanicsProblemDefinition.hpp"
52
53
69template<unsigned DIM>
71{
73 static const unsigned NUM_VERTICES_PER_ELEMENT = DIM;
74
76 static const unsigned NUM_NODES_PER_ELEMENT = DIM*(DIM+1)/2; // assuming quadratic
77
82
85
86protected:
89
92
95
100 void DoAssemble();
101
102
114 c_vector<double, STENCIL_SIZE>& rBElem,
115 unsigned boundaryConditionIndex);
116
117public:
124 : AbstractFeAssemblerInterface<true,false>(),
125 mpMesh(pMesh),
126 mpProblemDefinition(pProblemDefinition)
127 {
128 assert(pMesh);
129 assert(pProblemDefinition);
130
131 //Check that the mesh is Quadratic
132 QuadraticMesh<DIM>* p_quad_mesh = dynamic_cast<QuadraticMesh<DIM>* >(pMesh);
133 DistributedQuadraticMesh<DIM>* p_distributed_quad_mesh = dynamic_cast<DistributedQuadraticMesh<DIM>* >(pMesh);
134
135 if ((p_quad_mesh == NULL) && (p_distributed_quad_mesh == NULL))
136 {
137 EXCEPTION("Continuum mechanics solvers require a quadratic mesh");
138 }
139 // In general a mechanics problem is non-polynomial.
140 // We therefore use the highest order integration rule available.
141 mpQuadRule = new GaussianQuadratureRule<DIM-1>(3);
142 }
143
148 {
149 delete mpQuadRule;
150 }
151};
152
153
154template<unsigned DIM>
156{
157 if (this->mVectorToAssemble==NULL)
158 {
159 EXCEPTION("Vector to be assembled has not been set");
160 }
161
162 if (PetscVecTools::GetSize(this->mVectorToAssemble) != (DIM+1)*mpMesh->GetNumNodes() )
163 {
164 EXCEPTION("Vector provided to be assembled has size " << PetscVecTools::GetSize(this->mVectorToAssemble) << ", not expected size of " << (DIM+1)*mpMesh->GetNumNodes() << " ((dim+1)*num_nodes)");
165 }
166
167 // Zero the matrix/vector if it is to be assembled
168 if (this->mZeroVectorBeforeAssembly)
169 {
170 PetscVecTools::Zero(this->mVectorToAssemble);
171 }
172
173
174 if (mpProblemDefinition->GetTractionBoundaryConditionType() != NO_TRACTIONS)
175 {
176 c_vector<double, STENCIL_SIZE> b_elem = zero_vector<double>(STENCIL_SIZE);
177
178 for (unsigned bc_index=0; bc_index<mpProblemDefinition->rGetTractionBoundaryElements().size(); bc_index++)
179 {
180 BoundaryElement<DIM-1,DIM>& r_boundary_element = *(mpProblemDefinition->rGetTractionBoundaryElements()[bc_index]);
181 AssembleOnBoundaryElement(r_boundary_element, b_elem, bc_index);
182
183 unsigned p_indices[STENCIL_SIZE];
184 for (unsigned i=0; i<NUM_NODES_PER_ELEMENT; i++)
185 {
186 for (unsigned j=0; j<DIM; j++)
187 {
188 p_indices[DIM*i+j] = (DIM+1)*r_boundary_element.GetNodeGlobalIndex(i) + j;
189 }
190 }
191 // Note: The pressure block of b_elem will be zero, but this bit still needs to be
192 // set to avoid memory leaks.
193 for (unsigned i=0; i<DIM /*vertices per boundary elem */; i++)
194 {
195 p_indices[DIM*NUM_NODES_PER_ELEMENT + i] = (DIM+1)*r_boundary_element.GetNodeGlobalIndex(i)+DIM;
196 }
197
198 PetscVecTools::AddMultipleValues<STENCIL_SIZE>(this->mVectorToAssemble, p_indices, b_elem);
199 }
200 }
201}
202
203template<unsigned DIM>
205 c_vector<double,STENCIL_SIZE>& rBelem,
206 unsigned boundaryConditionIndex)
207{
208 rBelem.clear();
209
210 c_vector<double, DIM> weighted_direction;
211 double jacobian_determinant;
212 mpMesh->GetWeightedDirectionForBoundaryElement(rBoundaryElement.GetIndex(), weighted_direction, jacobian_determinant);
213
214 c_vector<double,NUM_NODES_PER_ELEMENT> phi;
215
216 for (unsigned quad_index=0; quad_index<mpQuadRule->GetNumQuadPoints(); quad_index++)
217 {
218 double wJ = jacobian_determinant * mpQuadRule->GetWeight(quad_index);
219 const ChastePoint<DIM-1>& quad_point = mpQuadRule->rGetQuadPoint(quad_index);
221
222 c_vector<double,DIM> traction = zero_vector<double>(DIM);
223 switch (mpProblemDefinition->GetTractionBoundaryConditionType())
224 {
225 case ELEMENTWISE_TRACTION:
226 {
227 traction = mpProblemDefinition->rGetElementwiseTractions()[boundaryConditionIndex];
228 break;
229 }
230 default:
231 // Functional traction not implemented yet..
233 }
234
235 for (unsigned index=0; index<NUM_NODES_PER_ELEMENT*DIM; index++)
236 {
237 unsigned spatial_dim = index%DIM;
238 unsigned node_index = (index-spatial_dim)/DIM;
239
240 assert(node_index < NUM_NODES_PER_ELEMENT);
241
242 rBelem(index) += traction(spatial_dim) * phi(node_index) * wJ;
243 }
244 }
245}
246
247
248#endif // CONTINUUMMECHANICSNEUMANNBCSASSEMBLER_HPP_
#define EXCEPTION(message)
#define NEVER_REACHED
unsigned GetIndex() const
ContinuumMechanicsNeumannBcsAssembler(AbstractTetrahedralMesh< DIM, DIM > *pMesh, ContinuumMechanicsProblemDefinition< DIM > *pProblemDefinition)
ContinuumMechanicsProblemDefinition< DIM > * mpProblemDefinition
void AssembleOnBoundaryElement(BoundaryElement< DIM-1, DIM > &rElement, c_vector< double, STENCIL_SIZE > &rBElem, unsigned boundaryConditionIndex)
static unsigned GetSize(Vec vector)
static void Zero(Vec vector)
static void ComputeBasisFunctions(const ChastePoint< ELEMENT_DIM > &rPoint, c_vector< double,(ELEMENT_DIM+1) *(ELEMENT_DIM+2)/2 > &rReturnValue)