22#ifdef ENABLE_PYTHON_BINDING
56 ObjectiveFunctionDataImpl() =
default;
57 virtual ~ObjectiveFunctionDataImpl() =
default;
77 MatrixDouble &coords, boost::shared_ptr<MatrixDouble> u_ptr,
78 boost::shared_ptr<MatrixDouble> stress_ptr,
79 boost::shared_ptr<MatrixDouble> strain_ptr,
80 boost::shared_ptr<MatrixDouble> o_ptr,
bool symmetrize =
true);
97 MatrixDouble &coords, boost::shared_ptr<MatrixDouble> u_ptr,
98 boost::shared_ptr<MatrixDouble> stress_ptr,
99 boost::shared_ptr<MatrixDouble> strain_ptr,
100 boost::shared_ptr<MatrixDouble> o_ptr,
bool symmetrize =
true);
117 MatrixDouble &coords, boost::shared_ptr<MatrixDouble> u_ptr,
118 boost::shared_ptr<MatrixDouble> stress_ptr,
119 boost::shared_ptr<MatrixDouble> strain_ptr,
120 boost::shared_ptr<MatrixDouble> o_ptr,
bool symmetrize =
true);
137 MatrixDouble &coords, boost::shared_ptr<MatrixDouble> u_ptr,
138 boost::shared_ptr<MatrixDouble> stress_ptr,
139 boost::shared_ptr<MatrixDouble> strain_ptr,
140 boost::shared_ptr<MatrixDouble> o_ptr,
bool symmetrize =
true);
144 boost::shared_ptr<MatrixDouble> u_ptr,
145 boost::shared_ptr<MatrixDouble> t_ptr,
146 boost::shared_ptr<VectorDouble> o_ptr,
147 bool symmetrize =
true);
150 evalBoundaryObjectiveGradientTraction(
MatrixDouble &coords,
151 boost::shared_ptr<MatrixDouble> u_ptr,
152 boost::shared_ptr<MatrixDouble> t_ptr,
153 boost::shared_ptr<MatrixDouble> o_ptr);
157 boost::shared_ptr<MatrixDouble> u_ptr,
158 boost::shared_ptr<MatrixDouble> t_ptr,
159 boost::shared_ptr<MatrixDouble> o_ptr);
179 std::array<double, 3> ¢roid,
184 bp::object mainNamespace;
202 np::ndarray coords, np::ndarray u,
204 np::ndarray stress, np::ndarray strain, np::ndarray &o
223 np::ndarray coords, np::ndarray u,
225 np::ndarray stress, np::ndarray strain, np::ndarray &o
244 np::ndarray coords, np::ndarray u,
246 np::ndarray stress, np::ndarray strain, np::ndarray &o
266 np::ndarray coords, np::ndarray u,
268 np::ndarray stress, np::ndarray strain, np::ndarray &o
274 np::ndarray coords, np::ndarray u,
276 np::ndarray
t, np::ndarray &o
282 np::ndarray coords, np::ndarray u,
284 np::ndarray
t, np::ndarray &o
290 np::ndarray coords, np::ndarray u,
292 np::ndarray
t, np::ndarray &o
312 int block_id, np::ndarray coords, np::ndarray centroid, np::ndarray bbodx,
328 np::ndarray convertToNumPy(std::vector<double> &data,
int rows,
341 np::ndarray convertToNumPy(
double *ptr,
int s);
370boost::shared_ptr<ObjectiveFunctionData>
372 auto ptr = boost::make_shared<ObjectiveFunctionDataImpl>();
401ObjectiveFunctionDataImpl::initPython(
const std::string py_file) {
406 auto main_module = bp::import(
"__main__");
407 mainNamespace = main_module.attr(
"__dict__");
410 bp::exec_file(py_file.c_str(), mainNamespace, mainNamespace);
414 }
catch (bp::error_already_set
const &) {
423 const auto nb_gauss_pts = s.size1();
431 auto t_s = getFTensor2SymmetricFromMat<SPACE_DIM>(s);
432 for (
size_t ii = 0; ii != nb_gauss_pts; ++ii) {
433 t_f(
i,
j) = t_s(
i,
j);
440void ObjectiveFunctionDataImpl::copyToSymmetric(
double *ptr,
MatrixDouble &s) {
441 const auto nb_gauss_pts = s.size1();
448 auto t_s = getFTensor2SymmetricFromMat<SPACE_DIM>(s);
449 for (
size_t ii = 0; ii != nb_gauss_pts; ++ii) {
450 t_s(
i,
j) = (t_f(
i,
j) || t_f(
j,
i)) / 2.0;
483MoFEMErrorCode ObjectiveFunctionDataImpl::evalInteriorObjectiveFunction(
484 MatrixDouble &coords, boost::shared_ptr<MatrixDouble> u_ptr,
485 boost::shared_ptr<MatrixDouble> stress_ptr,
486 boost::shared_ptr<MatrixDouble> strain_ptr,
487 boost::shared_ptr<MatrixDouble> o_ptr,
bool symmetrize) {
493 convertToNumPy(coords.data(), coords.size1(), coords.size2());
495 auto np_u = convertToNumPy(u_ptr->data(), u_ptr->size1(), u_ptr->size2());
499 auto full_stress = symmetrize ? copyToFull(*(stress_ptr)) : *(stress_ptr);
500 auto full_strain = symmetrize ? copyToFull(*(strain_ptr)) : *(strain_ptr);
503 auto np_stress = convertToNumPy(full_stress.data(), full_stress.size1(),
504 full_stress.size2());
505 auto np_strain = convertToNumPy(full_strain.data(), full_strain.size1(),
506 full_strain.size2());
509 const auto nb_gauss_pts = full_strain.size1();
510 np::ndarray np_output =
511 np::empty(bp::make_tuple(nb_gauss_pts), np::dtype::get_builtin<double>());
514 CHKERR interiorObjectiveFunctionImpl(np_coords, np_u, np_stress, np_strain,
518 if (np_output.get_nd() != 1 || np_output.get_shape()[0] != nb_gauss_pts) {
521 "Wrong shape of Objective Function from python expected (" +
522 std::to_string(nb_gauss_pts) +
"), got (" +
523 std::to_string(np_output.get_shape()[0]) +
")");
527 o_ptr->resize(1, nb_gauss_pts,
false);
528 double *val_ptr =
reinterpret_cast<double *
>(np_output.get_data());
529 std::copy(val_ptr, val_ptr + nb_gauss_pts, o_ptr->data().begin());
531 }
catch (bp::error_already_set
const &) {
569MoFEMErrorCode ObjectiveFunctionDataImpl::evalInteriorObjectiveGradientStress(
570 MatrixDouble &coords, boost::shared_ptr<MatrixDouble> u_ptr,
571 boost::shared_ptr<MatrixDouble> stress_ptr,
572 boost::shared_ptr<MatrixDouble> strain_ptr,
573 boost::shared_ptr<MatrixDouble> o_ptr,
bool symmetrize) {
579 convertToNumPy(coords.data(), coords.size1(), coords.size2());
580 auto np_u = convertToNumPy(u_ptr->data(), u_ptr->size1(), u_ptr->size2());
583 auto full_stress = symmetrize ? copyToFull(*(stress_ptr)) : *(stress_ptr);
584 auto full_strain = symmetrize ? copyToFull(*(strain_ptr)) : *(strain_ptr);
587 auto np_stress = convertToNumPy(full_stress.data(), full_stress.size1(),
588 full_stress.size2());
589 auto np_strain = convertToNumPy(full_strain.data(), full_strain.size1(),
590 full_strain.size2());
592 np::ndarray np_output =
593 np::empty(bp::make_tuple(full_strain.size1(), full_strain.size2()),
594 np::dtype::get_builtin<double>());
597 CHKERR interiorObjectiveGradientStressImpl(np_coords, np_u, np_stress, np_strain,
601 if (np_output.get_shape()[0] != full_strain.size1() ||
602 np_output.get_shape()[1] != full_strain.size2()) {
605 "Wrong shape of Objective Gradient from python expected (" +
606 std::to_string(full_strain.size1()) +
", " +
607 std::to_string(full_strain.size2()) +
"), got (" +
608 std::to_string(np_output.get_shape()[0]) +
", " +
609 std::to_string(np_output.get_shape()[1]) +
")");
613 o_ptr->resize(stress_ptr->size1(), stress_ptr->size2(),
false);
615 double *val_ptr =
reinterpret_cast<double *
>(np_output.get_data());
617 copyToSymmetric(val_ptr, *(o_ptr));
619 double *val_ptr =
reinterpret_cast<double *
>(np_output.get_data());
620 std::copy(val_ptr, val_ptr + stress_ptr->size1() * stress_ptr->size2(),
621 o_ptr->data().begin());
624 }
catch (bp::error_already_set
const &) {
663MoFEMErrorCode ObjectiveFunctionDataImpl::evalInteriorObjectiveGradientStrain(
664 MatrixDouble &coords, boost::shared_ptr<MatrixDouble> u_ptr,
665 boost::shared_ptr<MatrixDouble> stress_ptr,
666 boost::shared_ptr<MatrixDouble> strain_ptr,
667 boost::shared_ptr<MatrixDouble> o_ptr,
bool symmetrize) {
673 convertToNumPy(coords.data(), coords.size1(), coords.size2());
674 auto np_u = convertToNumPy(u_ptr->data(), u_ptr->size1(), u_ptr->size2());
677 auto full_stress = symmetrize ? copyToFull(*(stress_ptr)) : *(stress_ptr);
678 auto full_strain = symmetrize ? copyToFull(*(strain_ptr)) : *(strain_ptr);
680 auto np_stress = convertToNumPy(full_stress.data(), full_stress.size1(),
681 full_stress.size2());
682 auto np_strain = convertToNumPy(full_strain.data(), full_strain.size1(),
683 full_strain.size2());
686 np::ndarray np_output =
687 np::empty(bp::make_tuple(full_strain.size1(), full_strain.size2()),
688 np::dtype::get_builtin<double>());
691 CHKERR interiorObjectiveGradientStrainImpl(np_coords, np_u, np_stress, np_strain,
695 if (np_output.get_shape()[0] != full_strain.size1() ||
696 np_output.get_shape()[1] != full_strain.size2()) {
699 "Wrong shape of Objective Gradient from python expected (" +
700 std::to_string(full_strain.size1()) +
", " +
701 std::to_string(full_strain.size2()) +
"), got (" +
702 std::to_string(np_output.get_shape()[0]) +
", " +
703 std::to_string(np_output.get_shape()[1]) +
")");
706 o_ptr->resize(strain_ptr->size1(), strain_ptr->size2(),
false);
708 double *val_ptr =
reinterpret_cast<double *
>(np_output.get_data());
709 copyToSymmetric(val_ptr, *(o_ptr));
711 double *val_ptr =
reinterpret_cast<double *
>(np_output.get_data());
712 std::copy(val_ptr, val_ptr + strain_ptr->size1() * strain_ptr->size2(),
713 o_ptr->data().begin());
716 }
catch (bp::error_already_set
const &) {
757MoFEMErrorCode ObjectiveFunctionDataImpl::evalInteriorObjectiveGradientU(
758 MatrixDouble &coords, boost::shared_ptr<MatrixDouble> u_ptr,
759 boost::shared_ptr<MatrixDouble> stress_ptr,
760 boost::shared_ptr<MatrixDouble> strain_ptr,
761 boost::shared_ptr<MatrixDouble> o_ptr,
bool symmetrize) {
767 convertToNumPy(coords.data(), coords.size1(), coords.size2());
768 auto np_u = convertToNumPy(u_ptr->data(), u_ptr->size1(), u_ptr->size2());
771 auto full_stress = symmetrize ? copyToFull(*(stress_ptr)) : *(stress_ptr);
772 auto full_strain = symmetrize ? copyToFull(*(strain_ptr)) : *(strain_ptr);
774 auto np_stress = convertToNumPy(full_stress.data(), full_stress.size1(),
775 full_stress.size2());
776 auto np_strain = convertToNumPy(full_strain.data(), full_strain.size1(),
777 full_strain.size2());
780 np::ndarray np_output =
781 np::empty(bp::make_tuple(u_ptr->size1(), u_ptr->size2()),
782 np::dtype::get_builtin<double>());
786 CHKERR interiorObjectiveGradientUImpl(np_coords, np_u, np_stress, np_strain,
790 if (np_output.get_shape()[0] != u_ptr->size1() ||
791 np_output.get_shape()[1] != u_ptr->size2()) {
794 "Wrong shape of Objective Gradient from python expected (" +
795 std::to_string(u_ptr->size1()) +
", " +
796 std::to_string(u_ptr->size2()) +
"), got (" +
797 std::to_string(np_output.get_shape()[0]) +
", " +
798 std::to_string(np_output.get_shape()[1]) +
")");
802 o_ptr->resize(u_ptr->size1(), u_ptr->size2(),
false);
803 double *val_ptr =
reinterpret_cast<double *
>(np_output.get_data());
804 std::copy(val_ptr, val_ptr + u_ptr->size1() * u_ptr->size2(),
805 o_ptr->data().begin());
807 }
catch (bp::error_already_set
const &) {
815MoFEMErrorCode ObjectiveFunctionDataImpl::evalBoundaryObjectiveGradientTraction(
816 MatrixDouble &coords, boost::shared_ptr<MatrixDouble> u_ptr,
817 boost::shared_ptr<MatrixDouble> t_ptr,
818 boost::shared_ptr<MatrixDouble> o_ptr) {
823 convertToNumPy(coords.data(), coords.size1(), coords.size2());
824 auto np_u = convertToNumPy(u_ptr->data(), u_ptr->size1(), u_ptr->size2());
825 auto np_t = convertToNumPy(t_ptr->data(), t_ptr->size1(), t_ptr->size2());
827 np::ndarray np_output =
828 np::empty(bp::make_tuple(u_ptr->size1(), u_ptr->size2()),
829 np::dtype::get_builtin<double>());
831 CHKERR boundaryObjectiveGradientTractionImpl(np_coords, np_u, np_t, np_output);
834 if (np_output.get_shape()[0] != u_ptr->size1() ||
835 np_output.get_shape()[1] != u_ptr->size2()) {
838 "Wrong shape of Objective Gradient from python expected (" +
839 std::to_string(u_ptr->size1()) +
", " +
840 std::to_string(u_ptr->size2()) +
"), got (" +
841 std::to_string(np_output.get_shape()[0]) +
", " +
842 std::to_string(np_output.get_shape()[1]) +
")");
845 o_ptr->resize(u_ptr->size1(), u_ptr->size2(),
false);
846 double *val_ptr =
reinterpret_cast<double *
>(np_output.get_data());
847 std::copy(val_ptr, val_ptr + u_ptr->size1() * u_ptr->size2(),
848 o_ptr->data().begin());
850 }
catch (bp::error_already_set
const &) {
857MoFEMErrorCode ObjectiveFunctionDataImpl::evalBoundaryObjectiveFunction(
858 MatrixDouble &coords, boost::shared_ptr<MatrixDouble> u_ptr,
859 boost::shared_ptr<MatrixDouble> t_ptr,
860 boost::shared_ptr<VectorDouble> o_ptr,
bool symmetrize) {
866 convertToNumPy(coords.data(), coords.size1(), coords.size2());
867 auto np_u = convertToNumPy(u_ptr->data(), u_ptr->size1(), u_ptr->size2());
868 auto np_t = convertToNumPy(t_ptr->data(), t_ptr->size1(), t_ptr->size2());
870 np::ndarray np_output = np::empty(bp::make_tuple(t_ptr->size2()),
871 np::dtype::get_builtin<double>());
873 CHKERR boundaryObjectiveFunctionImpl(np_coords, np_u, np_t, np_output);
876 if (np_output.get_nd() != 1 || np_output.get_shape()[0] != t_ptr->size2()) {
879 "Wrong shape of Objective Function from python expected (" +
880 std::to_string(t_ptr->size2()) +
"), got (" +
881 std::to_string(np_output.get_shape()[0]) +
")");
884 o_ptr->resize(t_ptr->size2(),
false);
885 double *val_ptr =
reinterpret_cast<double *
>(np_output.get_data());
886 std::copy(val_ptr, val_ptr + t_ptr->size2(), o_ptr->data().begin());
888 }
catch (bp::error_already_set
const &) {
895MoFEMErrorCode ObjectiveFunctionDataImpl::evalBoundaryObjectiveGradientU(
896 MatrixDouble &coords, boost::shared_ptr<MatrixDouble> u_ptr,
897 boost::shared_ptr<MatrixDouble> t_ptr,
898 boost::shared_ptr<MatrixDouble> o_ptr) {
902 convertToNumPy(coords.data(), coords.size1(), coords.size2());
903 auto np_u = convertToNumPy(u_ptr->data(), u_ptr->size1(), u_ptr->size2());
904 auto np_t = convertToNumPy(t_ptr->data(), t_ptr->size1(), t_ptr->size2());
906 np::ndarray np_output =
907 np::empty(bp::make_tuple(u_ptr->size1(), u_ptr->size2()),
908 np::dtype::get_builtin<double>());
910 CHKERR boundaryObjectiveGradientUImpl(np_coords, np_u, np_t, np_output);
913 if (np_output.get_shape()[0] != u_ptr->size1() ||
914 np_output.get_shape()[1] != u_ptr->size2()) {
917 "Wrong shape of Objective Gradient from python expected (" +
918 std::to_string(u_ptr->size1()) +
", " +
919 std::to_string(u_ptr->size2()) +
"), got (" +
920 std::to_string(np_output.get_shape()[0]) +
", " +
921 std::to_string(np_output.get_shape()[1]) +
")");
924 o_ptr->resize(u_ptr->size1(), u_ptr->size2(),
false);
925 double *val_ptr =
reinterpret_cast<double *
>(np_output.get_data());
926 std::copy(val_ptr, val_ptr + u_ptr->size1() * u_ptr->size2(),
927 o_ptr->data().begin());
929 }
catch (bp::error_already_set
const &) {
972 int block_id,
MatrixDouble &coords, std::array<double, 3> ¢roid,
979 CHKERR numberOfModes(block_id, nb_modes);
983 convertToNumPy(coords.data(), coords.size1(), coords.size2());
987 convertToNumPy(centroid.data(), 3);
988 auto np_bbodx = convertToNumPy(
992 np::ndarray np_output =
993 np::empty(bp::make_tuple(nb_modes, coords.size1(), coords.size2()),
994 np::dtype::get_builtin<double>());
997 CHKERR blockModesImpl(block_id, np_coords, np_centroid, np_bbodx,
1001 if (np_output.get_shape()[0] != nb_modes ||
1002 np_output.get_shape()[1] != coords.size1() ||
1003 np_output.get_shape()[2] != coords.size2()) {
1005 "Wrong shape of Modes from python expected (" +
1006 std::to_string(nb_modes) +
", " +
1007 std::to_string(coords.size1()) +
", " +
1008 std::to_string(coords.size2()) +
"), got (" +
1009 std::to_string(np_output.get_shape()[0]) +
", " +
1010 std::to_string(np_output.get_shape()[1]) +
", " +
1011 std::to_string(np_output.get_shape()[2]) +
")");
1015 o_ptr.resize(nb_modes, coords.size1() * coords.size2(),
false);
1016 double *val_ptr =
reinterpret_cast<double *
>(np_output.get_data());
1018 std::copy(val_ptr, val_ptr + coords.size1() * coords.size2() * nb_modes,
1019 o_ptr.data().begin());
1021 }
catch (bp::error_already_set
const &) {
1029MoFEMErrorCode ObjectiveFunctionDataImpl::interiorObjectiveFunctionImpl(
1031 np::ndarray coords, np::ndarray u,
1033 np::ndarray stress, np::ndarray strain, np::ndarray &o
1039 if (bp::extract<bool>(mainNamespace.attr(
"__contains__")(
"f"))) {
1041 o = bp::extract<np::ndarray>(
1042 mainNamespace[
"f"](coords, u, stress, strain));
1043 }
else if (bp::extract<bool>(
1044 mainNamespace.attr(
"__contains__")(
"f_interior"))) {
1045 o = bp::extract<np::ndarray>(
1046 mainNamespace[
"f_interior"](coords, u, stress, strain));
1050 "Python function f_interior(coords,u,stress,strain) is not defined");
1053 }
catch (bp::error_already_set
const &) {
1061MoFEMErrorCode ObjectiveFunctionDataImpl::interiorObjectiveGradientStressImpl(
1063 np::ndarray coords, np::ndarray u,
1065 np::ndarray stress, np::ndarray strain, np::ndarray &o
1071 if (bp::extract<bool>(mainNamespace.attr(
"__contains__")(
"f_stress"))) {
1073 o = bp::extract<np::ndarray>(
1074 mainNamespace[
"f_stress"](coords, u, stress, strain));
1075 }
else if (bp::extract<bool>(
1076 mainNamespace.attr(
"__contains__")(
"f_interior_stress"))) {
1077 o = bp::extract<np::ndarray>(
1078 mainNamespace[
"f_interior_stress"](coords, u, stress, strain));
1082 "Python function f_interior_stress(coords,u,stress,strain) is not defined");
1085 }
catch (bp::error_already_set
const &) {
1093MoFEMErrorCode ObjectiveFunctionDataImpl::interiorObjectiveGradientStrainImpl(
1095 np::ndarray coords, np::ndarray u,
1097 np::ndarray stress, np::ndarray strain, np::ndarray &o
1103 if (bp::extract<bool>(mainNamespace.attr(
"__contains__")(
"f_strain"))) {
1105 o = bp::extract<np::ndarray>(
1106 mainNamespace[
"f_strain"](coords, u, stress, strain));
1107 }
else if (bp::extract<bool>(
1108 mainNamespace.attr(
"__contains__")(
"f_interior_strain"))) {
1109 o = bp::extract<np::ndarray>(
1110 mainNamespace[
"f_interior_strain"](coords, u, stress, strain));
1114 "Python function f_interior_strain(coords,u,stress,strain) is not defined");
1117 }
catch (bp::error_already_set
const &) {
1125MoFEMErrorCode ObjectiveFunctionDataImpl::interiorObjectiveGradientUImpl(
1127 np::ndarray coords, np::ndarray u,
1129 np::ndarray stress, np::ndarray strain, np::ndarray &o
1135 if (bp::extract<bool>(mainNamespace.attr(
"__contains__")(
"f_u"))) {
1137 o = bp::extract<np::ndarray>(
1138 mainNamespace[
"f_u"](coords, u, stress, strain));
1139 }
else if (bp::extract<bool>(
1140 mainNamespace.attr(
"__contains__")(
"f_interior_u"))) {
1141 o = bp::extract<np::ndarray>(
1142 mainNamespace[
"f_interior_u"](coords, u, stress, strain));
1146 "Python function f_interior_u(coords,u,stress,strain) is not defined");
1149 }
catch (bp::error_already_set
const &) {
1157MoFEMErrorCode ObjectiveFunctionDataImpl::boundaryObjectiveGradientTractionImpl(
1159 np::ndarray coords, np::ndarray u,
1161 np::ndarray
t, np::ndarray &o
1167 if (bp::extract<bool>(mainNamespace.attr(
"__contains__")(
"f_boundary_t"))) {
1168 o = bp::extract<np::ndarray>(mainNamespace[
"f_boundary_t"](coords, u,
t));
1172 "Python function f_boundary_t(coords,u,t) is not defined");
1175 }
catch (bp::error_already_set
const &) {
1182MoFEMErrorCode ObjectiveFunctionDataImpl::boundaryObjectiveFunctionImpl(
1184 np::ndarray coords, np::ndarray u,
1186 np::ndarray
t, np::ndarray &o
1192 if (bp::extract<bool>(mainNamespace.attr(
"__contains__")(
"f_boundary"))) {
1193 o = bp::extract<np::ndarray>(mainNamespace[
"f_boundary"](coords, u,
t));
1194 }
else if (bp::extract<bool>(
1195 mainNamespace.attr(
"__contains__")(
"f_boundary_function"))) {
1196 o = bp::extract<np::ndarray>(
1197 mainNamespace[
"f_boundary_function"](coords, u,
t));
1201 "Python function f_boundary(coords,u,t) is not defined");
1204 }
catch (bp::error_already_set
const &) {
1211MoFEMErrorCode ObjectiveFunctionDataImpl::boundaryObjectiveGradientUImpl(
1213 np::ndarray coords, np::ndarray u,
1215 np::ndarray
t, np::ndarray &o
1221 if (bp::extract<bool>(mainNamespace.attr(
"__contains__")(
"f_boundary_u"))) {
1222 o = bp::extract<np::ndarray>(mainNamespace[
"f_boundary_u"](coords, u,
t));
1226 "Python function f_boundary_u(coords,u,t) is not defined");
1229 }
catch (bp::error_already_set
const &) {
1236MoFEMErrorCode ObjectiveFunctionDataImpl::numberOfModes(
int block_id,
1241 if (bp::extract<bool>(
1242 mainNamespace.attr(
"__contains__")(
"number_of_modes"))) {
1243 modes = bp::extract<int>(mainNamespace[
"number_of_modes"](block_id));
1247 "Python function number_of_modes(block_id) is not defined");
1250 }
catch (bp::error_already_set
const &) {
1258MoFEMErrorCode ObjectiveFunctionDataImpl::blockModesImpl(
int block_id,
1260 np::ndarray centroid,
1265 if (bp::extract<bool>(mainNamespace.attr(
"__contains__")(
"block_modes"))) {
1266 o = bp::extract<np::ndarray>(
1267 mainNamespace[
"block_modes"](block_id, coords, centroid, bbodx));
1271 "Python function block_modes(block_id,coords,centroid,bbox) is not "
1274 }
catch (bp::error_already_set
const &) {
1303ObjectiveFunctionDataImpl::convertToNumPy(std::vector<double> &data,
int rows,
1305 auto dtype = np::dtype::get_builtin<double>();
1306 auto size = bp::make_tuple(rows, nb_gauss_pts);
1307 auto stride = bp::make_tuple(nb_gauss_pts *
sizeof(
double),
sizeof(
double));
1308 return (np::from_data(data.data(), dtype, size, stride, bp::object()));
1311inline np::ndarray ObjectiveFunctionDataImpl::convertToNumPy(
double *ptr,
1313 auto dtype = np::dtype::get_builtin<double>();
1314 auto size = bp::make_tuple(s);
1315 auto stride = bp::make_tuple(
sizeof(
double));
1316 return (np::from_data(ptr, dtype, size, stride, bp::object()));
1321boost::shared_ptr<ObjectiveFunctionData>
1324 "Python objective function requires Boost.NumPy");