Nektar++
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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 
39 
40 #include "ProcessScalar.h"
41 
42 using namespace std;
43 using namespace Nektar::NekMeshUtils;
44 
45 namespace Nektar
46 {
47 namespace Utilities
48 {
49 
50 ModuleKey ProcessScalar::className = GetModuleFactory().RegisterCreatorFunction(
51  ModuleKey(eProcessModule, "scalar"),
52  ProcessScalar::create,
53  "Impose a scalar function z=f(x,y) on a surface.");
54 
55 ProcessScalar::ProcessScalar(MeshSharedPtr m) : ProcessModule(m)
56 {
57  m_config["surf"] = ConfigOption(
58  false, "-1", "Tag identifying surface/composite to process.");
59  m_config["nq"] =
60  ConfigOption(false, "-1", "Number of quadrature points to generate.");
61  m_config["scalar"] = ConfigOption(false, "", "Expression to evaluate.");
62 }
63 
65 {
66 }
67 
69 {
70  int i, j, k;
71  string surf = m_config["surf"].as<string>();
72 
73  // Obtain vector of surface IDs from string.
74  vector<unsigned int> surfs;
75  ParseUtils::GenerateSeqVector(surf.c_str(), surfs);
76  sort(surfs.begin(), surfs.end());
77 
78  // If we're running in verbose mode print out a list of surfaces.
79  if (m_mesh->m_verbose)
80  {
81  cout << "ProcessScalar: extracting surface"
82  << (surfs.size() > 1 ? "s" : "") << " " << surf << endl;
83  }
84 
85  const int nq = m_config["nq"].as<int>();
86  string expr = m_config["scalar"].as<string>();
87 
89  int rExprId = rEval.DefineFunction("x y z", expr);
90 
91  // Make a copy of all existing elements of one dimension lower.
92  vector<ElementSharedPtr> el = m_mesh->m_element[m_mesh->m_expDim - 1];
93 
94  // Iterate over list of surface elements.
95  for (i = 0; i < el.size(); ++i)
96  {
97  // Work out whether this lies on our surface of interest.
98  vector<int> inter, tags = el[i]->GetTagList();
99 
100  sort(tags.begin(), tags.end());
101  set_intersection(surfs.begin(),
102  surfs.end(),
103  tags.begin(),
104  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 }
STL namespace.
pair< ModuleType, string > ModuleKey
NekDouble m_y
Y-coordinate.
Definition: Node.h:401
static bool GenerateSeqVector(const char *const str, std::vector< unsigned int > &vec)
Definition: ParseUtils.hpp:79
Represents a point in the domain.
Definition: Node.h:60
virtual void Process()
Write mesh to output file.
Represents a command-line configuration option.
boost::shared_ptr< Node > NodeSharedPtr
Definition: Node.h:50
std::map< std::string, ConfigOption > m_config
List of configuration values.
This class defines evaluator of analytic (symbolic) mathematical expressions. Expressions are allowed...
NekDouble m_x
X-coordinate.
Definition: Node.h:399
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...
boost::shared_ptr< Mesh > MeshSharedPtr
Shared pointer to a mesh.
Definition: Mesh.h:147
Abstract base class for processing modules.
boost::shared_ptr< Face > FaceSharedPtr
Definition: Face.h:153
NekDouble m_z
Z-coordinate.
Definition: Node.h:403
std::pair< ModuleType, std::string > ModuleKey
ModuleFactory & GetModuleFactory()
tKey RegisterCreatorFunction(tKey idKey, CreatorFunction classCreator, tDescription pDesc="")
Register a class with the factory.
Definition: NekFactory.hpp:215