Skip to content

Commit

Permalink
Trasnform: cleanup rotate, translate, homothety
Browse files Browse the repository at this point in the history
  • Loading branch information
benoit128 committed Oct 23, 2024
1 parent 55d3dd6 commit 2196679
Show file tree
Hide file tree
Showing 7 changed files with 87 additions and 716 deletions.
53 changes: 0 additions & 53 deletions Cassiopee/Transform/Transform/Fortran/HomothetyF.for

This file was deleted.

84 changes: 0 additions & 84 deletions Cassiopee/Transform/Transform/Fortran/RotateF.for

This file was deleted.

54 changes: 0 additions & 54 deletions Cassiopee/Transform/Transform/Fortran/TranslateF.for

This file was deleted.

50 changes: 0 additions & 50 deletions Cassiopee/Transform/Transform/coordTransform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,56 +39,6 @@ extern "C"
const E_Int& ni, const E_Int& nj, const E_Int& nk,
E_Float* x, E_Float* y, E_Float* z);
}
// ============================================================================
/* Homothety from an array describing a mesh */
// ============================================================================
PyObject* K_TRANSFORM::homothety(PyObject* self, PyObject* args)
{
E_Float xc, yc, zc;
E_Float alpha;
PyObject* array;
if (!PYPARSETUPLE_(args, O_ TRRR_ R_,
&array, &xc, &yc, &zc, &alpha))
{
return NULL;
}

// Check array
E_Int nil, njl, nkl;
FldArrayF* f; FldArrayI* cn;
char* varString; char* eltType;
E_Int res =
K_ARRAY::getFromArray3(array, varString, f, nil, njl, nkl, cn, eltType);

if (res != 1 && res != 2)
{
PyErr_SetString(PyExc_TypeError,
"homothety: not a valid array.");
return NULL;
}

E_Int posx = K_ARRAY::isCoordinateXPresent(varString);
E_Int posy = K_ARRAY::isCoordinateYPresent(varString);
E_Int posz = K_ARRAY::isCoordinateZPresent(varString);
if (posx == -1 || posy == -1 || posz == -1)
{
RELEASESHAREDB(res, array, f, cn);
PyErr_SetString(PyExc_TypeError,
"homothety: can't find coordinates in array.");
return NULL;
}
posx++; posy++; posz++;

E_Int npts = f->getSize();
// Homothety
k6homothety_(npts,
f->begin(posx), f->begin(posy), f->begin(posz),
xc, yc, zc, alpha,
f->begin(posx), f->begin(posy), f->begin(posz));
RELEASESHAREDB(res, array, f, cn);
Py_INCREF(Py_None);
return Py_None;
}

// ============================================================================
/* Contract python array describing a mesh */
Expand Down
85 changes: 85 additions & 0 deletions Cassiopee/Transform/Transform/homothety.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
/*
Copyright 2013-2024 Onera.
This file is part of Cassiopee.
Cassiopee is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Cassiopee is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Cassiopee. If not, see <http://www.gnu.org/licenses/>.
*/

# include "transform.h"

using namespace std;
using namespace K_FUNC;
using namespace K_FLD;

// ============================================================================
// Homothety array2/3 - in place
//=============================================================================
PyObject* K_TRANSFORM::homothety(PyObject* self, PyObject* args)
{
E_Float xc, yc, zc, alpha;
PyObject* array;
if (!PYPARSETUPLE_(args, O_ TRRR_ R_,
&array, &xc, &yc, &zc, &alpha))
return NULL;

// Check array
E_Int nil, njl, nkl;
FldArrayF* f; FldArrayI* cn;
char* varString; char* eltType;
E_Int res = K_ARRAY::getFromArray3(array, varString, f, nil, njl, nkl,
cn, eltType);

if (res != 1 && res != 2)
{
PyErr_SetString(PyExc_TypeError,
"homothety: invalid array.");
return NULL;
}
E_Int posx = K_ARRAY::isCoordinateXPresent(varString);
E_Int posy = K_ARRAY::isCoordinateYPresent(varString);
E_Int posz = K_ARRAY::isCoordinateZPresent(varString);

if (posx == -1 || posy == -1 || posz == -1)
{
RELEASESHAREDB(res, array, f, cn);
PyErr_SetString(PyExc_TypeError,
"homothety: can't find coordinates in array.");
return NULL;
}
posx++; posy++; posz++;
E_Int npts = f->getSize();
E_Float* xt = f->begin(posx);
E_Float* yt = f->begin(posy);
E_Float* zt = f->begin(posz);

#pragma omp parallel default(shared)
{
E_Float rx, ry, rz;
#pragma omp for
for (E_Int ind = 0; ind < npts; ind++)
{
rx = xt[ind]-xc;
ry = yt[ind]-yc;
rz = zt[ind]-zc;
xt[ind] = xc + alpha*rx;
yt[ind] = yc + alpha*ry;
zt[ind] = zc + alpha*rz;
}
}

RELEASESHAREDB(res, array, f, cn);
Py_INCREF(Py_None);
return Py_None;
}
Loading

0 comments on commit 2196679

Please sign in to comment.