Nektar++
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
ProcessC0Projection.cpp
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////////////
2 //
3 // File: ProcessC0Projection.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 C0 projection.
33 //
34 ////////////////////////////////////////////////////////////////////////////////
35 
36 #include <string>
37 #include <iostream>
38 using namespace std;
39 
40 #include "ProcessC0Projection.h"
41 
44 
45 namespace Nektar
46 {
47 namespace Utilities
48 {
49 
50 ModuleKey ProcessC0Projection::className =
52  ModuleKey(eProcessModule, "C0Projection"),
53  ProcessC0Projection::create, "Computes C0 projection.");
54 
55 ProcessC0Projection::ProcessC0Projection(FieldSharedPtr f) : ProcessModule(f)
56 {
57  m_config["fields"] = ConfigOption(false,"All","Start field to project");
58 }
59 
61 {
62 }
63 
64 void ProcessC0Projection::Process(po::variables_map &vm)
65 {
66  if (m_f->m_verbose)
67  {
68  cout << "ProcessC0Projection: Projecting field into C0 space..."
69  << endl;
70  }
71 
72  // generate an C0 expansion field with no boundary conditions.
73  bool savedef = m_f->m_declareExpansionAsContField;
74  m_f->m_declareExpansionAsContField = true;
75  m_c0ProjectExp = m_f->AppendExpList(m_f->m_fielddef[0]->m_numHomogeneousDir,
76  "DefaultVar",true);
77  m_f->m_declareExpansionAsContField = savedef;
78 
79  int nfields = m_f->m_exp.size();
80 
81  string fields = m_config["fields"].as<string>();
82  vector<unsigned int> processFields;
83 
84  if(fields.compare("All") == 0)
85  {
86  for(int i = 0; i < nfields; ++i)
87  {
88  processFields.push_back(i);
89  }
90  }
91  else
92  {
94  processFields),
95  "Failed to interpret field string in C0Projection");
96  }
97 
98  for (int i = 0; i < processFields.size(); ++i)
99  {
100  ASSERTL0(processFields[i] < nfields,
101  "Attempt to process field that is larger than then number of "
102  "fields available");
103 
104  if (m_f->m_verbose)
105  {
106  cout << "\t Processing field: " << processFields[i] << endl;
107  }
108  m_c0ProjectExp->BwdTrans(m_f->m_exp[processFields[i]]->GetCoeffs(),
109  m_f->m_exp[processFields[i]]->UpdatePhys());
110  m_c0ProjectExp->FwdTrans(m_f->m_exp[processFields[i]]->GetPhys(),
111  m_f->m_exp[processFields[i]]->UpdateCoeffs());
112  }
113 
114  // reset FieldDef in case of serial input and parallel output
115  std::vector<LibUtilities::FieldDefinitionsSharedPtr> FieldDef
116  = m_f->m_exp[0]->GetFieldDefinitions();
117  // reset up FieldData with new values before projecting
118  std::vector<std::vector<NekDouble> > FieldData(FieldDef.size());
119 
120  for(int i = 0; i < nfields; ++i)
121  {
122  for (int j = 0; j < FieldDef.size(); ++j)
123  {
124  FieldDef[j]->m_fields.push_back(m_f->m_fielddef[0]->m_fields[i]);
125  m_f->m_exp[i]->AppendFieldData(FieldDef[j], FieldData[j]);
126  }
127  }
128 
129  m_f->m_fielddef = FieldDef;
130  m_f->m_data = FieldData;
131 }
132 
133 }
134 }