diff --git a/python/swig/model.i b/python/swig/model.i index 4cb6acdba..5fbdc89df 100644 --- a/python/swig/model.i +++ b/python/swig/model.i @@ -1,116 +1,121 @@ /** * @file model.i * * @author Guillaume Anciaux * @author Aurelia Isabel Cuba Ramos * @author Nicolas Richart * * @date creation: Fri Dec 12 2014 * @date last modification: Wed Nov 11 2015 * * @brief model wrapper * * @section LICENSE * * Copyright (©) 2015 EPFL (Ecole Polytechnique Fédérale de Lausanne) Laboratory * (LSMS - Laboratoire de Simulation en Mécanique des Solides) * * Akantu is free software: you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License as published by the Free * Software Foundation, either version 3 of the License, or (at your option) any * later version. * * Akantu 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 Lesser General Public License for more * details. * * You should have received a copy of the GNU Lesser General Public License * along with Akantu. If not, see . * */ %{ #include "boundary_condition_python_functor.hh" #include "model_solver.hh" #include "non_linear_solver.hh" + #include "sparse_matrix_aij.hh" %} namespace akantu { %ignore Model::createSynchronizerRegistry; %ignore Model::getSynchronizerRegistry; %ignore Model::createParallelSynch; %ignore Model::getDOFSynchronizer; %ignore Model::registerFEEngineObject; %ignore Model::unregisterFEEngineObject; // %ignore Model::getFEEngineBoundary; // %ignore Model::getFEEngine; %ignore Model::getFEEngineClass; %ignore Model::getFEEngineClassBoundary; %ignore Model::setParser; %ignore Model::updateDataForNonLocalCriterion; %ignore IntegrationPoint::operator=; } %include "sparse_matrix.i" %include "fe_engine.hh" %rename(FreeBoundaryDirichlet) akantu::BC::Dirichlet::FreeBoundary; %rename(FreeBoundaryNeumann) akantu::BC::Neumann::FreeBoundary; %rename(PythonBoundary) akantu::BC::Dirichlet::PythonFunctor; %include "boundary_condition_functor.hh" %include "boundary_condition.hh" %include "boundary_condition_python_functor.hh" %include "communication_buffer.hh" %include "data_accessor.hh" //%include "synchronizer.hh" //%include "synchronizer_registry.hh" %include "model.hh" %include "non_linear_solver.hh" %include "model_options.hh" %extend akantu::Model { void initFullImpl( const akantu::ModelOptions & options = akantu::ModelOptions()){ $self->initFull(options); }; + akantu::SparseMatrixAIJ & getMatrix(const std::string & name){ + return dynamic_cast($self->getDOFManager().getMatrix(name)); + }; + %insert("python") %{ def initFull(self, *args, **kwargs): if len(args) == 0: import importlib as __aka_importlib _module = __aka_importlib.import_module(self.__module__) _cls = getattr(_module, "{0}Options".format(self.__class__.__name__)) options = _cls() if len(kwargs) > 0: for key, val in kwargs.items(): if key[0] == '_': key = key[1:] setattr(options, key, val) else: options = args[0] self.initFullImpl(options) %} void solveStep(const akantu::ID & id=""){ $self->solveStep(id); } akantu::NonLinearSolver & getNonLinearSolver(const akantu::ID & id=""){ return $self->getNonLinearSolver(id); } } %extend akantu::NonLinearSolver { void set(const std::string & id, akantu::Real val){ if (id == "max_iterations") $self->set(id, int(val)); else if (id == "convergence_type") $self->set(id, akantu::SolveConvergenceCriteria(UInt(val))); else $self->set(id, val); } } diff --git a/python/swig/sparse_matrix.i b/python/swig/sparse_matrix.i index f3c2dc6b0..24785d7a1 100644 --- a/python/swig/sparse_matrix.i +++ b/python/swig/sparse_matrix.i @@ -1,34 +1,36 @@ %include "sparse_matrix.hh" +%include "sparse_matrix_aij.hh" + %pythoncode %{ import scipy.sparse import numpy as _np class AkantuSparseMatrix (scipy.sparse.coo_matrix) : def __init__(self,aka_sparse): self.aka_sparse = aka_sparse - matrix_type = self.aka_sparse.getSparseMatrixType() + matrix_type = self.aka_sparse.getMatrixType() sz = self.aka_sparse.size() row = self.aka_sparse.getIRN()[:,0] -1 col = self.aka_sparse.getJCN()[:,0] -1 data = self.aka_sparse.getA()[:,0] row = row.copy() col = col.copy() data = data.copy() if matrix_type == _symmetric: non_diags = (row != col) row_sup = col[non_diags] col_sup = row[non_diags] data_sup = data[non_diags] col = _np.concatenate((col,col_sup)) row = _np.concatenate((row,row_sup)) data = _np.concatenate((data,data_sup)) scipy.sparse.coo_matrix.__init__(self,(data, (row,col)),shape=(sz,sz)) %}