Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
572 changes: 286 additions & 286 deletions biophysics/Neuron.cpp

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion builtins/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ set(SRCS
Arith.cpp
Group.cpp
Mstring.cpp
Func.cpp
# Func.cpp
MooseParser.cpp
Function.cpp
Variable.cpp
InputVariable.cpp
Expand Down
157 changes: 79 additions & 78 deletions builtins/Function.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,29 +59,29 @@ static const double TriggerThreshold = 0.0;
static SrcFinfo1<double> *valueOut()
{
static SrcFinfo1<double> valueOut("valueOut",
"Evaluated value of the function for the current variable values.");
"Evaluated value of the function for the current variable values.");
return &valueOut;
}

static SrcFinfo1< double > *derivativeOut()
{
static SrcFinfo1< double > derivativeOut("derivativeOut",
"Value of derivative of the function for the current variable values");
"Value of derivative of the function for the current variable values");
return &derivativeOut;
}

static SrcFinfo1< double > *rateOut()
{
static SrcFinfo1< double > rateOut("rateOut",
"Value of time-derivative of the function for the current variable values");
"Value of time-derivative of the function for the current variable values");
return &rateOut;
}

static SrcFinfo1< vector < double > *> *requestOut()
{
static SrcFinfo1< vector < double > * > requestOut(
"requestOut",
"Sends request for input variable from a field on target object");
"requestOut",
"Sends request for input variable from a field on target object");
return &requestOut;

}
Expand Down Expand Up @@ -168,8 +168,9 @@ const Cinfo * Function::initCinfo()
"max var. max of all arguments\n"
"sum var. sum of all arguments\n"
"avg var. mean value of all arguments\n"
"rnd 0 rand(), random float between 0 and 1, honors global moose.seed.\n"
"rand 1 rand(seed), random float between 0 and 1, \n"
" if seed = -1, then a 'random' seed is created.\n"
" if seed = -1, then a 'random' seed is used.\n"
"rand2 3 rand(a, b, seed), random float between a and b, \n"
" if seed = -1, a 'random' seed is created using either\n"
" by random_device or by reading system clock\n"
Expand Down Expand Up @@ -235,89 +236,89 @@ const Cinfo * Function::initCinfo()
// Shared messages
///////////////////////////////////////////////////////////////////
static DestFinfo process( "process",
"Handles process call, updates internal time stamp.",
new ProcOpFunc< Function >( &Function::process ) );
"Handles process call, updates internal time stamp.",
new ProcOpFunc< Function >( &Function::process ) );
static DestFinfo reinit( "reinit",
"Handles reinit call.",
new ProcOpFunc< Function >( &Function::reinit ) );
"Handles reinit call.",
new ProcOpFunc< Function >( &Function::reinit ) );
static Finfo* processShared[] = { &process, &reinit };

static SharedFinfo proc( "proc",
"This is a shared message to receive Process messages "
"from the scheduler objects."
"The first entry in the shared msg is a MsgDest "
"for the Process operation. It has a single argument, "
"ProcInfo, which holds lots of information about current "
"time, thread, dt and so on. The second entry is a MsgDest "
"for the Reinit operation. It also uses ProcInfo. ",
processShared, sizeof( processShared ) / sizeof( Finfo* )
);
/*
static DestFinfo trigger( "trigger",
"Handles trigger input. Argument is timestamp of event. This is "
"compatible with spike events as well as chemical ones. ",
new OpFunc1< Function, double >( &Function::trigger ) );
*/
"This is a shared message to receive Process messages "
"from the scheduler objects."
"The first entry in the shared msg is a MsgDest "
"for the Process operation. It has a single argument, "
"ProcInfo, which holds lots of information about current "
"time, thread, dt and so on. The second entry is a MsgDest "
"for the Reinit operation. It also uses ProcInfo. ",
processShared, sizeof( processShared ) / sizeof( Finfo* )
);
/*
static DestFinfo trigger( "trigger",
"Handles trigger input. Argument is timestamp of event. This is "
"compatible with spike events as well as chemical ones. ",
new OpFunc1< Function, double >( &Function::trigger ) );
*/

