Commit 2c0d489f authored by Gregor Olenik's avatar Gregor Olenik
Browse files

fix merge conflict

parents 65a2138b 478e154a
/*---------------------------------------------------------------------------*\
License
This file is part of OGL.
OGL is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
Class
Foam::GKOCG
Author: Gregor Olenik <go@hpsim.de>
SourceFiles
GKOCG.C
\*---------------------------------------------------------------------------*/
#ifndef OGL_STOPPING_CRITERION_H
#define OGL_STOPPING_CRITERION_H
#include <ginkgo/ginkgo.hpp>
#include "fvCFD.H"
namespace Foam {
class OpenFOAMStoppingCriterion
: public gko::EnablePolymorphicObject<OpenFOAMStoppingCriterion,
gko::stop::Criterion> {
friend class gko::EnablePolymorphicObject<OpenFOAMStoppingCriterion,
gko::stop::Criterion>;
using Criterion = gko::stop::Criterion;
using vec = gko::matrix::Dense<scalar>;
private:
label iter_ = 0;
public:
GKO_CREATE_FACTORY_PARAMETERS(parameters, Factory)
{
/**
* Boolean set by the user to stop the iteration process
*/
// TODO check why GKO_FACTORY_PARAMETER_SCALAR does not work
scalar GKO_FACTORY_PARAMETER(openfoam_absolute_tolerance, 1.0e-6);
scalar GKO_FACTORY_PARAMETER(openfoam_relative_tolerance, 0.0);
scalar GKO_FACTORY_PARAMETER(openfoam_norm_factor, 1.0);
label GKO_FACTORY_PARAMETER(openfoam_minIter, 0);
label GKO_FACTORY_PARAMETER(openfoam_maxIter, 0);
};
GKO_ENABLE_CRITERION_FACTORY(OpenFOAMStoppingCriterion, parameters,
Factory);
GKO_ENABLE_BUILD_METHOD(Factory);
protected:
bool check_impl(gko::uint8 stoppingId, bool setFinalized,
gko::Array<gko::stopping_status> *stop_status,
bool *one_changed,
const Criterion::Updater &updater) override
{
iter_++;
auto *dense_r = gko::as<vec>(updater.residual_);
auto exec = dense_r->get_executor();
auto res = vec::create(exec, gko::dim<2>{1, 1});
auto vec_abs = gko::clone(dense_r);
const label cells = dense_r->get_size()[0];
vec_abs->compute_absolute_inplace();
auto unit = vec::create(dense_r->get_executor(), gko::dim<2>{cells, 1});
unit->fill(1.0);
const auto unit_t = unit->transpose();
unit_t->apply(gko::lend(vec_abs), gko::lend(res));
auto res_host = vec::create(exec->get_master(), gko::dim<2>{1, 1});
res_host->copy_from(gko::lend(res));
bool result = false;
scalar normalised_res_norm =
res_host->at(0) / parameters_.openfoam_norm_factor;
// printf("normalised res norm %f\n", normalised_res_norm);
// printf("iter %d\n", iter_);
if ((normalised_res_norm < parameters_.openfoam_absolute_tolerance) &&
(iter_ >= parameters_.openfoam_minIter)) {
result = true;
}
if (iter_ >= parameters_.openfoam_maxIter) {
result = true;
}
if (result) {
this->set_all_statuses(stoppingId, setFinalized, stop_status);
*one_changed = true;
}
return result;
}
explicit OpenFOAMStoppingCriterion(
std::shared_ptr<const gko::Executor> exec)
: EnablePolymorphicObject<OpenFOAMStoppingCriterion, Criterion>(
std::move(exec))
{}
explicit OpenFOAMStoppingCriterion(const Factory *factory,
const gko::stop::CriterionArgs &args)
: EnablePolymorphicObject<OpenFOAMStoppingCriterion, Criterion>(
factory->get_executor()),
parameters_{factory->get_parameters()}
{}
};
} // namespace Foam
#endif
......@@ -60,7 +60,7 @@ public:
std::shared_ptr<T> get_ptr() { return ptr_; };
bool writeData(Ostream &) const {};
bool writeData(Ostream &) const { return false; };
};
typedef IOPtr<gko::matrix::Coo<scalar>> GKOCOOIOPtr;
......@@ -70,111 +70,6 @@ typedef IOPtr<gko::ReferenceExecutor> GKOReferenceExecPtr;
typedef IOPtr<gko::OmpExecutor> GKOOmpExecPtr;
typedef IOPtr<gko::HipExecutor> GKOHipExecPtr;
template <>
inline bool typeGlobal<GKOCOOIOPtr>()
{
return true;
}
template <>
inline bool typeGlobal<GKOExecPtr>()
{
return true;
}
class OpenFOAMStoppingCriterion
: public gko::EnablePolymorphicObject<OpenFOAMStoppingCriterion,
gko::stop::Criterion> {
friend class gko::EnablePolymorphicObject<OpenFOAMStoppingCriterion,
gko::stop::Criterion>;
using Criterion = gko::stop::Criterion;
using vec = gko::matrix::Dense<scalar>;
private:
label iter_ = 0;
public:
GKO_CREATE_FACTORY_PARAMETERS(parameters, Factory)
{
/**
* Boolean set by the user to stop the iteration process
*/
// TODO check why GKO_FACTORY_PARAMETER_SCALAR does not work
scalar GKO_FACTORY_PARAMETER(openfoam_absolute_tolerance, 1.0e-6);
scalar GKO_FACTORY_PARAMETER(openfoam_relative_tolerance, 0.0);
scalar GKO_FACTORY_PARAMETER(openfoam_norm_factor, 1.0);
label GKO_FACTORY_PARAMETER(openfoam_minIter, 0);
label GKO_FACTORY_PARAMETER(openfoam_maxIter, 0);
};
GKO_ENABLE_CRITERION_FACTORY(OpenFOAMStoppingCriterion, parameters,
Factory);
GKO_ENABLE_BUILD_METHOD(Factory);
protected:
bool check_impl(gko::uint8 stoppingId, bool setFinalized,
gko::Array<gko::stopping_status> *stop_status,
bool *one_changed,
const Criterion::Updater &updater) override
{
iter_++;
auto *dense_r = gko::as<vec>(updater.residual_);
auto exec = dense_r->get_executor();
auto res = vec::create(exec, gko::dim<2>{1, 1});
auto vec_abs = gko::clone(dense_r);
const label cells = dense_r->get_size()[0];
vec_abs->compute_absolute_inplace();
auto unit = vec::create(dense_r->get_executor(), gko::dim<2>{cells, 1});
unit->fill(1.0);
const auto unit_t = unit->transpose();
unit_t->apply(gko::lend(vec_abs), gko::lend(res));
auto res_host = vec::create(exec->get_master(), gko::dim<2>{1, 1});
res_host->copy_from(gko::lend(res));
bool result = false;
scalar normalised_res_norm =
res_host->at(0) / parameters_.openfoam_norm_factor;
// printf("normalised res norm %f\n", normalised_res_norm);
// printf("iter %d\n", iter_);
if ((normalised_res_norm < parameters_.openfoam_absolute_tolerance) &&
(iter_ >= parameters_.openfoam_minIter)) {
result = true;
}
if (iter_ >= parameters_.openfoam_maxIter) {
result = true;
}
if (result) {
this->set_all_statuses(stoppingId, setFinalized, stop_status);
*one_changed = true;
}
return result;
}
explicit OpenFOAMStoppingCriterion(
std::shared_ptr<const gko::Executor> exec)
: EnablePolymorphicObject<OpenFOAMStoppingCriterion, Criterion>(
std::move(exec))
{}
explicit OpenFOAMStoppingCriterion(const Factory *factory,
const gko::stop::CriterionArgs &args)
: EnablePolymorphicObject<OpenFOAMStoppingCriterion, Criterion>(
factory->get_executor()),
parameters_{factory->get_parameters()}
{}
};
class lduLduCommonBase {
const objectRegistry &db_;
......@@ -203,10 +98,10 @@ class lduLduCommonBase {
const bool verbose_;
const word app_executor_name_;
const word device_executor_name_;
const word app_executor_name_;
// if sorting_idxs_ was found in object registry it does not
// need to be resorted
mutable bool is_sorted_;
......@@ -316,11 +211,11 @@ public:
label maxIter() const { return maxIter_; }
const label nCells() const { return nCells_; };
label nCells() const { return nCells_; };
const label nElems() const { return nElems_; };
label nElems() const { return nElems_; };
const label nNeighbours() const { return nNeighbours_; };
label nNeighbours() const { return nNeighbours_; };
//
bool get_update_sys_matrix() const { return (update_sysMatrix_ == "yes"); }
......
......@@ -61,8 +61,8 @@ public:
std::vector<std::shared_ptr<const gko::stop::CriterionFactory>>
criterion_vec) const
{
if (preconditioner_ == "none")
return create_default(exec, criterion_vec);
// if (preconditioner_ == "none")
return create_default(exec, criterion_vec);
};
std::unique_ptr<gko::solver::Bicgstab<double>::Factory,
......
......@@ -174,14 +174,19 @@ public:
// if system matrix is not stored create it
// and set shared pointer
//
auto gkomatrix = gko::share(
mtx::create(device_exec, gko::dim<2>(nCells(), nCells()),
val_array::view(ref_exec(), nElems(), &values_[0]),
idx_array::view(ref_exec(), nElems(), &col_idxs_[0]),
idx_array::view(ref_exec(), nElems(), &row_idxs_[0])));
val_array::view(gko::ReferenceExecutor::create(),
nElems(), &values_[0]),
idx_array::view(gko::ReferenceExecutor::create(),
nElems(), &col_idxs_[0]),
idx_array::view(gko::ReferenceExecutor::create(),
nElems(), &row_idxs_[0])));
// if updating system matrix is not needed store ptr in obj registry
if (!get_update_sys_matrix()) {
Info << "store sys matrix" << endl;
const fileName path = sys_matrix_name;
gkomatrix_ptr = new GKOCOOIOPtr(IOobject(path, db), gkomatrix);
}
......
......@@ -46,6 +46,7 @@ class Results:
"resolution",
"processes",
"run_time",
"success",
]
self.current_col_vals = []
self.report_handle = open(self.fn, "a+", 1)
......@@ -63,8 +64,8 @@ class Results:
processes,
]
def add(self, run):
outp = self.current_col_vals + [run]
def add(self, run, success):
outp = self.current_col_vals + [run, success]
outps = ",".join(map(str, outp))
print(outps)
self.report_handle.write(outps + "\n")
......@@ -306,10 +307,15 @@ class Case:
while accumulated_time < time_runs or iters < min_runs:
iters += 1
start = datetime.datetime.now()
ret = check_output([self.of_solver], cwd=self.path)
success = 0
try:
ret = check_output([self.of_solver], cwd=self.path)
success = 1
except:
pass
end = datetime.datetime.now()
run_time = (end - start).total_seconds() - self.init_time
self.results_accumulator.add(run_time)
self.results_accumulator.add(run_time, success)
accumulated_time += run_time
self.executor.clean_enviroment()
self.executor.current_num_processes = 1
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment