Skip to content

Commit

Permalink
revising Amanzi chem pks
Browse files Browse the repository at this point in the history
  • Loading branch information
ecoon committed Feb 28, 2025
1 parent a0e5d41 commit 90c8735
Show file tree
Hide file tree
Showing 7 changed files with 125 additions and 633 deletions.
4 changes: 2 additions & 2 deletions src/pks/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ include_directories(${GEOCHEM_SOURCE_DIR})
include_directories(${CHEMPK_SOURCE_DIR})

set(ats_pks_src_files
pk_helpers.cc
chem_pk_helpers.cc
pk_bdf_default.cc
pk_physical_default.cc
pk_physical_bdf_default.cc
Expand All @@ -17,7 +17,7 @@ set(ats_pks_src_files
)

set(ats_pks_inc_files
pk_helpers.hh
chem_pk_helpers.hh
pk_bdf_default.hh
pk_physical_default.hh
pk_physical_bdf_default.hh
Expand Down
74 changes: 74 additions & 0 deletions src/pks/chem_pk_helpers.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
/*
Copyright 2010-202x held jointly by participating institutions.
ATS is released under the three-clause BSD License.
The terms of use and "as is" disclaimer for this license are
provided in the top-level COPYRIGHT file.
Authors: Ethan Coon ([email protected])
*/

#include "chem_pk_helpers.hh"
#include "Chemistry_PK.hh"

namespace Amanzi {

// -----------------------------------------------------------------------------
// Helper functions for working with Amanzi's Chemistry PK
// -----------------------------------------------------------------------------
void
convertConcentrationToAmanzi(const Epetra_MultiVector& mol_dens,
int num_aqueous,
const Epetra_MultiVector& tcc_ats,
Epetra_MultiVector& tcc_amanzi)
{
// convert from mole fraction [mol C / mol H20] to [mol C / L]
for (int k = 0; k != num_aqueous; ++k) {
for (int c = 0; c != tcc_ats.MyLength(); ++c) {
// 1.e-3 converts L to m^3
tcc_amanzi[k][c] = tcc_ats[k][c] * mol_dens[0][c] * 1.e-3;
}
}
}

void
convertConcentrationToATS(const Epetra_MultiVector& mol_dens,
int num_aqueous,
const Epetra_MultiVector& tcc_amanzi,
Epetra_MultiVector& tcc_ats)
{
// convert from [mol C / L] to mol fraction [mol C / mol H20]
for (int k = 0; k != num_aqueous; ++k) {
for (int c = 0; c != tcc_amanzi.MyLength(); ++c) {
tcc_ats[k][c] = tcc_amanzi[k][c] / (mol_dens[0][c] * 1.e-3);
}
}
}


bool
advanceChemistry(Teuchos::RCP<AmanziChemistry::Chemistry_PK> chem_pk,
double t_old,
double t_new,
bool reinit,
const Epetra_MultiVector& mol_dens,
Teuchos::RCP<Epetra_MultiVector> tcc,
Teuchos::Time& timer)
{
bool fail = false;
int num_aqueous = chem_pk->num_aqueous_components();
convertConcentrationToAmanzi(mol_dens, num_aqueous, *tcc, *tcc);
chem_pk->set_aqueous_components(tcc);

{
auto monitor = Teuchos::rcp(new Teuchos::TimeMonitor(timer));
fail = chem_pk->AdvanceStep(t_old, t_new, reinit);
}
if (fail) return fail;

*tcc = *chem_pk->aqueous_components();
convertConcentrationToATS(mol_dens, num_aqueous, *tcc, *tcc);
return fail;
}


} // namespace Amanzi
46 changes: 46 additions & 0 deletions src/pks/chem_pk_helpers.hh
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
Copyright 2010-202x held jointly by participating institutions.
ATS is released under the three-clause BSD License.
The terms of use and "as is" disclaimer for this license are
provided in the top-level COPYRIGHT file.
Authors: Ethan Coon ([email protected])
*/

//! A set of helper functions for doing common things in PKs.
#pragma once

#include "Teuchos_TimeMonitor.hpp"
#include "Epetra_MultiVector.hpp"

namespace Amanzi {

namespace AmanziChemistry {
class Chemistry_PK;
}

// -----------------------------------------------------------------------------
// Helper functions for working with Amanzi's Chemistry PK
// -----------------------------------------------------------------------------
void
convertConcentrationToAmanzi(const Epetra_MultiVector& mol_den,
int num_aqueous,
const Epetra_MultiVector& tcc_ats,
Epetra_MultiVector& tcc_amanzi);

void
convertConcentrationToATS(const Epetra_MultiVector& mol_den,
int num_aqueous,
const Epetra_MultiVector& tcc_ats,
Epetra_MultiVector& tcc_amanzi);

bool
advanceChemistry(Teuchos::RCP<AmanziChemistry::Chemistry_PK> chem_pk,
double t_old,
double t_new,
bool reinit,
const Epetra_MultiVector& mol_dens,
Teuchos::RCP<Epetra_MultiVector> tcc,
Teuchos::Time& timer);

} // namespace Amanzi
Loading

0 comments on commit 90c8735

Please sign in to comment.