Modifying the example N. 1 (C++ source code without TCL)

For developers writing C++, Fortran, Java, code who have questions or comments to make.

Moderators: silvia, selimgunay, Moderators

Post Reply
carlos
Posts: 23
Joined: Fri May 05, 2006 8:30 am
Location: Universidad Pais Vasco

Modifying the example N. 1 (C++ source code without TCL)

Post by carlos »

Hello Frank,

First of all, thank you for the Opensees workshop. It was very interesting and useful

I’m trying to modify the example supplied with the source code (\examples\examples1\main.cpp). I want to replace the truss element by the elasticbeamcolumn element. I already have introduced the new element type with the PDelta transformation. I use Microsoft Studio 2003.

The problem now is that I’m trying to introduce the test energy and when the the file CTestEnergyIncr.h is included, the compiler gives the following errors:

Compiling...
main.cpp
c:\OpenSees\SRC\convergenceTest\ConvergenceTest.h(48) : warning C4822: 'main::ConvergenceTest::ConvergenceTest' : local class member function does not have a body
c:\OpenSees\SRC\convergenceTest\ConvergenceTest.h(49) : warning C4822: 'main::ConvergenceTest::~ConvergenceTest' : local class member function does not have a body
c:\OpenSees\SRC\convergenceTest\CTestEnergyIncr.h(47) : warning C4822: 'main::CTestEnergyIncr::CTestEnergyIncr' : local class member function does not have a body
c:\OpenSees\SRC\convergenceTest\CTestEnergyIncr.h(48) : warning C4822: 'main::CTestEnergyIncr::CTestEnergyIncr' : local class member function does not have a body
c:\OpenSees\SRC\convergenceTest\CTestEnergyIncr.h(51) : warning C4822: 'main::CTestEnergyIncr::~CTestEnergyIncr' : local class member function does not have a body
c:\OpenSees\SRC\convergenceTest\CTestEnergyIncr.h(53) : warning C4822: 'main::CTestEnergyIncr::getCopy' : local class member function does not have a body
c:\OpenSees\SRC\convergenceTest\CTestEnergyIncr.h(55) : warning C4822: 'main::CTestEnergyIncr::setTolerance' : local class member function does not have a body
c:\OpenSees\SRC\convergenceTest\CTestEnergyIncr.h(56) : warning C4822: 'main::CTestEnergyIncr::setEquiSolnAlgo' : local class member function does not have a body
c:\OpenSees\SRC\convergenceTest\CTestEnergyIncr.h(58) : warning C4822: 'main::CTestEnergyIncr::test' : local class member function does not have a body
c:\OpenSees\SRC\convergenceTest\CTestEnergyIncr.h(59) : warning C4822: 'main::CTestEnergyIncr::start' : local class member function does not have a body
c:\OpenSees\SRC\convergenceTest\CTestEnergyIncr.h(61) : warning C4822: 'main::CTestEnergyIncr::getNumTests' : local class member function does not have a body
c:\OpenSees\SRC\convergenceTest\CTestEnergyIncr.h(62) : warning C4822: 'main::CTestEnergyIncr::getMaxNumTests' : local class member function does not have a body
c:\OpenSees\SRC\convergenceTest\CTestEnergyIncr.h(63) : warning C4822: 'main::CTestEnergyIncr::getRatioNumToMax' : local class member function does not have a body
c:\OpenSees\SRC\convergenceTest\CTestEnergyIncr.h(64) : warning C4822: 'main::CTestEnergyIncr::getNorms' : local class member function does not have a body
c:\OpenSees\SRC\convergenceTest\CTestEnergyIncr.h(66) : warning C4822: 'main::CTestEnergyIncr::sendSelf' : local class member function does not have a body
c:\OpenSees\SRC\convergenceTest\CTestEnergyIncr.h(67) : warning C4822: 'main::CTestEnergyIncr::recvSelf' : local class member function does not have a body
c:\OpenSees\EXAMPLES\Example1\main.cpp(303) : error C2440: 'initializing' : cannot convert from 'Linear *' to 'main::EquiSolnAlgo *'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
c:\OpenSees\EXAMPLES\Example1\main.cpp(309) : error C2440: 'initializing' : cannot convert from 'BandSPDLinSOE *' to 'main::LinearSOE *'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
c:\OpenSees\EXAMPLES\Example1\main.cpp(317) : error C2664: 'StaticAnalysis::StaticAnalysis(Domain &,ConstraintHandler &,DOF_Numberer &,AnalysisModel &,EquiSolnAlgo &,LinearSOE &,StaticIntegrator &,ConvergenceTest *)' : cannot convert parameter 5 from 'main::EquiSolnAlgo' to 'EquiSolnAlgo &'
A reference that is not to 'const' cannot be bound to a non-lvalue


These errors dissapear if the references to the test energy are removed.

I use Opensees V1.7.1 and I’m able to compile and run it without any problems with TCL scripts.

Could you please give some ideas. I have also tried to include a recorder but the compiler gives the same type of errors.



Best regards,

Carlos
carlos
Posts: 23
Joined: Fri May 05, 2006 8:30 am
Location: Universidad Pais Vasco

Post by carlos »

Hello,

I have success now. It was my fault as I had not built completely the project.

Thanks,

Carlos
carlos
Posts: 23
Joined: Fri May 05, 2006 8:30 am
Location: Universidad Pais Vasco

Post by carlos »

Hello Again,

After some work, I have modified the example for working with an elasticbeamcolumn.

I use a PDelta transformation for it. Now I'm trying to use a Corotational transformation but I'm not able do to it.

If in the source code attached I uncomment the line:
//crdTransf3d = new CorotCrdTransf3d(crdTransfTag, vecxzPlane, jntOffsetI, jntOffsetJ);

then, I compiles, but during building microsoft studio gives the following error:

error LNK2019: unresolved external symbol "public: __thiscall CorotCrdTransf3d::CorotCrdTransf3d(int,class Vector const &,class Vector const &,class Vector const &)" (??0CorotCrdTransf3d@@QAE@HABVVector@@00@Z) referenced in function _main
.\..\..\bin/quickMain.exe : fatal error LNK1120: 1 unresolved externals


I have not found the file <CorotCrdTransf3d.cpp> on the source code released with Version 1.7.1 nor on the web page. ¿Do I need this file?. It is quite strange as if I build opensees.exe it works with the Corotational Transformation (running from TCL).

Could you please give some advice about this matter?.

Regards,

Carlos



#include <OPS_Globals.h>
#include <StandardStream.h>

#include <ArrayOfTaggedObjects.h>

// includes for the domain classes
#include <Domain.h>
#include <Node.h>
#include <Truss.h>
#include <ElasticMaterial.h>
#include <SP_Constraint.h>
#include <LoadPattern.h>
#include <LinearSeries.h>
#include <NodalLoad.h>

// includes for the analysis classes
#include <StaticAnalysis.h>
#include <AnalysisModel.h>
#include <Linear.h>
#include <NewtonRaphson.h>

#include <PenaltyConstraintHandler.h>
#include <TransformationConstraintHandler.h>
#include <DOF_Numberer.h>
#include <RCM.h>
#include <LoadControl.h>
#include <BandSPDLinSOE.h>
#include <BandSPDLinLapackSolver.h>
#include <SymSparseLinSolver.h>
# include <SymSparseLinSOE.h>

# include <DataOutputHandler.h>
# include <DataOutputFileHandler.h>
#include <NodeRecorder.h>
#include <Recorder.h>
#include <string.h>

#include <movableobject.h>
#include <taggedobject.h>
#include <crdtransf.h>
#include <crdtransf2d.h>
#include <corotcrdtransf2d.h>
#include <CorotCrdTransf3d.h>
#include <PDeltaCrdTransf2d.h>
#include <PDeltaCrdTransf3d.h>
#include <Domain.h>
#include <CTestEnergyIncr.h>

#include <C:\OpenSees\SRC\element\elasticBeamColumn\ElasticBeam2d.h>
#include <C:\OpenSees\SRC\element\elasticBeamColumn\ElasticBeam3d.h>



#include <Domain.h>

#include <tcl.h>
#include <tk.h>

#include <stdio.h>
#include <string.h>

// init the global variabled defined in OPS_Globals.h
StandardStream sserr;
OPS_Stream *opserrPtr = &sserr;

double ops_Dt = 0;
Domain *ops_TheActiveDomain = 0;
Element *ops_TheActiveElement = 0;

Element *theBeam = 0;

// main routine
int main(int argc, char **argv)
{
//
// now create a domain and a modelbuilder
// and build the model
//
Domain *theDomain = new Domain();



Node *node1 = new Node(1,6,0.0,0.0,0.0);
theDomain->addNode(node1);
Node *node2 = new Node(2,6,3.0,0.0,0.0);
theDomain->addNode(node2);


Vector vecxzPlane(3); // vector that defines local xz plane
Vector jntOffsetI(3), jntOffsetJ(3); // joint offsets in global coordinates

vecxzPlane[0]=0;
vecxzPlane[1]=1;
vecxzPlane[2]=0;

int crdTransfTag;
PDeltaCrdTransf3d *crdTransf3d_2;
CorotCrdTransf3d *crdTransf3d;

crdTransfTag=1; //Transformacion

// crdTransf3d = new CorotCrdTransf3d(crdTransfTag, vecxzPlane, jntOffsetI, jntOffsetJ);
crdTransf3d_2 = new PDeltaCrdTransf3d(crdTransfTag, vecxzPlane, jntOffsetI, jntOffsetJ);

theBeam = new ElasticBeam3d ( 1,
0.0005 ,
2.100E+11,
8.100E+10,
0.0002 ,
0.0001 ,
0.0001 ,
1 ,
2,
*crdTransf3d_2);
theDomain->addElement(theBeam);



// SP_Constraint *theSP = new SP_Constraint(currentSpTag, nodeId, i, 0.0);

SP_Constraint *sp1 = new SP_Constraint(0, 1, 0, 0.0);
SP_Constraint *sp2 = new SP_Constraint(1, 1, 1, 0.0);
SP_Constraint *sp3 = new SP_Constraint(2, 1, 2, 0.0);
SP_Constraint *sp4 = new SP_Constraint(3, 1, 3, 0.0);
SP_Constraint *sp5 = new SP_Constraint(4, 1, 4, 0.0);
SP_Constraint *sp6 = new SP_Constraint(5, 1, 5, 0.0);
theDomain->addSP_Constraint(sp1);
theDomain->addSP_Constraint(sp2);
theDomain->addSP_Constraint(sp3);
theDomain->addSP_Constraint(sp4);
theDomain->addSP_Constraint(sp5);
theDomain->addSP_Constraint(sp6);


// construct a linear time series object using constructor:
// LinearSeries()

TimeSeries *theSeries = new LinearSeries();

// construct a load pattren using constructor:
// LoadPattern(tag)
// and then set it's TimeSeries and add it to the domain

LoadPattern *theLoadPattern = new LoadPattern(1);
theLoadPattern->setTimeSeries(theSeries);
theDomain->addLoadPattern(theLoadPattern);

// construct a nodal load using constructor:
// NodalLoad(tag, nodeID, Vector &)
// first construct a Vector of size 2 and set the values NOTE C INDEXING
// then construct the load and add it to the domain

Vector theLoadValues(6);
theLoadValues(0) = -1000.0;
theLoadValues(1) = -1000.0;
theLoadValues(2) = -1000.0;
theLoadValues(3) = 0;
theLoadValues(4) = 0;
theLoadValues(5) = 0;

NodalLoad *theLoad = new NodalLoad(1, 2, theLoadValues);
theDomain->addNodalLoad(theLoad, 1);

// create an Analysis object to perform a static analysis of the model
// - constructs:
// AnalysisModel of type AnalysisModel,
// EquiSolnAlgo of type Linear
// StaticIntegrator of type LoadControl
// ConstraintHandler of type Penalty
// DOF_Numberer which uses RCM
// LinearSOE of type Band SPD
// and then the StaticAnalysis object


ConvergenceTest *theNewTest = 0;
theNewTest = new CTestEnergyIncr(1.0e-16,20,1,2);

char fileName[300];
strcpy(fileName,"c:\\pruebas\\salida.txt");

DataOutputHandler *theDataOutputHandler = 0;
theDataOutputHandler = new DataOutputFileHandler(fileName, DATA_FILE);


ID theNodes(0,16);
ID theDofs(0, 6);

theNodes[0]=1;
theNodes[1]=2;
theDofs[0]=0;
theDofs[1]=1;
theDofs[2]=2;
theDofs[3]=3;
theDofs[4]=4;
theDofs[5]=5;

char responseID[300];
strcpy(responseID,"disp");
bool echoTimeFlag = true;
// TCL_Char *responseID;

NodeRecorder *theRecorder=0;
// (*theRecorder) = new NodeRecorder(theDofs,
// theNodes,
// sensitivity,
// responseID,
// theDomain,
// *theDataOutputHandler,
// dT,
// echoTimeFlag);
theRecorder = new NodeRecorder(theDofs,
theNodes,
0,
responseID,
*theDomain,
*theDataOutputHandler,
0,
echoTimeFlag);
if ((theRecorder == 0) || (theDomain->addRecorder(*theRecorder)) < 0) {
opserr << "WARNING could not add to domain - recorder " << argv[1]<< endln;
if (theRecorder == 0)
opserr << "could not create recorder\n";
else
delete theRecorder;
}

AnalysisModel *theModel = new AnalysisModel();
EquiSolnAlgo *theSolnAlgo = new NewtonRaphson();
StaticIntegrator *theIntegrator = new LoadControl(0.1, 1, 0.1, 0.1);
ConstraintHandler *theHandler = new TransformationConstraintHandler();
RCM *theRCM = new RCM();
DOF_Numberer *theNumberer = new DOF_Numberer(*theRCM);

int lSparse = 1;

SymSparseLinSolver *theSolver = new SymSparseLinSolver();
LinearSOE *theSOE = new SymSparseLinSOE(*theSolver, lSparse);

// BandSPDLinSolver *theSolver = new BandSPDLinLapackSolver();
// LinearSOE *theSOE = new BandSPDLinSOE(*theSolver);

StaticAnalysis theAnalysis(*theDomain,
*theHandler,
*theNumberer,
*theModel,
*theSolnAlgo,
*theSOE,
*theIntegrator,
theNewTest
);

// perform the analysis & print out the results for the domain
int numSteps = 20;
theAnalysis.analyze(numSteps);
// theAnalysis.analyze(numSteps);
opserr << *theDomain;

exit(0);
}
fmk
Site Admin
Posts: 5884
Joined: Fri Jun 11, 2004 2:33 pm
Location: UC Berkeley
Contact:

Post by fmk »

carlos,

am afraid youare out of luck there .. the corotational scource code has not been released, so i cannot put it in the relased code.
carlos
Posts: 23
Joined: Fri May 05, 2006 8:30 am
Location: Universidad Pais Vasco

Post by carlos »

Hello Frank,

I not really interested on modify the code, only on using it. I have seen that exist the file corotational.lib and that the binary file Opensees.exe works with the Corotational transformation.

I think that my real problem is that I'm not skilled on C++ and I do not know how to compile the example (The same command appears on the file TclGeomTransfCommand.cpp and it runs).

I`m trying to have access during the different steps to the existing forces on the model (in the same way as with the TCL command nodedisp) and modify the model according them. If it is not possible to compile the example I think that I even could modify some of the existing files on the code source to gain access to the Corotational Transformation. But this solution would not be very fancy and will difficult futures updates.


Could you help me please?.

Regards,
fmk
Site Admin
Posts: 5884
Joined: Fri Jun 11, 2004 2:33 pm
Location: UC Berkeley
Contact:

Post by fmk »

try adding the corotational lib to the project for the main, add it in the link section of the project settings.
Post Reply