Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixing initial state values in MPhys #321

Open
wants to merge 42 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 34 commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
5a36918
Adding info print control when setting the aeroproblem for ADflow and…
lamkina Aug 19, 2023
177c020
Reverting import ordering
lamkina Aug 19, 2023
4fff8c6
Adding surface coordinate fix
lamkina Aug 22, 2023
c580310
Turning on printing in the ADflow solver comp
lamkina Aug 24, 2023
8b68ffc
Merge branch 'main' of github.com:mdolab/adflow into mphys_fix
lamkina Aug 24, 2023
1130ab8
Updated the logic to only print when the aeroproblem actually changes
lamkina Aug 24, 2023
6a17ec4
Updated the logic to only print when the aeroproblem actually changes
lamkina Aug 24, 2023
aff3806
Merge branch 'main' into mphys_fix
lamkina Aug 24, 2023
35962fb
Merge branch 'main' into mphys_fix_2
A-CGray Aug 24, 2023
146eaa9
Merge branch 'main' into mphys_fix
A-CGray Sep 6, 2023
2c4405a
Merge branch 'main' into mphys_fix_2
A-CGray Sep 6, 2023
fed1c61
Merge branch 'main' into mphys_fix_2
A-CGray Sep 11, 2023
63773ca
Merge branch 'main' into mphys_fix
A-CGray Sep 12, 2023
2b74de3
Adding info print control when setting the aeroproblem for ADflow and…
lamkina Aug 19, 2023
22d9783
Reverting import ordering
lamkina Aug 19, 2023
574b184
Adding surface coordinate fix
lamkina Aug 22, 2023
bcce60b
Updated the logic to only print when the aeroproblem actually changes
lamkina Aug 24, 2023
767105f
Merge branch 'mphys_fix_2' of github.com:lamkina/adflow into mphys_fix_2
lamkina Sep 14, 2023
3e750a7
Revert "Updated the logic to only print when the aeroproblem actually…
lamkina Sep 14, 2023
432c7b6
Revert "Adding info print control when setting the aeroproblem for AD…
lamkina Sep 14, 2023
736a62c
Merge branch 'main' of github.com:mdolab/adflow into mphys_fix
lamkina Sep 14, 2023
b529803
Switched from passing arguments to using options and module variables
lamkina Sep 14, 2023
169e69a
Forgot to run black
lamkina Sep 14, 2023
76eae9b
Added extra flag for printing info in setAeroProblem
lamkina Sep 14, 2023
c1ff161
Removed hacky fix for setting initial states in ADflow
lamkina Sep 22, 2023
3f73f1c
Merge branch 'main' of github.com:mdolab/adflow into mphys_fix
lamkina Sep 22, 2023
b8f11da
Re-ran fprettify
lamkina Sep 22, 2023
6edb1db
Removed unnecessary print logic
lamkina Sep 22, 2023
7322d05
Merge branch 'mphys_fix_2' of github.com:lamkina/adflow into mphys_in…
lamkina Sep 22, 2023
483865b
Fixed updatebcdataalllevels calls
lamkina Sep 22, 2023
cbb68d3
Free stream states are working using _set_vectors()
lamkina Sep 22, 2023
d26c838
Need to turn printing back on after setting the AP
lamkina Sep 22, 2023
530ad9e
Merge branch 'mphys_fix' of github.com:lamkina/adflow into mphys_init…
lamkina Sep 22, 2023
267b7b7
Ran black again
lamkina Sep 22, 2023
ed0c6fd
Removing typo
lamkina Sep 26, 2023
947282e
Merge branch 'main' into mphys_init_guess_fix
lamkina Sep 26, 2023
e0b0d5a
Merge branch 'main' into mphys_init_guess_fix
A-CGray Sep 28, 2023
261172d
Merge branch 'main' of github.com:mdolab/adflow into mphys_init_guess…
lamkina Oct 24, 2023
b45bab5
Merge branch 'main' of github.com:mdolab/adflow into mphys_init_guess…
lamkina Nov 4, 2023
4d5ecf6
Merge branch 'main' of github.com:mdolab/adflow into mphys_init_guess…
lamkina Nov 10, 2023
d26295d
Cleaning up missed output printing
lamkina Nov 10, 2023
78b8cc0
Merge branch 'main' into mphys_init_guess_fix
A-CGray Mar 18, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
48 changes: 43 additions & 5 deletions adflow/mphys/mphys_adflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,14 +91,14 @@
coordsUpdated = False
if "x_aero" in inputs:
newSurfCoord = inputs["x_aero"].reshape((-1, 3))
currentSurfCoord = solver.getSurfaceCoordinates(groupName=solver.meshFamilyGroup, includeZipper=False)
currentSurfCoord = solver.mesh.getSurfaceCoordinates() # Get coordinates directly from IDWarp

