Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reduction of the use of rtemplate #445

Merged
merged 33 commits into from
Sep 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
28b88db
Moving to NodeTypeGroups
llaniewski Aug 18, 2023
61a30eb
Adding Lists
llaniewski Aug 18, 2023
eff37c2
Correcting the initialisation order
llaniewski Aug 18, 2023
ba00733
Correcting the error in Iam- macros
llaniewski Aug 18, 2023
7432b8b
correcting mask values in def.cpp
llaniewski Aug 19, 2023
a5631ed
correcting node type groups in vtkLattice
llaniewski Aug 19, 2023
cfc19a8
Correcting edge cases in Lists.cpp
llaniewski Aug 20, 2023
81aab2b
Making default Thing invalid
llaniewski Aug 22, 2023
985bac8
Adding Model and SetSetting to Lattice
llaniewski Aug 22, 2023
398c8ba
Moving acParam to model lists
llaniewski Aug 22, 2023
499179e
Separating Things to a header
llaniewski Aug 22, 2023
955f86a
Changing search names
llaniewski Aug 22, 2023
f2eb80b
Moving Handlers to model lists
llaniewski Aug 23, 2023
62238e3
Removing Rt suffix from non Rt files
llaniewski Aug 23, 2023
d8f1fb0
Separating r utils
llaniewski Aug 23, 2023
bd7b940
Reducing dependencies for Handlers
llaniewski Aug 23, 2023
480f3c7
Fixing paranoid errors
llaniewski Aug 23, 2023
918adf5
Adding gzip fopen function to utils
llaniewski Aug 23, 2023
45f14e5
Moving vtkLattice to model lists
llaniewski Aug 23, 2023
42d6693
Removing Rt suffix from non Rt files
llaniewski Aug 23, 2023
7d6f787
Moving hdf5Lattice to model lists
llaniewski Aug 23, 2023
4d21ec2
Removing Rt suffix from non Rt files
llaniewski Aug 23, 2023
7102511
Minor fixes
llaniewski Aug 23, 2023
762fdcc
Removing model-specific values from ZoneSettings
llaniewski Aug 23, 2023
8ba7c7e
Moving Sampler to model lists
llaniewski Aug 23, 2023
dfc8aa5
Removing Rt suffix from non Rt files
llaniewski Aug 23, 2023
ca67014
Correcting non-cross cuda constant
llaniewski Aug 23, 2023
28db25e
Making cuda.cu macros more consistent
llaniewski Aug 24, 2023
fea3c64
Correcting for RunR
llaniewski Aug 24, 2023
f3d559e
Deleting unused things in Lattice
llaniewski Aug 24, 2023
70c66fd
Dividing iteration into functions
llaniewski Aug 24, 2023
be9a369
Deleting not used setting functions
llaniewski Aug 25, 2023
a7659dc
Actions as table
llaniewski Aug 28, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 0 additions & 18 deletions src/CommonHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,9 @@
#define COMMONHANDLER_H

#include "Consts.h"

#include "pugixml.hpp"
#include "Global.h"
#include <mpi.h>
#include "cross.h"
#include "Region.h"
#include "LatticeContainer.h"
#include "Lattice.h"
#include "vtkLattice.h"
#include "Geometry.h"
#include "utils.h"
#include "unit.h"
#include "spline.h"
#include <sstream>
#include <string>
#include <fstream>
#include <iostream>
#include <vector>
#include <iomanip>
#include <assert.h>

#include "Solver.h"

