Nektar++
Loading...
Searching...
No Matches
Field.cpp
Go to the documentation of this file.
1///////////////////////////////////////////////////////////////////////////////
2//
3// File: Field.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: Python wrapper for Field class.
32//
33///////////////////////////////////////////////////////////////////////////////
34
35#include <FieldUtils/Field.hpp>
39
40using namespace Nektar;
41using namespace Nektar::FieldUtils;
42
43// Called at the start of every loop over nparts.
44// Args: FieldSharedPtr "f",
45// Python's sys.argv stored as a Python list called "py_argv",
46// and the partition number stored as an integer called "part".
47// Function: clears data stored in f, defines f->m_partComm.
48void NewPartition(FieldSharedPtr f, py::list &py_argv, int part)
49{
50 std::cout << std::endl << "Processing partition: " << part << std::endl;
51 f->ClearField();
52
53 PyCppCommandLine cpp(py_argv);
54
55 f->m_partComm = std::shared_ptr<FieldConvertComm>(
56 new FieldConvertComm(cpp.GetArgc(), cpp.GetArgv(), f->m_nParts, part));
57}
58
59// Wrapper around the Field constructor
60// Args: FieldConvert command line arguments.
61// Function: constructs a FieldSharedPtr "f", defines f->m_defComm if
62// nparts specified, and stores a line arguments in f->m_vm.
63// Returns: f
64FieldSharedPtr Field_Init(py::list &argv, int nparts = 0, int output_points = 0,
65 int output_points_hom_z = 0, bool error = false,
66 bool force_output = false, bool no_equispaced = false,
67 int npz = 0, std::string onlyshape = "",
68 int part_only = 0, int part_only_overlapping = 0,
69 bool useSessionVariables = false,
70 bool useSessionExpansion = false,
71 bool verbose = false, std::string domain = "")
72{
73 // Construct shared pointer to a Field object.
74 std::shared_ptr<Field> f = MemoryManager<Field>::AllocateSharedPtr();
75
76 if (py::len(argv) > 0)
77 {
78 // Get argc and argv from the Python command line.
79 PyCppCommandLine cpp(argv);
80
81 // Define the MPI Communicator.
83 "Serial", cpp.GetArgc(), cpp.GetArgv());
84
85 if (nparts)
86 {
87 f->m_vm.insert(
88 std::make_pair("nparts", po::variable_value(nparts, false)));
89 if (nparts > 1)
90 {
91 f->m_nParts = nparts;
92 f->m_defComm = f->m_comm;
93 }
94 }
95 }
96
97 // Populate m_vm.
98 if (output_points)
99 {
100 f->m_vm.insert(std::make_pair(
101 "output-points", po::variable_value(output_points, false)));
102 }
103
104 if (output_points_hom_z)
105 {
106 f->m_vm.insert(
107 std::make_pair("output-points-hom-z",
108 po::variable_value(output_points_hom_z, false)));
109 }
110
111 if (error)
112 {
113 f->m_vm.insert(std::make_pair("error", po::variable_value()));
114 }
115
116 if (force_output)
117 {
118 f->m_vm.insert(std::make_pair("force-output", po::variable_value()));
119 }
120
121 if (domain.size())
122 {
124 "The doamin option in field is deprecated. Please use "
125 "the xml option range=\"xmax,xmin,ymax,ymin\", \n\t i.e."
126 "InputModule.Create(\"xml\", field, \"myfile.xml\", "
127 "range=\"-1,1,-1,1\").Run()");
128 }
129
130 if (no_equispaced)
131 {
132 f->m_vm.insert(std::make_pair("no-equispaced", po::variable_value()));
133 }
134
135 if (npz)
136 {
137 f->m_vm.insert(std::make_pair("npz", po::variable_value(npz, false)));
138 }
139
140 if (onlyshape.size())
141 {
142 f->m_vm.insert(
143 std::make_pair("onlyshape", po::variable_value(onlyshape, false)));
144 }
145
146 if (part_only)
147 {
148 f->m_vm.insert(
149 std::make_pair("part-only", po::variable_value(part_only, false)));
150 }
151
152 if (part_only_overlapping)
153 {
154 f->m_vm.insert(
155 std::make_pair("part-only-overlapping",
156 po::variable_value(part_only_overlapping, false)));
157 }
158
159 if (useSessionVariables)
160 {
161 f->m_vm.insert(
162 std::make_pair("use_session_variables", po::variable_value()));
163 }
164
165 if (useSessionExpansion)
166 {
167 f->m_vm.insert(
168 std::make_pair("use_session_expansion", po::variable_value()));
169 }
170
171 if (verbose)
172 {
173 f->m_vm.insert(std::make_pair("verbose", po::variable_value()));
174 }
175
176 return f;
177}
178
179// Get the i-th Pts field
181{
182 return f->m_fieldPts->GetPts(i);
183}
184
185// Set the i-th Pts field
186// TODO: The reference for inarray is unavailable in Python if it's not a const
187// [work] Array<OneD, NekDouble> inarray
188// [fail] Array<OneD, NekDouble> &inarray
189// [work] const Array<OneD, const NekDouble> &inarray
190void Field_SetPts(FieldSharedPtr f, const int i,
191 const Array<OneD, const NekDouble> &inarray)
192{
193 f->m_fieldPts->SetPts(i, inarray);
194}
195
196void export_Field(py::module &m)
197{
198 py::class_<Field, std::shared_ptr<Field>>(m, "Field")
199 .def(py::init<>(&Field_Init), py::arg("argv") = py::list(),
200 py::arg("nparts") = 0, py::arg("output_points") = 0,
201 py::arg("output_points_hom_z") = 0, py::arg("error") = false,
202 py::arg("force_output") = false, py::arg("no_equispaced") = false,
203 py::arg("npz") = 0, py::arg("onlyshape") = "",
204 py::arg("part_only") = 0, py::arg("part_only_overlapping") = 0,
205 py::arg("use_session_variables") = false,
206 py::arg("use_session_expansion") = false,
207 py::arg("verbose") = false, py::arg("domain") = "")
208
209 .def("GetPts", &Field_GetPts)
210 .def("SetPts", &Field_SetPts)
211 .def("ClearField", &Field::ClearField)
212 .def("NewPartition", &NewPartition)
213 .def("ReadFieldDefs", &Field::ReadFieldDefs)
214
215 .def("SetupFromExpList", &Field::SetupFromExpList)
216
217 .def_readwrite("graph", &Field::m_graph)
218 .def_readwrite("session", &Field::m_session)
219 .def_readwrite("verbose", &Field::m_verbose)
220 .def_readwrite("comm", &Field::m_comm);
221}
#define NEKERROR(type, msg)
Assert Level 0 – Fundamental assert which is used whether in FULLDEBUG, DEBUG or OPT compilation mode...
void export_Field(py::module &m)
Definition Field.cpp:196
void NewPartition(FieldSharedPtr f, py::list &py_argv, int part)
Definition Field.cpp:48
void Field_SetPts(FieldSharedPtr f, const int i, const Array< OneD, const NekDouble > &inarray)
Definition Field.cpp:190
const Array< OneD, const NekDouble > Field_GetPts(FieldSharedPtr f, const int i)
Definition Field.cpp:180
FieldSharedPtr Field_Init(py::list &argv, int nparts=0, int output_points=0, int output_points_hom_z=0, bool error=false, bool force_output=false, bool no_equispaced=false, int npz=0, std::string onlyshape="", int part_only=0, int part_only_overlapping=0, bool useSessionVariables=false, bool useSessionExpansion=false, bool verbose=false, std::string domain="")
Definition Field.cpp:64
tBaseSharedPtr CreateInstance(tKey idKey, tParam... args)
Create an instance of the class referred to by idKey.
static std::shared_ptr< DataType > AllocateSharedPtr(const Args &...args)
Allocate a shared pointer from the memory pool.
std::shared_ptr< Field > FieldSharedPtr
Definition Field.hpp:1026
CommFactory & GetCommFactory()
int GetArgc()
Returns the constructed argc.
char ** GetArgv()
Returns the constructed argv.
Helper structure to construct C++ command line argc and argv variables from a Python list.