예제 #1
0
/*
 * View Matrix:
 *  RX  RY  RZ  -PX
 *  UX  UY  UZ  -PY
 *  -FX -FY -FZ -PZ
 *  0   0   0   1
 *
 *  First, create the translation matrix (only the position 'P' values).
 *  Then construct the rotation matrix (upper-left 3x3).
 *  The view matrix is V = R * T.
 *  Note that 'up' must be udpated as the camera rotates.
 */
m4 look_at(v3 pos, v3 t_pos, v3 up) {
	m4 t_mat = id4();

	// Apply translation.
	t_mat.m[3] = -pos.v[0];
	t_mat.m[7] = -pos.v[1];
	t_mat.m[11] = -pos.v[2];

	// Find right/forwards/up rotational vectors.
	// Distance from camera to target
	v3 dist = t_pos - pos;
	// Forward vector is pointing towards the target.
	v3 f = normalize(dist);
	// R is F x U.
	v3 r = cross(f, up);
	// Recalculate up as R x F.
	v3 u = cross(r, f);
	// Create rotation matrix.
	m4 r_mat(r.v[0], r.v[1], r.v[2], 0,
			 u.v[0], u.v[1], u.v[2], 0,
			 -f.v[0], -f.v[1], -f.v[2], 0,
			 0, 0, 0, 1);

	// R * T to get the view matrix.
	m4 v_mat = r_mat * t_mat;
	return v_mat;
}
void tst_QOrganizerCollection::idStringFunctions()
{
    // TODO: review test
    QOrganizerCollectionId id1(makeId("a", 1));
    QOrganizerCollectionId id2(makeId("a", 1));
    QOrganizerCollectionId id3(makeId("b", 1));
    QOrganizerCollectionId id4(makeId("a", 2));
    QVERIFY(qHash(id1) == qHash(id2));
    QVERIFY(qHash(id1) != qHash(id4));

    // note that the toString and fromString functions are
    // engine and id specific.  This test merely checks that
    // the API is hooked up correctly.

    QVERIFY(id1.toString() == id2.toString());
    QVERIFY(id1.toString() != id3.toString());
    QVERIFY(id1.toString() != id4.toString());
    QVERIFY(id3.toString() != id4.toString());

    // this should "work" -- string of the correct format
    QString prebuiltidstring = QString("qtorganizer") + QString(":") + QString("a") + QString("::") + QString::number(2);
    QOrganizerCollectionId rebuiltid = QOrganizerCollectionId::fromString(prebuiltidstring);
    // QVERIFY(rebuiltid == id4); // -- this requires a working backend.

    // this string has the right format and one parameter, but requires a working backend
    prebuiltidstring = QString("qtorganizer") + QString(":") + QString("a") + QString(":") + QString("key=value") + QString(":") + QString::number(2);
    rebuiltid = QOrganizerCollectionId::fromString(prebuiltidstring);
    // QVERIFY(rebuiltid == id4); // -- this requires a working backend.

    // this string has the right format and some parameters, but requires a working backend
    prebuiltidstring = QString("qtorganizer") + QString(":") + QString("a") + QString(":") + QString("key=value&key2=value2") + QString(":") + QString::number(2);
    rebuiltid = QOrganizerCollectionId::fromString(prebuiltidstring);
    // QVERIFY(rebuiltid == id4); // -- this requires a working backend.

    // this string has the right format but misses the value for a parameter
    prebuiltidstring = QString("qtorganizer") + QString(":") + QString("a") + QString(":") + QString("key=value&key2=") + QString(":") + QString::number(2);
    rebuiltid = QOrganizerCollectionId::fromString(prebuiltidstring);
    // QVERIFY(rebuiltid == id4); // -- this requires a working backend.

    // this string misses a field (the parameters)
    prebuiltidstring = QString("qtorganizer") + QString(":") + QString("a") + QString(":") + QString::number(2);
    rebuiltid = QOrganizerCollectionId::fromString(prebuiltidstring);
    QVERIFY(rebuiltid == QOrganizerCollectionId()); // invalid so should be null.

    // this string misses two fields (params plus manager uri)
    prebuiltidstring = QString("qtorganizer") + QString(":") + QString::number(2);
    rebuiltid = QOrganizerCollectionId::fromString(prebuiltidstring);
    QVERIFY(rebuiltid == QOrganizerCollectionId()); // invalid so should be null.

    // this string misses the prefix (qtorganizer)
    prebuiltidstring = QString("notorganizer") + QString(":") + QString("a") + QString("::") + QString::number(2);
    rebuiltid = QOrganizerCollectionId::fromString(prebuiltidstring);
    QVERIFY(rebuiltid == QOrganizerCollectionId()); // invalid so should be null.

    // this string misses the manager uri
    prebuiltidstring = QString("notorganizer") + QString(":::") + QString::number(2);
    rebuiltid = QOrganizerCollectionId::fromString(prebuiltidstring);
    QVERIFY(rebuiltid == QOrganizerCollectionId()); // invalid so should be null.
}
예제 #3
0
파일: changes.c 프로젝트: deyaaeldeen/Schml
int64_t u10_run_test(int64_t clos, int64_t i, int64_t acc) { 
  int64_t id1_clos = ((int64_t*)clos)[2];
  int64_t id2_clos = ((int64_t*)clos)[3];
  int64_t id3_clos = ((int64_t*)clos)[4];
  int64_t id4_clos = ((int64_t*)clos)[5];
  int64_t (*id1)(int64_t, int64_t) = 
    (int64_t(*)(int64_t, int64_t)) ((int64_t*) id1_clos)[0];
  int64_t (*id2)(int64_t, int64_t) = 
    (int64_t(*)(int64_t, int64_t)) ((int64_t*) id2_clos)[0];
  int64_t (*id3)(int64_t, int64_t) = 
    (int64_t(*)(int64_t, int64_t)) ((int64_t*) id3_clos)[0];
  int64_t (*id4)(int64_t, int64_t) = 
    (int64_t(*)(int64_t, int64_t)) ((int64_t*) id4_clos)[0];
  int64_t tmp1 = id1(id1_clos, (1 + acc));
  int64_t tmp2 = id2(id2_clos, tmp1);
  int64_t tmp3 = id3(id3_clos, tmp2);
  return id4(id4_clos, tmp3);
}
void tst_QOrganizerCollection::idHash()
{
    // TODO: review tests
    QOrganizerCollectionId id1(makeId(QString(), 1));
    QOrganizerCollectionId id2(makeId(QString(), 1));
    QOrganizerCollectionId id3(makeId(QString(), 2));
    QOrganizerCollectionId id4(makeId("a", 1));
    QVERIFY(qHash(id1) == qHash(id2));
    QVERIFY(qHash(id1) != qHash(id3));
    // note that the hash function is dependent on the id type
    // in BasicCollectionLocalId, the hash function ignores the managerUri.

    QSet<QOrganizerCollectionId> set;
    set.insert(id1);
    set.insert(id2);
    set.insert(id3);
    set.insert(id4);
    QCOMPARE(set.size(), 3);
}
void tst_QOrganizerCollection::idLessThan()
{
    // TODO: review tests
    QOrganizerCollectionId id1(makeId("a", 1));
    QOrganizerCollectionId id2(makeId("a", 1));
    QVERIFY(!(id1 < id2));
    QVERIFY(!(id2 < id1));
    QVERIFY(id1 == id2);
    QOrganizerCollectionId id3(makeId("a", 2));
    QOrganizerCollectionId id4(makeId("b", 1));
    QOrganizerCollectionId id5(makeId(QString(), 2));
    QVERIFY(id1 < id3);
    QVERIFY(!(id3 < id1));
    QVERIFY(id1 < id4);
    QVERIFY(!(id4 < id1));
    QVERIFY(id3 < id4);
    QVERIFY(!(id4 < id3));
    QVERIFY(id5 < id1);
    QVERIFY(!(id1 < id5));
}
예제 #6
0
/*
 * Create a rotation matrix from a quaternion.
 */
m4 quaternion_to_rotation(quat q) {
	m4 mat = id4();
	// 1 - 2y^2 - 2z^2
	mat.m[0] = 1 - 2*q.q[2]*q.q[2] - 2*q.q[3]*q.q[3];
	// 2xy - 2az
	mat.m[1] = 2*q.q[1]*q.q[2] - 2*q.q[0]*q.q[3];
	// 2xz + 2ay
	mat.m[2] = 2*q.q[1]*q.q[3] + 2*q.q[0]*q.q[2];
	// 2xy + 2az
	mat.m[4] = 2*q.q[1]*q.q[2] + 2*q.q[0]*q.q[3];
	// 1 - 2x^2 - 2z^2
	mat.m[5] = 1 - 2*q.q[1]*q.q[1] - 2*q.q[3]*q.q[3];
	// 2yz - 2az
	mat.m[6] = 2*q.q[2]*q.q[3] - 2*q.q[0]*q.q[1];
	// 2xz - 2ay
	mat.m[8] = 2*q.q[1]*q.q[3] - 2*q.q[0]*q.q[2];
	// 2yz + 2ax
	mat.m[9] = 2*q.q[2]*q.q[3] + 2*q.q[0]*q.q[1];
	// 1 - 2x^2 - 2y^2
	mat.m[10] = 1 - 2*q.q[1]*q.q[1] - 2*q.q[2]*q.q[2];

	return mat;
}
void ElasticDamageModel<EvalT, Traits>::
computeState(typename Traits::EvalData workset,
    std::map<std::string, Teuchos::RCP<PHX::MDField<ScalarT>>> dep_fields,
    std::map<std::string, Teuchos::RCP<PHX::MDField<ScalarT>>> eval_fields)
{
  //bool print = false;
  //if (typeid(ScalarT) == typeid(RealType)) print = true;
  //cout.precision(15);

  // extract dependent MDFields
  PHX::MDField<ScalarT> strain = *dep_fields["Strain"];
  PHX::MDField<ScalarT> poissons_ratio = *dep_fields["Poissons Ratio"];
  PHX::MDField<ScalarT> elastic_modulus = *dep_fields["Elastic Modulus"];

  // retrieve appropriate field name strings
  std::string cauchy_string = (*field_name_map_)["Cauchy_Stress"];
  std::string energy_string = (*field_name_map_)["Matrix_Energy"];
  std::string damage_string = (*field_name_map_)["Matrix_Damage"];
  std::string tangent_string = (*field_name_map_)["Material Tangent"];

  // extract evaluated MDFields
  PHX::MDField<ScalarT> stress = *eval_fields[cauchy_string];
  PHX::MDField<ScalarT> energy = *eval_fields[energy_string];
  PHX::MDField<ScalarT> damage = *eval_fields[damage_string];
  PHX::MDField<ScalarT> tangent;
    
  if(compute_tangent_) {
    tangent = *eval_fields[tangent_string];
  }

  // previous state
  Albany::MDArray energy_old =
      (*workset.stateArrayPtr)[energy_string + "_old"];

  ScalarT mu, lame;
  ScalarT alpha, damage_deriv;

  // Define some tensors for use
  Intrepid::Tensor<ScalarT> I(Intrepid::eye<ScalarT>(num_dims_));
  Intrepid::Tensor<ScalarT> epsilon(num_dims_), sigma(num_dims_);

  Intrepid::Tensor4<ScalarT> Ce(num_dims_);
  Intrepid::Tensor4<ScalarT> id4(num_dims_);
  Intrepid::Tensor4<ScalarT> id3(Intrepid::identity_3<ScalarT>(num_dims_));

  id4 = 0.5 * (Intrepid::identity_1<ScalarT>(num_dims_)
      + Intrepid::identity_2<ScalarT>(num_dims_));

  for (int cell = 0; cell < workset.numCells; ++cell) {
    for (int pt = 0; pt < num_pts_; ++pt) {
      // local parameters
      mu = elastic_modulus(cell, pt)
          / (2.0 * (1.0 + poissons_ratio(cell, pt)));
      lame = elastic_modulus(cell, pt) * poissons_ratio(cell, pt)
          / (1.0 + poissons_ratio(cell, pt))
          / (1.0 - 2.0 * poissons_ratio(cell, pt));

      // small strain tensor
      epsilon.fill(strain,cell, pt,0,0);

      // undamaged elasticity tensor
      Ce = lame * id3 + 2.0 * mu * id4;

      // undamaged energy
      energy(cell, pt) =
          0.5 * Intrepid::dotdot(Intrepid::dotdot(epsilon, Ce), epsilon);

      // undamaged Cauchy stress
      sigma = Intrepid::dotdot(Ce, epsilon);

      // maximum thermodynamic force
      alpha = energy_old(cell, pt);
      if (energy(cell, pt) > alpha) alpha = energy(cell, pt);

      // damage term
      damage(cell, pt) = max_damage_
          * (1 - std::exp(-alpha / saturation_));

      // derivative of damage w.r.t alpha
      damage_deriv =
          max_damage_ / saturation_ * std::exp(-alpha / saturation_);

      // tangent for matrix considering damage
      if(compute_tangent_) {
        Ce = (1.0 - damage(cell, pt)) * Ce
          - damage_deriv * Intrepid::tensor(sigma, sigma);
      }

      // total Cauchy stress
      for (int i(0); i < num_dims_; ++i) {
        for (int j(0); j < num_dims_; ++j) {
          stress(cell, pt, i, j) =
              (1.0 - damage(cell, pt)) * sigma(i, j);
        }
      }

      // total tangent
      if(compute_tangent_) {
        for (int i(0); i < num_dims_; ++i) {
          for (int j(0); j < num_dims_; ++j) {
            for (int k(0); k < num_dims_; ++k) {
              for (int l(0); l < num_dims_; ++l) {

                tangent(cell, pt, i, j, k, l) = Ce(i, j, k, l);

              }
            }
          }
        }
      }// compute_tangent_

    } // pt
  } // cell
}
예제 #8
0
파일: main.cpp 프로젝트: lge88/OpenSees
int main(int argc, char **argv)
{
    bool fail = false;

    //
    //	now create a domain and a modelbuilder
    //  and build the model
    //
    FEM_ObjectBroker theBroker;
    Domain *theDomain = new Domain();

    FileDatastore *theDatabase
        = new FileDatastore("/tmp/database/test1",*theDomain,theBroker);
    FileDatastore &theDb = *theDatabase;

    opserr << "TESTING IDs: \n";

    ID id1(2);
    id1(0) = 1;
    id1(1) = 1;
    ID id0(2);
    id0(0) = 0;
    id0(1) = 0;
    ID id2(2);
    id2(0) = 2;
    id2(1) = 2;
    ID id3(2);
    id3(0) = 3;
    id3(1) = 3;
    ID id4(2);
    id4(0) = 4;
    id4(1) = 4;
    ID id5(2);
    id5(0) = 5;
    id5(1) = 5;
    ID id6(2);
    id6(0) = 6;
    id6(1) = 6;


    theDb.sendID(1,1,id1);
    theDb.sendID(1,2,id2);
    theDb.sendID(2,1,id3);
    theDb.sendID(2,2,id4);

    opserr << "RESULTS\n";
    ID recvID(2);
    theDb.recvID(1,1,recvID);
    opserr << "1: " << recvID;
    theDb.recvID(1,2,recvID);
    opserr << "2: " << recvID;
    theDb.recvID(2,1,recvID);
    opserr << "3: " << recvID;
    theDb.recvID(2,2,recvID);
    opserr << "4: " << recvID;

    theDb.sendID(1,1,id1);
    theDb.sendID(3,1,id3);
    theDb.sendID(2,1,id2);


    theDb.sendID(0,1,id0);
    theDb.sendID(1,2,id1);
    theDb.sendID(2,2,id2);
    theDb.sendID(3,1,id3);
    theDb.sendID(5,1,id5);
    theDb.sendID(4,1,id4);
    theDb.sendID(1,1,id1);




    theDb.recvID(3,1,id5);
    opserr << "3: " << id5;
    theDb.recvID(1,1,id5);
    opserr << "1: " << id5;
    theDb.recvID(2,1,id5);

    opserr << "2: " << id5;
    theDb.recvID(1,2,id5);
    opserr << "1: " << id5;
    theDb.recvID(2,2,id5);

    opserr << "3: " << id5;
    theDb.recvID(3,1,id5);
    opserr << "3: " << id5;

    theDb.recvID(4,1,id5);
    opserr << "4: " << id5;
    theDb.recvID(5,1,id5);
    opserr << "5: " << id5;

    opserr << "FAILURE: " << theDb.recvID(6,1,id5) << " returned\n";
    opserr << "FAILURE " <<  theDb.recvID(6,1,id5) << " returned\n";

    theDb.recvID(0,1,id5);
    opserr << "0: " << id5;
    theDb.recvID(5,1,id5);
    opserr << "5: " << id5;

    ID id64(4);
    id64(0) = 6;
    id64(1) = 6;
    id64(2) = 6;
    id64(3) = 6;
    theDb.sendID(6,1,id64);
    theDb.recvID(6,1,id64);
    opserr << id64;


    opserr << "TESTING MATRICES: \n";

    Matrix mat1(2,2);
    mat1(0,0) = 1.1;
    mat1(0,1) = 11.1;
    mat1(1,0) = 111.1;
    mat1(1,1) = 1111.1;

    Matrix mat2(2,2);
    mat2(0,0) = 2.2;
    mat2(0,1) = 22.2;
    mat2(1,0) = 222.2;
    mat2(1,1) = 2222.2;

    theDb.sendMatrix(2,1,mat2);
    theDb.sendMatrix(1,1,mat1);
    theDb.sendMatrix(3,2,mat2);
    theDb.sendMatrix(3,1,mat1);

    Matrix mat3(2,2);
    theDb.recvMatrix(1,1,mat3);
    opserr << mat1 << mat3 << endln;
    theDb.recvMatrix(2,1,mat3);
    opserr << mat2 << mat3 << endln;
    theDb.recvMatrix(3,2,mat3);
    opserr << mat2 << mat3 << endln;
    theDb.recvMatrix(3,1,mat3);
    opserr << mat1 << mat3 << endln;

    //    theDb.sendMatrix(2,1,mat1);
    theDb.recvMatrix(2,1,mat3);
    opserr << mat2 << mat3;



    opserr << "TESTING VECTORS: \n";

    Vector vect1(2);
    vect1(0) = 1.1;
    vect1(1) = 2.22;

    Vector vect2(2);
    vect2(0) = 3;
    vect2(1) = 4.2;

    Vector vect3(2);
    vect3(0) = 5;
    vect3(1) = 6;

    Vector vect4(2);
    vect4(0) = 7;
    vect4(1) = 8.8e12;

    theDb.sendVector(1,1,vect1);
    theDb.sendVector(1,2,vect2);
    theDb.sendVector(2,1,vect3);
    theDb.sendVector(2,2,vect4);

    opserr << "RESULTS\n";
    Vector vect5(2);
    theDb.recvVector(1,1,vect5);
    opserr << vect1 << vect5 << endln;
    theDb.recvVector(1,2,vect5);
    opserr << vect2 << vect5 << endln;
    theDb.recvVector(2,1,vect5);
    opserr << vect3 << vect5 << endln;
    theDb.recvVector(2,2,vect5);
    opserr << vect4 << vect5 << endln;

    theDb.sendVector(2,2,vect1);
    theDb.sendVector(2,1,vect2);
    theDb.sendVector(1,2,vect3);
    theDb.sendVector(1,1,vect4);

    theDb.recvVector(1,1,vect5);
    opserr << vect4 << vect5 << endln;
    theDb.recvVector(1,2,vect5);
    opserr << vect3 << vect5 << endln;
    theDb.recvVector(2,1,vect5);
    opserr << vect2 << vect5 << endln;
    theDb.recvVector(2,2,vect5);
    opserr << vect1 << vect5 << endln;


    theDb.sendVector(4,4,vect5);
    theDb.recvVector(4,4,vect5);
    opserr << vect5 << vect5 << endln;

    theDb.recvVector(5,5,vect5);
    opserr << "FAIL\n";

    theDatabase->commitState(0);

    /*  */

    /*
    theDb.sendID(2,2,id1);
    theDb.sendID(2,1,id2);
    theDb.sendID(1,2,id3);
    theDb.sendID(1,1,id4);

    theDb.recvID(1,1,id5);
    opserr << id5;
    theDb.recvID(1,2,id5);
    opserr << id5;
    theDb.recvID(2,1,id5);
    opserr << id5;
    theDb.recvID(2,2,id5);
    opserr << id5;

    theDb.sendID(4,4,id5);
    theDb.recvID(4,4,id5);
    opserr << id5;

    theDb.recvID(5,5,id5);
    opserr << id5;
    */

    /**************************

    **************************/
    /*

    */

//  theModelBuilder->buildFE_Model();
//  theDb.commitState(0);
//  theDb.restoreState(0);


    // theDb.restoreElements(0);

    /*
    theDb.restoreNode(1,0);
    theDb.restoreNode(2,0);
    theDb.restoreNode(3,0);
    theDb.restoreNode(4,0);
    theDb.restoreElement(0,0);
    theDb.restoreElement(1,0);
    theDb.restoreElement(2,0);
    */

    //  opserr << *theDomain;

    delete theDatabase;

    exit(0);
}