"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "Functions/F_Octave.cpp" between
getdp-3.4.0-source.tgz and getdp-3.5.0-source.tgz

About: GetDP is a general finite element solver using mixed elements to discretize de Rham-type complexes in one, two and three dimensions.

F_Octave.cpp  (getdp-3.4.0-source.tgz):F_Octave.cpp  (getdp-3.5.0-source.tgz)
// GetDP - Copyright (C) 1997-2021 P. Dular and C. Geuzaine, University of Liege // GetDP - Copyright (C) 1997-2022 P. Dular and C. Geuzaine, University of Liege
// //
// See the LICENSE.txt file for license information. Please report all // See the LICENSE.txt file for license information. Please report all
// issues on https://gitlab.onelab.info/getdp/getdp/issues. // issues on https://gitlab.onelab.info/getdp/getdp/issues.
#include "GetDPConfig.h" #include "GetDPConfig.h"
#include "ProData.h" #include "ProData.h"
#include "F.h" #include "F.h"
#include "Message.h" #include "Message.h"
extern struct CurrentData Current ; extern struct CurrentData Current;
// This file defines a simple interface to Octave. // This file defines a simple interface to Octave.
// //
// * To configure GetDP with Octave support, point cmake to Octave's library and // * To configure GetDP with Octave support, point cmake to Octave's library and
// include directories, e.g.: // include directories, e.g.:
// //
// cmake -DCMAKE_PREFIX_PATH="/opt/local/include/octave-3.6.4; // cmake -DCMAKE_PREFIX_PATH="/opt/local/include/octave-3.6.4;
// /opt/local/lib/octave/3.6.4" .. // /opt/local/lib/octave/3.6.4" ..
// //
// * The Octave interpreter will be initialized when GetDP is started; you can // * The Octave interpreter will be initialized when GetDP is started; you can
skipping to change at line 63 skipping to change at line 63
// Message::Error("Octave error"); // Message::Error("Octave error");
#if defined(HAVE_OCTAVE) #if defined(HAVE_OCTAVE)
#undef HAVE_ARPACK #undef HAVE_ARPACK
#include <octave/oct.h> #include <octave/oct.h>
#include <octave/parse.h> #include <octave/parse.h>
void F_Octave(F_ARG) void F_Octave(F_ARG)
{ {
if(!Fct->String){ if(!Fct->String) {
Message::Error("Missing Octave expression: use Octave[arguments]{\"expressio Message::Error(
n\"}"); "Missing Octave expression: use Octave[arguments]{\"expression\"}");
for (int k = 0; k < Current.NbrHar; k++) for(int k = 0; k < Current.NbrHar; k++) V->Val[MAX_DIM * k] = 0.;
V->Val[MAX_DIM * k] = 0. ;
V->Type = SCALAR; V->Type = SCALAR;
return; return;
} }
// we could do this more efficiently by directly storing the values in octave // we could do this more efficiently by directly storing the values in octave
// (instead of parsing) // (instead of parsing)
std::string expr; std::string expr;
for(int i = 0; i < Fct->NbrArguments; i++){ for(int i = 0; i < Fct->NbrArguments; i++) {
char tmp[256]; char tmp[256];
if((A + i)->Type == SCALAR){ if((A + i)->Type == SCALAR) {
if(Current.NbrHar == 2) if(Current.NbrHar == 2)
sprintf(tmp, "input{%d} = %.16g+%.16gi;", i + 1, sprintf(tmp, "input{%d} = %.16g+%.16gi;", i + 1, (A + i)->Val[0],
(A + i)->Val[0], (A + i)->Val[MAX_DIM]); (A + i)->Val[MAX_DIM]);
else else
sprintf(tmp, "input{%d} = %.16g;", i + 1, (A + i)->Val[0]); sprintf(tmp, "input{%d} = %.16g;", i + 1, (A + i)->Val[0]);
} }
else{ else {
Message::Error("Non-scalar Octave arguments not coded yet"); Message::Error("Non-scalar Octave arguments not coded yet");
} }
expr += tmp; expr += tmp;
} }
expr += Fct->String; expr += Fct->String;
int status; int status;
octave_value out; octave_value out;
// FIXME: it seems like we cannot evaluate several octave statements at // FIXME: it seems like we cannot evaluate several octave statements at
// once !?!? // once !?!?
//out = eval_string(expr.c_str(), false, status); // out = eval_string(expr.c_str(), false, status);
//if(status) Message::Error("Octave evaluation error"); // if(status) Message::Error("Octave evaluation error");
// FIXME: this will break when semi-colons are present in expressions for // FIXME: this will break when semi-colons are present in expressions for
// something else than statement boundaries // something else than statement boundaries
std::string::size_type first = 0; std::string::size_type first = 0;
while(1){ while(1) {
std::string::size_type last = expr.find_first_of(";", first); std::string::size_type last = expr.find_first_of(";", first);
std::string str = expr.substr(first, last - first + 1); std::string str = expr.substr(first, last - first + 1);
if(str.size()){ if(str.size()) {
//Message::Info("Evaluating %s", str.c_str()); // Message::Info("Evaluating %s", str.c_str());
out = eval_string(str.c_str(), false, status); out = eval_string(str.c_str(), false, status);
if(status) Message::Error("Octave evaluation error"); if(status) Message::Error("Octave evaluation error");
} }
if(last == std::string::npos) break; if(last == std::string::npos) break;
first = last + 1; first = last + 1;
} }
for (int k = 0; k < Current.NbrHar; k++) for(int k = 0; k < Current.NbrHar; k++)
for (int j = 0; j < 9; j++) for(int j = 0; j < 9; j++) V->Val[MAX_DIM * k + j] = 0.;
V->Val[MAX_DIM * k + j] = 0. ;
if(out.is_real_scalar()){ if(out.is_real_scalar()) {
V->Val[0] = out.double_value(); V->Val[0] = out.double_value();
V->Type = SCALAR; V->Type = SCALAR;
} }
else if(out.is_complex_scalar()){ else if(out.is_complex_scalar()) {
V->Val[0] = out.complex_value().real(); V->Val[0] = out.complex_value().real();
V->Val[MAX_DIM] = out.complex_value().imag(); V->Val[MAX_DIM] = out.complex_value().imag();
V->Type = SCALAR; V->Type = SCALAR;
} }
else if(out.is_real_matrix() || else if(out.is_real_matrix() || out.is_complex_matrix()) {
out.is_complex_matrix()){
Message::Error("Octave matrix output not coded yet"); Message::Error("Octave matrix output not coded yet");
V->Type = VECTOR ; V->Type = VECTOR;
} }
} }
#else #else
void F_Octave(F_ARG) void F_Octave(F_ARG)
{ {
Message::Error("You need to compile GetDP with Octave support to use Octave fu Message::Error(
nctions"); "You need to compile GetDP with Octave support to use Octave functions");
V->Val[0] = 0. ; V->Val[0] = 0.;
V->Type = SCALAR ; V->Type = SCALAR;
} }
#endif #endif
 End of changes. 16 change blocks. 
29 lines changed or deleted 26 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)