Skip to content

Commit

Permalink
moves when the chem engine is set, which allows transport parseParame…
Browse files Browse the repository at this point in the history
…terList to use specie names
  • Loading branch information
ecoon committed Jan 30, 2025
1 parent 3ed1b58 commit 0ff4edc
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 35 deletions.
35 changes: 15 additions & 20 deletions src/pks/mpc/mpc_coupled_reactivetransport.cc
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,20 @@ MPCCoupledReactiveTransport::MPCCoupledReactiveTransport(
void
MPCCoupledReactiveTransport::parseParameterList()
{
WeakMPC::parseParameterList();
cast_sub_pks_();
coupled_chemistry_pk_->parseParameterList();

// communicate chemistry engine to transport.
#ifdef ALQUIMIA_ENABLED
transport_pk_->setChemEngine(
Teuchos::rcp_static_cast<AmanziChemistry::Alquimia_PK>(chemistry_pk_),
chemistry_pk_->chem_engine());
transport_pk_surf_->setChemEngine(
Teuchos::rcp_static_cast<AmanziChemistry::Alquimia_PK>(chemistry_pk_surf_),
chemistry_pk_surf_->chem_engine());
#endif

coupled_transport_pk_->parseParameterList();

domain_ = Keys::readDomain(*plist_, "domain", "domain");
domain_surf_ = Keys::readDomainHint(*plist_, domain_, "domain", "surface");
Expand All @@ -57,8 +70,6 @@ MPCCoupledReactiveTransport::parseParameterList()
void
MPCCoupledReactiveTransport::Setup()
{
cast_sub_pks_();

// must Setup transport first to get alias for saturation, etc set up correctly
coupled_transport_pk_->Setup();
coupled_chemistry_pk_->Setup();
Expand Down Expand Up @@ -106,27 +117,11 @@ MPCCoupledReactiveTransport::cast_sub_pks_()
Teuchos::rcp_dynamic_cast<Transport::Transport_ATS>(coupled_transport_pk_->get_subpk(1));
AMANZI_ASSERT(transport_pk_surf_ != Teuchos::null);

chemistry_pk_ =
Teuchos::rcp_dynamic_cast<AmanziChemistry::Chemistry_PK>(coupled_chemistry_pk_->get_subpk(0));
AMANZI_ASSERT(chemistry_pk_ != Teuchos::null);
chemistry_pk_surf_ =
Teuchos::rcp_dynamic_cast<AmanziChemistry::Chemistry_PK>(coupled_chemistry_pk_->get_subpk(1));
AMANZI_ASSERT(chemistry_pk_surf_ != Teuchos::null);

AMANZI_ASSERT(transport_pk_->domain() == chemistry_pk_->domain());
AMANZI_ASSERT(transport_pk_surf_->domain() == chemistry_pk_surf_->domain());

// communicate chemistry engine to transport.
#ifdef ALQUIMIA_ENABLED
transport_pk_->SetupAlquimia(
Teuchos::rcp_static_cast<AmanziChemistry::Alquimia_PK>(chemistry_pk_),
chemistry_pk_->chem_engine());
transport_pk_surf_->SetupAlquimia(
Teuchos::rcp_static_cast<AmanziChemistry::Alquimia_PK>(chemistry_pk_surf_),
chemistry_pk_surf_->chem_engine());
#endif
}


// -----------------------------------------------------------------------------
//
// -----------------------------------------------------------------------------
Expand Down
32 changes: 20 additions & 12 deletions src/pks/mpc/mpc_reactivetransport.cc
Original file line number Diff line number Diff line change
Expand Up @@ -39,21 +39,34 @@ MPCReactiveTransport::MPCReactiveTransport(Teuchos::ParameterList& pk_tree,


void
MPCReactiveTransport::Setup()
MPCReactiveTransport::parseParameterList()
{
cast_sub_pks_();
chemistry_pk_->parseParameterList();

#ifdef ALQUIMIA_ENABLED
transport_pk_->setChemEngine(
Teuchos::rcp_static_cast<AmanziChemistry::Alquimia_PK>(chemistry_pk_),
chemistry_pk_->chem_engine());
#endif

// now transport can be parse with knowledge of names
transport_pk_->parseParameterList();
}


void
MPCReactiveTransport::Setup()
{
transport_pk_->Setup();
chemistry_pk_->Setup();


S_->Require<CompositeVector, CompositeVectorSpace>(tcc_key_, tag_next_, "state")
.SetMesh(S_->GetMesh(domain_))
->SetGhosted()
->AddComponent("cell", AmanziMesh::Entity_kind::CELL, chemistry_pk_->num_aqueous_components());
S_->RequireEvaluator(tcc_key_, tag_next_);


S_->Require<CompositeVector, CompositeVectorSpace>(mol_dens_key_, tag_next_)
.SetMesh(S_->GetMesh(domain_))
->SetGhosted()
Expand All @@ -64,18 +77,13 @@ MPCReactiveTransport::Setup()
void
MPCReactiveTransport::cast_sub_pks_()
{
transport_pk_ = Teuchos::rcp_dynamic_cast<Transport::Transport_ATS>(sub_pks_[1]);
AMANZI_ASSERT(transport_pk_ != Teuchos::null);

// cast and call parse on chemistry
chemistry_pk_ = Teuchos::rcp_dynamic_cast<AmanziChemistry::Chemistry_PK>(sub_pks_[0]);
AMANZI_ASSERT(chemistry_pk_ != Teuchos::null);

// communicate chemistry engine to transport.
#ifdef ALQUIMIA_ENABLED
transport_pk_->SetupAlquimia(
Teuchos::rcp_static_cast<AmanziChemistry::Alquimia_PK>(chemistry_pk_),
chemistry_pk_->chem_engine());
#endif
// now chem engine is set and we can hand it to transport
transport_pk_ = Teuchos::rcp_dynamic_cast<Transport::Transport_ATS>(sub_pks_[1]);
AMANZI_ASSERT(transport_pk_ != Teuchos::null);
}

// -----------------------------------------------------------------------------
Expand Down
3 changes: 3 additions & 0 deletions src/pks/mpc/mpc_reactivetransport.hh
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ class MPCReactiveTransport : public WeakMPC {

// PK methods
virtual double get_dt() override;

virtual void parseParameterList() override;

virtual void Setup() override;
virtual void Initialize() override;
virtual bool AdvanceStep(double t_old, double t_new, bool reinit = false) override;
Expand Down
2 changes: 1 addition & 1 deletion src/pks/transport/transport_ats.hh
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ class Transport_ATS : public PK_PhysicalExplicit<Epetra_Vector> {

// coupling with chemistry
#ifdef ALQUIMIA_ENABLED
void SetupAlquimia(Teuchos::RCP<AmanziChemistry::Alquimia_PK> chem_pk,
void setChemEngine(Teuchos::RCP<AmanziChemistry::Alquimia_PK> chem_pk,
Teuchos::RCP<AmanziChemistry::ChemistryEngine> chem_engine);
#endif

Expand Down
6 changes: 4 additions & 2 deletions src/pks/transport/transport_ats_pk.cc
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ Transport_ATS::set_tags(const Tag& current, const Tag& next)
****************************************************************** */
#ifdef ALQUIMIA_ENABLED
void
Transport_ATS::SetupAlquimia(Teuchos::RCP<AmanziChemistry::Alquimia_PK> chem_pk,
Transport_ATS::setChemEngine(Teuchos::RCP<AmanziChemistry::Alquimia_PK> chem_pk,
Teuchos::RCP<AmanziChemistry::ChemistryEngine> chem_engine)
{
chem_pk_ = chem_pk;
Expand Down Expand Up @@ -985,6 +985,7 @@ Transport_ATS ::Advance_Dispersion_Diffusion_(double t_old, double t_new)
// Disperse and diffuse aqueous components
for (int i = 0; i < num_aqueous_; i++) {
FindDiffusionValue_(component_names_[i], &md_new, &phase);
AMANZI_ASSERT(phase == 0);
md_change = md_new - md_old;
md_old = md_new;

Expand Down Expand Up @@ -1055,8 +1056,9 @@ Transport_ATS ::Advance_Dispersion_Diffusion_(double t_old, double t_new)
// are treated with a hack of the accumulation term.
D_.clear();
md_old = 0.0;
for (int i = num_aqueous_; i < num_components_; i++) {
for (int i = num_aqueous_; i < (num_aqueous_ + num_gaseous_); i++) {
FindDiffusionValue_(component_names_[i], &md_new, &phase);
AMANZI_ASSERT(phase == 1);
md_change = md_new - md_old;
md_old = md_new;

Expand Down

0 comments on commit 0ff4edc

Please sign in to comment.