Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • am-dept/amfe
  • Paul.Dechamps/amfe
2 results
Show changes
Commits on Source (3)
......@@ -125,16 +125,12 @@ IF(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
EXECUTE_PROCESS(COMMAND ${PYTHON_EXECUTABLE} -m site --user-site OUTPUT_VARIABLE PY_SITE OUTPUT_STRIP_TRAILING_WHITESPACE)
SET(CMAKE_INSTALL_PREFIX "${PY_SITE}/amfe" CACHE STRING "Install location" FORCE)
ENDIF()
# Write and add __init__.py to install location #TODO consider pre-writing init.py and install as __init__.py
FILE(WRITE "${CMAKE_BINARY_DIR}/__init__.py"
"# Add this dir to the python path so that sub-dir can be imported as sub-module\nimport os.path, sys\nsys.path.append(os.path.dirname(os.path.realpath(__file__)))\n")
IF(WIN32 AND CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
FILE(APPEND "${CMAKE_BINARY_DIR}/__init__.py"
"# Windows-MSVC\nfrom .fwk import wutils\nwutils.initDLL()\n")
ELSEIF(UNIX AND NOT APPLE)
# RPATH for Linux
IF(UNIX AND NOT APPLE)
SET(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}")
ENDIF()
INSTALL(FILES ${CMAKE_BINARY_DIR}/__init__.py DESTINATION ${CMAKE_INSTALL_PREFIX})
# Copy init.py as __init__.py to install location
INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/init.py DESTINATION ${CMAKE_INSTALL_PREFIX} RENAME __init__.py)
# -- Sub directories
ADD_SUBDIRECTORY( fwk )
......
......@@ -17,6 +17,7 @@
from . import wutils
wutils.initDLL()
wutils.findbins('fwk')
from fwkw import *
......@@ -113,10 +113,6 @@ def findbins(modname, dirB=['build','wavesB'], verb=False): # changer wavesB en
mod = __import__(modwrap)
print('[findbins] loading ', mod.__file__)
# initialisations
initDLL()
initMKL(parseargs().k)
# attention! si waves and heat possedent des classes de mêmes noms,
# c'est celle du premier module qui sera chargée!
# => ne pas charger waves et heat en même temps tant qu'il n'y a pas de namespaces
......@@ -137,7 +133,7 @@ def initDLL():
# ------------------------------------------------------------------------------
def initMKL(nthreads):
def initMKL(nthreads, verb=False):
import os
# we try to have full control over the threading environment
# => set MKL/OMP variables if (and only if) they are not set!
......@@ -162,11 +158,14 @@ def initMKL(nthreads):
if not 'OMP_DYNAMIC' in os.environ:
os.environ['OMP_DYNAMIC'] = 'FALSE'
# display variables
for s in ['OMP_', 'MKL', 'KMP']:
print('* %s environment:' % s)
for key, value in os.environ.items():
if s in key:
print('\t%s = %s' % (key, value))
print(f'Envrionment initialized for MKL with {nthreads} threads.')
if verb:
for s in ['OMP_', 'MKL', 'KMP']:
print('* %s environment:' % s)
for key, value in os.environ.items():
if s in key:
print(' %s = %s' % (key, value))
print('')
# ------------------------------------------------------------------------------
......@@ -284,6 +283,7 @@ def run():
# parse args
args = parseargs()
initMKL(args.k, verb=True) # initialize threading layer and number of threads
if args.fpe:
fwk.enableFpe() # enables floating point exceptions at runtime
print(ccolors.ANSI_YELLOW + 'Floating point exceptions will cause numpy to overflow!' + ccolors.ANSI_RESET)
......
# THIS FILE IS INTENDED FOR INSTALLATION ONLY (copied as __init__.py), NOT FOR DEVELOPMENT
# Add this dir to the python path so that sub-dir can be imported as sub-module
import os.path, sys
sys.path.append(os.path.dirname(os.path.realpath(__file__)))
......@@ -112,9 +112,11 @@ namespace std {
%shared_ptr(tbox::MshImport)
%nodefault tbox::MshImport;
%immutable tbox::MshImport::msh; // read-only variable (no setter)
%include "wMshImport.h"
%shared_ptr(tbox::MshExport)
%nodefault tbox::MshExport;
%immutable tbox::MshExport::msh; // read-only variable (no setter)
%include "wMshExport.h"
%shared_ptr(tbox::GmshImport)
%include "wGmshImport.h"
......@@ -140,6 +142,8 @@ namespace std {
%include "wGroups.h"
%warnfilter(+509);
%shared_ptr(tbox::MshDeform);
%immutable tbox::MshDeform::msh; // read-only variable (no setter)
%immutable tbox::MshDeform::nthreads;
%include "wMshDeform.h" // included after std templates because it needs them
%shared_ptr(tbox::MshCrack);
%include "wMshCrack.h"
......
......@@ -37,6 +37,8 @@ namespace tbox
class TBOX_API MshCrack : public fwk::wSharedObject
{
private:
std::shared_ptr<MshData> msh; ///< mesh
int nDim; ///< number of dimensions
bool hasCrack; ///< flag telling if mesh already has crack
std::map<Node *, Node *> nodMap; ///< map between nodes on both side of crack
Group *crckGrp; ///< physical group of crack
......@@ -50,9 +52,6 @@ private:
void swapNodes(Element *e);
public:
std::shared_ptr<MshData> msh;
int nDim;
MshCrack(std::shared_ptr<MshData> _msh, int _nDim);
virtual ~MshCrack();
......
......@@ -32,7 +32,10 @@
using namespace tbox;
MshDeform::MshDeform(std::shared_ptr<MshData> _msh, int _nDim) : wSharedObject(), nDim(_nDim), field(false), fixed(false), moving(false), msh(_msh)
MshDeform::MshDeform(std::shared_ptr<MshData> _msh,
int _nDim, int nthrds) : wSharedObject(), nDim(_nDim),
field(false), fixed(false), moving(false),
msh(_msh), nthreads(nthrds)
{
// Check problem dimension
if (nDim != 2 && nDim != 3)
......@@ -41,10 +44,13 @@ MshDeform::MshDeform(std::shared_ptr<MshData> _msh, int _nDim) : wSharedObject()
fldGrp = nullptr;
symBndGrp = nullptr;
// Initialize multithreading
nthreads = 1;
// Get mesh size
mshSize = msh->nodes.size();
// Display configuration
std::cout << "--- Mesh morpher (linear elasticity) ---\n"
<< "Number of threads: " << nthreads << "\n"
<< std::endl;
}
/**
......@@ -449,14 +455,13 @@ void MshDeform::deform()
Eigen::VectorXd f = Eigen::VectorXd::Zero(nDim * mshSize), q = Eigen::VectorXd::Zero(nDim * mshSize);
// Build stiffness matrix and RHS
std::cout << "--- Deforming mesh using linear elasticiy equations ---\n"
<< "Number of threads: " << nthreads << "\n"
<< "Assembling matrices... " << std::flush;
std::cout << "- Deforming mesh:\n"
<< "assembling matrices... " << std::flush;
this->build(K);
this->build(f);
std::cout << "done" << std::endl;
// Solve the SoE
std ::cout << "Solving equations... " << std::flush;
std ::cout << "solving equations... " << std::flush;
Gmres gmres;
// set the preconditioner
gmres.setFillFactor(2);
......@@ -471,7 +476,7 @@ void MshDeform::deform()
std::cout << "done (#it: " << gmres.getIterations() << ", error: " << std::scientific << gmres.getError() << std::fixed << ")" << std::endl;
// Update position
std ::cout << "Updating mesh... " << std::flush;
std ::cout << "updating mesh... " << std::flush;
for (auto n : msh->nodes)
{
for (int m = 0; m < nDim; m++)
......@@ -492,7 +497,8 @@ void MshDeform::deform()
e->update();
for (auto e : intBndElems)
e->update();
std::cout << "done" << std::endl;
std::cout << "done\n"
<< std::endl;
}
/**
......
......@@ -63,7 +63,7 @@ public:
std::shared_ptr<MshData> msh;
int nthreads;
MshDeform(std::shared_ptr<MshData> _msh, int _nDim);
MshDeform(std::shared_ptr<MshData> _msh, int _nDim, int nthrds = 1);
virtual ~MshDeform() { std::cout << "~MshDeform()\n"; }
void setField(std::string const &fldName);
......
......@@ -39,13 +39,11 @@ def main():
msh = gmsh.MeshLoader("models/beam.geo",__file__).execute(**pars)
gmshWriter = tbox.GmshExport(msh)
# create mesh deformation handler
mshDef = tbox.MshDeform(msh, 2)
mshDef = tbox.MshDeform(msh, 2, nthrds=parseargs().k)
mshDef.setField("internalField")
mshDef.addFixed(["clamp"])
mshDef.addMoving(["tip"])
mshDef.initialize()
args = parseargs()
mshDef.nthreads = args.k
# deform the mesh (dummy translation of "tip" nodes)
mshDef.savePos()
......
......@@ -38,13 +38,11 @@ def main():
msh = gmsh.MeshLoader("models/beam3.geo",__file__).execute(**pars)
gmshWriter = tbox.GmshExport(msh)
# create mesh deformation handler
mshDef = tbox.MshDeform(msh, 3)
mshDef = tbox.MshDeform(msh, 3, nthrds=parseargs().k)
mshDef.setField("field")
mshDef.addFixed(["clamp"])
mshDef.addMoving(["tip"])
mshDef.initialize()
args = parseargs()
mshDef.nthreads = args.k
# deform the mesh (dummy translation of "tip" nodes)
mshDef.savePos()
......