Nektar++
Functions
Field.cpp File Reference
#include <FieldUtils/Field.hpp>
#include <FieldUtils/FieldConvertComm.hpp>
#include <LibUtilities/Python/NekPyConfig.hpp>

Go to the source code of this file.

Functions

char ** ConvertCommandLine (py::list &py_argv)
 
void NewPartition (FieldSharedPtr f, py::list &py_argv, int part)
 
FieldSharedPtr Field_Init (py::list &py_argv, int nparts=0, int output_points=0, int output_points_hom_z=0, bool error=false, bool force_output=false, std::string domain="", 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)
 
const Array< OneD, const NekDoubleField_GetPts (FieldSharedPtr f, const int i)
 
void Field_SetPts (FieldSharedPtr f, const int i, const Array< OneD, const NekDouble > &inarray)
 
void export_Field ()
 

Function Documentation

◆ ConvertCommandLine()

char ** ConvertCommandLine ( py::list &  py_argv)

Definition at line 43 of file Field.cpp.

44{
45 int i, argc = py::len(py_argv), bufSize = 0;
46 char **argv = new char *[argc + 1], *p;
47
48 for (i = 0; i < argc; ++i)
49 {
50 std::string tmp = py::extract<std::string>(py_argv[i]);
51 bufSize += tmp.size() + 1;
52 }
53
54 std::vector<char> buf(bufSize);
55 for (i = 0, p = &buf[0]; i < argc; ++i)
56 {
57 std::string tmp = py::extract<std::string>(py_argv[i]);
58 std::copy(tmp.begin(), tmp.end(), p);
59 p[tmp.size()] = '\0';
60 argv[i] = p;
61 p += tmp.size() + 1;
62 }
63
64 argv[argc] = nullptr;
65 return argv;
66}
def copy(self)
Definition: pycml.py:2663

References CellMLToNektar.pycml::copy(), and CellMLToNektar.cellml_metadata::p.

Referenced by Field_Init(), and NewPartition().

◆ export_Field()

void export_Field ( )

Definition at line 216 of file Field.cpp.

217{
218 py::class_<Field, std::shared_ptr<Field>>("Field", py::no_init)
219 .def("GetPts", &Field_GetPts)
220 .def("SetPts", &Field_SetPts)
221 .def("ClearField", &Field::ClearField)
222 .def("NewPartition", &NewPartition)
223 .def("__init__",
224 py::make_constructor(
225 &Field_Init, py::default_call_policies(),
226 (py::arg("py_argv"), py::arg("nparts") = 0,
227 py::arg("output_points") = 0,
228 py::arg("output_points_hom_z") = 0, py::arg("error") = false,
229 py::arg("force_output") = false, py::arg("domain") = "",
230 py::arg("no_equispaced") = false, py::arg("npz") = 0,
231 py::arg("onlyshape") = "", py::arg("part_only") = 0,
232 py::arg("part_only_overlapping") = 0,
233 py::arg("use_session_variables") = false,
234 py::arg("use_session_expansion") = false,
235 py::arg("verbose") = false)));
236}
void NewPartition(FieldSharedPtr f, py::list &py_argv, int part)
Definition: Field.cpp:73
void Field_SetPts(FieldSharedPtr f, const int i, const Array< OneD, const NekDouble > &inarray)
Definition: Field.cpp:210
FieldSharedPtr Field_Init(py::list &py_argv, int nparts=0, int output_points=0, int output_points_hom_z=0, bool error=false, bool force_output=false, std::string domain="", 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)
Definition: Field.cpp:88
const Array< OneD, const NekDouble > Field_GetPts(FieldSharedPtr f, const int i)
Definition: Field.cpp:200

References Field_GetPts(), Field_Init(), Field_SetPts(), and NewPartition().

Referenced by BOOST_PYTHON_MODULE().

◆ Field_GetPts()

const Array< OneD, const NekDouble > Field_GetPts ( FieldSharedPtr  f,
const int  i 
)

Definition at line 200 of file Field.cpp.

201{
202 return f->m_fieldPts->GetPts(i);
203}

Referenced by export_Field().

◆ Field_Init()

FieldSharedPtr Field_Init ( py::list &  py_argv,
int  nparts = 0,
int  output_points = 0,
int  output_points_hom_z = 0,
bool  error = false,
bool  force_output = false,
std::string  domain = "",
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 
)

