Skip to content

Commit

Permalink
Use SAMRAI functions to set fields to scalar value (#72)
Browse files Browse the repository at this point in the history
  • Loading branch information
jeanlucf22 authored Apr 4, 2022
1 parent 07130a6 commit f1188c4
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 324 deletions.
52 changes: 4 additions & 48 deletions source/ConstantHeatCapacityStrategy.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,34 +8,10 @@
// This file is part of AMPE.
// For details, see https://github.com/LLNL/AMPE
// Please also read AMPE/LICENSE.
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
// - Redistributions of source code must retain the above copyright notice,
// this list of conditions and the disclaimer below.
// - Redistributions in binary form must reproduce the above copyright notice,
// this list of conditions and the disclaimer (as noted below) in the
// documentation and/or other materials provided with the distribution.
// - Neither the name of the LLNS/LLNL nor the names of its contributors may be
// used to endorse or promote products derived from this software without
// specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL LAWRENCE LIVERMORE NATIONAL SECURITY,
// LLC, UT BATTELLE, LLC,
// THE U.S. DEPARTMENT OF ENERGY OR CONTRIBUTORS BE LIABLE FOR ANY
// DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
// OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
// HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
// IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
#include "ConstantHeatCapacityStrategy.h"

#include "SAMRAI/pdat/CellData.h"
#include "SAMRAI/math/HierarchyCellDataOpsReal.h"

ConstantHeatCapacityStrategy::ConstantHeatCapacityStrategy(const double cp,
const int cp_id)
Expand All @@ -46,35 +22,15 @@ ConstantHeatCapacityStrategy::ConstantHeatCapacityStrategy(const double cp,
}

void ConstantHeatCapacityStrategy::setCurrentValue(
std::shared_ptr<hier::PatchHierarchy> patch_hierarchy)
std::shared_ptr<hier::PatchHierarchy> hierarchy)
{
assert(d_cp_id >= 0);

static bool first_time = true;

if (first_time) {
int maxln = patch_hierarchy->getFinestLevelNumber();

for (int ln = 0; ln <= maxln; ln++) {

std::shared_ptr<hier::PatchLevel> level =
patch_hierarchy->getPatchLevel(ln);

assert(level->checkAllocated(d_cp_id));

for (hier::PatchLevel::Iterator p(level->begin()); p != level->end();
p++) {

std::shared_ptr<hier::Patch> patch = *p;

std::shared_ptr<pdat::CellData<double> > cp_data(
SAMRAI_SHARED_PTR_CAST<pdat::CellData<double>, hier::PatchData>(
patch->getPatchData(d_cp_id)));
assert(cp_data);

cp_data->fillAll(d_cp);
}
}
math::HierarchyCellDataOpsReal<double> mathops(hierarchy);
mathops.setToScalar(d_cp_id, d_cp);
}

first_time = false;
Expand Down
109 changes: 0 additions & 109 deletions source/PhaseFreeEnergyStrategy.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,30 +8,6 @@
// This file is part of AMPE.
// For details, see https://github.com/LLNL/AMPE
// Please also read AMPE/LICENSE.
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
// - Redistributions of source code must retain the above copyright notice,
// this list of conditions and the disclaimer below.
// - Redistributions in binary form must reproduce the above copyright notice,
// this list of conditions and the disclaimer (as noted below) in the
// documentation and/or other materials provided with the distribution.
// - Neither the name of the LLNS/LLNL nor the names of its contributors may be
// used to endorse or promote products derived from this software without
// specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL LAWRENCE LIVERMORE NATIONAL SECURITY,
// LLC, UT BATTELLE, LLC,
// THE U.S. DEPARTMENT OF ENERGY OR CONTRIBUTORS BE LIABLE FOR ANY
// DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
// OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
// HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
// IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
#include "PhaseFreeEnergyStrategy.h"
#include "SAMRAI/pdat/CellData.h"
Expand Down Expand Up @@ -73,31 +49,6 @@ PhaseFreeEnergyStrategy::PhaseFreeEnergyStrategy(

//=======================================================================

void PhaseFreeEnergyStrategy::computeFreeEnergyLiquid(
const std::shared_ptr<hier::PatchHierarchy> hierarchy,
const int temperature_id, const int fl_id, const bool gp)
{
assert(fl_id >= 0);
(void)temperature_id; // unused

for (int ln = 0; ln <= hierarchy->getFinestLevelNumber(); ln++) {
std::shared_ptr<hier::PatchLevel> level = hierarchy->getPatchLevel(ln);

for (hier::PatchLevel::Iterator ip(level->begin()); ip != level->end();
ip++) {
std::shared_ptr<hier::Patch> patch = *ip;

std::shared_ptr<pdat::CellData<double> > fl(
SAMRAI_SHARED_PTR_CAST<pdat::CellData<double>, hier::PatchData>(
patch->getPatchData(fl_id)));
assert(fl);

fl->fillAll(d_f_l);
}
}
}

//=======================================================================
void PhaseFreeEnergyStrategy::computeFreeEnergyLiquid(hier::Patch& patch,
const int temperature_id,
const int fl_id,
Expand All @@ -116,31 +67,6 @@ void PhaseFreeEnergyStrategy::computeFreeEnergyLiquid(hier::Patch& patch,

//=======================================================================

void PhaseFreeEnergyStrategy::computeFreeEnergySolidA(
const std::shared_ptr<hier::PatchHierarchy> hierarchy,
const int temperature_id, const int fs_id, const bool gp)
{
assert(fs_id >= 0);
(void)temperature_id; // unused

for (int ln = 0; ln <= hierarchy->getFinestLevelNumber(); ln++) {
std::shared_ptr<hier::PatchLevel> level = hierarchy->getPatchLevel(ln);

for (hier::PatchLevel::Iterator ip(level->begin()); ip != level->end();
ip++) {
std::shared_ptr<hier::Patch> patch = *ip;

std::shared_ptr<pdat::CellData<double> > fs(
SAMRAI_SHARED_PTR_CAST<pdat::CellData<double>, hier::PatchData>(
patch->getPatchData(fs_id)));
assert(fs);

fs->fillAll(d_f_a);
}
}
}

//=======================================================================
void PhaseFreeEnergyStrategy::computeFreeEnergySolidA(hier::Patch& patch,
const int temperature_id,
const int fs_id,
Expand All @@ -158,42 +84,7 @@ void PhaseFreeEnergyStrategy::computeFreeEnergySolidA(hier::Patch& patch,
}

//=======================================================================
//
// double PhaseFreeEnergyStrategy::computeValFreeEnergySolidB(
// const double temperature,
// const double conc,
// const bool gp )
//{
// return d_f_b;
//}
//
//=======================================================================

void PhaseFreeEnergyStrategy::computeFreeEnergySolidB(
const std::shared_ptr<hier::PatchHierarchy> hierarchy,
const int temperature_id, const int fs_id, const bool gp)
{
assert(fs_id >= 0);
(void)temperature_id; // unused

for (int ln = 0; ln <= hierarchy->getFinestLevelNumber(); ln++) {
std::shared_ptr<hier::PatchLevel> level = hierarchy->getPatchLevel(ln);

for (hier::PatchLevel::Iterator ip(level->begin()); ip != level->end();
ip++) {
std::shared_ptr<hier::Patch> patch = *ip;

std::shared_ptr<pdat::CellData<double> > fs(
SAMRAI_SHARED_PTR_CAST<pdat::CellData<double>, hier::PatchData>(
patch->getPatchData(fs_id)));
assert(fs);

fs->fillAll(d_f_b);
}
}
}

//=======================================================================
void PhaseFreeEnergyStrategy::computeFreeEnergySolidB(hier::Patch& patch,
const int temperature_id,
const int fs_id,
Expand Down
36 changes: 0 additions & 36 deletions source/PhaseFreeEnergyStrategy.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,30 +8,6 @@
// This file is part of AMPE.
// For details, see https://github.com/LLNL/AMPE
// Please also read AMPE/LICENSE.
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
// - Redistributions of source code must retain the above copyright notice,
// this list of conditions and the disclaimer below.
// - Redistributions in binary form must reproduce the above copyright notice,
// this list of conditions and the disclaimer (as noted below) in the
// documentation and/or other materials provided with the distribution.
// - Neither the name of the LLNS/LLNL nor the names of its contributors may be
// used to endorse or promote products derived from this software without
// specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL LAWRENCE LIVERMORE NATIONAL SECURITY,
// LLC, UT BATTELLE, LLC,
// THE U.S. DEPARTMENT OF ENERGY OR CONTRIBUTORS BE LIABLE FOR ANY
// DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
// OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
// HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
// IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
#ifndef included_PhaseFreeEnergyStrategy
#define included_PhaseFreeEnergyStrategy
Expand All @@ -56,18 +32,6 @@ class PhaseFreeEnergyStrategy : public FreeEnergyStrategy

~PhaseFreeEnergyStrategy(){};

void computeFreeEnergyLiquid(
const std::shared_ptr<hier::PatchHierarchy> hierarchy,
const int temperature_id, const int fl_id, const bool gp);

void computeFreeEnergySolidA(
const std::shared_ptr<hier::PatchHierarchy> hierarchy,
const int temperature_id, const int fs_id, const bool gp);

void computeFreeEnergySolidB(
const std::shared_ptr<hier::PatchHierarchy> hierarchy,
const int temperature_id, const int fs_id, const bool gp);

void computeFreeEnergyLiquid(hier::Patch& patch, const int temperature_id,
const int fl_id, const bool gp);

Expand Down
31 changes: 3 additions & 28 deletions source/QuatIntegrator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2416,34 +2416,9 @@ void QuatIntegrator::setUniformDiffusionCoeffForQuat(
tbox::pout << "dval=" << dval << std::endl;

// set diffusion coefficients
for (int amr_level = 0; amr_level < maxl; amr_level++) {

// tbox::pout<<"QuatSplitIntegrator, level = "<<amr_level<<endl;
std::shared_ptr<hier::PatchLevel> this_patch_level =
hierarchy->getPatchLevel(amr_level);

for (hier::PatchLevel::Iterator this_p(this_patch_level->begin());
this_p != this_patch_level->end(); ++this_p) {
std::shared_ptr<hier::Patch> this_patch = *this_p;

std::shared_ptr<pdat::SideData<double> > diffusion(
SAMRAI_SHARED_PTR_CAST<pdat::SideData<double>, hier::PatchData>(
this_patch->getPatchData(d_quat_diffusion_id)));
diffusion->fillAll(dval);

std::shared_ptr<pdat::SideData<double> > grad_side_copy_data(
SAMRAI_SHARED_PTR_CAST<pdat::SideData<double>, hier::PatchData>(
this_patch->getPatchData(d_quat_grad_side_copy_id)));
assert(grad_side_copy_data);
grad_side_copy_data->fillAll(alpha);

std::shared_ptr<pdat::SideData<double> > grad_side_data(
SAMRAI_SHARED_PTR_CAST<pdat::SideData<double>, hier::PatchData>(
this_patch->getPatchData(d_quat_grad_side_id)));
assert(grad_side_data);
grad_side_data->fillAll(alpha);
}
}
math::HierarchySideDataOpsReal<double> smathops(hierarchy);
smathops.setToScalar(d_quat_diffusion_id, dval);
smathops.setToScalar(d_quat_grad_side_copy_id, alpha);
}

//-----------------------------------------------------------------------
Expand Down
59 changes: 10 additions & 49 deletions source/QuatModel.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2818,30 +2818,15 @@ void QuatModel::initializeLevelData(
}

if (!d_model_parameters.with_concentration()) {
for (hier::PatchLevel::Iterator ip(level->begin()); ip != level->end();
ip++) {
std::shared_ptr<hier::Patch> patch = *ip;

if (d_model_parameters.free_energy_type()[0] == 's') {
std::shared_ptr<pdat::CellData<double> > fl(
SAMRAI_SHARED_PTR_CAST<pdat::CellData<double>, hier::PatchData>(
patch->getPatchData(d_f_l_id)));
assert(fl);
fl->fillAll(d_model_parameters.free_energy_liquid());
}
std::shared_ptr<pdat::CellData<double> > fa(
SAMRAI_SHARED_PTR_CAST<pdat::CellData<double>, hier::PatchData>(
patch->getPatchData(d_f_a_id)));
assert(fa);
fa->fillAll(d_model_parameters.free_energy_solid_A());
math::HierarchyCellDataOpsReal<double> mathops(hierarchy);

if (d_model_parameters.with_three_phases()) {
std::shared_ptr<pdat::CellData<double> > fb(
SAMRAI_SHARED_PTR_CAST<pdat::CellData<double>, hier::PatchData>(
patch->getPatchData(d_f_b_id)));
assert(fb);
fb->fillAll(d_model_parameters.free_energy_solid_B());
}
if (d_model_parameters.free_energy_type()[0] == 's') {
mathops.setToScalar(d_f_l_id, d_model_parameters.free_energy_liquid());
}
mathops.setToScalar(d_f_a_id, d_model_parameters.free_energy_solid_A());
if (d_model_parameters.with_three_phases()) {
mathops.setToScalar(d_f_b_id,
d_model_parameters.free_energy_solid_B());
}
}
}
Expand Down Expand Up @@ -4700,35 +4685,11 @@ void QuatModel::computeUniformPhaseMobility(
if (time == old_time && cache == CACHE) return;
old_time = time;

int maxln = hierarchy->getFinestLevelNumber();
for (int ln = 0; ln <= maxln; ln++) {
std::shared_ptr<hier::PatchLevel> patch_level =
hierarchy->getPatchLevel(ln);

computeUniformPhaseMobility(patch_level, phase_id, mobility_id, time);
}
}

void QuatModel::computeUniformPhaseMobility(
const std::shared_ptr<hier::PatchLevel> level, int& phase_id,
int& mobility_id, const double time)
{
(void)time;

if (phase_id < 0) phase_id = d_phase_scratch_id;
if (mobility_id < 0) mobility_id = d_phase_mobility_id;

for (hier::PatchLevel::Iterator p(level->begin()); p != level->end(); ++p) {

std::shared_ptr<hier::Patch> patch = *p;

std::shared_ptr<pdat::CellData<double> > mobility_data(
SAMRAI_SHARED_PTR_CAST<pdat::CellData<double>, hier::PatchData>(
patch->getPatchData(mobility_id)));
assert(mobility_data);

mobility_data->fillAll(d_model_parameters.phase_mobility());
}
math::HierarchyCellDataOpsReal<double> mathops(hierarchy);
mathops.setToScalar(mobility_id, d_model_parameters.phase_mobility());
}

//-----------------------------------------------------------------------
Expand Down
3 changes: 0 additions & 3 deletions source/QuatModel.h
Original file line number Diff line number Diff line change
Expand Up @@ -209,9 +209,6 @@ class QuatModel : public PFModel
void computeUniformPhaseMobility(
const std::shared_ptr<hier::PatchHierarchy> hierarchy, int& phase_id,
int& mobility_id, const double time, const CACHE_TYPE cache = CACHE);
void computeUniformPhaseMobility(
const std::shared_ptr<hier::PatchLevel> patch_level, int& phase_id,
int& mobility_id, const double time);

void computeEtaMobility(
const std::shared_ptr<hier::PatchHierarchy> hierarchy, int& phase_id,
Expand Down
Loading

0 comments on commit f1188c4

Please sign in to comment.