Check warning on line 94 in adflow/mphys/mphys_adflow.py

View check run for this annotation

Codecov / codecov/patch

adflow/mphys/mphys_adflow.py#L94

Added line #L94 was not covered by tests
coordsAreEqual = np.allclose(newSurfCoord, currentSurfCoord, rtol=1e-14, atol=1e-14)
coordsAreEqual = solver.comm.allreduce(coordsAreEqual, op=MPI.LAND)
if not coordsAreEqual:
if solver.comm.rank == 0:
print("Updating surface coords", flush=True)
solver.setSurfaceCoordinates(newSurfCoord, groupName=solver.meshFamilyGroup)
solver.updateGeometryInfo()
solver.updateGeometryInfo(warpMesh=False)

Check warning on line 101 in adflow/mphys/mphys_adflow.py

View check run for this annotation

Codecov / codecov/patch

adflow/mphys/mphys_adflow.py#L101

Added line #L101 was not covered by tests
coordsUpdated = True
return coordsUpdated

Expand Down Expand Up @@ -164,8 +164,17 @@

updatesMade = ap != solver.curAP

# These flags control printing alpha and boundary condition warnings
# when we update the aeroproblem. We only want these to print when
# we actually switch the aeroproblem.
solver.setOption("printIterations", updatesMade)
solver.adflow.inputiteration.printbcwarnings = updatesMade

Check warning on line 171 in adflow/mphys/mphys_adflow.py

View check run for this annotation

Codecov / codecov/patch

adflow/mphys/mphys_adflow.py#L170-L171

Added lines #L170 - L171 were not covered by tests
solver.setAeroProblem(ap)

# Turn printing back on
solver.setOption("printIterations", True)
solver.adflow.inputiteration.printbcwarnings = True

Check warning on line 176 in adflow/mphys/mphys_adflow.py

View check run for this annotation

Codecov / codecov/patch

adflow/mphys/mphys_adflow.py#L175-L176

Added lines #L175 - L176 were not covered by tests

if inputs is not None:
tmp = {}
for args, _ in ap_vars:
Expand Down Expand Up @@ -227,7 +236,7 @@
return self._getTriangulatedMeshSurface(groupName=groupName)

def _getTriangulatedMeshSurface(self, groupName=None, **kwargs):
"""
"""©
lamkina marked this conversation as resolved.
Show resolved Hide resolved
This function returns a trianguled verision of the surface
mesh on all processors. The intent is to use this for doing
constraints in DVConstraints.
Expand Down Expand Up @@ -333,12 +342,17 @@

def compute(self, inputs, outputs):
solver = self.solver
set_surf_coords(solver, inputs)
coords_updated = set_surf_coords(solver, inputs)
if coords_updated:
solver.mesh.warpMesh()

Check warning on line 347 in adflow/mphys/mphys_adflow.py

View check run for this annotation

Codecov / codecov/patch

adflow/mphys/mphys_adflow.py#L345-L347

Added lines #L345 - L347 were not covered by tests

outputs["adflow_vol_coords"] = solver.mesh.getSolverGrid()

def compute_jacvec_product(self, inputs, d_inputs, d_outputs, mode):
solver = self.solver
set_surf_coords(solver, inputs)
coords_updated = set_surf_coords(solver, inputs)
if coords_updated:
solver.mesh.warpMesh()

Check warning on line 355 in adflow/mphys/mphys_adflow.py

View check run for this annotation

Codecov / codecov/patch

adflow/mphys/mphys_adflow.py#L353-L355

Added lines #L353 - L355 were not covered by tests

if mode == "fwd":
if "adflow_vol_coords" in d_outputs:
Expand Down Expand Up @@ -422,6 +436,23 @@
def _set_states(self, outputs):
self.solver.setStates(outputs["adflow_states"])

def _setup_vectors(self, root_vectors):
super()._setup_vectors(root_vectors)

Check warning on line 440 in adflow/mphys/mphys_adflow.py

View check run for this annotation

Codecov / codecov/patch

adflow/mphys/mphys_adflow.py#L439-L440

Added lines #L439 - L440 were not covered by tests

# Turn off extra printouts
self.solver.setOption("printIterations", False)
self.solver.adflow.inputiteration.printbcwarnings = False

Check warning on line 444 in adflow/mphys/mphys_adflow.py

View check run for this annotation

Codecov / codecov/patch

adflow/mphys/mphys_adflow.py#L443-L444

Added lines #L443 - L444 were not covered by tests

# Set the AP
self.solver.setAeroProblem(self.ap)

Check warning on line 447 in adflow/mphys/mphys_adflow.py

View check run for this annotation

Codecov / codecov/patch

adflow/mphys/mphys_adflow.py#L447

Added line #L447 was not covered by tests

# Turn printing back on
self.solver.setOption("printIterations", True)
self.solver.adflow.inputiteration.printbcwarnings = True

Check warning on line 451 in adflow/mphys/mphys_adflow.py

View check run for this annotation

Codecov / codecov/patch

adflow/mphys/mphys_adflow.py#L450-L451

Added lines #L450 - L451 were not covered by tests
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems that this was retained after merging (same for above). I think you probably want to restore the previous state as done in PR #307. See here for original comment.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch. I'm not sure how I did this, but nonetheless I'll get it fixed.


# Set the OM states to be equal to the free stream
self.set_val("adflow_states", self.solver.getStates())

Check warning on line 454 in adflow/mphys/mphys_adflow.py

View check run for this annotation

Codecov / codecov/patch

adflow/mphys/mphys_adflow.py#L454

Added line #L454 was not covered by tests

def apply_nonlinear(self, inputs, outputs, residuals):
solver = self.solver
ap = self.ap
Expand All @@ -433,6 +464,7 @@
def solve_nonlinear(self, inputs, outputs):
solver = self.solver
ap = self.ap

if self._do_solve:
setAeroProblem(solver, ap, self.ap_vars, inputs=inputs, outputs=outputs, print_dict=False)
ap.solveFailed = False # might need to clear this out?
Expand Down Expand Up @@ -955,8 +987,14 @@
ap = self.ap

# re-set the AP so that we are sure state is updated
solver.setOption("printIterations", False)
solver.adflow.inputiteration.printbcwarnings = False # Turn off extra printouts

Check warning on line 991 in adflow/mphys/mphys_adflow.py

View check run for this annotation

Codecov / codecov/patch

adflow/mphys/mphys_adflow.py#L990-L991

Added lines #L990 - L991 were not covered by tests
solver.setAeroProblem(ap)

# Reset back to true to preserve normal ADflow printout structure
solver.setOption("printIterations", True)
solver.adflow.inputiteration.printbcwarnings = True

Check warning on line 996 in adflow/mphys/mphys_adflow.py

View check run for this annotation

Codecov / codecov/patch

adflow/mphys/mphys_adflow.py#L995-L996

Added lines #L995 - L996 were not covered by tests

# write the solution files. Internally, this checks the
# types of solution files specified in the options and
# only outsputs these
Expand Down
27 changes: 24 additions & 3 deletions adflow/pyADflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,12 @@ def __init__(self, comm=None, options=None, debug=False, dtype="d"):
curDir = os.path.basename(os.path.dirname(os.path.realpath(__file__)))
self.adflow = MExt.MExt("libadflow", curDir, debug=debug)._module

# This is a flag not exposed to the user as an option that controls
# printing the boundary condition warnings. This should only
# be used in the MPhys layer when we make multiple calls to
# updateBCAllLevels.
self.adflow.inputiteration.printbcwarnings = True

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here, this should not be here, like in PR #307. See here for original comment.

libLoadTime = time.time()

# Information for base class:
Expand Down Expand Up @@ -3285,7 +3291,15 @@ def setSurfaceCoordinates(self, coordinates, groupName=None):
self.mesh.setSurfaceCoordinates(meshSurfCoords)

def setAeroProblem(self, aeroProblem, releaseAdjointMemory=True):
"""Set the supplied aeroProblem to be used in ADflow"""
"""Set the supplied aeroProblem to be used in ADflow.

Parameters
----------
aeroProblem : AeroProblem
The supplied aeroproblem to be set.
releaseAdjointMemory : bool, optional
Flag to release the adjoint memory when setting a new aeroproblem, by default True
"""

ptSetName = "adflow_%s_coords" % aeroProblem.name

Expand Down Expand Up @@ -3413,9 +3427,16 @@ def setAeroProblem(self, aeroProblem, releaseAdjointMemory=True):
self.adflow.anksolver.ank_cfl = aeroProblem.adflowData.ank_cfl

