Panzer  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Panzer_GeometricAggFieldPattern.cpp
Go to the documentation of this file.
1 // @HEADER
2 // ***********************************************************************
3 //
4 // Panzer: A partial differential equation assembly
5 // engine for strongly coupled complex multiphysics systems
6 // Copyright (2011) Sandia Corporation
7 //
8 // Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
9 // the U.S. Government retains certain rights in this software.
10 //
11 // Redistribution and use in source and binary forms, with or without
12 // modification, are permitted provided that the following conditions are
13 // met:
14 //
15 // 1. Redistributions of source code must retain the above copyright
16 // notice, this list of conditions and the following disclaimer.
17 //
18 // 2. Redistributions in binary form must reproduce the above copyright
19 // notice, this list of conditions and the following disclaimer in the
20 // documentation and/or other materials provided with the distribution.
21 //
22 // 3. Neither the name of the Corporation nor the names of the
23 // contributors may be used to endorse or promote products derived from
24 // this software without specific prior written permission.
25 //
26 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
27 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
30 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
31 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
32 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
33 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
34 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
35 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
36 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37 //
38 // Questions? Contact Roger P. Pawlowski (rppawlo@sandia.gov) and
39 // Eric C. Cyr (eccyr@sandia.gov)
40 // ***********************************************************************
41 // @HEADER
42 
44 
45 using Teuchos::RCP;
46 
47 namespace panzer {
48 
50  : patternBuilt_(false), dimension_(0)
51 {}
52 
54  : patternBuilt_(false), dimension_(0)
55 {
56  buildPattern(patterns);
57 }
58 
60  const Teuchos::RCP<const FieldPattern> & pattern)
61  : patternBuilt_(false), dimension_(0)
62 {
63  buildPattern(fieldType,pattern);
64 }
65 
67 {
68  std::size_t numPat = patterns.size();
69 
70  // must be at least one field to do something
71  if(numPat<1) {
72  bool no_patterns_to_construct = true;
73  TEUCHOS_TEST_FOR_EXCEPTION(no_patterns_to_construct,std::logic_error,
74  "GeometricAggFieldPattern::buildPattern requires at least one field pattern");
75  return;
76  }
77 
78  bool sameGeometry=true;
79  for(std::size_t i=1;i<patterns.size();i++)
80  sameGeometry &= patterns[0].second->sameGeometry(*(patterns[i].second));
81  TEUCHOS_TEST_FOR_EXCEPTION(not sameGeometry,std::logic_error,
82  "GeometricAggFieldPattern::buildPattern(): Patterns must "
83  "have the same geometry!");
84 
85  // copy cell topology
86  cellTopo_ = patterns[0].second->getCellTopology();
87 
88  // grab the dimension
89  dimension_ = patterns[0].second->getDimension();
90  patternData_.resize(dimension_+1);
91 
92  // build space for subcells
93  std::vector<int> subcellCount(dimension_+1);
94  for(std::size_t d=0;d<dimension_+1;d++) {
95  subcellCount[d] = patterns[0].second->getSubcellCount(d);
96  patternData_[d].resize(subcellCount[d]);
97  }
98 
99  // Build geometric pattern: increment it logically over all the
100  // subcells. Start with CG fields first. Then all DG fields. This
101  // is done so that we can use individual field pattern offsets when
102  // mapping DOFs to subcells.
103  int counter = 0;
104  for(std::size_t d=0;d<dimension_+1;d++) {
105  for(int s=0;s<subcellCount[d];s++) {
106  std::vector<int> & current = patternData_[d][s];
107  for(std::size_t p=0;p<patterns.size();p++) {
108  if ( (patterns[p].first) == FieldType::CG) {
109  RCP<const FieldPattern> field = (patterns[p]).second;
110  // if dofs exist, we have a geometric entity
111  const std::size_t num = ( (field->getSubcellIndices(d,s).size() > 0) ? 1 : 0 );
112  if(current.size()<num) {
113  for(int i=num-current.size();i>0;i--,counter++)
114  current.push_back(counter);
115  }
116  }
117  }
118  }
119  }
120 
121  // Add DG fields. These fields are considered internal "cell"
122  // fields for DOF numbering.
123  const int cellDim = dimension_;
124  for(std::size_t d=0;d<dimension_+1;d++) {
125  for(int s=0;s<subcellCount[d];s++) {
126  std::vector<int> & current = patternData_[cellDim][0];
127  for(std::size_t p=0;p<patterns.size();p++) {
128  if ( (patterns[p].first) == FieldType::DG) {
129  RCP<const FieldPattern> field = (patterns[p]).second;
130  // if dofs exist, we have a geometric entity
131  const std::size_t num = ( (field->getSubcellIndices(d,s).size() > 0) ? 1 : 0 );
132  if(current.size()<num) {
133  for(int i=num-current.size();i>0;i--,counter++)
134  current.push_back(counter);
135  }
136  }
137  }
138  }
139  }
140 
141  // record that the pattern has been built
142  patternBuilt_ = true;
143 }
144 
146  const Teuchos::RCP<const FieldPattern> & pattern)
147 {
148  std::vector<std::pair<FieldType,Teuchos::RCP<const FieldPattern>>> patterns;
149  patterns.push_back(std::make_pair(fieldType,pattern));
150  buildPattern(patterns);
151 }
152 
154 {
155  if(patternBuilt_) return patternData_[dim].size();
156 
157  TEUCHOS_TEST_FOR_EXCEPTION(true,std::logic_error,
158  "GeometricAggFieldPattern::getSubcellCount() cannot be called before "
159  "GeometricAggFieldPattern::buildPattern()");
160 }
161 
162 const std::vector<int> & GeometricAggFieldPattern::getSubcellIndices(int dim,int cellIndex) const
163 {
164  if(patternBuilt_) return patternData_[dim][cellIndex];
165 
166  TEUCHOS_TEST_FOR_EXCEPTION(true,std::logic_error,
167  "GeometricAggFieldPattern::getSubcellIndices() cannot be called before "
168  "GeometricAggFieldPattern::buildPattern()");
169 }
170 
172 {
173  if(patternBuilt_) return dimension_;
174 
175  TEUCHOS_TEST_FOR_EXCEPTION(true,std::logic_error,
176  "GeometricAggFieldPattern::getDimension() cannot be called before "
177  "GeometricAggFieldPattern::buildPattern()");
178 }
179 
180 shards::CellTopology GeometricAggFieldPattern::getCellTopology() const
181 {
182  if(patternBuilt_) return cellTopo_;
183 
184  TEUCHOS_TEST_FOR_EXCEPTION(true,std::logic_error,
185  "GeometricAggFieldPattern::getCellTopology() cannot be called before "
186  "GeometricAggFieldPattern::buildPattern()");
187 }
188 
189 }
std::vector< std::vector< std::vector< int > > > patternData_
virtual const std::vector< int > & getSubcellIndices(int dim, int cellIndex) const
virtual bool sameGeometry(const FieldPattern &fp) const
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
FieldType
The type of discretization to use for a field pattern.
Continuous Galerkin Formulation.
PHX::MDField< ScalarT, panzer::Cell, panzer::BASIS > field
A field to which we&#39;ll contribute, or in which we&#39;ll store, the result of computing this integral...
virtual void buildPattern(const std::vector< std::pair< FieldType, Teuchos::RCP< const FieldPattern >>> &patterns)
virtual shards::CellTopology getCellTopology() const