Formulation.h 14.4 KB
Newer Older
1 2 3 4 5
/* 
    This file is a part of eXlibris C++ Library
    under the GNU General Public License:
    See the LICENSE.md files for terms and 
    conditions.
6
*/
7 8


9 10 11 12 13 14 15
#ifndef _Formulation_h_
#define _Formulation_h_
// DamageBandDyn
#include "Algorithm.h"
#include "TreatmentOfEssEnvOptimized.h"
#include "tools.h"
#include "refactoring.h"
16 17 18 19
#ifdef BUILDMAPPINGONCE
// Xfem
#include "xMappingBuilderHolder.h"
#endif
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276

class PostProcessing;

template <typename KINEMATIC,
          typename CONSTITUTIVELAW,
          typename GEOM,
          typename CONTACT>
class Formulation
{
public:
  typedef xfem::xValOperator<xfem::xIdentity<xfem::xVector> >                                       ValOp_t;
  typedef xfem::xGradOperator<typename KINEMATIC::StrainFun_t>                                      GradOp_t;
  typedef xfem::xFormBilinearWithLaw<ValOp_t, const xfem::xEval<double>, ValOp_t>                   MassForm_t;
  typedef xfem::xFormLinearWithLoad<GradOp_t, xfem::xEval<typename CONSTITUTIVELAW::StressTensor> > FintForm_t;
  typedef typename GEOM::IterDomain_t IterDomain_t;

  Formulation(KINEMATIC& kinematic_,
              CONSTITUTIVELAW& constitutive_law_,
              GEOM& geom_,
              CONTACT& contact_,
              xfem::xData& data_,
              xfem::xEntityFilter filter_init_,
              xfem::xEntityFilter filter_diri_,
              xfem::xEntityFilter filter_rigid_,
              PostProcessing& post_processing_) :
    kinematic(kinematic_),
    constitutive_law(constitutive_law_),
    geom(geom_),
    contact(contact_),
    data(data_),
    filter_init(filter_init_),
    filter_diri(filter_diri_),
    filter_rigid(filter_rigid_),
    mass_form(kinematic.getDensity()),
    fint_form(constitutive_law.getStress()),
    post_processing(post_processing_)
  {}

  int initialize()
  {
    const IterDomain_t& begin = geom.begin();
    const IterDomain_t& end = geom.end();
    const xfem::xIntegrationRule& integration_rule = geom.getIntegrationRule();
#ifdef BUILDMAPPINGONCE
    xfem::xMappingBuilderHolder& holder = xfem::xMappingBuilderHolderSingleton::instance(); 
    xfem::DeclareMapping(*holder.getMappingBuilder(), begin, end);
#endif
    AcceptEntityToEntity accept(xUpperAdjacencyFiltered(geom.getDomainFilter(), 2));
    xfem::xAcceptIntersectionBinary filter_init2(accept, filter_init);
    xfem::xAcceptIntersectionBinary filter_rigid2(accept, filter_rigid);
    TreatmentOfRigidMotion(data, kinematic.getDisplacementField(), kinematic.getVelocityField(), kinematic.getAccelerationField(), filter_rigid2);
    kinematic.initialize(begin, end);
#ifdef ENRICH
    kinematic.getDisplacementField().getValueManager()->PrintForDebug("dm_disp_1.txt");
    kinematic.getVelocityField().getValueManager()->PrintForDebug("dm_velo_1.txt");
    kinematic.getAccelerationField().getValueManager()->PrintForDebug("dm_accel_1.txt");
    if (geom.crackExist()) {
      kinematic.initializeEnrichment();
    }
    kinematic.getDisplacementField().getValueManager()->PrintForDebug("dm_disp_2.txt");
    kinematic.getVelocityField().getValueManager()->PrintForDebug("dm_velo_2.txt");
    kinematic.getAccelerationField().getValueManager()->PrintForDebug("dm_accel_2.txt");
#endif
    TreatmentOfInitCond(data, kinematic.getDisplacementField(), kinematic.getVelocityField(), geom.getIntegrationRule(1), kinematic.getSub(), filter_init2);
    constitutive_law.initialize(begin, end, integration_rule);
    int nb_dofs = kinematic.getNbDofs();
    message("Formulation", "number of dofs "+toString<int>(nb_dofs));
    return nb_dofs;
  }

