Chaste  Release::3.4
StokesFlowAssembler.hpp
1 /*
2 
3 Copyright (c) 2005-2016, University of Oxford.
4 All rights reserved.
5 
6 University of Oxford means the Chancellor, Masters and Scholars of the
7 University of Oxford, having an administrative office at Wellington
8 Square, Oxford OX1 2JD, UK.
9 
10 This file is part of Chaste.
11 
12 Redistribution and use in source and binary forms, with or without
13 modification, 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 
23 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
24 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
27 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
28 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
29 GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30 HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
32 OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 
34 */
35 
36 #ifndef STOKESFLOWASSEMBLER_HPP_
37 #define STOKESFLOWASSEMBLER_HPP_
38 
39 #include "AbstractContinuumMechanicsAssembler.hpp"
40 #include "StokesFlowProblemDefinition.hpp"
41 
42 
61 template<unsigned DIM>
63 {
64 friend class TestStokesFlowAssembler;
65 
66 private:
68  static const unsigned NUM_VERTICES_PER_ELEMENT = DIM+1;
69 
71  static const unsigned NUM_NODES_PER_ELEMENT = (DIM+1)*(DIM+2)/2; // assuming quadratic
72 
78 
84 
87 
95  double mScaleFactor;
96 
97 
113  c_matrix<double,SPATIAL_BLOCK_SIZE_ELEMENTAL,SPATIAL_BLOCK_SIZE_ELEMENTAL> ComputeSpatialSpatialMatrixTerm(
114  c_vector<double, NUM_NODES_PER_ELEMENT>& rQuadPhi,
115  c_matrix<double, DIM, NUM_NODES_PER_ELEMENT>& rGradQuadPhi,
116  c_vector<double,DIM>& rX,
117  Element<DIM,DIM>* pElement)
118  {
119  c_matrix<double,SPATIAL_BLOCK_SIZE_ELEMENTAL,SPATIAL_BLOCK_SIZE_ELEMENTAL> ret = zero_matrix<double>(SPATIAL_BLOCK_SIZE_ELEMENTAL,SPATIAL_BLOCK_SIZE_ELEMENTAL);
120 
121  double mu = mpProblemDefinition->GetViscosity();
122 
123  for (unsigned index1=0; index1<NUM_NODES_PER_ELEMENT*DIM; index1++)
124  {
125  unsigned spatial_dim1 = index1%DIM;
126  unsigned node_index1 = (index1-spatial_dim1)/DIM;
127 
128  for (unsigned index2=0; index2<NUM_NODES_PER_ELEMENT*DIM; index2++)
129  {
130  unsigned spatial_dim2 = index2%DIM;
131  unsigned node_index2 = (index2-spatial_dim2)/DIM;
132 
133  ret(index1,index2) += mu
134  * mScaleFactor // virtually always 1, see doxygen for this variable
135  * rGradQuadPhi(spatial_dim1, node_index2)
136  * rGradQuadPhi(spatial_dim2, node_index1);
137 
138  for(unsigned k=0; k<DIM; k++)
139  {
140  ret(index1,index2) += mu
141  * (spatial_dim1==spatial_dim2)
142  * rGradQuadPhi(k, node_index1)
143  * rGradQuadPhi(k, node_index2);
144  }
145  }
146  }
147  return ret;
148 
149  }
150 
168  c_matrix<double,SPATIAL_BLOCK_SIZE_ELEMENTAL,PRESSURE_BLOCK_SIZE_ELEMENTAL> ComputeSpatialPressureMatrixTerm(
169  c_vector<double, NUM_NODES_PER_ELEMENT>& rQuadPhi,
170  c_matrix<double, DIM, NUM_NODES_PER_ELEMENT>& rGradQuadPhi,
171  c_vector<double, NUM_VERTICES_PER_ELEMENT>& rLinearPhi,
172  c_matrix<double, DIM, NUM_VERTICES_PER_ELEMENT>& rGradLinearPhi,
173  c_vector<double,DIM>& rX,
174  Element<DIM,DIM>* pElement)
175  {
176  c_matrix<double,SPATIAL_BLOCK_SIZE_ELEMENTAL,PRESSURE_BLOCK_SIZE_ELEMENTAL> ret = zero_matrix<double>(SPATIAL_BLOCK_SIZE_ELEMENTAL,PRESSURE_BLOCK_SIZE_ELEMENTAL);
177 
178  for (unsigned index1=0; index1<NUM_NODES_PER_ELEMENT*DIM; index1++)
179  {
180  unsigned spatial_dim1 = index1%DIM;
181  unsigned node_index1 = (index1-spatial_dim1)/DIM;
182 
183  for (unsigned index2=0; index2<NUM_VERTICES_PER_ELEMENT; index2++)
184  {
185  ret(index1,index2) += -rGradQuadPhi(spatial_dim1, node_index1) * rLinearPhi(index2);
186  }
187  }
188 
189  return ret;
190  }
191 
192  // We don't implement this method - so it is a zero block
193  //c_matrix<double,PRESSURE_BLOCK_SIZE_ELEMENTAL,PRESSURE_BLOCK_SIZE_ELEMENTAL> ComputePressurePressureMatrixTerm(
194  // c_vector<double, NUM_VERTICES_PER_ELEMENT>& rLinearPhi,
195  // c_matrix<double, DIM, NUM_VERTICES_PER_ELEMENT>& rGradLinearPhi,
196  // c_vector<double,DIM>& rX,
197  // Element<DIM,DIM>* pElement)
198 
199 
217  c_vector<double,SPATIAL_BLOCK_SIZE_ELEMENTAL> ComputeSpatialVectorTerm(
218  c_vector<double, NUM_NODES_PER_ELEMENT>& rQuadPhi,
219  c_matrix<double, DIM, NUM_NODES_PER_ELEMENT>& rGradQuadPhi,
220  c_vector<double,DIM>& rX,
221  Element<DIM,DIM>* pElement)
222  {
223  c_vector<double,SPATIAL_BLOCK_SIZE_ELEMENTAL> ret = zero_vector<double>(SPATIAL_BLOCK_SIZE_ELEMENTAL);
224 
225  c_vector<double,DIM> body_force = mpProblemDefinition->GetBodyForce(rX, 0.0);
226 
227  for (unsigned index=0; index<NUM_NODES_PER_ELEMENT*DIM; index++)
228  {
229  unsigned spatial_dim = index%DIM;
230  unsigned node_index = (index-spatial_dim)/DIM;
231 
232  ret(index) += body_force(spatial_dim) * rQuadPhi(node_index);
233  }
234 
235  return ret;
236  }
237 
238  // We don't implement this method - so it is a zero block of the vector:
239  //c_vector<double,PRESSURE_BLOCK_SIZE_ELEMENTAL> ComputePressureVectorTerm(
240  // c_vector<double, NUM_VERTICES_PER_ELEMENT>& rLinearPhi,
241  // c_matrix<double, DIM, NUM_VERTICES_PER_ELEMENT>& rGradLinearPhi,
242  // c_vector<double,DIM>& rX,
243  // Element<DIM,DIM>* pElement)
244 
245 public:
252  StokesFlowProblemDefinition<DIM>* pProblemDefinition)
253  : AbstractContinuumMechanicsAssembler<DIM,true,true>(pMesh),
254  mpProblemDefinition(pProblemDefinition),
255  mScaleFactor(1.0)
256  {
257  }
258 };
259 
260 #endif // STOKESFLOWASSEMBLER_HPP_
StokesFlowAssembler(AbstractTetrahedralMesh< DIM, DIM > *pMesh, StokesFlowProblemDefinition< DIM > *pProblemDefinition)
c_vector< double, SPATIAL_BLOCK_SIZE_ELEMENTAL > ComputeSpatialVectorTerm(c_vector< double, NUM_NODES_PER_ELEMENT > &rQuadPhi, c_matrix< double, DIM, NUM_NODES_PER_ELEMENT > &rGradQuadPhi, c_vector< double, DIM > &rX, Element< DIM, DIM > *pElement)
StokesFlowProblemDefinition< DIM > * mpProblemDefinition
static const unsigned PRESSURE_BLOCK_SIZE_ELEMENTAL
static const unsigned NUM_VERTICES_PER_ELEMENT
c_matrix< double, SPATIAL_BLOCK_SIZE_ELEMENTAL, SPATIAL_BLOCK_SIZE_ELEMENTAL > ComputeSpatialSpatialMatrixTerm(c_vector< double, NUM_NODES_PER_ELEMENT > &rQuadPhi, c_matrix< double, DIM, NUM_NODES_PER_ELEMENT > &rGradQuadPhi, c_vector< double, DIM > &rX, Element< DIM, DIM > *pElement)
static const unsigned SPATIAL_BLOCK_SIZE_ELEMENTAL
c_matrix< double, SPATIAL_BLOCK_SIZE_ELEMENTAL, PRESSURE_BLOCK_SIZE_ELEMENTAL > ComputeSpatialPressureMatrixTerm(c_vector< double, NUM_NODES_PER_ELEMENT > &rQuadPhi, c_matrix< double, DIM, NUM_NODES_PER_ELEMENT > &rGradQuadPhi, c_vector< double, NUM_VERTICES_PER_ELEMENT > &rLinearPhi, c_matrix< double, DIM, NUM_VERTICES_PER_ELEMENT > &rGradLinearPhi, c_vector< double, DIM > &rX, Element< DIM, DIM > *pElement)
static const unsigned NUM_NODES_PER_ELEMENT