25 #include "BasicMeshes.hpp"
26 #include "customOperators.hpp"
27 #include <Operators.hpp>
28 #include <bitpit_common.hpp>
44 m_origin_temp = {{0.0,0.0,0.0}};
45 m_span_temp = {{1.0,1.0,1.0}};
46 m_inflimits_temp = {{0.0,0.0,0.0}};
47 m_refsystem_temp[0] = {{1.0,0.0,0.0}};
48 m_refsystem_temp[1] = {{0.0,1.0,0.0}};
49 m_refsystem_temp[2] = {{0.0,0.0,1.0}};
83 switch(other.
m_shape->getShapeType()){
87 if (pp !=
nullptr)
m_shape = std::unique_ptr<BasicShape>(
new Wedge(*(pp)));
93 if (pp !=
nullptr)
m_shape = std::unique_ptr<BasicShape>(
new Cylinder(*(pp)));
99 if (pp !=
nullptr)
m_shape = std::unique_ptr<BasicShape>(
new Sphere(*(pp)));
105 if (pp !=
nullptr)
m_shape = std::unique_ptr<BasicShape>(
new Cube(*(pp)));
112 m_origin_temp = other.m_origin_temp;
113 m_span_temp = other.m_span_temp;
114 m_inflimits_temp = other.m_inflimits_temp;
115 m_refsystem_temp = other.m_refsystem_temp;
116 m_shapetype_temp = other.m_shapetype_temp;
142 std::swap(m_nx, x.m_nx);
143 std::swap(m_ny, x.m_ny);
144 std::swap(m_nz, x.m_nz);
147 std::swap(m_dx, x.m_dx);
148 std::swap(m_dy, x.m_dy);
149 std::swap(m_dz, x.m_dz);
152 std::swap(m_xnode, x.m_xnode);
153 std::swap(m_ynode, x.m_ynode);
154 std::swap(m_znode, x.m_znode);
155 std::swap(m_xedge, x.m_xedge);
156 std::swap(m_yedge, x.m_yedge);
157 std::swap(m_zedge, x.m_zedge);
159 std::swap(m_origin_temp,x.m_origin_temp);
160 std::swap(m_span_temp,x.m_span_temp);
161 std::swap(m_inflimits_temp,x.m_inflimits_temp);
162 std::swap(m_refsystem_temp,x.m_refsystem_temp);
163 std::swap(m_shapetype_temp,x.m_shapetype_temp);
165 std::swap(m_setorigin,x.m_setorigin);
166 std::swap(m_setspan,x.m_setspan);
167 std::swap(m_setInfLimits,x.m_setInfLimits);
168 std::swap(m_setRefSys,x.m_setRefSys);
169 std::swap(m_isBuild,x.m_isBuild);
172 std::unique_ptr<BasicShape> tempshape;
173 switch(x.m_shape->getShapeType()){
176 const Wedge * pp =
dynamic_cast<const Wedge*
>(x.m_shape.get());
177 if (pp !=
nullptr) tempshape = std::unique_ptr<BasicShape>(
new Wedge(*(pp)));
183 if (pp !=
nullptr) tempshape = std::unique_ptr<BasicShape>(
new Cylinder(*(pp)));
188 const Sphere * pp =
dynamic_cast<const Sphere*
>(x.m_shape.get());
189 if (pp !=
nullptr) tempshape = std::unique_ptr<BasicShape>(
new Sphere(*(pp)));
194 const Cube * pp =
dynamic_cast<const Cube*
>(x.m_shape.get());
195 if (pp !=
nullptr) tempshape = std::unique_ptr<BasicShape>(
new Cube(*(pp)));
200 x.m_shape = std::move(m_shape);
201 m_shape = std::move(tempshape);
224 if (
getShape() ==
nullptr)
return(m_origin_temp);
232 if (
getShape() ==
nullptr)
return(m_span_temp);
240 if (
getShape() ==
nullptr)
return(m_inflimits_temp);
248 if (
getShape() ==
nullptr)
return(m_refsystem_temp);
272 if (
getShape() ==
nullptr)
return(m_shapetype_temp);
282 return(
getShape()->getCoordinateType(0));
291 return(
getShape()->getCoordinateType(i));
300 return(
getShape()->getCoordinateType(1));
309 return(
getShape()->getCoordinateType(2));
317 std::array<CoordType, 3> types;
318 for (
int i=0; i<3; i++){
330 res[0] =
m_dx*scale[0]; res[1] =
m_dy*scale[1]; res[2] =
m_dz*scale[2];
492 for (
int i=0; i<np; i++){
504 for (
int i=0; i<np; i++){
517 for (
int i=0; i<np; i++){
529 for (
int i=0; i<np; i++){
543 m_origin_temp = origin;
590 m_inflimits_temp[dir] = inflim;
622 m_refsystem_temp[0] = axis0;
623 m_refsystem_temp[1] = axis1;
624 m_refsystem_temp[2] = axis2;
661 m_refsystem_temp[0] = axes[0];
662 m_refsystem_temp[1] = axes[1];
663 m_refsystem_temp[2] = axes[2];
718 m_origin_temp =
m_shape.get()->getOrigin();
719 m_span_temp =
m_shape.get()->getSpan();
720 m_inflimits_temp =
m_shape.get()->getInfLimits();
721 m_refsystem_temp =
m_shape.get()->getRefSystem();
732 spanMat[0].fill(1); spanMat[2].fill(1); spanMat[2].fill(1);
733 spanMat[1][1] = spanMat[2][1] = 2*BITPIT_PI;
734 spanMat[2][2] = BITPIT_PI;
738 for(
int i=0; i<3; ++i) spanMat[i] = m_span_temp;
744 m_shape = std::unique_ptr<BasicShape>(
new Wedge(origin,spanMat[0]));
747 m_shape = std::unique_ptr<BasicShape>(
new Cylinder(origin,spanMat[1]));
750 m_shape = std::unique_ptr<BasicShape>(
new Sphere(origin, spanMat[2]));
753 m_shape = std::unique_ptr<BasicShape>(
new Cube(origin, spanMat[0]));
758 m_shape.get()->setInfLimits(m_inflimits_temp[0],0);
759 m_shape.get()->setInfLimits(m_inflimits_temp[1],1);
760 m_shape.get()->setInfLimits(m_inflimits_temp[2],2);
765 m_shape.get()->setRefSystem(m_refsystem_temp);
779 if(shape ==
nullptr)
return;
789 const Wedge * pp =
dynamic_cast<const Wedge*
>(shape);
790 if (pp !=
nullptr)
m_shape = std::unique_ptr<BasicShape>(
new Wedge(*(pp)));
796 if (pp !=
nullptr)
m_shape = std::unique_ptr<BasicShape>(
new Cylinder(*(pp)));
802 if (pp !=
nullptr)
m_shape = std::unique_ptr<BasicShape>(
new Sphere(*(pp)));
807 const Cube * pp =
dynamic_cast<const Cube*
>(shape);
808 if (pp !=
nullptr)
m_shape = std::unique_ptr<BasicShape>(
new Cube(*(pp)));
862 for (
int i=0; i<3; i++){
904 dimLimit[1] = 5; dimLimit[2] = 3;
917 for(
int i=0; i<3; ++i){
918 if(spacing[i] != 0.0) {
919 dim[i] = (int) std::floor(span2[i]/spacing[i] +0.5) + 1;
921 dim[i] = dimLimit[i];
959 dimLimit[1] = 5; dimLimit[2] = 3;
970 for(
int i=0; i<3; ++i){
971 if(spacing[i] != 0.0) {
972 dim[i] = (int) std::floor(span2[i]/spacing[i] +0.5) + 1;
974 dim[i] = dimLimit[i];
1000 m_origin_temp = {{0.0,0.0,0.0}};
1001 m_span_temp = {{1.0,1.0,1.0}};
1002 m_inflimits_temp = {{0.0,0.0,0.0}};
1003 for(
int i=0; i<3; ++i){m_refsystem_temp[i].fill(0.0); m_refsystem_temp[i][i] = 1.0;}
1023 i = std::min(
m_nx-1, std::max(0, (
int) std::floor((P[0]-locOr[0])/
m_dx)));
1024 j = std::min(
m_ny-1, std::max(0, (
int) std::floor((P[1]-locOr[1])/
m_dy)));
1025 k = std::min(
m_nz-1, std::max(0, (
int) std::floor((P[2]-locOr[2])/
m_dz)));
1037 darray3E temp = conArray<double,3>(point);
1065 int index = N_ /
m_nz;
1081 int index = N_ / (
m_nz+1);
1082 j = index % (
m_ny+1);
1083 i = index / (
m_ny+1);
1091 return(
getShape()->toWorldCoord(point));
1099 darray3E temp = conArray<double,3>(point);
1109 int size = list_points.size();
1111 for(
int i=0; i<size; ++i){
1122 return(
getShape()->toLocalCoord(point));
1127 darray3E temp = conArray<double,3>(point);
1138 int size = list_points.size();
1140 for(
int i=0; i<size; ++i){
1154 int i0, j0, k0, ip, jp, kp;
1155 double wx0,wx1,wy0,wy1,wz0,wz1;
1159 if (P[0] >
m_xnode[i0]) { ip = std::min(i0+1,
m_nx-1); }
1160 else { ip = std::max(0, i0-1); }
1161 if (P[1] >
m_ynode[j0]) { jp = std::min(j0+1,
m_ny-1); }
1162 else { jp = std::max(0, j0-1); }
1163 if (P[2] >
m_znode[k0]) { kp = std::min(k0+1,
m_nz-1); }
1164 else { kp = std::max(0, k0-1); }
1167 wx1 = std::max(0.0, std::min(1.0, std::abs((P[0] -
m_xnode[i0])/
m_dx))); wx0 = 1.0 - wx1;
1168 wy1 = std::max(0.0, std::min(1.0, std::abs((P[1] -
m_ynode[j0])/
m_dy))); wy0 = 1.0 - wy1;
1169 wz1 = std::max(0.0, std::min(1.0, std::abs((P[2] -
m_znode[k0])/
m_dz))); wz0 = 1.0 - wz1;
1192 int i0, j0, k0, ip, jp, kp;
1193 double wx0,wx1,wy0,wy1,wz0,wz1;
1197 if (P[0] >
m_xnode[i0]) { ip = std::min(i0+1,
m_nx-1); }
1198 else { ip = std::max(0, i0-1); }
1199 if (P[1] >
m_ynode[j0]) { jp = std::min(j0+1,
m_ny-1); }
1200 else { jp = std::max(0, j0-1); }
1201 if (P[2] >
m_znode[k0]) { kp = std::min(k0+1,
m_nz-1); }
1202 else { kp = std::max(0, k0-1); }
1205 wx1 = std::max(0.0, std::min(1.0, std::abs((P[0] -
m_xnode[i0])/
m_dx))); wx0 = 1.0 - wx1;
1206 wy1 = std::max(0.0, std::min(1.0, std::abs((P[1] -
m_ynode[j0])/
m_dy))); wy0 = 1.0 - wy1;
1207 wz1 = std::max(0.0, std::min(1.0, std::abs((P[2] -
m_znode[k0])/
m_dz))); wz0 = 1.0 - wz1;
1210 double result = wz0 * wx0 * wy0 * (double)celldata[
accessCellIndex(i0,j0,k0)]
1219 int result2 =std::floor(result+0.5);
1230 int i0, j0, k0, ip, jp, kp;
1231 double wx0,wx1,wy0,wy1,wz0,wz1;
1236 if (P[0] >
m_xnode[i0]) { ip = std::min(i0+1,
m_nx-1); }
1237 else { ip = std::max(0, i0-1); }
1238 if (P[1] >
m_ynode[j0]) { jp = std::min(j0+1,
m_ny-1); }
1239 else { jp = std::max(0, j0-1); }
1240 if (P[2] >
m_znode[k0]) { kp = std::min(k0+1,
m_nz-1); }
1241 else { kp = std::max(0, k0-1); }
1244 wx1 = std::max(0.0, std::min(1.0, std::abs((P[0] -
m_xnode[i0])/
m_dx))); wx0 = 1.0 - wx1;
1245 wy1 = std::max(0.0, std::min(1.0, std::abs((P[1] -
m_ynode[j0])/
m_dy))); wy0 = 1.0 - wy1;
1246 wz1 = std::max(0.0, std::min(1.0, std::abs((P[2] -
m_znode[k0])/
m_dz))); wz0 = 1.0 - wz1;
1268 int i0, j0, k0, ip, jp, kp;
1269 double wx0,wx1,wy0,wy1,wz0,wz1;
1273 i0 = std::max(0, std::min(
m_nx, (
int) std::floor((P[0]-locOr[0])/
m_dx)));
1274 j0 = std::max(0, std::min(
m_ny, (
int) std::floor((P[1]-locOr[1])/
m_dy)));
1275 k0 = std::max(0, std::min(
m_nz, (
int) std::floor((P[2]-locOr[2])/
m_dz)));
1277 if (P[0] >=
m_xedge[i0]) { ip = std::min(i0+1,
m_nx); }
1278 else { ip = std::max(0, i0-1); }
1279 if (P[1] >=
m_yedge[j0]) { jp = std::min(j0+1,
m_ny); }
1280 else { jp = std::max(0, j0-1); }
1281 if (P[2] >=
m_zedge[k0]) { kp = std::min(k0+1,
m_nz); }
1282 else { kp = std::max(0, k0-1); }
1285 wx1 = std::max(0.0, std::min(1.0, std::abs((P[0] -
m_xedge[i0])/
m_dx))); wx0 = 1.0 - wx1;
1286 wy1 = std::max(0.0, std::min(1.0, std::abs((P[1] -
m_yedge[j0])/
m_dy))); wy0 = 1.0 - wy1;
1287 wz1 = std::max(0.0, std::min(1.0, std::abs((P[2] -
m_zedge[k0])/
m_dz))); wz0 = 1.0 - wz1;
1308 int i0, j0, k0, ip, jp, kp;
1309 double wx0,wx1,wy0,wy1,wz0,wz1;
1313 i0 = std::max(0, std::min(
m_nx, (
int) std::floor((P[0]-locOr[0])/
m_dx)));
1314 j0 = std::max(0, std::min(
m_ny, (
int) std::floor((P[1]-locOr[1])/
m_dy)));
1315 k0 = std::max(0, std::min(
m_nz, (
int) std::floor((P[2]-locOr[2])/
m_dz)));
1317 if (P[0] >=
m_xedge[i0]) { ip = std::min(i0+1,
m_nx); }
1318 else { ip = std::max(0, i0-1); }
1319 if (P[1] >=
m_yedge[j0]) { jp = std::min(j0+1,
m_ny); }
1320 else { jp = std::max(0, j0-1); }
1321 if (P[2] >=
m_zedge[k0]) { kp = std::min(k0+1,
m_nz); }
1322 else { kp = std::max(0, k0-1); }
1325 wx1 = std::max(0.0, std::min(1.0, std::abs((P[0] -
m_xedge[i0])/
m_dx))); wx0 = 1.0 - wx1;
1326 wy1 = std::max(0.0, std::min(1.0, std::abs((P[1] -
m_yedge[j0])/
m_dy))); wy0 = 1.0 - wy1;
1327 wz1 = std::max(0.0, std::min(1.0, std::abs((P[2] -
m_zedge[k0])/
m_dz))); wz0 = 1.0 - wz1;
1330 double result = wz0 * wx0 * wy0 * (double)pointdata[
accessPointIndex(i0,j0,k0)]
1339 int result2 = std::floor(result+0.5);
1350 int i0, j0, k0, ip, jp, kp;
1351 double wx0,wx1,wy0,wy1,wz0,wz1;
1355 i0 = std::max(0, std::min(
m_nx, (
int) std::floor((P[0]-locOr[0])/
m_dx)));
1356 j0 = std::max(0, std::min(
m_ny, (
int) std::floor((P[1]-locOr[1])/
m_dy)));
1357 k0 = std::max(0, std::min(
m_nz, (
int) std::floor((P[2]-locOr[2])/
m_dz)));
1360 if (P[0] >=
m_xedge[i0]) { ip = std::min(i0+1,
m_nx); }
1361 else { ip = std::max(0, i0-1); }
1362 if (P[1] >=
m_yedge[j0]) { jp = std::min(j0+1,
m_ny); }
1363 else { jp = std::max(0, j0-1); }
1364 if (P[2] >=
m_zedge[k0]) { kp = std::min(k0+1,
m_nz); }
1365 else { kp = std::max(0, k0-1); }
1368 wx1 = std::max(0.0, std::min(1.0, std::abs((P[0] -
m_xedge[i0])/
m_dx))); wx0 = 1.0 - wx1;
1369 wy1 = std::max(0.0, std::min(1.0, std::abs((P[1] -
m_yedge[j0])/
m_dy))); wy0 = 1.0 - wy1;
1370 wz1 = std::max(0.0, std::min(1.0, std::abs((P[2] -
m_zedge[k0])/
m_dz))); wz0 = 1.0 - wz1;
1397 int counterFile,
bool codexFlag,
1401 bitpit::VTKFormat codex = bitpit::VTKFormat::ASCII;
1402 if(codexFlag){codex=bitpit::VTKFormat::APPENDED;}
1405 int sizeTot = dim[0]*dim[1]*dim[2];
1408 if(extPoints !=
nullptr && (
int)extPoints->size() == sizeTot){
1409 activeP = *extPoints;
1411 activeP.resize(sizeTot);
1412 for(
int i=0; i<sizeTot; i++){
1420 for(
auto & val: conn){
1426 datalab.resize(activeP.size(), -1);
1428 bitpit::VTKUnstructuredGrid vtk(folder, outfile, bitpit::VTKElementType::VERTEX);
1429 vtk.setGeomData( bitpit::VTKUnstructuredField::POINTS, activeP) ;
1430 vtk.setGeomData( bitpit::VTKUnstructuredField::CONNECTIVITY, conn) ;
1431 vtk.setDimensions(conn.size(), activeP.size());
1432 vtk.addData(
"labels",bitpit::VTKFieldType::SCALAR, bitpit::VTKLocation::POINT, datalab) ;
1433 vtk.setCodex(codex);
1434 if(counterFile>=0){vtk.setCounter(counterFile);}
1450 bitpit::VTKFormat codex = bitpit::VTKFormat::ASCII;
1451 if(codexFlag){codex=bitpit::VTKFormat::APPENDED;}
1454 int sizeTot = dim[0]*dim[1]*dim[2];
1457 for(
int i=0; i<sizeTot; i++){
1464 for(
auto & val: conn){
1470 bitpit::VTKUnstructuredGrid vtk(folder, outfile, bitpit::VTKElementType::VERTEX);
1471 vtk.setGeomData( bitpit::VTKUnstructuredField::POINTS, activeP) ;
1472 vtk.setGeomData( bitpit::VTKUnstructuredField::CONNECTIVITY, conn) ;
1473 vtk.setDimensions(conn.size(), activeP.size());
1474 vtk.setCodex(codex);
1475 if(counterFile>=0){vtk.setCounter(counterFile);}
1477 bitpit::VTKLocation loc = bitpit::VTKLocation::POINT;
1478 vtk.addData(
"field",bitpit::VTKFieldType::SCALAR, loc, data) ;
1493 int counterFile,
bool codexFlag,
1497 bitpit::VTKFormat codex = bitpit::VTKFormat::ASCII;
1498 if(codexFlag){codex=bitpit::VTKFormat::APPENDED;}
1501 int sizePt = dim[0]*dim[1]*dim[2];
1502 int sizeCl = (dim[0]-1)*(dim[1]-1)*(dim[2]-1);
1507 if(extPoints !=
nullptr && (
int)extPoints->size() == sizePt){
1508 activeP = *extPoints;
1511 for(
int i=0; i<sizePt; i++){
1516 for(
int i=0; i<sizeCl; ++i){
1521 datalab.resize(activeP.size(),-1);
1523 bitpit::VTKElementType elDM = bitpit::VTKElementType::HEXAHEDRON;
1524 bitpit::VTKUnstructuredGrid vtk(folder, outfile, elDM);
1525 vtk.setGeomData( bitpit::VTKUnstructuredField::POINTS, activeP) ;
1526 vtk.setGeomData( bitpit::VTKUnstructuredField::CONNECTIVITY, activeConn) ;
1527 vtk.setDimensions(sizeCl, sizePt);
1528 vtk.addData(
"labels",bitpit::VTKFieldType::SCALAR, bitpit::VTKLocation::POINT, datalab) ;
1529 vtk.setCodex(codex);
1530 if(counterFile>=0){vtk.setCounter(counterFile);}
1546 bitpit::VTKFormat codex = bitpit::VTKFormat::ASCII;
1547 if(codexFlag){codex=bitpit::VTKFormat::APPENDED;}
1550 int sizePt = dim[0]*dim[1]*dim[2];
1551 int sizeCl = (dim[0]-1)*(dim[1]-1)*(dim[2]-1);
1556 for(
int i=0; i<sizePt; i++){
1560 for(
int i=0; i<sizeCl; ++i){
1564 bitpit::VTKElementType elDM = bitpit::VTKElementType::HEXAHEDRON;
1565 bitpit::VTKUnstructuredGrid vtk(folder, outfile, elDM);
1566 vtk.setGeomData( bitpit::VTKUnstructuredField::POINTS, activeP) ;
1567 vtk.setGeomData( bitpit::VTKUnstructuredField::CONNECTIVITY, activeConn) ;
1568 vtk.setDimensions(sizeCl, sizePt);
1570 vtk.setCodex(codex);
1571 if(counterFile>=0){vtk.setCounter(counterFile);}
1573 bitpit::VTKLocation loc = bitpit::VTKLocation::POINT;
1574 if ((
int)data.size() == sizeCl) loc = bitpit::VTKLocation::CELL;
1576 vtk.addData(
"field",bitpit::VTKFieldType::SCALAR, loc, data) ;
1624 if(
getShape() ==
nullptr){
return false;}
1634 dimLimit[1] = 5; dimLimit[2] = 3;
1641 m_nx = std::max(
m_nx, dimLimit[0]-1);
1642 m_ny = std::max(
m_ny, dimLimit[1]-1);
1643 m_nz = std::max(
m_nz, dimLimit[2]-1);
1654 for (
int i = 0; i <
m_nx+1; i++) {
m_xedge[i] = locOr[0] + ((double) i) *
m_dx;}
1655 for (
int i = 0; i <
m_ny+1; i++) {
m_yedge[i] = locOr[1] + ((double) i) *
m_dy;}
1656 for (
int i = 0; i <
m_nz+1; i++) {
m_zedge[i] = locOr[2] + ((double) i) *
m_dz;}