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 // Permission is hereby granted, free of charge, to any person obtaining a
14 // copy of this software and associated documentation files (the "Software"),
15 // to deal in the Software without restriction, including without limitation
16 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
17 // and/or sell copies of the Software, and to permit persons to whom the
18 // Software is furnished to do so, subject to the following conditions:
19 //
20 // The above copyright notice and this permission notice shall be included
21 // in all copies or substantial portions of the Software.
22 //
23 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
24 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
25 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
26 // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
27 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
28 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
29 // DEALINGS IN THE SOFTWARE.
30 //
31 // Description: Add scalar function curvature to a given surface.
32 //
33 ////////////////////////////////////////////////////////////////////////////////
34 
38 
39 #include "ProcessScalar.h"
40 
41 using namespace std;
42 using namespace Nektar::NekMeshUtils;
43 
44 namespace Nektar
45 {
46 namespace Utilities
47 {
48 
49 ModuleKey ProcessScalar::className = GetModuleFactory().RegisterCreatorFunction(
50  ModuleKey(eProcessModule, "scalar"),
51  ProcessScalar::create,
52  "Impose a scalar function z=f(x,y) on a surface.");
53 
54 ProcessScalar::ProcessScalar(MeshSharedPtr m) : ProcessModule(m)
55 {
56  m_config["surf"] = ConfigOption(
57  false, "-1", "Tag identifying surface/composite to process.");
58  m_config["nq"] =
59  ConfigOption(false, "-1", "Number of quadrature points to generate.");
60  m_config["scalar"] = ConfigOption(false, "", "Expression to evaluate.");
61 }
62 
64 {
65 }
66 
68 {
69  int i, j, k;
70  string surf = m_config["surf"].as<string>();
71 
72  // Obtain vector of surface IDs from string.
73  vector<unsigned int> surfs;
74  ParseUtils::GenerateSeqVector(surf, surfs);
75  sort(surfs.begin(), surfs.end());
76 
77  // If we're running in verbose mode print out a list of surfaces.
78  if (m_mesh->m_verbose)
79  {
80  cout << "ProcessScalar: extracting surface"
81  << (surfs.size() > 1 ? "s" : "") << " " << surf << endl;
82  }
83 
84  const int nq = m_config["nq"].as<int>();
85  string expr = m_config["scalar"].as<string>();
86 
88  int rExprId = rEval.DefineFunction("x y z", expr);
89 
90  // Make a copy of all existing elements of one dimension lower.
91  vector<ElementSharedPtr> el = m_mesh->m_element[m_mesh->m_expDim - 1];
92 
93  // Iterate over list of surface elements.
94  for (i = 0; i < el.size(); ++i)
95  {
96  // Work out whether this lies on our surface of interest.
97  vector<int> inter, tags = el[i]->GetTagList();
98 
99  sort(tags.begin(), tags.end());
100  set_intersection(surfs.begin(),
101  surfs.end(),
102  tags.begin(),
103  tags.end(),
104  back_inserter(inter));
105 
106  // It doesn't continue to next element.
107  if (inter.size() != 1)
108  {
109  continue;
110  }
111 
112  // Grab face link.
113  FaceSharedPtr f = el[i]->GetFaceLink();
114 
115  // Update vertices
116  for (j = 0; j < 4; ++j)
117  {
118  NodeSharedPtr n = f->m_vertexList[j];
119  n->m_z = rEval.Evaluate(rExprId, n->m_x, n->m_y, 0.0, 0.0);
120 
121  if (n->m_z < 1e-32)
122  {
123  n->m_z = 0;
124  }
125  }
126 
127  // Put curvature into edges
128  for (j = 0; j < f->m_edgeList.size(); ++j)
129  {
130  NodeSharedPtr n1 = f->m_edgeList[j]->m_n1;
131  NodeSharedPtr n2 = f->m_edgeList[j]->m_n2;
132  Node disp = *n2 - *n1;
133 
134  f->m_edgeList[j]->m_edgeNodes.clear();
135 
136  for (k = 1; k < nq - 1; ++k)
137  {
138  Node n = *n1 + disp * k / (nq - 1.0);
139  n.m_z = rEval.Evaluate(rExprId, n.m_x, n.m_y, 0.0, 0.0);
140  if (n.m_z < 1e-32)
141  {
142  n.m_z = 0;
143  }
144 
145  f->m_edgeList[j]->m_edgeNodes.push_back(
146  NodeSharedPtr(new Node(n)));
147  }
148  }
149  }
150 }
151 }
152 }
int DefineFunction(const std::string &vlist, const std::string &expr)
Defines a function for the purposes of evaluation.
STL namespace.
NekDouble m_y
Y-coordinate.
Definition: Node.h:410
std::shared_ptr< Mesh > MeshSharedPtr
Shared pointer to a mesh.
Definition: Mesh.h:156
Represents a point in the domain.
Definition: Node.h:62
std::shared_ptr< Node > NodeSharedPtr
Definition: CADVert.h:49
std::shared_ptr< Face > FaceSharedPtr
Definition: Face.h:155
std::pair< ModuleType, std::string > ModuleKey
virtual void Process()
Write mesh to output file.
Represents a command-line configuration option.
std::map< std::string, ConfigOption > m_config
List of configuration values.
Interpreter class for the evaluation of mathematical expressions.
Definition: Interpreter.h:77
NekDouble m_x
X-coordinate.
Definition: Node.h:408
Abstract base class for processing modules.
tKey RegisterCreatorFunction(tKey idKey, CreatorFunction classCreator, std::string pDesc="")
Register a class with the factory.
Definition: NekFactory.hpp:199
NekDouble m_z
Z-coordinate.
Definition: Node.h:412
std::pair< ModuleType, std::string > ModuleKey
ModuleFactory & GetModuleFactory()
static bool GenerateSeqVector(const std::string &str, std::vector< unsigned int > &out)
Takes a comma-separated compressed string and converts it to entries in a vector. ...
Definition: ParseUtils.cpp:108