#define ITERATION_STOP 1
Expand Down
9 changes: 5 additions & 4 deletions src/Consts.h.Rt
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@
}
ret
}
for (n in names(Node)) { ?>
#define NODE_<?%-20s n ?> 0x<?%s big_hex(Node[n]) ?> <?R
for (n in rows(NodeTypes)) { ?>
#define <?%-20s n$Index ?> 0x<?%s big_hex(n$value) ?> <?R
}
for (n in names(Node_Group)) { ?>
#define NODE_<?%-20s n ?> 0x<?%s big_hex(Node_Group[n]) ?> <?R
for (n in rows(NodeTypeGroups)) { ?>
#define <?%-20s n$Index ?> 0x<?%s big_hex(n$mask) ?> <?R
}
?>
<?R
Expand All @@ -48,6 +48,7 @@
?>

typedef <?%s FlagT ?> flag_t;
typedef unsigned int big_flag_t;

<?R for (e in names(Enums)) { ?>
enum <?%s e ?> { <?%s paste(Enums[[e]],collapse=",") ?> }; <?R
Expand Down
1 change: 1 addition & 0 deletions src/Handlers/BSpline.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "BSpline.h"
std::string BSpline::xmlname = "BSpline";
#include "../HandlerFactory.h"
#include "../spline.h"

int BSpline::Init () {
Pars = -1;
Expand Down
47 changes: 47 additions & 0 deletions src/Handlers/IfContainer.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#include "IfContainer.h"

std::string IfContainer::xmlname = "EvalIf";

int IfContainer::Init () {
GenericAction::Init();
pugi::xml_attribute present = node.attribute("opt_present");
pugi::xml_attribute missing = node.attribute("opt_missing");
std::string option;
bool positive = false;
if (present) {
if (missing) {
ERROR("Use either opt_present or opt_missing (not both) in IfContainer\n");
return -1;
}
option = present.value();
positive = true;
} else if (missing) {
option = present.value();
positive = false;
} else {
ERROR("Use either opt_present or opt_missing (not both) in IfContainer\n");
return -1;
}
const Model::Option& it = solver->lattice->model->options.by_name(option);
if (!it) {
ERROR("Unknown option in IfContainer: %s\n", option.c_str());
return -1;
}
if (it.isActive == positive) {
debug1("EvalIf - proceed\n");
return GenericAction::ExecuteInternal();
} else {
debug1("EvalIf - skipped\n");
return 0;
}
}


int IfContainer::Finish () {
GenericAction::Unstack();
return GenericAction::Finish();
}


// Register the handler (basing on xmlname) in the Handler Factory
template class HandlerFactory::Register< GenericAsk< IfContainer > >;
58 changes: 0 additions & 58 deletions src/Handlers/IfContainer.cpp.Rt

This file was deleted.

File renamed without changes.
2 changes: 1 addition & 1 deletion src/Handlers/MainContainer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ int MainContainer::Init () {

solver->outIterFile("config", ".xml", filename);
pugi::xml_node n = solver->configfile.child("CLBConfig").append_child("Run");
n.append_attribute("model").set_value(MODEL);
n.append_attribute("model").set_value(solver->lattice->model->name.c_str());
pugi::xml_node c = n.append_child("Code");
c.append_attribute("version").set_value(VERSION);
#ifdef CALC_DOUBLE_PRECISION
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
<?R
#include "../HandlerFactory.h"
source("conf.R")
c_header()
?>

#include "OptimalControl.h"

std::string OptimalControl::xmlname = "OptimalControl";

int OptimalControl::Init () {
Expand All @@ -30,13 +25,12 @@ int OptimalControl::Init () {
return -1;
}
}
<?R for (v in rows(ZoneSettings)) { ?>
if (par == "<?%s v$name?>") par_index = <?%s v$Index?>;
<?R } ?>
if (par_index < 0) {
const Model::ZoneSetting& it = solver->lattice->model->zonesettings.by_name(par);
if (!it) {
error("Unknown param %s in OptimalControl\n", par.c_str());
return -1;
}
par_index = it.id;
output("Selected %s (%d) in zone \"%s\" (%d) for optimal control\n", par.c_str(), par_index, zone.c_str(), zone_number);
} else {
ERROR("Parameter \"what\" needed in %s\n",node.name());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
<?R
#include "../HandlerFactory.h"
source("conf.R")
c_header()
?>

#include "OptimalControlSecond.h"

std::string OptimalControlSecond::xmlname = "OptimalControlSecond";

int OptimalControlSecond::Init () {
Expand All @@ -30,13 +25,12 @@ int OptimalControlSecond::Init () {
return -1;
}
}
<?R for (v in rows(ZoneSettings)) { ?>
if (par == "<?%s v$name?>") par_index = <?%s v$Index?>;
<?R } ?>
if (par_index < 0) {
const Model::ZoneSetting& it = solver->lattice->model->zonesettings.by_name(par);
if (!it) {
error("Unknown param %s in OptimalControl\n", par.c_str());
return -1;
}
par_index = it.id;
output("Selected %s (%d) in zone \"%s\" (%d) for optimal control\n", par.c_str(), par_index, zone.c_str(), zone_number);
} else {
ERROR("Parameter \"what\" needed in %s\n",node.name());
Expand Down
42 changes: 42 additions & 0 deletions src/Handlers/acObjective.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#include "acObjective.h"
std::string acObjective::xmlname = "Objective";

int acObjective::Init () {
Model * model = solver->lattice->model;
int zone_number = 0;
size_t n = model->globals.size();
double* glob = new double[n];
double* grad = new double[n];
double* inObj = new double[n];
double obj = 0;
for (size_t i = 0; i < n; i++) {
glob[i] = solver->lattice->globals[i];
inObj[i] = 0;
}
MPI_Bcast(glob, model->globals.size(), MPI_DOUBLE, 0, solver->mpi_comm);
pugi::xml_attribute attr;
for (const Model::Objective& it : model->objectives) {
attr = node.attribute(it.name.c_str());
if (attr) {
double weight = attr.as_double();
double ret;
it.fun(glob, &ret, grad);
obj = obj + weight * ret;
for (size_t i = 0; i < n; i++) {
inObj[i] = inObj[i] + weight * grad[i];
}
}
}
for (const Model::Global& it : model->globals) {
if (it.inObjId >= 0) solver->lattice->zSet.set(it.inObjId, zone_number, inObj[it.id]);
}
const Model::Global& obj_glob = model->globals.by_name("Objective");
if (obj_glob) solver->lattice->globals[ obj_glob.id ] = obj;
delete[] glob;
delete[] grad;
delete[] inObj;
return 0;
}

// Register the handler (basing on xmlname) in the Handler Factory
template class HandlerFactory::Register< GenericAsk< acObjective > >;
54 changes: 0 additions & 54 deletions src/Handlers/acObjective.cpp.Rt

This file was deleted.

7 changes: 1 addition & 6 deletions src/Handlers/acOptimize.cpp.Rt
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
<?R
#include "../HandlerFactory.h"
source("conf.R")
c_header()
?>

<?R source("lib/utils.R") ?>
#include "acOptimize.h"

int acOptimize::OptimizerInit () {
Expand Down
41 changes: 18 additions & 23 deletions src/Handlers/acParam.cpp.Rt → src/Handlers/acParam.cpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
<?R
#include "../HandlerFactory.h"
source("conf.R")
c_header()
?>

#include "acParam.h"

std::string acParam::xmlname = "Param";

int acParam::Init () {
Expand Down Expand Up @@ -39,26 +34,26 @@ int acParam::Init () {
ERROR("Setting name not specified in Param element\n");
return -2;
}
<?R for (v in rows(Settings)) { ?>
} else if (par == "<?%s v$name?>") {
output("Setting %s to %s (%lf)\n", par.c_str(), value.c_str(), val);
solver->lattice-><?%s v$FunName ?>(val);
<?R }
for (v in rows(ZoneSettings)) { ?>
} else if (par == "<?%s v$name?>") {
output("Setting %s in zone %s (%d) to %s (%lf)\n", par.c_str(), zone.c_str(), zone_number, value.c_str(), val);
solver->lattice->zSet.set(<?%s v$Index?>, zone_number, val);
<?R } ?>
} else {
if (permissive) {
if (gauge != "") {
notice("Unknown setting %s with gauge\n", par.c_str());
const Model::Setting& it = solver->lattice->model->settings.by_name(par);
const Model::ZoneSetting& zoneit = solver->lattice->model->zonesettings.by_name(par);
if (it) {
output("Setting %s to %s (%lf)\n", par.c_str(), value.c_str(), val);
solver->lattice->SetSetting(it, val);
} else if (zoneit) {
output("Setting %s in zone %s (%d) to %s (%lf)\n", par.c_str(), zone.c_str(), zone_number, value.c_str(), val);
solver->lattice->zSet.set(zoneit.id, zone_number, val);
} else {
if (permissive) {
if (gauge != "") {
notice("Unknown setting %s with gauge\n", par.c_str());
} else {
WARNING("Unknown setting %s\n", par.c_str());
}
} else {
WARNING("Unknown setting %s\n", par.c_str());
ERROR("Unknown setting %s\n", par.c_str());
return -3;
}
} else {
ERROR("Unknown setting %s\n", par.c_str());
return -3;
}
}
return 0;
Expand Down
Loading