Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F61131558
model.cpp
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Sat, May 4, 17:58
Size
5 KB
Mime Type
text/x-c++
Expires
Mon, May 6, 17:58 (1 d, 23 h)
Engine
blob
Format
Raw Data
Handle
17469858
Attached To
rTAMAAS tamaas
model.cpp
View Options
/**
* @file
*
* @author Lucas Frérot <lucas.frerot@epfl.ch>
*
* @section LICENSE
*
* Copyright (©) 2017 EPFL (Ecole Polytechnique Fédérale de
* Lausanne) Laboratory (LSMS - Laboratoire de Simulation en Mécanique des
* Solides)
*
* Tamaas 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.
*
* Tamaas 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 Tamaas. If not, see <http://www.gnu.org/licenses/>.
*
*/
/* -------------------------------------------------------------------------- */
#include "wrap.hh"
#include "model.hh"
#include "model_factory.hh"
#include "functional.hh"
#include "adhesion_functional.hh"
#include <pybind11/stl.h>
/* -------------------------------------------------------------------------- */
__BEGIN_TAMAAS__
namespace
functional
{
namespace
wrap
{
/// Class for extension of Functional in python
class
PyFunctional
:
public
Functional
{
public
:
using
Functional
::
Functional
;
// Overriding pure virtual functions
Real
computeF
(
GridBase
<
Real
>&
variable
,
GridBase
<
Real
>&
dual
)
const
override
{
PYBIND11_OVERLOAD_PURE
(
Real
,
Functional
,
computeF
,
variable
,
dual
);
}
void
computeGradF
(
GridBase
<
Real
>&
variable
,
GridBase
<
Real
>&
gradient
)
const
override
{
PYBIND11_OVERLOAD_PURE
(
void
,
Functional
,
computeGradF
,
variable
,
gradient
);
}
};
}
}
namespace
wrap
{
using
namespace
py
::
literals
;
/// Wrap functional classes
void
wrapFunctionals
(
py
::
module
&
mod
)
{
py
::
class_
<
functional
::
Functional
,
functional
::
wrap
::
PyFunctional
>
func
(
mod
,
"Functional"
);
func
.
def
(
py
::
init
<
const
BEEngine
&>
())
.
def
(
"computeF"
,
&
functional
::
Functional
::
computeF
)
.
def
(
"computeGradF"
,
&
functional
::
Functional
::
computeGradF
);
py
::
class_
<
functional
::
AdhesionFunctional
>
adh
(
mod
,
"AdhesionFunctional"
,
func
);
adh
.
def_property
(
"parameters"
,
&
functional
::
AdhesionFunctional
::
getParameters
,
&
functional
::
AdhesionFunctional
::
setParameters
)
// legacy wrapper code
.
def
(
"setParameters"
,
&
functional
::
AdhesionFunctional
::
setParameters
);
py
::
class_
<
functional
::
ExponentialAdhesionFunctional
>
(
mod
,
"ExponentialAdhesionFunctional"
,
adh
)
.
def
(
py
::
init
<
const
BEEngine
&
,
const
GridBase
<
Real
>&>
(),
"be_engine"
_a
,
"surface"
_a
);
py
::
class_
<
functional
::
MaugisAdhesionFunctional
>
(
mod
,
"MaugisAdhesionFunctional"
,
adh
)
.
def
(
py
::
init
<
const
BEEngine
&
,
const
GridBase
<
Real
>&>
(),
"be_engine"
_a
,
"surface"
_a
);
py
::
class_
<
functional
::
SquaredExponentialAdhesionFunctional
>
(
mod
,
"SquaredExponentialAdhesionFunctional"
,
adh
)
.
def
(
py
::
init
<
const
BEEngine
&
,
const
GridBase
<
Real
>&>
(),
"be_engine"
_a
,
"surface"
_a
);
}
/// Wrap BEEngine classes
void
wrapBEEngine
(
py
::
module
&
mod
)
{
py
::
class_
<
BEEngine
>
(
mod
,
"BEEngine"
)
.
def
(
"solveNeumann"
,
&
BEEngine
::
solveNeumann
)
.
def
(
"solveDirichlet"
,
&
BEEngine
::
solveDirichlet
)
.
def
(
"getModel"
,
&
BEEngine
::
getModel
,
py
::
return_value_policy
::
reference
);
}
/// Wrap Models
void
wrapModelClass
(
py
::
module
&
mod
)
{
py
::
enum_
<
model_type
>
(
mod
,
"model_type"
)
.
value
(
"basic_1d"
,
model_type
::
basic_1d
)
.
value
(
"basic_2d"
,
model_type
::
basic_2d
)
.
value
(
"surface_1d"
,
model_type
::
surface_1d
)
.
value
(
"surface_2d"
,
model_type
::
surface_2d
)
.
value
(
"volume_1d"
,
model_type
::
volume_1d
)
.
value
(
"volume_2d"
,
model_type
::
volume_2d
);
py
::
class_
<
Model
>
(
mod
,
"Model"
)
.
def
(
"setElasticity"
,
&
Model
::
setElasticity
,
"E"
_a
,
"nu"
_a
)
.
def_property
(
"E"
,
&
Model
::
getYoungModulus
,
&
Model
::
setYoungModulus
)
.
def_property
(
"nu"
,
&
Model
::
getPoissonRatio
,
&
Model
::
setPoissonRatio
)
.
def
(
"getHertzModulus"
,
&
Model
::
getHertzModulus
)
.
def
(
"getYoungModulus"
,
&
Model
::
getYoungModulus
)
.
def
(
"getShearModulus"
,
&
Model
::
getShearModulus
)
.
def
(
"getPoissonRatio"
,
&
Model
::
getPoissonRatio
)
.
def
(
"getTraction"
,
(
GridBase
<
Real
>
&
(
Model
::*
)())
&
Model
::
getTraction
)
.
def
(
"getDisplacement"
,
(
GridBase
<
Real
>
&
(
Model
::*
)())
&
Model
::
getDisplacement
)
.
def
(
"getSystemSize"
,
&
Model
::
getSystemSize
)
.
def
(
"getDiscretization"
,
&
Model
::
getDiscretization
)
.
def
(
"solveNeumann"
,
&
Model
::
solveNeumann
)
.
def
(
"solveDirichlet"
,
&
Model
::
solveDirichlet
)
.
def
(
"getBEEngine"
,
&
Model
::
getBEEngine
,
py
::
return_value_policy
::
reference
)
.
def
(
"__repr__"
,
[](
const
Model
&
m
)
{
std
::
stringstream
ss
;
ss
<<
m
;
return
ss
.
str
();
});
}
/// Wrap factor for models
void
wrapModelFactory
(
py
::
module
&
mod
)
{
py
::
class_
<
ModelFactory
>
(
mod
,
"ModelFactory"
)
.
def_static
(
"createModel"
,
&
ModelFactory
::
createModel
,
"model_type"
_a
,
"system_size"
_a
,
"discretization"
_a
);
}
void
wrapModel
(
py
::
module
&
mod
)
{
wrapBEEngine
(
mod
);
wrapModelClass
(
mod
);
wrapModelFactory
(
mod
);
wrapFunctionals
(
mod
);
}
}
// namespace wrap
__END_TAMAAS__
Event Timeline
Log In to Comment