Panzer Version of the Day
Loading...
Searching...
No Matches
Panzer_GeometricAggFieldPattern.cpp
Go to the documentation of this file.
1// @HEADER
2// *****************************************************************************
3// Panzer: A partial differential equation assembly
4// engine for strongly coupled complex multiphysics systems
5//
6// Copyright 2011 NTESS and the Panzer contributors.
7// SPDX-License-Identifier: BSD-3-Clause
8// *****************************************************************************
9// @HEADER
10
12
13using Teuchos::RCP;
14
15namespace panzer {
16
18 : patternBuilt_(false), dimension_(0)
19{}
20
21 GeometricAggFieldPattern::GeometricAggFieldPattern(std::vector<std::pair<FieldType,Teuchos::RCP<const FieldPattern>>> & patterns)
22 : patternBuilt_(false), dimension_(0)
23{
24 buildPattern(patterns);
25}
26
28 const Teuchos::RCP<const FieldPattern> & pattern)
29 : patternBuilt_(false), dimension_(0)
30{
31 buildPattern(fieldType,pattern);
32}
33
34void GeometricAggFieldPattern::buildPattern(const std::vector<std::pair<FieldType,Teuchos::RCP<const FieldPattern>>> & patterns)
35{
36 std::size_t numPat = patterns.size();
37
38 // must be at least one field to do something
39 if(numPat<1) {
40 bool no_patterns_to_construct = true;
41 TEUCHOS_TEST_FOR_EXCEPTION(no_patterns_to_construct,std::logic_error,
42 "GeometricAggFieldPattern::buildPattern requires at least one field pattern");
43 return;
44 }
45
46 bool sameGeometry=true;
47 for(std::size_t i=1;i<patterns.size();i++)
48 sameGeometry &= patterns[0].second->sameGeometry(*(patterns[i].second));
49 TEUCHOS_TEST_FOR_EXCEPTION(not sameGeometry,std::logic_error,
50 "GeometricAggFieldPattern::buildPattern(): Patterns must "
51 "have the same geometry!");
52
53 // copy cell topology
54 cellTopo_ = patterns[0].second->getCellTopology();
55
56 // grab the dimension
57 dimension_ = patterns[0].second->getDimension();
58 patternData_.resize(dimension_+1);
59
60 // build space for subcells
61 std::vector<int> subcellCount(dimension_+1);
62 for(std::size_t d=0;d<dimension_+1;d++) {
63 subcellCount[d] = patterns[0].second->getSubcellCount(d);
64 patternData_[d].resize(subcellCount[d]);
65 }
66
67 // Build geometric pattern: increment it logically over all the
68 // subcells. Start with CG fields first. Then all DG fields. This
69 // is done so that we can use individual field pattern offsets when
70 // mapping DOFs to subcells.
71 int counter = 0;
72 for(std::size_t d=0;d<dimension_+1;d++) {
73 for(int s=0;s<subcellCount[d];s++) {
74 std::vector<int> & current = patternData_[d][s];
75 for(std::size_t p=0;p<patterns.size();p++) {
76 if ( (patterns[p].first) == FieldType::CG) {
77 RCP<const FieldPattern> field = (patterns[p]).second;
78 // if dofs exist, we have a geometric entity
79 const std::size_t num = ( (field->getSubcellIndices(d,s).size() > 0) ? 1 : 0 );
80 if(current.size()<num) {
81 for(int i=num-current.size();i>0;i--,counter++)
82 current.push_back(counter);
83 }
84 }
85 }
86 }
87 }
88
89 // Add DG fields. These fields are considered internal "cell"
90 // fields for DOF numbering.
91 const int cellDim = dimension_;
92 for(std::size_t d=0;d<dimension_+1;d++) {
93 for(int s=0;s<subcellCount[d];s++) {
94 std::vector<int> & current = patternData_[cellDim][0];
95 for(std::size_t p=0;p<patterns.size();p++) {
96 if ( (patterns[p].first) == FieldType::DG) {
97 RCP<const FieldPattern> field = (patterns[p]).second;
98 // if dofs exist, we have a geometric entity
99 const std::size_t num = ( (field->getSubcellIndices(d,s).size() > 0) ? 1 : 0 );
100 if(current.size()<num) {
101 for(int i=num-current.size();i>0;i--,counter++)
102 current.push_back(counter);
103 }
104 }
105 }
106 }
107 }
108
109 // record that the pattern has been built
110 patternBuilt_ = true;
111}
112
114 const Teuchos::RCP<const FieldPattern> & pattern)
115{
116 std::vector<std::pair<FieldType,Teuchos::RCP<const FieldPattern>>> patterns;
117 patterns.push_back(std::make_pair(fieldType,pattern));
118 buildPattern(patterns);
119}
120
122{
123 if(patternBuilt_) return patternData_[dim].size();
124
125 TEUCHOS_TEST_FOR_EXCEPTION(true,std::logic_error,
126 "GeometricAggFieldPattern::getSubcellCount() cannot be called before "
127 "GeometricAggFieldPattern::buildPattern()");
128}
129
130const std::vector<int> & GeometricAggFieldPattern::getSubcellIndices(int dim,int cellIndex) const
131{
132 if(patternBuilt_) return patternData_[dim][cellIndex];
133
134 TEUCHOS_TEST_FOR_EXCEPTION(true,std::logic_error,
135 "GeometricAggFieldPattern::getSubcellIndices() cannot be called before "
136 "GeometricAggFieldPattern::buildPattern()");
137}
138
140{
141 if(patternBuilt_) return dimension_;
142
143 TEUCHOS_TEST_FOR_EXCEPTION(true,std::logic_error,
144 "GeometricAggFieldPattern::getDimension() cannot be called before "
145 "GeometricAggFieldPattern::buildPattern()");
146}
147
149{
150 if(patternBuilt_) return cellTopo_;
151
152 TEUCHOS_TEST_FOR_EXCEPTION(true,std::logic_error,
153 "GeometricAggFieldPattern::getCellTopology() cannot be called before "
154 "GeometricAggFieldPattern::buildPattern()");
155}
156
157}
PHX::MDField< ScalarT, panzer::Cell, panzer::BASIS > field
A field to which we'll contribute, or in which we'll store, the result of computing this integral.
virtual bool sameGeometry(const FieldPattern &fp) const
std::vector< std::vector< std::vector< int > > > patternData_
virtual const std::vector< int > & getSubcellIndices(int dim, int cellIndex) const
virtual void buildPattern(const std::vector< std::pair< FieldType, Teuchos::RCP< const FieldPattern > > > &patterns)
virtual shards::CellTopology getCellTopology() const
FieldType
The type of discretization to use for a field pattern.
@ DG
Continuous Galerkin Formulation.