예제 #1
0
#endif
#define _FN0(rt, s, d, f) _FN(SEXP_OP_FCALL0, 0, 0, rt, SEXP_FALSE, SEXP_FALSE, SEXP_FALSE, s, d, f)
#define _FN1(rt, a1, s, d, f) _FN(SEXP_OP_FCALL1, 1, 0, rt, a1, SEXP_FALSE, SEXP_FALSE, s, d, f)
#define _FN1OPT(rt, a1, s, d, f) _FN(SEXP_OP_FCALL1, 0, 1, rt, a1, SEXP_FALSE, SEXP_FALSE, s, d, f)
#define _FN1OPTP(rt, a1, s, d, f) _FN(SEXP_OP_FCALL1, 0, 3, rt, a1, SEXP_FALSE, SEXP_FALSE, s, d, f)
#define _FN2(rt, a1, a2, s, d, f) _FN(SEXP_OP_FCALL2, 2, 0, rt, a1, a2, SEXP_FALSE, s, d, f)
#define _FN2OPT(rt, a1, a2, s, d, f) _FN(SEXP_OP_FCALL2, 1, 1, rt, a1, a2, SEXP_FALSE, s, d, f)
#define _FN2OPTP(rt, a1, a2, s, d, f) _FN(SEXP_OP_FCALL2, 1, 3, rt, a1, a2, SEXP_FALSE, s, d, f)
#define _FN3(rt, a1, a2, a3, s, d, f) _FN(SEXP_OP_FCALL3, 3, 0, rt, a1, a2, a3, s, d, f)
#define _FN3OPT(rt, a1, a2, a3, s, d, f) _FN(SEXP_OP_FCALL3, 2, 1, rt, a1, a2, a3, s, d, f)
#define _FN4(rt, a1, a2, a3, s, d, f) _FN(SEXP_OP_FCALL4, 4, 0, rt, a1, a2, a3, s, d, f)
#define _FN5(rt, a1, a2, a3, s, d, f) _FN(SEXP_OP_FCALLN, 5, 0, rt, a1, a2, a3, s, d, f)
#define _PARAM(n, t) _OP(SEXP_OPC_PARAMETER, SEXP_OP_PARAMETER_REF, 0, 1, t, t, SEXP_FALSE, SEXP_FALSE, 0, n, SEXP_FALSE, 0)

static struct sexp_opcode_struct opcodes[] = {
_PARAM("current-input-port", _I(SEXP_IPORT)),
_PARAM("current-output-port", _I(SEXP_OPORT)),
_PARAM("current-error-port", _I(SEXP_OPORT)),
_PARAM("current-exception-handler", _I(SEXP_PROCEDURE)),
_PARAM("interaction-environment", _I(SEXP_ENV)),
_OP(SEXP_OPC_GETTER, SEXP_OP_CAR, 1, 0, _I(SEXP_OBJECT), _I(SEXP_PAIR), SEXP_FALSE, SEXP_FALSE, 0, "car", 0, NULL),
_OP(SEXP_OPC_SETTER, SEXP_OP_SET_CAR, 2, 0, SEXP_VOID, _I(SEXP_PAIR), _I(SEXP_OBJECT), SEXP_FALSE, 0, "set-car!", 0, NULL),
_OP(SEXP_OPC_GETTER, SEXP_OP_CDR, 1, 0, _I(SEXP_OBJECT), _I(SEXP_PAIR), SEXP_FALSE, SEXP_FALSE, 0, "cdr", 0, NULL),
_OP(SEXP_OPC_SETTER, SEXP_OP_SET_CDR, 2, 0, SEXP_VOID, _I(SEXP_PAIR), _I(SEXP_OBJECT), SEXP_FALSE, 0, "set-cdr!", 0, NULL),
_OP(SEXP_OPC_GETTER, SEXP_OP_VECTOR_REF, 2, 0, _I(SEXP_OBJECT), _I(SEXP_VECTOR), _I(SEXP_FIXNUM), SEXP_FALSE, 0,"vector-ref", 0, NULL),
_OP(SEXP_OPC_SETTER, SEXP_OP_VECTOR_SET, 3, 0, SEXP_VOID, _I(SEXP_VECTOR), _I(SEXP_FIXNUM), _I(SEXP_OBJECT), 0,"vector-set!", 0, NULL),
_OP(SEXP_OPC_GETTER, SEXP_OP_VECTOR_LENGTH, 1, 0, _I(SEXP_FIXNUM), _I(SEXP_VECTOR), SEXP_FALSE, SEXP_FALSE, 0,"vector-length", 0, NULL),
_OP(SEXP_OPC_GETTER, SEXP_OP_BYTES_REF, 2, 0, _I(SEXP_FIXNUM), _I(SEXP_BYTES), _I(SEXP_FIXNUM), SEXP_FALSE, 0,"bytevector-u8-ref", 0, NULL),
_OP(SEXP_OPC_SETTER, SEXP_OP_BYTES_SET, 3, 0, SEXP_VOID, _I(SEXP_BYTES), _I(SEXP_FIXNUM), _I(SEXP_FIXNUM), 0,"bytevector-u8-set!", 0, NULL),
_OP(SEXP_OPC_GETTER, SEXP_OP_BYTES_LENGTH, 1, 0, _I(SEXP_FIXNUM), _I(SEXP_BYTES), SEXP_FALSE, SEXP_FALSE, 0,"bytevector-length", 0, NULL),
#if SEXP_USE_UTF8_STRINGS
예제 #2
0
#endif

#define _FN0(rt, s, d, f) _FN(SEXP_OP_FCALL0, 0, 0, rt, SEXP_FALSE, SEXP_FALSE, SEXP_FALSE, s, d, f)
#define _FN1(rt, a1, s, d, f) _FN(SEXP_OP_FCALL1, 1, 0, rt, a1, SEXP_FALSE, SEXP_FALSE, s, d, f)
#define _FN1OPT(rt, a1, s, d, f) _FN(SEXP_OP_FCALL1, 0, 1, rt, a1, SEXP_FALSE, SEXP_FALSE, s, d, f)
#define _FN1OPTP(rt, a1, s, d, f) _FN(SEXP_OP_FCALL1, 0, 3, rt, a1, SEXP_FALSE, SEXP_FALSE, s, d, f)
#define _FN2(rt, a1, a2, s, d, f) _FN(SEXP_OP_FCALL2, 2, 0, rt, a1, a2, SEXP_FALSE, s, d, f)
#define _FN2OPT(rt, a1, a2, s, d, f) _FN(SEXP_OP_FCALL2, 1, 1, rt, a1, a2, SEXP_FALSE, s, d, f)
#define _FN2OPTP(rt, a1, a2, s, d, f) _FN(SEXP_OP_FCALL2, 1, 3, rt, a1, a2, SEXP_FALSE, s, d, f)
#define _FN3(rt, a1, a2, a3, s, d, f) _FN(SEXP_OP_FCALL3, 3, 0, rt, a1, a2, a3, s, d, f)
#define _FN3OPT(rt, a1, a2, a3, s, d, f) _FN(SEXP_OP_FCALL3, 2, 1, rt, a1, a2, a3, s, d, f)
#define _FN4(rt, a1, a2, a3, s, d, f) _FN(SEXP_OP_FCALL4, 4, 0, rt, a1, a2, a3, s, d, f)
#define _FN5(rt, a1, a2, a3, s, d, f) _FN(SEXP_OP_FCALLN, 5, 0, rt, a1, a2, a3, s, d, f)

static struct sexp_opcode_struct opcodes[] = {
_PARAM("current-input-port", _I(SEXP_IPORT)),
_PARAM("current-output-port", _I(SEXP_OPORT)),
_PARAM("current-error-port", _I(SEXP_OPORT)),
_PARAM("current-exception-handler", _I(SEXP_PROCEDURE)),
_PARAM("interaction-environment", _I(SEXP_ENV)),
_PARAM("current-usage-environment", _I(SEXP_ENV)),
_PARAM("current-transformer-environment", _I(SEXP_ENV)),
_PARAM("current-renamer", _I(SEXP_PROCEDURE)),
_PARAM("command-line", SEXP_NULL),
_OP(SEXP_OPC_GETTER, SEXP_OP_CAR, 1, 0, _I(SEXP_OBJECT), _I(SEXP_PAIR), SEXP_FALSE, SEXP_FALSE, 0, "car", 0, NULL),
_OP(SEXP_OPC_SETTER, SEXP_OP_SET_CAR, 2, 0, SEXP_VOID, _I(SEXP_PAIR), _I(SEXP_OBJECT), SEXP_FALSE, 0, "set-car!", 0, NULL),
_OP(SEXP_OPC_GETTER, SEXP_OP_CDR, 1, 0, _I(SEXP_OBJECT), _I(SEXP_PAIR), SEXP_FALSE, SEXP_FALSE, 0, "cdr", 0, NULL),
_OP(SEXP_OPC_SETTER, SEXP_OP_SET_CDR, 2, 0, SEXP_VOID, _I(SEXP_PAIR), _I(SEXP_OBJECT), SEXP_FALSE, 0, "set-cdr!", 0, NULL),
_GETTER("pair-source", SEXP_PAIR, 2),
_SETTER("pair-source-set!", SEXP_PAIR, 2),
_GETTER("syntactic-closure-rename", SEXP_SYNCLO, 3),
void GrDiffusionWrongBTCS::diffuse(GrSimulationGrid&, const int time) const
{
  std::cerr << " GrDiffusionWrongBTCS::diffuse no longer supported: not updated for grid swapping or mac attractant" << std::endl;
  exit(1);

#if 0
  GrGrid& grid = simGrid.getGrid();

  const double muTNF = _PARAM(_diffusivityTNF) * 6 / (4e-6);
  const double muChemokines = _PARAM(_diffusivityChemokines) * 6 / (4e-6);
  const double degTNF = _PARAM(_degRateTNF);
  const double degChemokines = _PARAM(_degRateChemokines);
  const double dAttractant = _PARAM(_dAttractant);
  const double ok = 0.001; // allowable error for good enough convergence

  // we have to use the heap here, since oldGrid does not fit in the stack
  GrGrid* pOldGrid = (GrGrid*) malloc(sizeof(GrGrid));

  double errTNF = 2 * ok;
  double errCCL2 = 2 * ok;
  double errCCL5 = 2 * ok;
  double errCXCL9 = 2 * ok;

  // dt = 6s, solve for 10 minutes = 100 * 6 seconds
  for (int t = 0; t < 100; t++)
    {
      for (int i = 0; i < NROWS; i++)
        {
          for (int j = 0; j < NCOLS; j++)
            {
              GridCell& cell = grid(i, j);

              // secrete
              Agent* pAgent = cell.getAgent(0);
              if (pAgent)
                {
                  printf("SEC (%d,%d)\n", i, j);
                  pAgent->secrete(grid, false);
                }

              pAgent = cell.getAgent(1);
              if (pAgent)
                {
                  printf("SEC (%d,%d)\n", i, j);
                  pAgent->secrete(grid, false);
                }

              if (cell.isCaseated())
                cell.incMacAttractant(dAttractant);
            }
        }

      // update pOldGrid
      memcpy(pOldGrid, &grid, sizeof(GrGrid));

      for (int k = 0; k < 100 && (errTNF > ok || errCCL2 > ok || errCCL5 > ok || errCXCL9 > ok);  k++)
        {
          double localErrTNF = 0, localErrCCL2 = 0, localErrCCL5 = 0, localErrCXCL9 = 0;
          for (int i = NROWS - 1; i >= 0; i--)
            {
              for (int j = NCOLS - 1; j >= 0; j--)
                {
                  GridCell& oldCell = (*pOldGrid)(i, j);
                  GridCell& cell = grid(i, j);
                  GridCell& cell_i_min_1_j = (i > 0) ? (*pOldGrid)(i - 1, j) : cell;
                  GridCell& cell_i_plus_1_j =  (i < NROWS - 1) ? (*pOldGrid)(i + 1, j) : cell;
                  GridCell& cell_i_j_min_1 = (j > 0) ? (*pOldGrid)(i, j - 1) : cell;
                  GridCell& cell_i_j_plus_1 = (j < NCOLS - 1) ? (*pOldGrid)(i, j + 1) : cell;

                  if (errTNF > ok)
                    {
                      double tnf_i_j_old = oldCell.getTNF();
                      double tnf_i_j = cell.getTNF();
                      double tnf_i_min_1_j = (i > 0) ? cell_i_min_1_j.getTNF() : 0;
                      double tnf_i_plus_1_j = (i < NROWS - 1) ? cell_i_plus_1_j.getTNF() : 0;
                      double tnf_i_j_min_1 = (j > 0) ? cell_i_j_min_1.getTNF() : 0;
                      double tnf_i_j_plus_1 = (j < NCOLS - 1) ? cell_i_j_plus_1.getTNF() : 0;

                      double res = tnf_i_j_old - (muTNF + 1) * tnf_i_j +
                                   0.25 * muTNF * (tnf_i_min_1_j + tnf_i_plus_1_j + tnf_i_j_min_1 + tnf_i_j_plus_1);
                      grid(i, j).incTNF(res);

                      localErrTNF += fabs(res);
                    }
                  if (errCCL2 > ok)
                    {
                      double ccl2_i_j_old = oldCell.getCCL2();
                      double ccl2_i_j = cell.getCCL2();
                      double ccl2_i_min_1_j = (i > 0) ? cell_i_min_1_j.getCCL2() : 0;
                      double ccl2_i_plus_1_j = (i < NROWS - 1) ? cell_i_plus_1_j.getCCL2() : 0;
                      double ccl2_i_j_min_1 = (j > 0) ? cell_i_j_min_1.getCCL2() : 0;
                      double ccl2_i_j_plus_1 = (j < NCOLS - 1) ? cell_i_j_plus_1.getCCL2() : 0;

                      double res = ccl2_i_j_old - (muChemokines + 1) * ccl2_i_j +
                                   0.25 * muChemokines * (ccl2_i_min_1_j + ccl2_i_plus_1_j + ccl2_i_j_min_1 + ccl2_i_j_plus_1);
                      grid(i, j).incCCL2(res);

                      localErrCCL2 += fabs(res);
                    }
                  if (errCCL5 > ok)
                    {
                      double ccl5_i_j_old = oldCell.getCCL5();
                      double ccl5_i_j = cell.getCCL5();
                      double ccl5_i_min_1_j = (i > 0) ? cell_i_min_1_j.getCCL5() : 0;
                      double ccl5_i_plus_1_j = (i < NROWS - 1) ? cell_i_plus_1_j.getCCL5() : 0;
                      double ccl5_i_j_min_1 = (j > 0) ? cell_i_j_min_1.getCCL5() : 0;
                      double ccl5_i_j_plus_1 = (j < NCOLS - 1) ? cell_i_j_plus_1.getCCL5() : 0;

                      double res = ccl5_i_j_old - (muChemokines + 1) * ccl5_i_j +
                                   0.25 * muChemokines * (ccl5_i_min_1_j + ccl5_i_plus_1_j + ccl5_i_j_min_1 + ccl5_i_j_plus_1);
                      grid(i, j).incCCL5(res);

                      localErrCCL5 += fabs(res);
                    }
                  if (errCXCL9 > ok)
                    {
                      double cxcl9_i_j_old = oldCell.getCXCL9();
                      double cxcl9_i_j = cell.getCXCL9();
                      double cxcl9_i_min_1_j = (i > 0) ? cell_i_min_1_j.getCXCL9() : 0;
                      double cxcl9_i_plus_1_j = (i < NROWS - 1) ? cell_i_plus_1_j.getCXCL9() : 0;
                      double cxcl9_i_j_min_1 = (j > 0) ? cell_i_j_min_1.getCXCL9() : 0;
                      double cxcl9_i_j_plus_1 = (j < NCOLS - 1) ? cell_i_j_plus_1.getCXCL9() : 0;

                      double res = cxcl9_i_j_old - (muChemokines + 1) * cxcl9_i_j +
                                   0.25 * muChemokines * (cxcl9_i_min_1_j + cxcl9_i_plus_1_j + cxcl9_i_j_min_1 + cxcl9_i_j_plus_1);
                      grid(i, j).incCXCL9(res);

                      localErrCXCL9 += fabs(res);
                    }
                }	/* j, columns */
            }	/*i, rows */

          errTNF = localErrTNF;
          errCCL2 = localErrCCL2;
          errCCL5 = localErrCCL5;
          errCXCL9 = localErrCXCL9;
        }	/* k, #iterations */

      // update _oldGrid, and compute degradation
      for (int i = 0; i < NROWS; i++)
        {
          for (int j = 0; j < NCOLS; j++)
            {
              GridCell& cell = grid(i, j);
              cell.setTNF(cell.getTNF() * degTNF);
              cell.setCCL2(cell.getCCL2() * degChemokines);
              cell.setCCL5(cell.getCCL5() * degChemokines);
              cell.setCXCL9(cell.getCXCL9() * degChemokines);
            }
        }
    }	/* t, timesteps */

  //delete pOldGrid;
  free(pOldGrid);
#endif
}