  void initiate(lalg::xCSRVector& disp_, lalg::xCSRVector& speed_, xfem::xAssembler& assembler_mass_, xfem::xAssembler& assembler_Fint_, xfem::xAssembler& assembler_Fext_, TreatmentOfEssEnvOptimized& treatment_of_ess_env_optimized_, double time_, double time_step_)
  {
    kinematic.readDisplacementField(disp_);
    kinematic.readVelocityField(speed_);

    const IterDomain_t& begin = geom.begin();
    const IterDomain_t& end = geom.end();
    const xfem::xIntegrationRule& integration_rule = geom.getIntegrationRule();
    AcceptEntityToEntity accept(xUpperAdjacencyFiltered(geom.getDomainFilter(), 2));
    xfem::xAcceptIntersectionBinary filter_init2(accept, filter_init);
    xfem::xAcceptIntersectionBinary filter_diri2(accept, filter_diri);
    xfem::xField& displacement_field = kinematic.getDisplacementField();
    xfem::xField& velocity_field = kinematic.getVelocityField();
    xfem::xField& acceleration_field = kinematic.getAccelerationField();

    xfem::Assemble(mass_form, assembler_mass_, integration_rule, displacement_field, displacement_field, begin, end);// BUG CORRECTION
    TreatmentOfAdditionalMass(data, displacement_field, acceleration_field, assembler_mass_, filter_init2);
    // double external_load_energy;
    TreatmentOfNatEnv(displacement_field, assembler_Fext_, integration_rule, data, data.allGroups, time_, time_step_, kinematic.getVelocity(), post_processing);
    xfem::Assemble(fint_form, assembler_Fint_, integration_rule, displacement_field, begin, end);

    treatment_of_ess_env_optimized_.initiate(displacement_field, velocity_field, acceleration_field, filter_diri2);
  }

  void restore(xfem::xAssembler& assembler_mass_, TreatmentOfEssEnvOptimized& treatment_of_ess_env_optimized_)
  {
    constitutive_law.restore(geom.begin(), geom.end(), geom.getIntegrationRule());

    AcceptEntityToEntity accept(xUpperAdjacencyFiltered(geom.getDomainFilter(), 2));
    xfem::xAcceptIntersectionBinary filter_init2(accept, filter_init);
    xfem::xAcceptIntersectionBinary filter_diri2(accept, filter_diri);
    xfem::xField& displacement_field = kinematic.getDisplacementField();
    xfem::xField& velocity_field = kinematic.getVelocityField();
    xfem::xField& acceleration_field = kinematic.getAccelerationField();
    const IterDomain_t& begin = geom.begin();
    const IterDomain_t& end = geom.end();
    const xfem::xIntegrationRule& integration_rule = geom.getIntegrationRule();

    xfem::Assemble(mass_form, assembler_mass_, integration_rule, displacement_field, displacement_field, begin, end);// BUG CORRECTION
    TreatmentOfAdditionalMass(data, displacement_field, acceleration_field, assembler_mass_, filter_init2);

    treatment_of_ess_env_optimized_.initiate(displacement_field, velocity_field, acceleration_field, filter_diri2);
  }

  void writeDisplacementField(const lalg::xCSRVector& disp_)  { kinematic.writeDisplacementField(disp_);  }
  void writeVelocityField    (const lalg::xCSRVector& speed_) { kinematic.writeVelocityField(speed_);     }
  void writeAccelerationField(const lalg::xCSRVector& accel_) { kinematic.writeAccelerationField(accel_); }
  void readDisplacementField (lalg::xCSRVector& disp_)        { kinematic.readDisplacementField(disp_);   }
  void readVelocityField     (lalg::xCSRVector& speed_)       { kinematic.readVelocityField(speed_);      }
  void readAccelerationField (lalg::xCSRVector& accel_)       { kinematic.readAccelerationField(accel_);  }

  void update(double time_, int step_, double time_step_)
  {
    contact.compute(kinematic.getDisplacementField(), kinematic.getVelocityField(),
                    data, data.allGroups, time_step_, geom.getDomainFilter());
    constitutive_law.update(time_, step_, time_step_, geom.begin(), geom.end(), geom.getIntegrationRule()); // can invalidate iterators
  }

  int compute(xfem::xAssembler& assembler_Fint_, xfem::xAssembler& assembler_Fext_, double time_, int step_, double time_step_)
  {
    constitutive_law.compute(time_, step_, time_step_, geom.begin(), geom.end(), geom.getIntegrationRule()); // can invalidate iterators
    constitutive_law.move(time_, step_, time_step_, geom.begin(), geom.end(), geom.getIntegrationRule()); // can invalidate iterators
#ifdef ENRICH
    // if (geom.crackExist())
    // {
    //   int old_no_dofs = kinematic.getNbDofs();
    //   kinematic.updateEnrichment()
    //   if (kinematic.getNbDofs()>old_nb_dofs) {
    //     message("Formulation", "number of dofs "+toString<int>(kinematic.getNbDofs()));
    //   }
    // }
#endif
    constitutive_law.compute_after(time_, step_, time_step_, geom.begin(), geom.end(), geom.getIntegrationRule());

    const IterDomain_t& begin = geom.begin();
    const IterDomain_t& end = geom.end();
    const xfem::xIntegrationRule& integration_rule = geom.getIntegrationRule();
    xfem::xField& displacement_field = kinematic.getDisplacementField();

    // double external_load_energy;
    // TreatmentOfNatEnv(displacement_field, assembler_Fext_, integration_rule, data, data.allGroups, time_, post_processing);
    TreatmentOfNatEnv(displacement_field, assembler_Fext_, integration_rule, data, data.allGroups, time_, time_step_, kinematic.getVelocity(), post_processing);
    xfem::Assemble(fint_form, assembler_Fint_, integration_rule, displacement_field, begin, end);

    return kinematic.getNbDofs();
  }
  void computeMass(xfem::xAssembler& assembler_mass_, double time_, int step_, double time_step_)
  {
    const IterDomain_t& begin = geom.begin();
    const IterDomain_t& end = geom.end();
    const xfem::xIntegrationRule& integration_rule = geom.getIntegrationRule();
    xfem::xField& displacement_field = kinematic.getDisplacementField();

    xfem::Assemble(mass_form, assembler_mass_, integration_rule, displacement_field, displacement_field, begin, end);// BUG CORRECTION
    AcceptEntityToEntity accept(xUpperAdjacencyFiltered(geom.getDomainFilter(), 2));
    xfem::xAcceptIntersectionBinary filter_init2(accept, filter_init);
    TreatmentOfAdditionalMass(data, displacement_field, displacement_field, assembler_mass_, filter_init2);
  }

#ifdef DEPRECATED
  void compute(xfem::xAssembler& assembler_mass_, xfem::xAssembler& assembler_Fint_, xfem::xAssembler& assembler_Fext_, double time_, int step_, double time_step_)
  {
    constitutive_law.compute(time_, step_, time_step_, geom.begin(), geom.end(), geom.getIntegrationRule()); // can invalidate iterators
    constitutive_law.move(time_, step_, time_step_, geom.begin(), geom.end(), geom.getIntegrationRule()); // can invalidate iterators
    constitutive_law.compute_after(time_, step_, time_step_, geom.begin(), geom.end(), geom.getIntegrationRule());

    const IterDomain_t& begin = geom.begin();
    const IterDomain_t& end = geom.end();
    const xfem::xIntegrationRule& integration_rule = geom.getIntegrationRule();
    xfem::xField& displacement_field = kinematic.getDisplacementField();

    // TreatmentOfNatEnv(displacement_field, assembler_Fext_, integration_rule, data, data.allGroups, time_, post_processing);
    TreatmentOfNatEnv(displacement_field, assembler_Fext_, integration_rule, data, data.allGroups, time_, time_step_, kinematic.getVelocity(), post_processing);
    xfem::Assemble(fint_form, assembler_Fint_, integration_rule, displacement_field, begin, end);
    xfem::Assemble(mass_form, assembler_mass_, integration_rule, displacement_field, displacement_field, begin, end);// BUG CORRECTION
    AcceptEntityToEntity accept(xUpperAdjacencyFiltered(geom.getDomainFilter(), 2));
    xfem::xAcceptIntersectionBinary filter_init2(accept, filter_init);
    TreatmentOfAdditionalMass(data, displacement_field, displacement_field, assembler_mass_, filter_init2);
  }

  void compute(xfem::xAssembler& assembler_Fext_, double time_, int step_, double time_step_)
  {
    constitutive_law.compute(time_, step_, time_step_, geom.begin(), geom.end(), geom.getIntegrationRule()); // can invalidate iterators
    constitutive_law.move(time_, step_, time_step_, geom.begin(), geom.end(), geom.getIntegrationRule()); // can invalidate iterators
    constitutive_law.compute_after(time_, step_, time_step_, geom.begin(), geom.end(), geom.getIntegrationRule());

    const xfem::xIntegrationRule& integration_rule = geom.getIntegrationRule();
    xfem::xField& displacement_field = kinematic.getDisplacementField();

    // TreatmentOfNatEnv(displacement_field, assembler_Fext_, integration_rule, data, data.allGroups, time_, post_processing);
    TreatmentOfNatEnv(displacement_field, assembler_Fext_, integration_rule, data, data.allGroups, time_, time_step_, kinematic.getVelocity(), post_processing);
  }
#endif

  void updateContact(double time_, int step_, double time_step_, lalg::xCSRVector& accel)
  {
    contact.updateAccel(kinematic.getAccelerationField());
    kinematic.readAccelerationField(accel);
  }

  void exportGmsh(double time_, int step_, double time_step_)
  {
    const IterDomain_t& begin = geom.begin();
    const IterDomain_t& end = geom.end();
    const xfem::xIntegrationRule& integration_rule = geom.getIntegrationRule();
    kinematic.exportGmsh(time_, step_, time_step_, begin, end, integration_rule);
    constitutive_law.exportGmsh(time_, step_, time_step_, begin, end, integration_rule);
  }

private:
  KINEMATIC& kinematic;
  CONSTITUTIVELAW& constitutive_law;
  GEOM& geom;
  CONTACT& contact;

  xfem::xData& data;
  xfem::xEntityFilter filter_init;
  xfem::xEntityFilter filter_diri;
  xfem::xEntityFilter filter_rigid;

  MassForm_t mass_form;
  FintForm_t fint_form;

  PostProcessing& post_processing;
};

// void KinematicSolverHPP<EVALMANAGER>::compute_sp(xAssembler& assembler_Fint_, xAssembler& assembler_Fext_, double time_, int step_, double time_step_, int frequency_)
// {
//   AcceptOnEqualAndGreaterIntTag prediction_filter(SpatialPartitioning::getPredictionFrequencyTag(), frequency_);
//   AcceptOnEqualAndGreaterIntTag assembling_filter(SpatialPartitioning::getAssemblingFrequencyTag(), frequency_);
//   AcceptOnUpperAdjacencyEqualAndGreaterIntTag fext_filter(SpatialPartitioning::getAssemblingFrequencyTag(), frequency_);

//   xSpaceFiltered::filter_t space_filter(prediction_filter);   // can improve much better the code here
//   xSpaceFiltered space_filtered_sp(KinBase_t::space, space_filter); // because a space filtered eliminates all non used shape functions in a loop

//   xDoubleManager& displacement_double_manager = KinBase_t::displacement_double_manager;
//   xField displacement_field_sp(&displacement_double_manager, space_filtered_sp); // this is time consuming

//   const typename EVALMANAGER::IterDomain_t& begin = KinBase_t::eval_manager->begin();
//   const typename EVALMANAGER::IterDomain_t& end = KinBase_t::eval_manager->end();
//   const xIntegrationRule& integration_rule = KinBase_t::eval_manager->getIntegrationRule();
//   xFilteredRegion<typename EVALMANAGER::IterDomain_t, xEntityFilter> fr_sp(begin, end , assembling_filter);
//   TreatmentOfNatEnv(displacement_field_sp, assembler_Fext_, integration_rule, KinBase_t::data, KinBase_t::data.allGroups, time_, fext_filter);
//   Assemble(*KinBase_t::Fint_form, assembler_Fint_, integration_rule, displacement_field_sp, fr_sp.begin(), fr_sp.end());
// }

#endif