Nektar++
ProcessSurfDistance.cpp
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////////////
2 //
3 // File: ProcessSurfDistance.cpp
4 //
5 // For more information, please see: http://www.nektar.info/
6 //
7 // The MIT License
8 //
9 // Copyright (c) 2006 Division of Applied Mathematics, Brown University (USA),
10 // Department of Aeronautics, Imperial College London (UK), and Scientific
11 // Computing and Imaging Institute, University of Utah (USA).
12 //
13 // License for the specific language governing rights and limitations under
14 // Permission is hereby granted, free of charge, to any person obtaining a
15 // copy of this software and associated documentation files (the "Software"),
16 // to deal in the Software without restriction, including without limitation
17 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
18 // and/or sell copies of the Software, and to permit persons to whom the
19 // Software is furnished to do so, subject to the following conditions:
20 //
21 // The above copyright notice and this permission notice shall be included
22 // in all copies or substantial portions of the Software.
23 //
24 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
25 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
26 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
27 // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
28 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
29 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
30 // DEALINGS IN THE SOFTWARE.
31 //
32 // Description: Computes height of elements connected to a surface.
33 //
34 ////////////////////////////////////////////////////////////////////////////////
35 
36 #include <string>
37 #include <iostream>
38 using namespace std;
39 
40 #include "ProcessSurfDistance.h"
41 
42 namespace Nektar
43 {
44 namespace Utilities
45 {
46 
47 ModuleKey ProcessSurfDistance::className =
49  ModuleKey(eProcessModule, "surfdistance"),
50  ProcessSurfDistance::create,
51  "Computes height of element connected to a surface.");
52 
53 ProcessSurfDistance::ProcessSurfDistance(FieldSharedPtr f)
54  : ProcessModule(f)
55 {
56  m_config["bnd"] = ConfigOption(false,"-1","Boundary region to calculate height");
57  f->m_writeBndFld = true;
58  f->m_declareExpansionAsContField = true;
59  m_f->m_fldToBnd = false;
60 }
61 
63 {
64 }
65 
66 void ProcessSurfDistance::Process(po::variables_map &vm)
67 {
68  int i, j, k, cnt;
69  int surf = m_config["bnd"].as<int>();
70 
71  ASSERTL0(surf >= 0, "Invalid surface "+boost::lexical_cast<string>(surf));
72 
73  // Add this boundary region to the list that we will output.
74  m_f->m_bndRegionsToWrite.push_back(surf);
75 
76  // Remove existing fields.
77  m_f->m_exp.resize(1);
78 
79  // Grab boundary expansions.
81  m_f->m_exp[0]->GetBndCondExpansions();
82 
83  // Get map that takes us from boundary element to element.
84  Array<OneD, int> BoundarytoElmtID, BoundarytoTraceID;
85  m_f->m_exp[0]->GetBoundaryToElmtMap(BoundarytoElmtID, BoundarytoTraceID);
86 
87  if (m_f->m_fielddef.size() == 0)
88  {
89  m_f->m_fielddef = m_f->m_exp[0]->GetFieldDefinitions();
90  m_f->m_fielddef[0]->m_fields.push_back("dist");
91  }
92  else
93  {
94  // Override field variable
95  m_f->m_fielddef[0]->m_fields[0] = "dist";
96  }
97 
98  for (i = cnt = 0; i < BndExp.num_elements(); ++i)
99  {
100  if (i != surf)
101  {
102  cnt += BndExp[i]->GetExpSize();
103  continue;
104  }
105 
106  for (j = 0; j < BndExp[i]->GetExpSize(); ++j, ++cnt)
107  {
108  int elmtNum = BoundarytoElmtID [cnt];
109  int facetNum = BoundarytoTraceID[cnt];
110 
111  // Get boundary and element expansions.
112  LocalRegions::ExpansionSharedPtr bndElmt = BndExp[i]->GetExp(j);
114  m_f->m_exp[0]->GetExp(elmtNum);
115 
116  ASSERTL0(elmt->DetShapeType() == LibUtilities::ePrism,
117  "Only prisms supported for now!");
118 
119  ASSERTL0(facetNum == 1 || facetNum == 3,
120  "Surface must be on a triangular face of the prism.");
121 
122  int nq = elmt ->GetTotPoints();
123  int nqBnd = bndElmt->GetTotPoints();
124 
126  x[0] = Array<OneD, NekDouble>(nq);
127  x[1] = Array<OneD, NekDouble>(nq);
128  x[2] = Array<OneD, NekDouble>(nq);
129  elmt->GetCoords(x[0], x[1], x[2]);
130 
131  Array<OneD, NekDouble> face1(nqBnd), face3(nqBnd);
133  BndExp[i]->UpdatePhys() + BndExp[i]->GetPhys_Offset(j);
134 
135  // Zero existing value.
136  Vmath::Zero(nqBnd, dist, 1);
137 
138  // Calculate distance between two faces of prism.
139  for (k = 0; k < 3; ++k)
140  {
141  elmt->GetFacePhysVals(1, bndElmt, x[k], face1);
142  elmt->GetFacePhysVals(3, bndElmt, x[k], face3);
143  Vmath::Vsub (nqBnd, face1, 1, face3, 1, face1, 1);
144  Vmath::Vvtvp(nqBnd, face1, 1, face1, 1, dist, 1, dist, 1);
145  }
146  }
147 
148  BndExp[i]->FwdTrans(BndExp[i]->GetPhys(), BndExp[i]->UpdateCoeffs());
149  }
150 }
151 
152 }
153 }
#define ASSERTL0(condition, msg)
Definition: ErrorUtil.hpp:161
pair< ModuleType, string > ModuleKey
virtual void Process()=0
void Vvtvp(int n, const T *w, const int incw, const T *x, const int incx, const T *y, const int incy, T *z, const int incz)
vvtvp (vector times vector plus vector): z = w*x + y
Definition: Vmath.cpp:428
map< string, ConfigOption > m_config
List of configuration values.
STL namespace.
FieldSharedPtr m_f
Field object.
boost::shared_ptr< Field > FieldSharedPtr
Definition: Field.hpp:677
void Vsub(int n, const T *x, const int incx, const T *y, const int incy, T *z, const int incz)
Subtract vector z = x-y.
Definition: Vmath.cpp:329
Represents a command-line configuration option.
boost::shared_ptr< Expansion > ExpansionSharedPtr
Definition: Expansion.h:68
void Zero(int n, T *x, const int incx)
Zero vector.
Definition: Vmath.cpp:359
ModuleFactory & GetModuleFactory()
Abstract base class for processing modules.
tKey RegisterCreatorFunction(tKey idKey, CreatorFunction classCreator, tDescription pDesc="")
Register a class with the factory.
Definition: NekFactory.hpp:215