def _setAeroProblemData(self, aeroProblem, firstCall=False):
"""After an aeroProblem has been associated with self.curAP, set
all the updated information in ADflow.

Parameters
----------
aeroProblem : AeroProblem
The current aeroProblem object.
firstCall : bool, optional
Flag that signifies this is being called for the first time, by default False
"""
After an aeroProblem has been associated with self.curAP, set
all the updated information in ADflow."""

# Set any additional adflow options that may be defined in the
# aeroproblem. While we do it we save the options that we've
Expand Down
13 changes: 7 additions & 6 deletions src/bcdata/BCData.F90
Original file line number Diff line number Diff line change
Expand Up @@ -2687,6 +2687,7 @@ subroutine setBCDataFineGrid(initializationPart)
use inputTimeSpectral, only: nTimeIntervalsSpectral
use iteration, only: groundLevel
use utils, only: setPointers, terminate
use inputIteration, only: printBCWarnings
implicit none
!
! Subroutine arguments.
Expand Down Expand Up @@ -2803,7 +2804,7 @@ subroutine setBCDataFineGrid(initializationPart)
call mpi_reduce(i, j, 1, adflow_integer, mpi_max, 0, &
ADflow_comm_world, ierr)

if (myID == 0 .and. j == 1) then
if (myID == 0 .and. j == 1 .and. printBCWarnings) then

print "(a)", "#"
print "(a)", "#*==================== !!! Warning !!! &
Expand All @@ -2827,7 +2828,7 @@ subroutine setBCDataFineGrid(initializationPart)
call mpi_reduce(i, j, 1, adflow_integer, mpi_max, 0, &
ADflow_comm_world, ierr)

if (myID == 0 .and. j == 1) then
if (myID == 0 .and. j == 1 .and. printBCWarnings) then

print "(a)", "#"
print "(a)", "#*==================== !!! Warning !!! &
Expand All @@ -2850,7 +2851,7 @@ subroutine setBCDataFineGrid(initializationPart)
call mpi_reduce(i, j, 1, adflow_integer, mpi_max, 0, &
ADflow_comm_world, ierr)

if (myID == 0 .and. j == 1) then
if (myID == 0 .and. j == 1 .and. printBCWarnings) then

print "(a)", "#"
print "(a)", "#*==================== !!! Warning !!! &
Expand All @@ -2874,7 +2875,7 @@ subroutine setBCDataFineGrid(initializationPart)
call mpi_reduce(i, j, 1, adflow_integer, mpi_max, 0, &
ADflow_comm_world, ierr)

if (myID == 0 .and. j == 1) then
if (myID == 0 .and. j == 1 .and. printBCWarnings) then

print "(a)", "#"
print "(a)", "#*==================== !!! Warning !!! &
Expand All @@ -2898,7 +2899,7 @@ subroutine setBCDataFineGrid(initializationPart)
call mpi_reduce(i, j, 1, adflow_integer, mpi_max, 0, &
ADflow_comm_world, ierr)

if (myID == 0 .and. j == 1) then
if (myID == 0 .and. j == 1 .and. printBCWarnings) then

print "(a)", "#"
print "(a)", "#*==================== !!! Warning !!! &
Expand All @@ -2921,7 +2922,7 @@ subroutine setBCDataFineGrid(initializationPart)
call mpi_reduce(i, j, 1, adflow_integer, mpi_max, 0, &
ADflow_comm_world, ierr)

if (myID == 0 .and. j == 1) then
if (myID == 0 .and. j == 1 .and. printBCWarnings) then

print "(a)", "#"
print "(a)", "#*==================== !!! Warning !!! &
Expand Down
1 change: 1 addition & 0 deletions src/f2py/adflow.pyf
Original file line number Diff line number Diff line change
Expand Up @@ -1086,6 +1086,7 @@ python module libadflow
logical :: printiterations
logical :: printwarnings
logical :: printnegativevolumes
logical :: printbcwarnings
real(kind=realtype) ::maxl2deviationfactor
logical :: uselinresmonitor
logical :: usedisscontinuation
Expand Down
1 change: 1 addition & 0 deletions src/modules/inputParam.F90
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,7 @@ module inputIteration
logical :: printIterations
logical :: printWarnings
logical :: printNegativeVolumes
logical :: printBCWarnings
real(kind=realType), dimension(4) :: turbResScale
logical :: useDissContinuation
real(kind=realType) :: dissContMagnitude, dissContMidpoint, dissContSharpness
Expand Down