Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
dartflo
Manage
Activity
Members
Plan
Wiki
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Analyze
Contributor analytics
CI/CD analytics
Repository analytics
Insights
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
Aerospace and Mechanical Engineering
dartflo
Commits
869dbad8
Commit
869dbad8
authored
5 days ago
by
Adrien Crovato
Browse files
Options
Downloads
Patches
Plain Diff
Update MPhys API to 2.0.0
parent
7336e1c5
No related branches found
Branches containing commit
Tags
v1.2.0
Tags containing commit
No related merge requests found
Pipeline
#55062
passed
5 days ago
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
dart/api/mphys.py
+22
-17
22 additions, 17 deletions
dart/api/mphys.py
with
22 additions
and
17 deletions
dart/api/mphys.py
+
22
−
17
View file @
869dbad8
...
...
@@ -38,7 +38,12 @@
import
numpy
as
np
import
openmdao.api
as
om
from
mphys.builder
import
Builder
from
mphys
import
Builder
,
MPhysVariables
# Define short aliases for convenience
XAERO0
=
MPhysVariables
.
Aerodynamics
.
Surface
.
Mesh
.
COORDINATES
XAERO
=
MPhysVariables
.
Aerodynamics
.
Surface
.
COORDINATES
FAERO
=
MPhysVariables
.
Aerodynamics
.
Surface
.
LOADS
# Surface mesh
class
DartMesh
(
om
.
IndepVarComp
):
...
...
@@ -64,7 +69,7 @@ class DartMesh(om.IndepVarComp):
for
i
in
range
(
len
(
self
.
bnd
.
nodes
)):
for
j
in
range
(
3
):
x_aero0
[
3
*
i
+
j
]
=
self
.
bnd
.
nodes
[
i
].
pos
[
j
]
self
.
add_output
(
'
x_aero0
'
,
distributed
=
True
,
val
=
x_aero0
,
desc
=
'
initial aerodynamic surface node coordinates
'
,
tags
=
[
'
mphys_coordinates
'
])
self
.
add_output
(
XAERO0
,
distributed
=
True
,
val
=
x_aero0
,
desc
=
'
initial aerodynamic surface node coordinates
'
,
tags
=
[
'
mphys_coordinates
'
])
def
get_triangulated_surface
(
self
):
"""
Triangulate the surface
...
...
@@ -120,10 +125,10 @@ class DartMorpher(om.ImplicitComponent):
self
.
mrf
=
self
.
options
[
'
mrf
'
]
self
.
adj
=
self
.
options
[
'
adj
'
]
# I/O
self
.
add_input
(
'
x_aero
'
,
distributed
=
True
,
shape_by_conn
=
True
,
desc
=
'
aerodynamic surface node coordinates
'
,
tags
=
[
'
mphys_coupling
'
])
self
.
add_input
(
XAERO
,
distributed
=
True
,
shape_by_conn
=
True
,
desc
=
'
aerodynamic surface node coordinates
'
,
tags
=
[
'
mphys_coupling
'
])
self
.
add_output
(
'
xv
'
,
val
=
np
.
zeros
(
self
.
dim
*
len
(
self
.
mrf
.
msh
.
nodes
)),
desc
=
'
aerodynamic volume node coordinates
'
,
tags
=
[
'
mphys_coupling
'
])
# volume node coordinates can be 2D or 3D
# Partials
# self.declare_partials(of=['xv'], wrt=[
'x_aero'
])
# self.declare_partials(of=['xv'], wrt=[
XAERO
])
def
solve_nonlinear
(
self
,
inputs
,
outputs
):
"""
Deform the volume mesh
...
...
@@ -132,7 +137,7 @@ class DartMorpher(om.ImplicitComponent):
self
.
mrf
.
savePos
()
for
i
in
range
(
len
(
self
.
bnd
.
nodes
)):
for
j
in
range
(
3
):
self
.
bnd
.
nodes
[
i
].
pos
[
j
]
=
inputs
[
'
x_aero
'
][
3
*
i
+
j
]
self
.
bnd
.
nodes
[
i
].
pos
[
j
]
=
inputs
[
XAERO
][
3
*
i
+
j
]
# Compute
self
.
mrf
.
deform
()
# Update outputs
...
...
@@ -157,10 +162,10 @@ class DartMorpher(om.ImplicitComponent):
if
'
xv
'
in
d_residuals
:
if
'
xv
'
in
d_outputs
:
d_outputs
[
'
xv
'
]
+=
self
.
adj
.
computeJacVecMesh
(
d_residuals
[
'
xv
'
])
# dX = dRx_dX^T * dRx
if
'
x_aero
'
in
d_inputs
:
if
XAERO
in
d_inputs
:
for
i
in
range
(
len
(
self
.
bnd
.
nodes
)):
for
j
in
range
(
self
.
dim
):
d_inputs
[
'
x_aero
'
][
3
*
i
+
j
]
-=
d_residuals
[
'
xv
'
][
self
.
dim
*
self
.
bnd
.
nodes
[
i
].
row
+
j
]
# dXs = -dX
d_inputs
[
XAERO
][
3
*
i
+
j
]
-=
d_residuals
[
'
xv
'
][
self
.
dim
*
self
.
bnd
.
nodes
[
i
].
row
+
j
]
# dXs = -dX
elif
mode
==
'
fwd
'
:
raise
NotImplementedError
(
'
DartMorpher - forward mode not implemented!
\n
'
)
...
...
@@ -191,7 +196,7 @@ class DartDummyMorpher(om.ExplicitComponent):
for
j
in
range
(
dim
):
xv
[
dim
*
i
+
j
]
=
msh
.
nodes
[
i
].
pos
[
j
]
# I/O
self
.
add_input
(
'
x_aero
'
,
distributed
=
True
,
shape_by_conn
=
True
,
desc
=
'
aerodynamic surface node coordinates
'
,
tags
=
[
'
mphys_coupling
'
])
self
.
add_input
(
XAERO
,
distributed
=
True
,
shape_by_conn
=
True
,
desc
=
'
aerodynamic surface node coordinates
'
,
tags
=
[
'
mphys_coupling
'
])
self
.
add_output
(
'
xv
'
,
val
=
xv
,
desc
=
'
aerodynamic volume node coordinates
'
,
tags
=
[
'
mphys_coupling
'
])
def
compute
(
self
,
inputs
,
outputs
):
...
...
@@ -303,9 +308,9 @@ class DartLoads(om.ExplicitComponent):
# I/O
self
.
add_input
(
'
xv
'
,
shape_by_conn
=
True
,
desc
=
'
aerodynamic volume node coordinates
'
,
tags
=
[
'
mphys_coupling
'
])
self
.
add_input
(
'
phi
'
,
shape_by_conn
=
True
,
desc
=
'
flow variables (potential)
'
,
tags
=
[
'
mphys_coupling
'
])
self
.
add_output
(
'
f_aero
'
,
distributed
=
True
,
val
=
np
.
zeros
(
3
*
len
(
self
.
bnd
.
nodes
)),
desc
=
'
aerodynamic loads
'
,
tags
=
[
'
mphys_coupling
'
])
self
.
add_output
(
FAERO
,
distributed
=
True
,
val
=
np
.
zeros
(
3
*
len
(
self
.
bnd
.
nodes
)),
desc
=
'
aerodynamic loads
'
,
tags
=
[
'
mphys_coupling
'
])
# Partials
# self.declare_partials(of=[
'f_aero'
], wrt=['xv', 'phi'])
# self.declare_partials(of=[
FAERO
], wrt=['xv', 'phi'])
def
compute
(
self
,
inputs
,
outputs
):
"""
Get the forces on moving body
...
...
@@ -313,7 +318,7 @@ class DartLoads(om.ExplicitComponent):
# NB: inputs already up-to-date because DartSolver has already been run
for
i
in
range
(
len
(
self
.
bnd
.
nodes
)):
for
j
in
range
(
3
):
outputs
[
'
f_aero
'
][
3
*
i
+
j
]
=
self
.
qinf
*
self
.
bnd
.
nLoads
[
i
][
j
]
outputs
[
FAERO
][
3
*
i
+
j
]
=
self
.
qinf
*
self
.
bnd
.
nLoads
[
i
][
j
]
def
compute_partials
(
self
,
inputs
,
partials
):
"""
Compute the partials gradients of the loads
...
...
@@ -324,11 +329,11 @@ class DartLoads(om.ExplicitComponent):
"""
Perform the matrix-vector product using the partial gradients of the loads
"""
if
mode
==
'
rev
'
:
if
'
f_aero
'
in
d_outputs
:
if
FAERO
in
d_outputs
:
if
'
xv
'
in
d_inputs
:
d_inputs
[
'
xv
'
]
+=
self
.
qinf
*
np
.
asarray
(
self
.
adj
.
computeJacVecLoadsMesh
(
d_outputs
[
'
f_aero
'
]))
# dX = dL_dX^T * dL
d_inputs
[
'
xv
'
]
+=
self
.
qinf
*
np
.
asarray
(
self
.
adj
.
computeJacVecLoadsMesh
(
d_outputs
[
FAERO
]))
# dX = dL_dX^T * dL
if
'
phi
'
in
d_inputs
:
d_inputs
[
'
phi
'
]
+=
self
.
qinf
*
np
.
asarray
(
self
.
adj
.
computeJacVecLoadsFlow
(
d_outputs
[
'
f_aero
'
]))
# dU = dL_dU^T * dL
d_inputs
[
'
phi
'
]
+=
self
.
qinf
*
np
.
asarray
(
self
.
adj
.
computeJacVecLoadsFlow
(
d_outputs
[
FAERO
]))
# dU = dL_dU^T * dL
elif
mode
==
'
fwd
'
:
raise
NotImplementedError
(
'
DartLoads - forward mode not implemented!
\n
'
)
...
...
@@ -449,12 +454,12 @@ class DartGroup(om.Group):
def
setup
(
self
):
# Components
if
self
.
options
[
'
mrf
'
]
is
None
:
self
.
add_subsystem
(
'
morpher
'
,
DartDummyMorpher
(
dim
=
self
.
options
[
'
sol
'
].
pbl
.
nDim
,
msh
=
self
.
options
[
'
sol
'
].
pbl
.
msh
),
promotes_inputs
=
[
'
x_aero
'
],
promotes_outputs
=
[
'
xv
'
])
self
.
add_subsystem
(
'
morpher
'
,
DartDummyMorpher
(
dim
=
self
.
options
[
'
sol
'
].
pbl
.
nDim
,
msh
=
self
.
options
[
'
sol
'
].
pbl
.
msh
),
promotes_inputs
=
[
XAERO
],
promotes_outputs
=
[
'
xv
'
])
else
:
self
.
add_subsystem
(
'
morpher
'
,
DartMorpher
(
dim
=
self
.
options
[
'
sol
'
].
pbl
.
nDim
,
bnd
=
self
.
options
[
'
bnd
'
],
mrf
=
self
.
options
[
'
mrf
'
],
adj
=
self
.
options
[
'
adj
'
]),
promotes_inputs
=
[
'
x_aero
'
],
promotes_outputs
=
[
'
xv
'
])
self
.
add_subsystem
(
'
morpher
'
,
DartMorpher
(
dim
=
self
.
options
[
'
sol
'
].
pbl
.
nDim
,
bnd
=
self
.
options
[
'
bnd
'
],
mrf
=
self
.
options
[
'
mrf
'
],
adj
=
self
.
options
[
'
adj
'
]),
promotes_inputs
=
[
XAERO
],
promotes_outputs
=
[
'
xv
'
])
self
.
add_subsystem
(
'
solver
'
,
DartSolver
(
sol
=
self
.
options
[
'
sol
'
],
adj
=
self
.
options
[
'
adj
'
],
rerr
=
self
.
options
[
'
rerr
'
]),
promotes_inputs
=
[
'
aoa
'
,
'
xv
'
],
promotes_outputs
=
[
'
phi
'
])
if
self
.
options
[
'
qinf
'
]
is
not
None
:
self
.
add_subsystem
(
'
loads
'
,
DartLoads
(
qinf
=
self
.
options
[
'
qinf
'
],
bnd
=
self
.
options
[
'
bnd
'
],
adj
=
self
.
options
[
'
adj
'
]),
promotes_inputs
=
[
'
xv
'
,
'
phi
'
],
promotes_outputs
=
[
'
f_aero
'
])
self
.
add_subsystem
(
'
loads
'
,
DartLoads
(
qinf
=
self
.
options
[
'
qinf
'
],
bnd
=
self
.
options
[
'
bnd
'
],
adj
=
self
.
options
[
'
adj
'
]),
promotes_inputs
=
[
'
xv
'
,
'
phi
'
],
promotes_outputs
=
[
FAERO
])
# Aerodynamic post-coupling group
class
DartPostGroup
(
om
.
Group
):
...
...
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