diff options
| author | stainer_t <thomas.stainer@oecd-nea.org> | 2025-09-08 13:48:49 +0200 |
|---|---|---|
| committer | stainer_t <thomas.stainer@oecd-nea.org> | 2025-09-08 13:48:49 +0200 |
| commit | 7dfcc480ba1e19bd3232349fc733caef94034292 (patch) | |
| tree | 03ee104eb8846d5cc1a981d267687a729185d3f3 /Yacs++/src | |
Initial commit from Polytechnique Montreal
Diffstat (limited to 'Yacs++/src')
| -rwxr-xr-x | Yacs++/src/Communication.cxx | 209 | ||||
| -rwxr-xr-x | Yacs++/src/Communication.hxx | 187 | ||||
| -rwxr-xr-x | Yacs++/src/FACT.cxx | 28 | ||||
| -rwxr-xr-x | Yacs++/src/FACT.hxx | 24 | ||||
| -rwxr-xr-x | Yacs++/src/Makefile | 117 | ||||
| -rwxr-xr-x | Yacs++/src/POW.cxx | 119 | ||||
| -rwxr-xr-x | Yacs++/src/POW.hxx | 35 | ||||
| -rwxr-xr-x | Yacs++/src/THM.cxx | 102 | ||||
| -rwxr-xr-x | Yacs++/src/THM.hxx | 33 |
9 files changed, 854 insertions, 0 deletions
diff --git a/Yacs++/src/Communication.cxx b/Yacs++/src/Communication.cxx new file mode 100755 index 0000000..4e2b99a --- /dev/null +++ b/Yacs++/src/Communication.cxx @@ -0,0 +1,209 @@ +#include "Communication.hxx" +using namespace std; + +Communication::Communication(): compo_(0) {} + +Communication::Communication(const Communication& comm) : compo_(comm.compo_) {} + +Communication::~Communication() {} + +int Communication::initialize(void * compo) { + //Initialize the connection with YACS. + char ret[64]; + compo_ = compo; + cerr << "Communication: Initialize the connection with YACS compo = " << compo_ << endl; + int info = cp_cd(compo_, ret); + cerr << "Communication: Initialize info = " << info << " ret= " << ret << endl; + return info; +} + +int Communication::terminate() { + //Close the connection with YACS. + cerr << "Communication: Close the connection with YACS compo = " << compo_ << endl; + int info = cp_fin(compo_, CP_ARRET); + cerr << "Communication: Terminate info = " << info << endl; + return info; + +} + +// send datastream + +int Communication::send(const int iteration, const string portName, const int& val ) { + int info = cp_een(compo_, CP_ITERATION, 0., iteration, (char*) portName.c_str(), + 1, (int*) &val); + return info; +} + +int Communication::send(const int iteration, const string portName, const int size, IntPtrConst& tab ) { + const float fUNUSED=0; + float temps(fUNUSED); + int info = cp_een(compo_, CP_ITERATION, temps, iteration, (char*) portName.c_str(), + size, (int*) &(tab[0])); + return info; +} + +int Communication::send(const int iteration, const string portName, const float& val ) { + int info = cp_ere(compo_, CP_ITERATION, 0., iteration, (char*) portName.c_str(), + 1, (float*) &val); + return info; +} + +int Communication::send(const int iteration, const string portName, const int size, FloatPtrConst& tab ) { + const float fUNUSED=0; + float temps(fUNUSED); + int info = cp_ere(compo_, CP_ITERATION, temps, iteration, (char*) portName.c_str(), + size, (float*) &(tab[0])); + return info; +} + +int Communication::send(const int iteration, const string portName, const double& val ) { + int info = cp_edb(compo_, CP_ITERATION, double(0.), iteration, (char*) portName.c_str(), + 1, (double*) &val); + return info; +} + +int Communication::send(const int iteration, const string portName, const int size, DoublePtrConst& tab ) { + const float fUNUSED=0; + double temps(fUNUSED); + int info = cp_edb(compo_, CP_ITERATION, temps, iteration, (char*) portName.c_str(), + size, (double*) &(tab[0])); + return info; +} + +int Communication::send(const int iteration, const string portName, const bool& val ) { + const float fUNUSED=0; + float temps(fUNUSED); + int* var; + var = new int[1]; + if (val) { + var[0] = 1; + } else { + var[0] = 0; + } + int info = cp_elo(compo_, CP_ITERATION, temps, iteration, (char*) portName.c_str(), 1, var); + delete [] var; + return info; +} + +int Communication::send(const int iteration, const string portName, const int size, BoolPtrConst& tab ) { + const float fUNUSED=0; + float temps(fUNUSED); + int* var; + var = new int[size]; + for (int i=0; i < size; ++i) { + if (tab[i]) { + var[i] = 1; + } else { + var[i] = 0; + } + } + int info = cp_elo(compo_, CP_ITERATION, temps, iteration, (char*) portName.c_str(), size, var); + delete [] var; + return info; +} + +// receive datastream + +int Communication::recv(int& iteration, const string portName, int& val ) { + float tempsi(0.) ; + float tempsf(1.) ; + int nbValuesImported; + int* var; + var = new int[1]; + int info = cp_len(compo_, CP_ITERATION, &tempsi, &tempsf, &iteration, + (char*) portName.c_str(), 1, &nbValuesImported, var); + val = var[0]; + delete [] var; + return info; +} + +int Communication::recv(int& iteration, const string portName, const int size, IntPtr& tab ) { + float tempsi(0.) ; + float tempsf(1.) ; + int nbValuesImported; + int* var; + var = new int[size]; + int info = cp_len(compo_, CP_ITERATION, &tempsi, &tempsf, &iteration, + (char*) portName.c_str(), size, &nbValuesImported, var); + for (int i=0; i < size; ++i) tab[i] = var[i]; + delete [] var; + return info; +} + +int Communication::recv(int& iteration, const string portName, float& val ) { + float tempsi(0.) ; + float tempsf(1.) ; + int nbValuesImported; + float* var; + var = new float[1]; + int info = cp_lre(compo_, CP_ITERATION, &tempsi, &tempsf, &iteration, + (char*) portName.c_str(), 1, &nbValuesImported, var); + val = var[0]; + delete [] var; + return info; +} + +int Communication::recv(int& iteration, const string portName, const int size, FloatPtr& tab ) { + float tempsi(0.) ; + float tempsf(1.) ; + int nbValuesImported; + float* var; + var = new float[size]; + int info = cp_lre(compo_, CP_ITERATION, &tempsi, &tempsf, &iteration, + (char*) portName.c_str(), size, &nbValuesImported, var); + for (int i=0; i < size; ++i) tab[i] = var[i]; + delete [] var; + return info; +} + +int Communication::recv(int& iteration, const string portName, double& val ) { + double tempsi(0.) ; + double tempsf(1.) ; + int nbValuesImported; + double* var; + var = new double[1]; + int info = cp_ldb(compo_, CP_ITERATION, &tempsi, &tempsf, &iteration, + (char*) portName.c_str(), 1, &nbValuesImported, var); + val = var[0]; + delete [] var; + return info; +} + +int Communication::recv(int& iteration, const string portName, const int size, DoublePtr& tab ) { + double tempsi(0.) ; + double tempsf(1.) ; + int nbValuesImported; + double* var; + var = new double[size]; + int info = cp_ldb(compo_, CP_ITERATION, &tempsi, &tempsf, &iteration, + (char*) portName.c_str(), size, &nbValuesImported, var); + for (int i=0; i < size; ++i) tab[i] = var[i]; + delete [] var; + return info; +} + +int Communication::recv(int& iteration, const string portName, bool& val ) { + float tempsi(0.) ; + float tempsf(1.) ; + int nbValuesImported; + int* var; + var = new int[1]; + int info = cp_llo(compo_, CP_ITERATION, &tempsi, &tempsf, &iteration, + (char*) portName.c_str(), 1, &nbValuesImported, (int*) var); + val = (var[0] == 1); + delete [] var; + return info; +} + +int Communication::recv(int& iteration, const string portName, const int size, BoolPtr& tab ) { + float tempsi(0.) ; + float tempsf(1.) ; + int nbValuesImported; + int* var; + var = new int[size]; + int info = cp_llo(compo_, CP_ITERATION, &tempsi, &tempsf, &iteration, + (char*) portName.c_str(), size, &nbValuesImported, (int*) var); + for (int i=0; i < size; ++i) tab[i] = (var[i] == 1); + delete [] var; + return info; +} diff --git a/Yacs++/src/Communication.hxx b/Yacs++/src/Communication.hxx new file mode 100755 index 0000000..ccec971 --- /dev/null +++ b/Yacs++/src/Communication.hxx @@ -0,0 +1,187 @@ +/** + * This class is an implementation of the C++ bindings for Calcium. + * Calcium capabilities with iteration synchronization are available for a program written in C++ + * by using methods belonging to the Communication class. + * + * The Communication class uses predefined declarations for some datatypes: + * <table border="0"> + * <tr> <td><tt>#define IntPtr</tt>:</td> <td><tt>boost::shared_array<int_32></tt></td> </tr> + * <tr> <td><tt>#define FloatPtr</tt>:</td> <td><tt>boost::shared_array<float_32></tt></td> </tr> + * <tr> <td><tt>#define DoublePtr</tt>:</td> <td><tt>boost::shared_array<double_64></tt></td> </tr> + * <tr> <td><tt>#define BoolPtr</tt>:</td> <td><tt>boost::shared_array<bool></tt></td> </tr> + * </table> + * <P> + * Moreover, send methods are constructing shared arrays that <i>cannot</i> be modified in the calling C++ + * code. To prevent this, they are declared <tt>const</tt> using the following predefined declarations: + * <table border="0"> + * <tr> <td><tt>#define IntPtrConst</tt>:</td> <td><tt>boost::shared_array<const int_32></tt></td> </tr> + * <tr> <td><tt>#define FloatPtrConst</tt>:</td> <td><tt>boost::shared_array<const float_32></tt></td> </tr> + * <tr> <td><tt>#define DoublePtrConst</tt>:</td> <td><tt>boost::shared_array<const double_64></tt></td> </tr> + * <tr> <td><tt>#define BoolPtrConst</tt>:</td> <td><tt>boost::shared_array<const bool></tt></td> </tr> + * </table> + * <P> + * + * @author Hadrien Leroyer, EDF and Alain Hebert, Ecole Polytechnique + * de Montreal (2013) + */ +#if ! defined( __Communication_hxx__ ) +#define __Communication_hxx__ + +#include <iostream> +#include "CalciumException.hxx" +extern "C" { +#include <unistd.h> +#include "calcium.h" +} +#include "Cle2000.hxx" + +class Communication { + +private: + + void* compo_; + +public: + /** use this constructor to create a new empty Communication object + */ + Communication(); + + /** use this constructor to create a new Communication object with an embedded component + * @param compo embedded component + */ + Communication(const Communication& compo); + +virtual ~Communication(); + + /** initialize the Communication object and set the embedded component + * @param compo embedded Calcium component + */ + int initialize(void* compo); + + /** close the Communication object + */ + int terminate(); + + /** send a single integer value + * @param iteration iteration index + * @param portName name of the datastream + * @param val integer value + */ + int send(const int iteration, const std::string portName, const int& val ); + + /** send an integer array + * @param iteration iteration index + * @param portName name of the datastream + * @param size size of the integer array + * @param tab integer array + */ + int send(const int iteration, const std::string portName, const int size, IntPtrConst& tab ); + + /** send a single real value + * @param iteration iteration index + * @param portName name of the datastream + * @param val real value + */ + int send(const int iteration, const std::string portName, const float& val ); + + /** send an real array + * @param iteration iteration index + * @param portName name of the datastream + * @param size size of the real array + * @param tab real array + */ + int send(const int iteration, const std::string portName, const int size, FloatPtrConst& tab ); + + /** send a single double precision real value + * @param iteration iteration index + * @param portName name of the datastream + * @param val double precision real value + */ + int send(const int iteration, const std::string portName, const double& val ); + + /** send an double precision real array + * @param iteration iteration index + * @param portName name of the datastream + * @param size size of the double precision real array + * @param tab double precision real array + */ + int send(const int iteration, const std::string portName, const int size, DoublePtrConst& tab ); + + /** send a single boolean value + * @param iteration iteration index + * @param portName name of the datastream + * @param val boolean value + */ + int send(const int iteration, const std::string portName, const bool& val ); + + /** send an boolean array + * @param iteration iteration index + * @param portName name of the datastream + * @param size size of the boolean array + * @param tab boolean array + */ + int send(const int iteration, const std::string portName, const int size, BoolPtrConst& tab ); + + /** receive a single integer value + * @param iteration iteration index + * @param portName name of the datastream + * @param val integer value + */ + int recv(int& iteration, const std::string portName, int& val ); + + /** receive an integer array + * @param iteration iteration index + * @param portName name of the datastream + * @param size size of the integer array + * @param tab integer array + */ + int recv(int& iteration, const std::string portName, const int size, IntPtr& tab ); + + /** receive a single real value + * @param iteration iteration index + * @param portName name of the datastream + * @param val real value + */ + int recv(int& iteration, const std::string portName, float& val ); + + /** receive an real array + * @param iteration iteration index + * @param portName name of the datastream + * @param size size of the real array + * @param tab real array + */ + int recv(int& iteration, const std::string portName, const int size, FloatPtr& tab ); + + /** receive a single double precision real value + * @param iteration iteration index + * @param portName name of the datastream + * @param val double precision real value + */ + int recv(int& iteration, const std::string portName, double& val ); + + /** receive an double precision real array + * @param iteration iteration index + * @param portName name of the datastream + * @param size size of the double precision real array + * @param tab double precision real array + */ + int recv(int& iteration, const std::string portName, const int size, DoublePtr& tab ); + + /** receive a single boolean value + * @param iteration iteration index + * @param portName name of the datastream + * @param val boolean value + */ + int recv(int& iteration, const std::string portName, bool& val ); + + /** receive a boolean array + * @param iteration iteration index + * @param portName name of the datastream + * @param size size of the oolean array + * @param tab boolean array + */ + int recv(int& iteration, const std::string portName, const int size, BoolPtr& tab ); + +}; + +#endif //#if ! defined( __Communication_hxx__ ) diff --git a/Yacs++/src/FACT.cxx b/Yacs++/src/FACT.cxx new file mode 100755 index 0000000..1b25937 --- /dev/null +++ b/Yacs++/src/FACT.cxx @@ -0,0 +1,28 @@ +#include "FACT.hxx" +#include "Cle2000.hxx" +using namespace boost; using namespace std; using namespace ganlib; + +FACT::FACT() { + cout << "New FACT object constructed.'" << endl; +} + +void FACT::run(long a, long& b) { + // construct the lifo stack + LifoPtr ipLifo = LifoPtr(new Lifo()); + ipLifo->push("input_val",int_32(a)); + ipLifo->pushEmpty("output_val","I"); + + // call the procedure with in-out CLE-2000 variables + Cle2000Ptr ipCle2000 = Cle2000Ptr(new Cle2000("fact", 0, ipLifo)); + ipCle2000->exec(); + + // recover and erase the lifo stack + int_32 output_val; ipLifo->pop(output_val); + b = (long)output_val; + + // empty the lifo stack + while (ipLifo->getMax() > 0) ipLifo->pop(); + + // end of case ----------------------------------------------------------- + cout << "FACT::run: successful end of execution" << endl; +} diff --git a/Yacs++/src/FACT.hxx b/Yacs++/src/FACT.hxx new file mode 100755 index 0000000..6e497cc --- /dev/null +++ b/Yacs++/src/FACT.hxx @@ -0,0 +1,24 @@ +/** + * This class is a C++ wrapper for calling the FACT.c2m CLE-2000 + procedure from YACS. + * <P> + * + * @author Alain Hebert, Ecole Polytechnique de Montreal (2013) + */ +#ifndef __FACT_HXX__ +#define __FACT_HXX__ + +class FACT { +public: + /** use this constructor to create a new FACT object + */ + FACT(); + + /** use this method to execute the FACT object + * @param a input integer + * @param b output integer containing factorial of a + */ + void run(long a, long& b); +}; // class FACT + +#endif diff --git a/Yacs++/src/Makefile b/Yacs++/src/Makefile new file mode 100755 index 0000000..ea4f522 --- /dev/null +++ b/Yacs++/src/Makefile @@ -0,0 +1,117 @@ +#--------------------------------------------------------------------------- +# +# Makefile for building the Yacs++ library and load module +# Author : A. Hebert (2018-5-10) +# +#--------------------------------------------------------------------------- +# +ARCH = $(shell uname -m) +ifneq (,$(filter $(ARCH),aarch64 arm64)) + nbit = +else + ifneq (,$(filter $(ARCH),i386 i686)) + nbit = -m32 + else + nbit = -m64 + endif +endif + +DIRNAME = $(shell uname -sm | sed 's/[ ]/_/') +OS = $(shell uname -s | cut -d"_" -f1) +opt = -O -g +ifeq ($(openmp),1) + COMP = -fopenmp +else + COMP = +endif + +ifeq ($(intel),1) + ccompiler = icpc +else + ifeq ($(nvidia),1) + ccompiler = nvc++ + else + ifeq ($(llvm),1) + ccompiler = clang++ + else + ccompiler = gcc + endif + endif +endif + +ifeq ($(OS),Darwin) + C = $(ccompiler) -std=c++11 + FLAGS = -DLinux -DUnix + CFLAGS = -Wall $(nbit) -fPIC +else +ifeq ($(OS),Linux) + ifeq ($(nvidia),1) + C = $(ccompiler) -std=c++14 + else + C = $(ccompiler) -std=c++17 + endif + FLAGS = -DLinux -DUnix + CFLAGS = -Wall $(nbit) -fPIC +else +ifeq ($(OS),CYGWIN) + C = g++ -std=c++11 + FLAGS = -DLinux -DUnix + CFLAGS = -Wall $(nbit) -fPIC +else +ifeq ($(OS),SunOS) + MAKE = gmake + C = cc + FLAGS = -DSunOS -DUnix + CFLAGS = $(nbit) +else +ifeq ($(OS),AIX) + opt = -O4 + MAKE = gmake + DIRNAME = AIX + C = xlc + FLAGS = -DAIX -DUnix + CFLAGS = -qstrict +else + $(error $(OS) is not a valid OS) +endif +endif +endif +endif +endif +lib = ../lib/$(DIRNAME) +INCLUDE = -I../../Ganlib/src/ -I../../Skin++/src/ + +ifeq ($(hdf5),1) + CFLAGS += -L${HDF5_DIR}/lib -lhdf5 +endif + +SRCC = $(shell ls *.cxx) +OBJC = $(SRCC:.cxx=.o) +all : sub-make libYacs++.a +ifeq ($(openmp),1) + @echo 'Yacs++: openmp is defined' +endif +ifeq ($(intel),1) + @echo 'Yacs++: intel is defined' +endif +ifeq ($(nvidia),1) + @echo 'Yacs++: nvidia is defined' +endif +ifeq ($(llvm),1) + @echo 'Yacs++: llvm is defined' +endif +ifeq ($(hdf5),1) + @echo 'Yacs++: hdf5 is defined' +endif +sub-make: + $(MAKE) openmp=$(openmp) intel=$(intel) nvidia=$(nvidia) llvm=$(llvm) hdf5=$(hdf5) -C ../../Skin++/src +%.o : %.cxx + $(C) $(CFLAGS) $(FLAGS) $(opt) $(COMP) $(INCLUDE) -I$(BOOST_ROOT) -I$(SALOME_KERNEL)/include/salome/ -c $< -o $@ +$(lib)/: + mkdir -p $(lib)/ +libYacs++.a: $(OBJC) $(lib)/ + ar r $@ $(OBJC) + cp $@ $(lib)/$@ +clean: + $(MAKE) -C ../../Skin++/src clean + /bin/rm -f *.o *.a sub-make temp. diff --git a/Yacs++/src/POW.cxx b/Yacs++/src/POW.cxx new file mode 100755 index 0000000..b2b2975 --- /dev/null +++ b/Yacs++/src/POW.cxx @@ -0,0 +1,119 @@ +#include "POW.hxx" +using namespace boost; using namespace std; using namespace ganlib; + +POW::POW() { + cout << "New POW object constructed.'" << endl; +} + +void POW::initialize(double power, void* component) +{ +power_ = power; +communicator_.initialize(component); +} + +void POW::run() +{ + // construct the Lifo stack for IniPowCompo + cout << "POW::run" << endl; + LifoPtr ipLifo1 = LifoPtr(new Lifo()); + ipLifo1->pushEmpty("Fmap", "LCM"); + ipLifo1->pushEmpty("Matex", "LCM"); + ipLifo1->pushEmpty("Cpo", "LCM"); + ipLifo1->pushEmpty("Track", "LCM"); + + // call IniPowCompo Cle-2000 procedure + Cle2000Ptr IniPowCompo = Cle2000Ptr(new Cle2000("IniPowCompo", 0, ipLifo1)); + IniPowCompo->exec(); + cout << "IniPowCompo execution completed" << endl; + + // recover the output LCM objects + ClcmPtr Fmap; ipLifo1->node("Fmap", Fmap); + ClcmPtr Matex; ipLifo1->node("Matex", Matex); + ClcmPtr Cpo; ipLifo1->node("Cpo", Cpo); + ClcmPtr Track; ipLifo1->node("Track", Track); + IntPtrConst stateVector = Fmap->getInt("STATE-VECTOR"); + long mylength = stateVector[0] * stateVector[1]; + long npar = stateVector[7]; + + // empty the Lifo stack + while (ipLifo1->getMax() > 0) ipLifo1->pop(); + + //iteration loop + ClcmPtr Flux, Thm; + float_32 densB = 2000.; + int iter = 0; + int continueLoop = 1; + float Keff_conv = 1.0; + LifoPtr ipLifo2 = LifoPtr(new Lifo()); + Cle2000Ptr PowComponent = Cle2000Ptr(new Cle2000("PowComponent", 0, ipLifo2)); + + while (continueLoop == 1) { + ++ iter; + cout << "POW: ITERATION NUMBER:" << iter << " continueLoop=" << continueLoop << endl; + + // construct the Lifo stack for PowComponent + ipLifo2->push("Fmap", Fmap); + ipLifo2->push("Matex", Matex); + if (iter == 1) { + ipLifo2->pushEmpty("Flux", "LCM"); + } else { + ipLifo2->push("Flux", Flux); + } + ipLifo2->push("Cpo", Cpo); + ipLifo2->push("Track", Track); + ipLifo2->push("iter", iter); + ipLifo2->push("powi", float_32(power_)); + ipLifo2->push("densB", densB); + + // call PowComponent Cle-2000 procedure + cout << "call PowComponent->exec" << endl; + PowComponent->exec(); + cout << "PowComponent execution completed" << endl; + ipLifo2->node("Flux", Flux); + FloatPtrConst Keff = Flux->getFloat("K-EFFECTIVE"); + cout << "POW: iter=" << iter << " ------------- Keffective=" << Keff[0] << endl; + Keff_conv = Keff[0]; + + // send reactor physics information + FloatPtrConst powerTab = Fmap->getFloat("BUND-PW"); + communicator_.send(iter, "powerTab", mylength, powerTab); + FloatPtrConst irradiationTab = Fmap->getFloat("BURN-INST"); + communicator_.send(iter, "irradiationTab", mylength, irradiationTab); + + // receive thermo-hydraulics information + ClcmPtr Jpmap = Fmap->getClcm("PARAM"); + IntPtr myIntPtr(new int_32[1]); myIntPtr[0] = 2; + for (int ipar=0; ipar<npar; ipar++) { + ClcmPtr Kpmap = Jpmap->getClcm(ipar); + StringPtrConst pname = Kpmap->getString("P-NAME"); + if (*pname == "T-FUEL ") { + FloatPtr myArray(new float_32[mylength]); + communicator_.recv(iter, "fuel_temperature", mylength, myArray); + Kpmap->put("P-VALUE", myArray, mylength); + Kpmap->put("P-TYPE", myIntPtr, 1); + } else if (*pname == "D-COOL ") { + FloatPtr myArray(new float_32[mylength]); + communicator_.recv(iter, "water_density", mylength, myArray); + Kpmap->put("P-VALUE", myArray, mylength); + Kpmap->put("P-TYPE", myIntPtr, 1); + } else if (*pname == "T-COOL ") { + FloatPtr myArray(new float_32[mylength]); + communicator_.recv(iter, "water_temperature", mylength, myArray); + Kpmap->put("P-VALUE", myArray, mylength); + Kpmap->put("P-TYPE", myIntPtr, 1); + } + } + Fmap->val(); + + // empty the Lifo stack + while (ipLifo2->getMax() > 0) ipLifo2->pop(); + + // receive the convergence flag + communicator_.recv(iter, "continueLoop", continueLoop); + cout << "POW: Value of continueLoop : "<< continueLoop << " at iteration " << iter << endl; + } + cout << "POW: close the Calcium communicator" << endl ; + communicator_.terminate(); + cout.precision(10); + cout << "POW: converged K-effective=" << Keff_conv << endl ; +} diff --git a/Yacs++/src/POW.hxx b/Yacs++/src/POW.hxx new file mode 100755 index 0000000..38aaeaf --- /dev/null +++ b/Yacs++/src/POW.hxx @@ -0,0 +1,35 @@ +/** + * This class is a C++ wrapper for a while loop calling a + * Cle-2000 procedure named PowComponent.c2m at each iteration. + * <P> + * + * @author Alain Hebert, Ecole Polytechnique de Montreal (2013) + */ +#ifndef __POW_HXX__ +#define __POW_HXX__ + +#include "Cle2000.hxx" +#include "Communication.hxx" + +class POW { +public: + /** use this constructor to create a new POW object + */ + POW(); + + /** use this method to assign a Calcium component to the POW object + * @param power thermal reactor power in MW + * @param component Calcium component reference + */ + void initialize(double power, void* component); + + /** use this method to execute the POW object + */ + void run(); + +private: + double power_; + Communication communicator_; +}; // class POW + +#endif diff --git a/Yacs++/src/THM.cxx b/Yacs++/src/THM.cxx new file mode 100755 index 0000000..fc8b2cc --- /dev/null +++ b/Yacs++/src/THM.cxx @@ -0,0 +1,102 @@ +#include "THM.hxx" +using namespace boost; using namespace std; using namespace ganlib; + +THM::THM() { + cout << "New THM object constructed.'" << endl; +} + +void THM::initialize(void* component) +{ +communicator_.initialize(component); +} + +void THM::run() +{ + // construct the Lifo stack for IniThmCompo + LifoPtr ipLifo1 = LifoPtr(new Lifo()); + ipLifo1->pushEmpty("Fmap", "LCM"); + ipLifo1->pushEmpty("Matex", "LCM"); + + // call IniComponent Cle-2000 procedure + Cle2000Ptr IniComponent = Cle2000Ptr(new Cle2000("IniThmCompo", 0, ipLifo1)); + IniComponent->exec(); + cout << "IniThmCompo execution completed" << endl; + + // recover the output LCM objects + ClcmPtr Fmap; ipLifo1->node("Fmap", Fmap); + ClcmPtr Matex; ipLifo1->node("Matex", Matex); + IntPtrConst stateVector = Fmap->getInt("STATE-VECTOR"); + long mylength = stateVector[0] * stateVector[1]; + long npar = stateVector[7]; + + // empty the Lifo stack + while (ipLifo1->getMax() > 0) ipLifo1->pop(); + + //iteration loop + ClcmPtr Flux, Thm; + float_32 densB = 2000.; + int iter = 0; + int continueLoop = 1; + LifoPtr ipLifo3 = LifoPtr(new Lifo()); + Cle2000Ptr ThmComponent = Cle2000Ptr(new Cle2000("ThmComponent", 0, ipLifo3)); + + while (continueLoop == 1) { + ++ iter; + cout << "THM: ITERATION NUMBER:" << iter << " continueLoop=" << continueLoop << endl; + + FloatPtr powerTab(new float_32[mylength]); + communicator_.recv(iter, "powerTab", mylength, powerTab ); + Fmap->put("BUND-PW", powerTab, mylength); + FloatPtr irradiationTab(new float_32[mylength]); + communicator_.recv(iter, "irradiationTab", mylength, irradiationTab ); + Fmap->put("BURN-INST", irradiationTab, mylength); + Fmap->val(); + + // construct the Lifo stack for ThmComponent + ipLifo3->push("Fmap", Fmap); + if (iter == 1) { + ipLifo3->pushEmpty("Thm", "LCM"); + } else { + ipLifo3->push("Thm", Thm); + } + ipLifo3->push("iter", iter); + ipLifo3->push("densB", densB); + ipLifo3->pushEmpty("CONV", "B"); + + // call ThmComponent Cle-2000 procedure + ThmComponent->exec(); + cout << "ThmComponent execution completed." << endl; + + // recover and send thermo-hydraulics information + ipLifo3->node("Thm", Thm); + ClcmPtr Jpmap = Fmap->getClcm("PARAM"); + for (int ipar=0; ipar<npar; ipar++) { + ClcmPtr Kpmap = Jpmap->getClcm(ipar); + StringPtrConst pname = Kpmap->getString("P-NAME"); + if (*pname == "C-BORE ") continue; + IntPtrConst ptype = Kpmap->getInt("P-TYPE"); + if (ptype[0] != 2) throw Cle2000Exception("THM failure"); + FloatPtrConst myArray = Kpmap->getFloat("P-VALUE"); + if (*pname == "T-FUEL ") { + communicator_.send(iter, "fuel_temperature", mylength, myArray); + } else if (*pname == "D-COOL ") { + communicator_.send(iter, "water_density", mylength, myArray); + } else if (*pname == "T-COOL ") { + communicator_.send(iter, "water_temperature", mylength, myArray); + } + } + + // recover convergence flag on top of Lifo object + bool CONV; + ipLifo3->pop(CONV); + if (CONV) continueLoop = 0; + + // empty the Lifo stack + while (ipLifo3->getMax() > 0) ipLifo3->pop(); + + communicator_.send(iter, "continueLoop", continueLoop); + cout << "THM: Value of continueLoop : "<< continueLoop << " at iteration " << iter << endl; + } + cout << "THM: close the Calcium communicator" << endl ; + communicator_.terminate(); +} diff --git a/Yacs++/src/THM.hxx b/Yacs++/src/THM.hxx new file mode 100755 index 0000000..a2d7752 --- /dev/null +++ b/Yacs++/src/THM.hxx @@ -0,0 +1,33 @@ +/** + * This class is a C++ wrapper for a while loop calling a + * Cle-2000 procedure named THMComponent.c2m at each iteration. + * <P> + * + * @author Alain Hebert, Ecole Polytechnique de Montreal (2013) + */ +#ifndef __THM_HXX__ +#define __THM_HXX__ + +#include "Cle2000.hxx" +#include "Communication.hxx" + +class THM { +public: + /** use this constructor to create a new THM object + */ + THM(); + + /** use this method to assign a Calcium component to the THM object + * @param component Calcium component reference + */ + void initialize(void* component); + + /** use this method to execute the THM object + */ + void run(); + +private: + Communication communicator_; +}; // class THM + +#endif |