Definition at line 88 of file Field.cpp.

97{
98 // Construct shared pointer to a Field object.
99 std::shared_ptr<Field> f = MemoryManager<Field>::AllocateSharedPtr();
100
101 // Get argc and argv from the Python command line.
102 int argc = py::len(py_argv);
103 char **argv = ConvertCommandLine(py_argv);
104
105 // Define the MPI Communicator.
106 f->m_comm =
107 LibUtilities::GetCommFactory().CreateInstance("Serial", argc, argv);
108
109 if (nparts)
110 {
111 f->m_vm.insert(
112 std::make_pair("nparts", po::variable_value(nparts, false)));
113 if (nparts > 1)
114 {
115 f->m_nParts = nparts;
116 f->m_defComm = f->m_comm;
117 }
118 }
119
120 // Populate m_vm.
121 if (output_points)
122 {
123 f->m_vm.insert(std::make_pair(
124 "output-points", po::variable_value(output_points, false)));
125 }
126
127 if (output_points_hom_z)
128 {
129 f->m_vm.insert(
130 std::make_pair("output-points-hom-z",
131 po::variable_value(output_points_hom_z, false)));
132 }
133
134 if (error)
135 {
136 f->m_vm.insert(std::make_pair("error", po::variable_value()));
137 }
138
139 if (force_output)
140 {
141 f->m_vm.insert(std::make_pair("force-output", po::variable_value()));
142 }
143
144 if (domain.size())
145 {
146 f->m_vm.insert(
147 std::make_pair("range", po::variable_value(domain, false)));
148 }
149
150 if (no_equispaced)
151 {
152 f->m_vm.insert(std::make_pair("no-equispaced", po::variable_value()));
153 }
154
155 if (npz)
156 {
157 f->m_vm.insert(std::make_pair("npz", po::variable_value(npz, false)));
158 }
159
160 if (onlyshape.size())
161 {
162 f->m_vm.insert(
163 std::make_pair("onlyshape", po::variable_value(onlyshape, false)));
164 }
165
166 if (part_only)
167 {
168 f->m_vm.insert(
169 std::make_pair("part-only", po::variable_value(part_only, false)));
170 }
171
172 if (part_only_overlapping)
173 {
174 f->m_vm.insert(
175 std::make_pair("part-only-overlapping",
176 po::variable_value(part_only_overlapping, false)));
177 }
178
179 if (useSessionVariables)
180 {
181 f->m_vm.insert(
182 std::make_pair("use_session_variables", po::variable_value()));
183 }
184
185 if (useSessionExpansion)
186 {
187 f->m_vm.insert(
188 std::make_pair("use_session_expansion", po::variable_value()));
189 }
190
191 if (verbose)
192 {
193 f->m_vm.insert(std::make_pair("verbose", po::variable_value()));
194 }
195
196 return f;
197}
char ** ConvertCommandLine(py::list &py_argv)
Definition: Field.cpp:43
tBaseSharedPtr CreateInstance(tKey idKey, tParam... args)
Create an instance of the class referred to by idKey.
Definition: NekFactory.hpp:143
General purpose memory allocation routines with the ability to allocate from thread specific memory p...
CommFactory & GetCommFactory()

References ConvertCommandLine(), Nektar::LibUtilities::NekFactory< tKey, tBase, tParam >::CreateInstance(), and Nektar::LibUtilities::GetCommFactory().

Referenced by export_Field().

◆ Field_SetPts()

void Field_SetPts ( FieldSharedPtr  f,
const int  i,
const Array< OneD, const NekDouble > &  inarray 
)

Definition at line 210 of file Field.cpp.

212{
213 f->m_fieldPts->SetPts(i, inarray);
214}

Referenced by export_Field().

◆ NewPartition()

void NewPartition ( FieldSharedPtr  f,
py::list &  py_argv,
int  part 
)

Definition at line 73 of file Field.cpp.

74{
75 std::cout << std::endl << "Processing partition: " << part << std::endl;
76 f->ClearField();
77 int argc = py::len(py_argv);
78 char **argv = ConvertCommandLine(py_argv);
79 f->m_partComm = std::shared_ptr<FieldConvertComm>(
80 new FieldConvertComm(argc, argv, f->m_nParts, part));
81}

References ConvertCommandLine().

Referenced by export_Field().