Nektar++
ProcessScalar.cpp
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////////////
2 //
3 // File: ProcessScalar.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: Add scalar function curvature to a given surface.
33 //
34 ////////////////////////////////////////////////////////////////////////////////
35 
36 #include "../MeshElements.h"
37 #include "ProcessScalar.h"
38 
40 #include <LocalRegions/QuadExp.h>
43 
44 #include <vector>
45 using namespace std;
46 
47 namespace Nektar
48 {
49  namespace Utilities
50  {
51  ModuleKey ProcessScalar::className =
53  ModuleKey(eProcessModule, "scalar"), ProcessScalar::create,
54  "Impose a scalar function z=f(x,y) on a surface.");
55 
56  ProcessScalar::ProcessScalar(MeshSharedPtr m) : ProcessModule(m)
57  {
58  m_config["surf"] = ConfigOption(false, "-1",
59  "Tag identifying surface/composite to process.");
60  m_config["nq"] = ConfigOption(false, "-1",
61  "Number of quadrature points to generate.");
62  m_config["scalar"] = ConfigOption(false, "",
63  "Expression to evaluate.");
64  }
65 
67  {
68  }
69 
71  {
72  int i, j, k;
73  string surf = m_config["surf"].as<string>();
74 
75  // Obtain vector of surface IDs from string.
76  vector<unsigned int> surfs;
77  ParseUtils::GenerateSeqVector(surf.c_str(), surfs);
78  sort(surfs.begin(), surfs.end());
79 
80  // If we're running in verbose mode print out a list of surfaces.
81  if (m_mesh->m_verbose)
82  {
83  cout << "ProcessScalar: extracting surface"
84  << (surfs.size() > 1 ? "s" : "") << " " << surf << endl;
85  }
86 
87  const int nq = m_config["nq"].as<int>();
88  string expr = m_config["scalar"].as<string>();
89 
91  int rExprId = rEval.DefineFunction("x y z", expr);
92 
93  // Make a copy of all existing elements of one dimension lower.
94  vector<ElementSharedPtr> el = m_mesh->m_element[m_mesh->m_expDim-1];
95 
96  // Iterate over list of surface elements.
97  for (i = 0; i < el.size(); ++i)
98  {
99  // Work out whether this lies on our surface of interest.
100  vector<int> inter, tags = el[i]->GetTagList();
101 
102  sort(tags.begin(), tags.end());
103  set_intersection(surfs.begin(), surfs.end(),
104  tags .begin(), tags .end(),
105  back_inserter(inter));
106 
107  // It doesn't continue to next element.
108  if (inter.size() != 1)
109  {
110  continue;
111  }
112 
113  // Grab face link.
114  FaceSharedPtr f = el[i]->GetFaceLink();
115 
116  // Update vertices
117  for (j = 0; j < 4; ++j)
118  {
119  NodeSharedPtr n = f->m_vertexList[j];
120  n->m_z = rEval.Evaluate(rExprId, n->m_x, n->m_y, 0.0, 0.0);
121 
122  if (n->m_z < 1e-32)
123  {
124  n->m_z = 0;
125  }
126  }
127 
128  // Put curvature into edges
129  for (j = 0; j < f->m_edgeList.size(); ++j)
130  {
131  NodeSharedPtr n1 = f->m_edgeList[j]->m_n1;
132  NodeSharedPtr n2 = f->m_edgeList[j]->m_n2;
133  Node disp = *n2-*n1;
134 
135  f->m_edgeList[j]->m_edgeNodes.clear();
136 
137  for (k = 1; k < nq-1; ++k)
138  {
139  Node n = *n1 + disp * k / (nq-1.0);
140  n.m_z = rEval.Evaluate(rExprId, n.m_x, n.m_y, 0.0, 0.0);
141  if (n.m_z < 1e-32)
142  {
143  n.m_z = 0;
144  }
145 
146  f->m_edgeList[j]->m_edgeNodes.push_back(
147  NodeSharedPtr(new Node(n)));
148  }
149  }
150  }
151  }
152  }
153 }
pair< ModuleType, string > ModuleKey
map< string, ConfigOption > m_config
List of configuration values.
STL namespace.
MeshSharedPtr m_mesh
Mesh object.
boost::shared_ptr< Face > FaceSharedPtr
Shared pointer to a face.
Definition: MeshElements.h:550
boost::shared_ptr< Node > NodeSharedPtr
Shared pointer to a Node.
Definition: MeshElements.h:195
static bool GenerateSeqVector(const char *const str, std::vector< unsigned int > &vec)
Definition: ParseUtils.hpp:78
NekDouble m_x
X-coordinate.
Definition: MeshElements.h:185
virtual void Process()
Write mesh to output file.
boost::shared_ptr< Mesh > MeshSharedPtr
Shared pointer to a mesh.
NekDouble m_y
Y-coordinate.
Definition: MeshElements.h:187
Represents a point in the domain.
Definition: MeshElements.h:74
This class defines evaluator of analytic (symbolic) mathematical expressions. Expressions are allowed...
Represents a command-line configuration option.
int DefineFunction(const std::string &vlist, const std::string &function)
This function allows one to define a function to evaluate. The first argument (vlist) is a list of va...
NekDouble m_z
Z-coordinate.
Definition: MeshElements.h:189
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