Mentions légales du service
Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
dolfin_dic
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Model registry
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
ALVAREZ BARRIENTOS Felipe
dolfin_dic
Commits
30f67d8a
You need to sign in or sign up before continuing.
Commit
30f67d8a
authored
6 years ago
by
Ezgi Berberglu
Browse files
Options
Downloads
Patches
Plain Diff
New project function
parent
2b8e94eb
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
project.py
+121
-0
121 additions, 0 deletions
project.py
with
121 additions
and
0 deletions
project.py
0 → 100644
+
121
−
0
View file @
30f67d8a
#coding=utf8
################################################################################
### ###
### Created by Ezgi Berberoğlu, 2018-2019 ###
### ###
### Swiss Federal Institute of Technology (ETH), Zurich, Switzerland ###
### ###
### And Martin Genet, 2016-2019 ###
### ###
### École Polytechnique, Palaiseau, France ###
### ###
################################################################################
import
dolfin
import
numpy
import
myPythonLibrary
as
mypy
import
myVTKPythonLibrary
as
myvtk
import
dolfin_dic
as
ddic
################################################################################
def
project
(
mesh
,
image_filename
,
image_field_name
=
"
displacement
"
,
image_quadrature
=
1
):
dV
=
dolfin
.
Measure
(
"
dx
"
,
domain
=
mesh
)
form_compiler_parameters_for_images
=
{}
form_compiler_parameters_for_images
[
"
quadrature_degree
"
]
=
image_quadrature
vfe
=
dolfin
.
VectorElement
(
family
=
"
Quadrature
"
,
cell
=
mesh
.
ufl_cell
(),
degree
=
image_quadrature
,
quad_scheme
=
"
default
"
)
vfs
=
dolfin
.
VectorFunctionSpace
(
mesh
=
mesh
,
family
=
"
Lagrange
"
,
degree
=
1
)
projected_func
=
dolfin
.
Function
(
vfs
,
name
=
image_field_name
)
U
=
dolfin
.
TrialFunction
(
vfs
)
V
=
dolfin
.
TestFunction
(
vfs
)
source_expr
=
dolfin
.
Expression
(
cppcode
=
'''
\
#include <vtkSmartPointer.h>
#include <vtkStructuredGridReader.h>
#include <vtkProbeFilter.h>
#include <vtkStructuredGrid.h>
#include <vtkPolyData.h>
#include <vtkPointData.h>
namespace dolfin
{
class MyExpr : public Expression
{
vtkSmartPointer<vtkStructuredGrid> sgrid;
vtkSmartPointer<vtkPoints> probe_points;
vtkSmartPointer<vtkPolyData> probe_polydata;
vtkSmartPointer<vtkProbeFilter> probe_filter;
public:
MyExpr():
Expression(3)
{
sgrid = vtkSmartPointer<vtkStructuredGrid>::New();
probe_points = vtkSmartPointer<vtkPoints>::New();
probe_polydata = vtkSmartPointer<vtkPolyData>::New();
probe_filter = vtkSmartPointer<vtkProbeFilter>::New();
}
void init_image(
const char* image_filename)
{
vtkSmartPointer<vtkStructuredGridReader> reader = vtkSmartPointer<vtkStructuredGridReader>::New();
reader->SetFileName(image_filename);
reader->Update();
sgrid = reader->GetOutput();
probe_filter->SetSourceData(sgrid);
}
void eval(
Array<double>& expr,
const Array<double>& X) const
{
probe_points->SetNumberOfPoints(1);
probe_points->SetPoint(0, X.data());
probe_polydata->SetPoints(probe_points);
probe_filter->SetInputData(probe_polydata);
probe_filter->Update();
probe_filter->GetOutput()->GetPointData()->GetArray(
"'''
+
image_field_name
+
'''"
)->GetTuple(0, expr.data());
}
};
}
'''
,
element
=
vfe
)
source_expr
.
init_image
(
image_filename
)
M
=
dolfin
.
assemble
(
dolfin
.
inner
(
U
,
V
)
*
dV
)
N
=
dolfin
.
assemble
(
dolfin
.
inner
(
source_expr
,
V
)
*
dV
,
form_compiler_parameters
=
form_compiler_parameters_for_images
)
dolfin
.
solve
(
M
,
projected_func
.
vector
(),
N
)
return
projected_func
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment