// GenFem - A high-level finite element library
// Copyright (C) 2010-2026 Eric Bechet
//
// See the LICENSE file for license information and contributions.
// Please report all bugs and problems to <bechet@cadxfem.org>.
#include "GmshGlobal.h"
#include "elasticitySolverXfem.h"
//#include "elasticitySolver.h"
#include "PView.h"
#include "PViewData.h"
#include "groupOfElements.h"
#include <iterator>
#include "function.h"
#include "fullMatrix.h"

int main (int argc, char* argv[])
{

  if (argc != 2){
    printf("usage : elasticity_xfem input_file_name\n");
    return -1;
  }

  GmshInitialize(argc, argv);
  // globals are still present in Gmsh

  GmshSetOption("General","Terminal",1.);

  // instanciate a solver
  elasticitySolverXfem mySolver (1000);
  //elasticitySolver mySolver (1000);

  // read some input file
  mySolver.readInputFile(argv[1]);
  
//  mySolver.buildVonMisesView(argv[1]);

  // build the linear system
  mySolver.BuildLinearSystem();
  // solve the problem
  mySolver.solve();
  //
  PView *pv = mySolver.buildDisplacementView("displacement");
  pv->getData()->writeMSH("disp.msh");
  delete pv;
  pv = mySolver.buildElasticEnergyView("elastic energy");
  pv->getData()->writeMSH("energ.msh", false);
  delete pv;
  //pv = mySolver.buildVonMisesView("Von Mises");
  //pv->getData()->writeMSH("vonmises.msh", false);
  //delete pv;

  // stop gmsh
  GmshFinalize();
}
