[cig-commits] r14084 - cs/cigma/trunk/src
luis at geodynamics.org
luis at geodynamics.org
Wed Feb 18 08:14:38 PST 2009
Author: luis
Date: 2009-02-18 08:14:38 -0800 (Wed, 18 Feb 2009)
New Revision: 14084
Modified:
cs/cigma/trunk/src/Field.h
cs/cigma/trunk/src/Function.cpp
cs/cigma/trunk/src/Function.h
cs/cigma/trunk/src/fn_disloc3d.cpp
cs/cigma/trunk/src/fn_disloc3d.h
cs/cigma/trunk/src/fn_explicit.h
cs/cigma/trunk/src/fn_gale2.h
cs/cigma/trunk/src/fn_one.cpp
cs/cigma/trunk/src/fn_one.h
cs/cigma/trunk/src/fn_test.h
cs/cigma/trunk/src/fn_zero.h
Log:
Added Function::init() virtual method to defer initialization
Modified: cs/cigma/trunk/src/Field.h
===================================================================
--- cs/cigma/trunk/src/Field.h 2009-02-18 16:14:36 UTC (rev 14083)
+++ cs/cigma/trunk/src/Field.h 2009-02-18 16:14:38 UTC (rev 14084)
@@ -24,12 +24,16 @@
int n_dim() const;
int n_rank() const;
+
bool eval(double *point, double *value);
- inline Function::type getType() const { return FIELD_FN; }
+ // XXX: move following two methods to a common BaseFunction class
+ // although, we'll have to override getType() here (to return FieldType)
+ void init() { }
+ inline FunctionType getType() const { return Function::FieldType; }
// XXX: move this method to DofHandler class
- void getCellDofs(int cellIndex, double *cellDofs); // XXX: move method to DofHandler
+ void getCellDofs(int cellIndex, double *cellDofs);
/* direct setters */
void setMesh(const boost::shared_ptr<MeshPart> mesh);
Modified: cs/cigma/trunk/src/Function.cpp
===================================================================
--- cs/cigma/trunk/src/Function.cpp 2009-02-18 16:14:36 UTC (rev 14083)
+++ cs/cigma/trunk/src/Function.cpp 2009-02-18 16:14:38 UTC (rev 14084)
@@ -1,11 +1,11 @@
#include "Function.h"
#include "FunctionRegistry.h"
#include "tri_logger.hpp"
-#include "fn_zero.h"
#include "Field.h"
#include "Exception.h"
#include <string>
#include <sstream>
+
using namespace std;
using namespace cigma;
using boost::shared_ptr;
@@ -25,13 +25,11 @@
TRI_LOG_STR("Function::NewFunction()");
TRI_LOG(fn_info);
+ const char* source = fn_info.fn_name.c_str();
+ const bool fn_exists = global_function_registry.hasFunction(source);
shared_ptr<Function> fn;
- const char* source = fn_info.fn_name.c_str();
-
- const bool fn_exists = global_function_registry.hasFunction(source);
-
if (fn_exists)
{
fn = global_function_registry.getFunction(source);
@@ -48,6 +46,12 @@
fn = field;
}
+ if (fn)
+ {
+ // Give the new function object a chance to initialize itself.
+ fn->init();
+ }
+
return fn;
}
Modified: cs/cigma/trunk/src/Function.h
===================================================================
--- cs/cigma/trunk/src/Function.h 2009-02-18 16:14:36 UTC (rev 14083)
+++ cs/cigma/trunk/src/Function.h 2009-02-18 16:14:38 UTC (rev 14084)
@@ -15,20 +15,24 @@
Function();
virtual ~Function();
+ /* initialize */
+ virtual void init() = 0;
+
/* call interface (raw) */
virtual int n_dim() const = 0;
virtual int n_rank() const = 0;
virtual bool eval(double *point, double *value) = 0;
/* Function type for dispatch */
- typedef enum
+ enum FunctionType
{
- GENERAL_FN = 0,
- FIELD_FN = 1,
- POINTWISE_FN = 2
- } type;
- virtual type getType() const = 0;
+ GeneralType = 0,
+ FieldType = 1,
+ PointwiseType = 2
+ };
+ virtual FunctionType getType() const = 0;
+
/* static factory methods */
static boost::shared_ptr<Function> New(std::string fn_name);
static boost::shared_ptr<Function> NewFunction(const FunctionInfo& fn_info);
Modified: cs/cigma/trunk/src/fn_disloc3d.cpp
===================================================================
--- cs/cigma/trunk/src/fn_disloc3d.cpp 2009-02-18 16:14:36 UTC (rev 14083)
+++ cs/cigma/trunk/src/fn_disloc3d.cpp 2009-02-18 16:14:38 UTC (rev 14084)
@@ -8,6 +8,14 @@
strikeslipnog::OkadaDisloc3d::OkadaDisloc3d()
{
+}
+
+strikeslipnog::OkadaDisloc3d::~OkadaDisloc3d()
+{
+}
+
+void strikeslipnog::OkadaDisloc3d::init()
+{
// elastic parameters
mu = 0.25;
nu = 0.25;
@@ -66,10 +74,6 @@
getM(&subfaults[0], nsubfaults, mu, &models[0]);
}
-strikeslipnog::OkadaDisloc3d::~OkadaDisloc3d()
-{
-}
-
bool strikeslipnog::OkadaDisloc3d::eval(double *station, double *disloc)
{
double flag = -1;
Modified: cs/cigma/trunk/src/fn_disloc3d.h
===================================================================
--- cs/cigma/trunk/src/fn_disloc3d.h 2009-02-18 16:14:36 UTC (rev 14083)
+++ cs/cigma/trunk/src/fn_disloc3d.h 2009-02-18 16:14:38 UTC (rev 14084)
@@ -27,11 +27,11 @@
OkadaDisloc3d();
~OkadaDisloc3d();
+ virtual void init();
virtual inline int n_dim() const { return 3; }
virtual inline int n_rank() const { return 3; }
- virtual inline Function::type getType() const { return GENERAL_FN; }
-
virtual bool eval(double *station, double *disloc);
+ virtual inline FunctionType getType() const { return Function::GeneralType; }
public:
double mu, nu;
Modified: cs/cigma/trunk/src/fn_explicit.h
===================================================================
--- cs/cigma/trunk/src/fn_explicit.h 2009-02-18 16:14:36 UTC (rev 14083)
+++ cs/cigma/trunk/src/fn_explicit.h 2009-02-18 16:14:38 UTC (rev 14084)
@@ -19,7 +19,8 @@
int n_rank() const;
bool eval(double *point, double *value);
- Function::type getType() const;
+ void init() { }
+ FunctionType getType() const { return Function::PointwiseType; }
bool getPoint(int i, double *point) const;
bool getValue(int i, double *value) const;
@@ -39,10 +40,4 @@
return values.n_dim();
}
-inline cigma::Function::type cigma::ExplicitFn::getType() const
-{
- return cigma::Function::POINTWISE_FN;
-}
-
-
#endif
Modified: cs/cigma/trunk/src/fn_gale2.h
===================================================================
--- cs/cigma/trunk/src/fn_gale2.h 2009-02-18 16:14:36 UTC (rev 14083)
+++ cs/cigma/trunk/src/fn_gale2.h 2009-02-18 16:14:38 UTC (rev 14084)
@@ -14,16 +14,15 @@
class benchmark::circular_inclusion::Pressure : public cigma::Function
{
public:
-
Pressure();
~Pressure();
-
+
virtual int n_dim() const { return 2; }
virtual int n_rank() const { return 1; }
- virtual Function::type getType() const { return GENERAL_FN; }
-
virtual bool eval(double *x, double *value);
+ virtual void init() { }
+ virtual FunctionType getType() const { return Function::GeneralType; }
};
#endif
Modified: cs/cigma/trunk/src/fn_one.cpp
===================================================================
--- cs/cigma/trunk/src/fn_one.cpp 2009-02-18 16:14:36 UTC (rev 14083)
+++ cs/cigma/trunk/src/fn_one.cpp 2009-02-18 16:14:38 UTC (rev 14084)
@@ -3,7 +3,7 @@
UnitScalarFn::UnitScalarFn()
{
- dim = 0;
+ dim = 1;
}
UnitScalarFn::~UnitScalarFn()
Modified: cs/cigma/trunk/src/fn_one.h
===================================================================
--- cs/cigma/trunk/src/fn_one.h 2009-02-18 16:14:36 UTC (rev 14083)
+++ cs/cigma/trunk/src/fn_one.h 2009-02-18 16:14:38 UTC (rev 14084)
@@ -20,7 +20,8 @@
bool eval(double *point, double *value);
- inline Function::type getType() const { return GENERAL_FN; }
+ void init() { }
+ inline FunctionType getType() const { return Function::GeneralType; }
void setDim(int dim);
Modified: cs/cigma/trunk/src/fn_test.h
===================================================================
--- cs/cigma/trunk/src/fn_test.h 2009-02-18 16:14:36 UTC (rev 14083)
+++ cs/cigma/trunk/src/fn_test.h 2009-02-18 16:14:38 UTC (rev 14084)
@@ -19,10 +19,11 @@
inline int n_dim() const { return 3; }
inline int n_rank() const { return 1; }
- inline type getType() const { return GENERAL_FN; }
-
bool eval(double *point, double *value);
+ void init() { }
+ inline FunctionType getType() const { return Function::GeneralType; }
+
};
@@ -35,10 +36,11 @@
inline int n_dim() const { return 2; }
inline int n_rank() const { return 1; }
- inline type getType() const { return GENERAL_FN; }
bool eval(double *point, double *value);
+ void init() { }
+ inline FunctionType getType() const { return Function::GeneralType; }
};
#endif
Modified: cs/cigma/trunk/src/fn_zero.h
===================================================================
--- cs/cigma/trunk/src/fn_zero.h 2009-02-18 16:14:36 UTC (rev 14083)
+++ cs/cigma/trunk/src/fn_zero.h 2009-02-18 16:14:38 UTC (rev 14084)
@@ -19,7 +19,8 @@
bool eval(double *point, double *value);
- inline Function::type getType() const { return GENERAL_FN; }
+ void init() { }
+ inline FunctionType getType() const { return Function::GeneralType; }
void setShape(int dim, int rank);
More information about the CIG-COMMITS
mailing list