static Finfo *functionFinfos[] =
{
&value,
&rate,
&derivative,
&mode,
&useTrigger,
&doEvalAtReinit,
&expr,
&numVars,
&inputs,
&constants,
&independent,
&proc,
requestOut(),
valueOut(),
rateOut(),
derivativeOut(),
};
{
&value,
&rate,
&derivative,
&mode,
&useTrigger,
&doEvalAtReinit,
&expr,
&numVars,
&inputs,
&constants,
&independent,
&proc,
requestOut(),
valueOut(),
rateOut(),
derivativeOut(),
};

static string doc[] =
{
"Name", "Function",
"Author", "Subhasis Ray",
"Description",
"General purpose function calculator using real numbers.\n"
"It can parse mathematical expression defining a function and evaluate"
" it and/or its derivative for specified variable values."
"You can assign expressions of the form::\n"
"\n"
"f(c0, c1, ..., cM, x0, x1, ..., xN, y0,..., yP ) \n"
"\n"
" where `ci`'s are constants and `xi`'s and `yi`'s are variables."

"The constants must be defined before setting the expression and"
" variables are connected via messages. The constants can have any"
" name, but the variable names must be of the form x{i} or y{i}"
" where i is increasing integer starting from 0.\n"
" The variables can be input from other moose objects."
" Such variables must be named `x{i}` in the expression and the source"
" field is connected to Function.x[i]'s `input` destination field.\n"
" In case the input variable is not available as a source field, but is"
" a value field, then the value can be requested by connecting the"
" `requestOut` message to the `get{Field}` destination on the target"
" object. Such variables must be specified in the expression as y{i}"
" and connecting the messages should happen in the same order as the"
" y indices.\n"
" This class handles only real numbers (C-double). Predefined constants"
" are: pi=3.141592..., e=2.718281..."
};
{
"Name", "Function",
"Author", "Subhasis Ray",
"Description",
"General purpose function calculator using real numbers.\n"
"It can parse mathematical expression defining a function and evaluate"
" it and/or its derivative for specified variable values."
"You can assign expressions of the form::\n"
"\n"
"f(c0, c1, ..., cM, x0, x1, ..., xN, y0,..., yP ) \n"
"\n"
" where `ci`'s are constants and `xi`'s and `yi`'s are variables."

"The constants must be defined before setting the expression and"
" variables are connected via messages. The constants can have any"
" name, but the variable names must be of the form x{i} or y{i}"
" where i is increasing integer starting from 0.\n"
" The variables can be input from other moose objects."
" Such variables must be named `x{i}` in the expression and the source"
" field is connected to Function.x[i]'s `input` destination field.\n"
" In case the input variable is not available as a source field, but is"
" a value field, then the value can be requested by connecting the"
" `requestOut` message to the `get{Field}` destination on the target"
" object. Such variables must be specified in the expression as y{i}"
" and connecting the messages should happen in the same order as the"
" y indices.\n"
" This class handles only real numbers (C-double). Predefined constants"
" are: pi=3.141592..., e=2.718281..."
};

static Dinfo< Function > dinfo;
static Cinfo functionCinfo("Function",
Neutral::initCinfo(),
functionFinfos,
sizeof(functionFinfos) / sizeof(Finfo*),
&dinfo,
doc,
sizeof(doc)/sizeof(string));
Neutral::initCinfo(),
functionFinfos,
sizeof(functionFinfos) / sizeof(Finfo*),
&dinfo,
doc,
sizeof(doc)/sizeof(string));
return &functionCinfo;

}
Expand Down
35 changes: 2 additions & 33 deletions builtins/Function.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,43 +12,12 @@
// URL:
// Keywords:
// Compatibility:
//
//

// Commentary:
//
// A new version of Func with FieldElements to collect data.
//
//

// Change log:
//
//
//
//
// This program 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, or
// (at your option) any later version.
//
// This program 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 this program; see the file COPYING. If not, write to
// the Free Software Foundation, Inc., 51 Franklin Street, Fifth
// Floor, Boston, MA 02110-1301, USA.
//
//

// Code:

#ifndef _MOOSE_FUNCTION_H_
#define _MOOSE_FUNCTION_H_

#include "../external/muparser/include/muParser.h"
#include "MooseParser.h"

/**
Simple function parser and evaluator for MOOSE. This can take a mathematical
Expand Down Expand Up @@ -158,7 +127,7 @@ class Function
map< string, double *> _constbuf; // for constants
string _independent; // index of independent variable

mu::Parser _parser;
MooseParser _parser;

void _clearBuffer();
void _showError(mu::Parser::exception_type &e) const;
Expand Down
18 changes: 18 additions & 0 deletions builtins/MooseParser.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/***
* Description: Class MooseParser.
*
* Created: 2019-05-30

* Author: Dilawar Singh <[email protected]>
* Organization: NCBS Bangalore
* License: MIT License
*/

#include "MooseParser.h"

MooseParser::MooseParser()
{}

MooseParser::~MooseParser()
{}

26 changes: 26 additions & 0 deletions builtins/MooseParser.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/***
* Description: MooseParser class.
*
* Created: 2019-05-30

* Author: Dilawar Singh <[email protected]>
* Organization: NCBS Bangalore
* License: MIT License
*/

#ifndef MOOSEPARSER_H
#define MOOSEPARSER_H

#include "../external/muparser/include/muParser.h"

class MooseParser : public mu::Parser
{
public:
MooseParser();
~MooseParser();

private:
/* data */
};

#endif /* end of include guard: MOOSEPARSER_H */
3 changes: 2 additions & 1 deletion external/muparser/include/muParser.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,8 @@ namespace mu
static value_type Rand2(value_type, value_type, value_type);

// Random number between 0 and 1, non-deterministic seed.
static value_type Rand( value_type );
static value_type Rand( value_type seed );
static value_type Rnd( );

// Prefix operators
// !!! Unary Minus is a MUST if you want to use negative signs !!!
Expand Down
18 changes: 17 additions & 1 deletion external/muparser/src/muParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
*/
#include "../include/muParser.h"
#include "../include/muParserTemplateMagic.h"
#include "../../../basecode/global.h"

//--- Standard includes ------------------------------------------------------------------------
#include <cmath>
Expand Down Expand Up @@ -112,10 +113,24 @@ namespace mu
value_type Parser::Fmod(value_type v1, value_type v2) { return fmod(v1, v2); }
value_type Parser::Quot(value_type v1, value_type v2) { return (int)(v1 / v2); }

value_type Parser::Rand( value_type seed = -1 )
{
static bool isSeedSet_ = false;

if( ! isSeedSet_ )
{
mu::rng.setSeed( seed );
isSeedSet_ = true;
}
return rng.uniform( ); /* Between 0 and 1 */
}

// If no seed is given,
value_type Parser::Rand( value_type seed )
value_type Parser::Rnd( )
{
static bool isSeedSet_ = false;
// check if global seed is set
size_t seed = moose::getGlobalSeed();
if( ! isSeedSet_ )
{
mu::rng.setSeed( seed );
Expand Down Expand Up @@ -330,6 +345,7 @@ namespace mu
DefineFun(_T("rint"), Rint);
DefineFun(_T("abs"), Abs);
DefineFun(_T("fmod"), Fmod);
DefineFun(_T("rnd"), Rnd);
DefineFun(_T("rand"), Rand);
DefineFun(_T("rand2"), Rand2);
// Functions with variable number of arguments
Expand Down
4 changes: 2 additions & 2 deletions ksolve/FuncTerm.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#ifndef _FUNC_TERM_H
#define _FUNC_TERM_H

#include "../external/muparser/include/muParser.h"
#include "../builtins/MooseParser.h"

class FuncTerm
{
Expand Down Expand Up @@ -44,7 +44,7 @@ class FuncTerm
double* args_;
// Look up reactants in the S vec.
vector< unsigned int > reactantIndex_;
mu::Parser parser_;
MooseParser parser_;
string expr_;
/**
* Scale factor to account for pool volume if we are assigning conc
Expand Down
Loading