Skip to content

changes/updates in regards to spr based error estimation/adaptive solve#41

Merged
seegyoung merged 62 commits into
PrincetonUniversity:masterfrom
mortezah:spr_based_error_estimation
Apr 14, 2022
Merged

changes/updates in regards to spr based error estimation/adaptive solve#41
seegyoung merged 62 commits into
PrincetonUniversity:masterfrom
mortezah:spr_based_error_estimation

Conversation

@mortezah

@mortezah mortezah commented Sep 20, 2021

Copy link
Copy Markdown
Collaborator

Summary

The changes in this PR are in regards to adaptive-solve implementation using spr-based error estimation. Additional updates/modifications are also included for things like solution transfer/field transfer/etc (see the detailed list at the end of this notes)

At this point, things work for both 2D/3D. There are a few new parameters introduced in the input file as follows:

  1. ispradapt (default 0): 1 to turn on spr-adapt and 0 to turn it off
  2. isprntime (default 10): an integer bigger than 0 to call spr-adapt every isprntime time steps
  3. isprweight (default 0.1): a real number smaller than 1 specifying the weight of error to calculate the size-field (note smaller weight results in much more aggressive adaptation).
  4. isprmaxsize (default 0.05): user-specified maximum allowed edge length in the entire mesh
  5. isprrefinelevel (default 1): maximum level of refinement allowed during each call to spr-adapt [for example a value of 3 means the lengths of the edges will not reduce by a factor of more than 8(= 2^3) in each call to spr-adapt
  6. isprcoarsenlevel (default -1): maximum level of coarsening allowed during each call to spr-adapt. use -1 to disable coarsening altogether [for example a value of 3 means the lengths of the edges will not increase by a factor of more than 8(= 2^3) in each call to spr-adapt

The high-level API that can be called on the Fortran side is adapt_by_spr. An example use is as follows

call adapt_by_spr(field_vec%id, psi_g, ntime, isprweight, isprmaxsize, isprrefinelevel, isprcoarsenlevel)

where field_vec contains the list of all the privacy variables (e.g. u_field, vz_field, chi_field, psi_field, etc) and the the second argument psi_g tells adapt_by_spr to use the psi_field for error estimation.

Checklist

  • add API for setting verbosity level of pumi print statements (useful for debugging mesh adapt)
  • fix the obvious memory leaks in solution-transfer code
  • update create_field and create_vector subroutines to take an optional prefix argument as the field name
  • add new APIs (both on the Fortran side and C++ side) to mark specific fields for solution transfer
  • add a new API in output.f90 to mark the fields for solution transfer following the same logic used to write fields to restart
  • add the basic spr routine to make sure you can run successive adapt solve loops [use any field for now]
  • update the spr routine to use the "psi" field instead.
  • add inputs for spr (weight, max_refine_level, max_coarsen_level, max_size)
  • merge master to this branch and do the tests (on stellar)
  • regression tests (on SCOREC)
  • regression tests (on STELLAR) (regression tests pass on stellar except for the adapt that has small differences in values)

Also makes some of the print infos more readable
There are a couple of new member functions to this class to identify if
a field is marked for solution transfer or not.
More clean up and testing needed
transfer

The fields that will be added to solution transfer will be specified on
the fortran side
To make them accessible on the fortran side
The optional input prefix (of type character string) can be used to name
the field on the C++ side.

This commit also adds fortran APIs to mark fields that need to be
transfered.
We will need to figure out a better way of categorizing all this
different cases, at some point
This is used to mark fields for solution transfer using the same logic
they are written to hdf5 restart files
and also mark them for solution transfer

The vectors defined in this file seem to be all needed in each solution
step so they must all be transferred during mesh adapt
to give all those fields proper names. this is done only for a 2d
example and more may need to be done for other examples. since the new
"prefix" argument in create_field api is optional this should not break
the other tests cases.
to be consistent with the latest changes on SCOREC/core
Conflicts:
	m3dc1_scorec/api/m3dc1_scorec.cc
	m3dc1_scorec/src/m3dc1_adapt.cc
	unstructured/newpar.f90
Note that something does not seem to work in parallel. Probably some
data structure changes that is needed for m3dc1 to work that your are
missing when doing spr-adapt
For the case of 3D these are handled outside of this loop according to
which fields have to be transfered during solution transfer
This is called after remove3D to initialize the data-structures on the
empty parts of the mesh, to avoid problems with entity orders when
restore3D is called.
@mortezah

Copy link
Copy Markdown
Collaborator Author

3D adapt development using spr for error estimation are also added to this pull-request. The main API is the same and works for both 2D and 3D.

@bclyons12

Copy link
Copy Markdown
Collaborator

@mortezah Excellent work. If you think it's ready, I can try using it myself. I tried compiling on stellar though and it doesn't look like the version of the SCOREC routines has been appropriately updated. Presumably they need to be installed and then linked to in stellar.mk?

If you want to try running a case, here's a 2D example on stellar based on a benchmark we're doing with NIMROD: /scratch/gpfs/bclyons/C1_135247. The pellet travels in from the outside, cooling the plasma and causing the current to contract. The regions of steepest gradient in density, temperature, pressure, and current all change continuously throughout the run. In the 2D run here, the gradients cause negative overshoots in temperature & pressure, strange current rings to form, and it goes numerically unstable. The adaptive meshing should help with this. Once we're confident it's working in 2D, we can restart it in 3D and test all that.

@mortezah

Copy link
Copy Markdown
Collaborator Author

@bclyons12. Yes, you are right, since I have made changes to the C++ side of the code as well as to the Fortran side, one needs to build m3dc1_scored to be able to use those changes. I am guessing ideally when things are merged m3dc1_scored library installations will be updated on all the production machines.

@seegyoung
seegyoung merged commit c655244 into PrincetonUniversity:master Apr 14, 2022
@seegyoung

Copy link
Copy Markdown
Collaborator

@bclyons12, please check out the latest M3DC1 and compile it with SCORECVER=adapt using stellart.mk.

I won't update the existing SCOREC libraries until everyone agrees to do so. So 3D adaptation will be available only with SCORECVER=adapt for a while. Also, please let me know if you have any other machines to test out 3D adaptation.

@mortezah

mortezah commented Apr 14, 2022

Copy link
Copy Markdown
Collaborator Author

@bclyons12, please check out the latest M3DC1 and compile it with SCORECVER=adapt using stellart.mk.

I won't update the existing SCOREC libraries until everyone agrees to do so. So 3D adaptation will be available only with SCORECVER=adapt for a while. Also, please let me know if you have any other machines to test out 3D adaptation.

@seegyoung

I think this is going to cause problems. By merging this branch into master all the latest changes in the Fortran side are there and if the m3dc1_scorec installation is not updated to use the latest changes, the build of m3dc1 executables is going to fail on every machine except stellar.

Also, we should avoid introducing extra flags such as SCORECVER etc, which makes keeping track of things difficult. All the changes that I have made in this branch are consistent and if they are all used properly everything should work and there should be no need for the additional flag in the build process.

@MarkShephard

Copy link
Copy Markdown
Collaborator

Given that, are you saying it should be updated everywhere? If yes, are we pretty sure that will not be an issue? We should get this resolved quickly.

@mortezah

Copy link
Copy Markdown
Collaborator Author

@MarkShephard yes that is true, m3dc1_scorec (which is the C++ part of M3DC1) has to be updated everywhere. I introduced new APIs there that are called from the Fortran side, and if the Fortran side is compiled against the old version of m3dc1_scorec the compilation will fail.

@bclyons12

Copy link
Copy Markdown
Collaborator

@mortezah @MarkShephard @seegyoung If this passes all regression tests, then I'm fine with the merge, but yes, we need to get the installation updated on all machines

@mortezah

mortezah commented Apr 14, 2022

Copy link
Copy Markdown
Collaborator Author

@bclyons12 @MarkShephard @seegyoung since I do not have access to all the machines I cannot confirm if the regression tests pass on all the machines. That was the main motivation behind having this reviewed before being merged.

@nferraro

nferraro commented Apr 14, 2022 via email

Copy link
Copy Markdown
Collaborator

@mortezah

Copy link
Copy Markdown
Collaborator Author

@nferraro @bclyons12 @MarkShephard @seegyoung @sjardin

I had a feeling that treating m3dc1_scorec as an external library is not ideal (since every time that is changed installations have to update everywhere). I was actually preparing a document (https://docs.google.com/document/d/10TkOtAaXKsX6s6reRhewc2rFYAw0y9EGMT1CkPcfJ7A/edit?usp=sharing) to suggest doing things differently which I guess is also consistent with what you call unified build systems. It would be good if you can take a look at that document and let me know if that is what you had in mind. Once that is agreed on, I can either update the current build system (using make) or move entirely to cmake to not only build the final Fortran executables but also build a local version of the m3dc1_scorec library to link against.

@sjardin

sjardin commented Apr 14, 2022 via email

Copy link
Copy Markdown
Collaborator

@mortezah

mortezah commented Apr 14, 2022

Copy link
Copy Markdown
Collaborator Author

@sjardin @bclyons12 @nferraro @MarkShephard

I will revert the merge, as I don't know how soon Seegyoung can install the updated libraries. Once we have a more streamlined way of m3dc1_scorec libraries I can then merge this branch back into master

@mortezah

Copy link
Copy Markdown
Collaborator Author

This might be a longer discussion that needs input from others. In the mean time, I would really appreciate it if the version in git master compiled, as I am trying to make some other changes and cannot compile as of now.

On Thu, Apr 14, 2022 at 2:03 PM Morteza @.> wrote: @nferraro https://github.com/nferraro @bclyons12 https://github.com/bclyons12 @MarkShephard https://github.com/MarkShephard @seegyoung https://github.com/seegyoung @sjardin https://github.com/sjardin I had a feeling that treating m3dc1_scorec as an external library is not ideal (since every time that is changed installations have to update everywhere). I was actually preparing a document ( https://docs.google.com/document/d/10TkOtAaXKsX6s6reRhewc2rFYAw0y9EGMT1CkPcfJ7A/edit?usp=sharing) to suggest doing things differently which I guess is also consistent with what you call unified build systems. It would be good if you can take a look at that document and let me know if that is what you had in mind. Once that is agreed on, I can either update the current build system (using make) or move entirely to cmake to not only build the final Fortran executables but also build a local version of the m3dc1_scorec library to link against. — Reply to this email directly, view it on GitHub <#41 (comment)>, or unsubscribe https://github.com/notifications/unsubscribe-auth/AIIVKSBSQT5Z5QOGUDRRVVLVFBMUNANCNFSM5EL4C65Q . You are receiving this because you were mentioned.Message ID: @.>
-- 609 243 2635

@sjardin I have just reverted the merge. If you do a git pull you should be able to compile. Let me know if there are any issues.

@seegyoung

Copy link
Copy Markdown
Collaborator

My apologies for causing any trouble. I wasn't aware that Morteza's branch is not ready for the merge.
Gladly, I haven't update any existing libraries on stellar so you should be able to work with master on Stellar.

Brendan can install Morteza' branch (Fortran code) only with SCORECVER=adapt. And I assume I don't have to do any thing special for now (Morteza, please correct me if I am wrong).

@bclyons12

Copy link
Copy Markdown
Collaborator

As @nferraro, I think is a good time to target a unified build between unstructured and m3dc1_scorec. It shouldn't be that hard since, on each system, we have .mk files for the code in unstructured and there are config.sh files for the code in m3dc1_scorec. I'm working on this now for stellar.

@nferraro

nferraro commented Apr 14, 2022 via email

Copy link
Copy Markdown
Collaborator

@mortezah

Copy link
Copy Markdown
Collaborator Author

As @nferraro, I think is a good time to target a unified build between unstructured and m3dc1_scorec. It shouldn't be that hard since, on each system, we have .mk files for the code in unstructured and there are config.sh files for the code in m3dc1_scorec. I'm working on this now for stellar.

I see two possible ways to achieve this:

  1. Have a shell script that first builds/install m3dc1_scorec locally using the latest version on GitHub and then use the current make system in unstructured to build the Fortran executables using the local build/install.
  2. Have a proper unified build using only either CMake or Make.

The second approach is the cleaner approach but requires a good deal of time/effort to put in place.

@bclyons12

Copy link
Copy Markdown
Collaborator

Unified build is working on stellar with #46. Need to review these changes then update accordingly for all systems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants